compiler_builtins/
x86_64.rs

1#![allow(unused_imports)]
2
3use core::intrinsics;
4
5// NOTE These functions are implemented using assembly because they using 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
10intrinsics! {
11    #[unsafe(naked)]
12    #[cfg(all(
13        any(
14            all(windows, target_env = "gnu"),
15            target_os = "cygwin",
16            target_os = "uefi"
17        ),
18        not(feature = "no-asm")
19    ))]
20    pub unsafe extern "C" fn ___chkstk_ms() {
21        core::arch::naked_asm!(
22            "push   %rcx",
23            "push   %rax",
24            "cmp    $0x1000,%rax",
25            "lea    24(%rsp),%rcx",
26            "jb     1f",
27            "2:",
28            "sub    $0x1000,%rcx",
29            "test   %rcx,(%rcx)",
30            "sub    $0x1000,%rax",
31            "cmp    $0x1000,%rax",
32            "ja     2b",
33            "1:",
34            "sub    %rax,%rcx",
35            "test   %rcx,(%rcx)",
36            "pop    %rax",
37            "pop    %rcx",
38            "ret",
39            options(att_syntax)
40        );
41    }
42}
43
44// HACK(https://github.com/rust-lang/rust/issues/62785): x86_64-unknown-uefi needs special LLVM
45// support unless we emit the _fltused
46mod _fltused {
47    #[unsafe(no_mangle)]
48    #[used]
49    #[cfg(target_os = "uefi")]
50    static _fltused: i32 = 0;
51}