Remove thread local for mach port (#3119)
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.
This commit is contained in:
@@ -392,20 +392,6 @@ unsafe extern "C" fn unwind(wasm_pc: *const u8) -> ! {
|
|||||||
wasmtime_longjmp(jmp_buf);
|
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
|
/// Exceptions on macOS can be delivered to either thread-level or task-level
|
||||||
/// exception ports. In wasmtime we choose to send the exceptions to
|
/// 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
|
/// thread-level ports. This means that we need to, for each thread that can
|
||||||
@@ -426,13 +412,15 @@ impl Drop for ClosePort {
|
|||||||
pub fn lazy_per_thread_init() -> Result<(), Trap> {
|
pub fn lazy_per_thread_init() -> Result<(), Trap> {
|
||||||
unsafe {
|
unsafe {
|
||||||
assert!(WASMTIME_PORT != MACH_PORT_NULL);
|
assert!(WASMTIME_PORT != MACH_PORT_NULL);
|
||||||
|
let this_thread = mach_thread_self();
|
||||||
let kret = thread_set_exception_ports(
|
let kret = thread_set_exception_ports(
|
||||||
MY_PORT.with(|p| p.0),
|
this_thread,
|
||||||
EXC_MASK_BAD_ACCESS | EXC_MASK_BAD_INSTRUCTION,
|
EXC_MASK_BAD_ACCESS | EXC_MASK_BAD_INSTRUCTION,
|
||||||
WASMTIME_PORT,
|
WASMTIME_PORT,
|
||||||
EXCEPTION_DEFAULT | MACH_EXCEPTION_CODES,
|
EXCEPTION_DEFAULT | MACH_EXCEPTION_CODES,
|
||||||
mach_addons::THREAD_STATE_NONE,
|
mach_addons::THREAD_STATE_NONE,
|
||||||
);
|
);
|
||||||
|
mach_port_deallocate(mach_task_self(), this_thread);
|
||||||
assert_eq!(kret, KERN_SUCCESS, "failed to set thread exception port");
|
assert_eq!(kret, KERN_SUCCESS, "failed to set thread exception port");
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
Reference in New Issue
Block a user