Use asm_cfg in probestack

cc https://www.github.com/rust-lang/rust/issues/140364
This commit is contained in:
Folkert de Vries 2025-06-24 20:40:08 +02:00 committed by GitHub
parent 9f4670fd2b
commit 962ff16101
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 23 deletions

View file

@ -7,6 +7,7 @@
#![feature(compiler_builtins)]
#![feature(core_intrinsics)]
#![feature(linkage)]
#![feature(asm_cfg)]
#![feature(naked_functions)]
#![feature(repr_simd)]
#![feature(macro_metavar_expr_concat)]

View file

@ -58,27 +58,6 @@
#[unsafe(naked)]
#[rustc_std_internal_symbol]
pub unsafe extern "custom" fn __rust_probestack() {
#[cfg(not(all(target_env = "sgx", target_vendor = "fortanix")))]
macro_rules! ret {
() => {
"ret"
};
}
#[cfg(all(target_env = "sgx", target_vendor = "fortanix"))]
macro_rules! ret {
// for this target, [manually patch for LVI].
//
// [manually patch for LVI]: https://software.intel.com/security-software-guidance/insights/deep-dive-load-value-injection#specialinstructions
() => {
"
pop %r11
lfence
jmp *%r11
"
};
}
core::arch::naked_asm!(
"
.cfi_startproc
@ -128,8 +107,18 @@ pub unsafe extern "custom" fn __rust_probestack() {
.cfi_def_cfa_register %rsp
.cfi_adjust_cfa_offset -8
",
ret!(),
"
#[cfg(not(all(target_env = "sgx", target_vendor = "fortanix")))]
" ret",
#[cfg(all(target_env = "sgx", target_vendor = "fortanix"))]
"
// for this target, [manually patch for LVI].
//
// [manually patch for LVI]: https://software.intel.com/security-software-guidance/insights/deep-dive-load-value-injection#specialinstructions
pop %r11
lfence
jmp *%r11
",
"
.cfi_endproc
",
options(att_syntax)