Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions lib/compiler/src/engine/artifact.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
//! Define `Artifact`, based on `ArtifactBuild`
//! to allow compiling and instantiating to be done as separate steps.

use std::sync::{
Arc,
atomic::{AtomicUsize, Ordering::SeqCst},
use std::{
sync::{
Arc,
atomic::{AtomicUsize, Ordering::SeqCst},
},
thread::sleep,
time::Duration,
};

#[cfg(feature = "compiler")]
Expand Down Expand Up @@ -128,6 +132,7 @@ impl Artifact {
tunables: &dyn Tunables,
hash_algorithm: Option<HashAlgorithm>,
) -> Result<Self, CompileError> {
let data = Box::leak(Box::from(data));
let mut inner_engine = engine.inner_mut();
let environ = ModuleEnvironment::new();
let translation = environ.translate(data).map_err(CompileError::Wasm)?;
Expand Down Expand Up @@ -1298,3 +1303,9 @@ impl Artifact {
}
}
}

impl Drop for Artifact {
fn drop(&mut self) {
eprintln!("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Dropping Artifact");
}
}
26 changes: 24 additions & 2 deletions lib/compiler/src/engine/unwind/systemv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@

//! Module for System V ABI unwind registry.

use core::sync::atomic::{AtomicUsize, Ordering::Relaxed};
use core::sync::atomic::{
AtomicBool, AtomicUsize,
Ordering::{self, Relaxed},
};
use std::sync::Once;

use crate::types::unwind::CompiledFunctionUnwindInfoReference;

Expand All @@ -14,7 +18,6 @@ pub struct UnwindRegistry {
#[cfg(all(target_os = "macos", target_arch = "aarch64"))]
compact_unwind_mgr: compact_unwind::CompactUnwindManager,
}

unsafe extern "C" {
// libunwind import
fn __register_frame(fde: *const u8);
Expand Down Expand Up @@ -145,6 +148,12 @@ impl UnwindRegistry {

#[allow(clippy::cast_ptr_alignment)]
unsafe fn register_frames(&mut self, eh_frame: &[u8]) {
// Register atexit handler that will tell us if exit has been called.
static INIT: Once = Once::new();
INIT.call_once(|| unsafe {
libc::atexit(atexit_handler);
});

#[cfg(all(target_os = "macos", target_arch = "aarch64"))]
{
// Special call for macOS on aarch64 to register the `.eh_frame` section.
Expand Down Expand Up @@ -243,8 +252,15 @@ impl UnwindRegistry {
}
}

static EXIT_CALLED: AtomicBool = AtomicBool::new(false);

extern "C" fn atexit_handler() {
EXIT_CALLED.store(true, Ordering::SeqCst);
}

impl Drop for UnwindRegistry {
fn drop(&mut self) {
eprintln!("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Dropping UnwindRegistry");
if self.published {
unsafe {
// libgcc stores the frame entries as a linked list in decreasing sort order
Expand All @@ -264,6 +280,12 @@ impl Drop for UnwindRegistry {

#[cfg(not(all(target_os = "macos", target_arch = "aarch64")))]
{
// We don't want to deregister frames in UnwindRegistry::Drop as that could be called during
// program shutdown and can collide with release_registered_frames and lead to
// crashes.
if EXIT_CALLED.load(Ordering::SeqCst) {
return;
}
__deregister_frame(*registration as *const _);
}
}
Expand Down
Loading