-
Notifications
You must be signed in to change notification settings - Fork 1.6k
fix(jit): Add MAP_JIT support for 100% stable JIT on ARM64 macOS #12077
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,5 +76,16 @@ pub(crate) fn set_readable_and_executable( | |
| } | ||
| } | ||
|
|
||
| // ARM64 macOS: Switch to execute mode for W^X compliance. | ||
| #[cfg(all(target_arch = "aarch64", target_os = "macos"))] | ||
| { | ||
| unsafe extern "C" { | ||
| fn pthread_jit_write_protect_np(enabled: libc::c_int); | ||
| } | ||
| unsafe { | ||
| pthread_jit_write_protect_np(1); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be possible to scope those pthread_jit_write_protect_np calls to the actual section that does the writes. That would be more secure. |
||
| } | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -141,16 +141,23 @@ fn riscv_flush_icache(start: u64, end: u64) -> Result<()> { | |
|
|
||
| pub(crate) use details::*; | ||
|
|
||
| // macOS ARM64: Use sys_icache_invalidate for icache coherence. | ||
| #[cfg(all(target_arch = "aarch64", target_os = "macos"))] | ||
| unsafe extern "C" { | ||
| fn sys_icache_invalidate(start: *const c_void, len: usize); | ||
| } | ||
|
|
||
| /// See docs on [crate::clear_cache] for a description of what this function is trying to do. | ||
| #[inline] | ||
| pub(crate) fn clear_cache(_ptr: *const c_void, _len: usize) -> Result<()> { | ||
| // TODO: On AArch64 we currently rely on the `mprotect` call that switches the memory from W+R | ||
| // to R+X to do this for us, however that is an implementation detail and should not be relied | ||
| // upon. | ||
| // We should call some implementation of `clear_cache` here. | ||
| // | ||
| // See: https://github.com/bytecodealliance/wasmtime/issues/3310 | ||
darmie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // macOS ARM64: Use sys_icache_invalidate for icache coherence. | ||
| #[cfg(all(target_arch = "aarch64", target_os = "macos"))] | ||
| unsafe { | ||
| sys_icache_invalidate(_ptr, _len); | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. #12133 implemented another approach for this.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, yes, I had forgotten that this PR also handled this detail. Thanks for connecting the dots! |
||
|
|
||
| #[cfg(all(target_arch = "riscv64", target_os = "linux"))] | ||
| riscv_flush_icache(_ptr as u64, (_ptr as u64) + (_len as u64))?; | ||
|
|
||
| Ok(()) | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.