Skip to content

Commit

Permalink
Remove thread local for mach port (#3119)
Browse files Browse the repository at this point in the history
This was needed a long time ago in the original implementation when the
function being called here was hotter than it was before, but nowadays
this function isn't hot as it's protected elsewhere from being
repeatedly called, so the caching thread local is no longer necessary.
  • Loading branch information
alexcrichton authored Jul 27, 2021
1 parent 8545ca9 commit b5f7b2f
Showing 1 changed file with 3 additions and 15 deletions.
18 changes: 3 additions & 15 deletions crates/runtime/src/traphandlers/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,20 +392,6 @@ unsafe extern "C" fn unwind(wasm_pc: *const u8) -> ! {
wasmtime_longjmp(jmp_buf);
}

thread_local! {
static MY_PORT: ClosePort = ClosePort(unsafe { mach_thread_self() });
}

struct ClosePort(mach_port_name_t);

impl Drop for ClosePort {
fn drop(&mut self) {
unsafe {
mach_port_deallocate(mach_task_self(), self.0);
}
}
}

/// Exceptions on macOS can be delivered to either thread-level or task-level
/// exception ports. In wasmtime we choose to send the exceptions to
/// thread-level ports. This means that we need to, for each thread that can
Expand All @@ -426,13 +412,15 @@ impl Drop for ClosePort {
pub fn lazy_per_thread_init() -> Result<(), Trap> {
unsafe {
assert!(WASMTIME_PORT != MACH_PORT_NULL);
let this_thread = mach_thread_self();
let kret = thread_set_exception_ports(
MY_PORT.with(|p| p.0),
this_thread,
EXC_MASK_BAD_ACCESS | EXC_MASK_BAD_INSTRUCTION,
WASMTIME_PORT,
EXCEPTION_DEFAULT | MACH_EXCEPTION_CODES,
mach_addons::THREAD_STATE_NONE,
);
mach_port_deallocate(mach_task_self(), this_thread);
assert_eq!(kret, KERN_SUCCESS, "failed to set thread exception port");
}
Ok(())
Expand Down

0 comments on commit b5f7b2f

Please sign in to comment.