-
Notifications
You must be signed in to change notification settings - Fork 824
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
Define shims for stack probes using naked functions with RFC 2873 style asm! #2082
Conversation
…le asm!. This should fix #1722.
cfg_if::cfg_if! { | ||
if #[cfg(all( | ||
target_os = "windows", | ||
target_env = "msvc", | ||
target_pointer_width = "64" | ||
))] { | ||
extern "C" { | ||
/// The probestack for Windows when compiled with MSVC | ||
pub fn __chkstk(); | ||
} | ||
/// Probestack check | ||
#[naked] | ||
#[no_mangle] | ||
pub unsafe extern "C" fn wasmer_probestack() { | ||
asm!("jmp {}", sym __chkstk, options (noreturn)); | ||
} | ||
} else if #[cfg(all(target_os = "windows", target_env = "gnu"))] { | ||
extern "C" { | ||
/// ___chkstk (note the triple underscore) is implemented in compiler-builtins/src/x86_64.rs | ||
/// by the Rust compiler for the MinGW target | ||
pub fn ___chkstk(); | ||
} | ||
/// Probestack check | ||
#[naked] | ||
#[no_mangle] | ||
pub unsafe extern "C" fn wasmer_probestack() { | ||
asm!("jmp {}", sym ___chkstk, options (noreturn)); | ||
} | ||
} else if #[cfg(any(target_arch = "x86_64", target_arch="x86"))] { | ||
extern "C" { | ||
/// Stack probe function for rust. | ||
pub fn __rust_probestack(); | ||
} | ||
/// Probestack check | ||
#[naked] | ||
#[no_mangle] | ||
pub unsafe extern "C" fn wasmer_probestack() { | ||
asm!("jmp {}", sym __rust_probestack, options (noreturn)); | ||
} | ||
} else { | ||
/// Probestack check is not used on this platform. | ||
#[no_mangle] | ||
pub unsafe extern "C" fn wasmer_probestack() { | ||
panic!(); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be a good idea to move this to the probestack file, if possible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be a good idea to re-enable the skipped test
👍 |
#![feature(asm)] | ||
#![feature(naked_functions)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider cfg_attr(nightly, feature(asm))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we want to ship a nightly-only feature
cfg_if::cfg_if! { | ||
if #[cfg(all( | ||
target_os = "windows", | ||
target_env = "msvc", | ||
target_pointer_width = "64" | ||
))] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And if we want to ship this for nigthly-only, we should feature gate this code based on nightly vs not nightly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is in the VM layer, and we already have C code in VM layer, perhaps we can bypass the "asm" feature if the user is not in nightly when compiling by using a asm function implemented in C.
C proper, as in official standard C, doesn't permit assembly in it either. That said, gcc and clang support assembly in C files for linux and mac with the same syntax. We'd need to do something different for Windows though. |
Closing this as it was fixed by #2548 |
This should fix #1722.
It's not clear whether we can merge this, new features are enabled in the lib.rs