| 1 | #![allow (unused_imports)] |
| 2 | |
| 3 | use core::intrinsics; |
| 4 | |
| 5 | // NOTE These functions are implemented using assembly because they use a custom |
| 6 | // calling convention which can't be implemented using a normal Rust function |
| 7 | |
| 8 | // NOTE These functions are never mangled as they are not tested against compiler-rt |
| 9 | |
| 10 | intrinsics! { |
| 11 | #[unsafe(naked)] |
| 12 | #[cfg (any(all(windows, target_env = "gnu" ), target_os = "cygwin" , target_os = "uefi" ))] |
| 13 | pub unsafe extern "custom" fn ___chkstk_ms() { |
| 14 | core::arch::naked_asm!( |
| 15 | "push %rcx" , |
| 16 | "push %rax" , |
| 17 | "cmp $0x1000,%rax" , |
| 18 | "lea 24(%rsp),%rcx" , |
| 19 | "jb 1f" , |
| 20 | "2:" , |
| 21 | "sub $0x1000,%rcx" , |
| 22 | "test %rcx,(%rcx)" , |
| 23 | "sub $0x1000,%rax" , |
| 24 | "cmp $0x1000,%rax" , |
| 25 | "ja 2b" , |
| 26 | "1:" , |
| 27 | "sub %rax,%rcx" , |
| 28 | "test %rcx,(%rcx)" , |
| 29 | "pop %rax" , |
| 30 | "pop %rcx" , |
| 31 | "ret" , |
| 32 | options(att_syntax) |
| 33 | ); |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | // HACK(https://github.com/rust-lang/rust/issues/62785): x86_64-unknown-uefi needs special LLVM |
| 38 | // support unless we emit the _fltused |
| 39 | mod _fltused { |
| 40 | #[unsafe(no_mangle )] |
| 41 | #[used ] |
| 42 | #[cfg (target_os = "uefi" )] |
| 43 | static _fltused: i32 = 0; |
| 44 | } |
| 45 | |