4949// We only define stack probing for these architectures today.
5050#![ cfg( any( target_arch = "x86_64" , target_arch = "x86" ) ) ]
5151
52- // SAFETY: defined in this module.
53- // FIXME(extern_custom): the ABI is not correct.
54- unsafe extern "C" {
55- pub fn __rust_probestack ( ) ;
56- }
57-
58- // A wrapper for our implementation of __rust_probestack, which allows us to
59- // keep the assembly inline while controlling all CFI directives in the assembly
60- // emitted for the function.
61- //
62- // This is the ELF version.
63- #[ cfg( not( any( target_vendor = "apple" , target_os = "uefi" ) ) ) ]
64- macro_rules! define_rust_probestack {
65- ( $body: expr) => {
66- concat!(
67- "
68- .pushsection .text.__rust_probestack
69- .globl __rust_probestack
70- .type __rust_probestack, @function
71- .hidden __rust_probestack
72- __rust_probestack:
73- " ,
74- $body,
75- "
76- .size __rust_probestack, . - __rust_probestack
77- .popsection
78- "
79- )
80- } ;
81- }
82-
83- #[ cfg( all( target_os = "uefi" , target_arch = "x86_64" ) ) ]
84- macro_rules! define_rust_probestack {
85- ( $body: expr) => {
86- concat!(
87- "
88- .globl __rust_probestack
89- __rust_probestack:
90- " ,
91- $body
92- )
93- } ;
94- }
95-
96- // Same as above, but for Mach-O. Note that the triple underscore
97- // is deliberate
98- #[ cfg( target_vendor = "apple" ) ]
99- macro_rules! define_rust_probestack {
100- ( $body: expr) => {
101- concat!(
102- "
103- .globl ___rust_probestack
104- ___rust_probestack:
105- " ,
106- $body
107- )
108- } ;
109- }
110-
111- // In UEFI x86 arch, triple underscore is deliberate.
112- #[ cfg( all( target_os = "uefi" , target_arch = "x86" ) ) ]
113- macro_rules! define_rust_probestack {
114- ( $body: expr) => {
115- concat!(
116- "
117- .globl ___rust_probestack
118- ___rust_probestack:
119- " ,
120- $body
121- )
122- } ;
123- }
124-
12552// Our goal here is to touch each page between %rsp+8 and %rsp+8-%rax,
12653// ensuring that if any pages are unmapped we'll make a page fault.
12754//
@@ -136,8 +63,10 @@ macro_rules! define_rust_probestack {
13663 target_arch = "x86_64" ,
13764 not( all( target_env = "sgx" , target_vendor = "fortanix" ) )
13865) ) ]
139- core:: arch:: global_asm!(
140- define_rust_probestack!(
66+ #[ unsafe( naked) ]
67+ #[ rustc_std_internal_symbol]
68+ pub unsafe extern "C" fn __rust_probestack ( ) {
69+ core:: arch:: naked_asm!(
14170 "
14271 .cfi_startproc
14372 pushq %rbp
@@ -187,10 +116,10 @@ core::arch::global_asm!(
187116 .cfi_adjust_cfa_offset -8
188117 ret
189118 .cfi_endproc
190- "
191- ) ,
192- options ( att_syntax )
193- ) ;
119+ " ,
120+ options ( att_syntax )
121+ )
122+ }
194123
195124// This function is the same as above, except that some instructions are
196125// [manually patched for LVI].
@@ -200,8 +129,10 @@ core::arch::global_asm!(
200129 target_arch = "x86_64" ,
201130 all( target_env = "sgx" , target_vendor = "fortanix" )
202131) ) ]
203- core:: arch:: global_asm!(
204- define_rust_probestack!(
132+ #[ unsafe( naked) ]
133+ #[ no_mangle]
134+ pub unsafe extern "C" fn __rust_probestack ( ) {
135+ core:: arch:: naked_asm!(
205136 "
206137 .cfi_startproc
207138 pushq %rbp
@@ -253,10 +184,10 @@ core::arch::global_asm!(
253184 lfence
254185 jmp *%r11
255186 .cfi_endproc
256- "
257- ) ,
258- options ( att_syntax )
259- ) ;
187+ " ,
188+ options ( att_syntax )
189+ )
190+ }
260191
261192#[ cfg( all( target_arch = "x86" , not( target_os = "uefi" ) ) ) ]
262193// This is the same as x86_64 above, only translated for 32-bit sizes. Note
@@ -267,8 +198,10 @@ core::arch::global_asm!(
267198// it does not actually match `extern "C"`.
268199//
269200// The ABI here is the same as x86_64, except everything is 32-bits large.
270- core:: arch:: global_asm!(
271- define_rust_probestack!(
201+ #[ unsafe( naked) ]
202+ #[ rustc_std_internal_symbol]
203+ pub unsafe extern "C" fn __rust_probestack ( ) {
204+ core:: arch:: naked_asm!(
272205 "
273206 .cfi_startproc
274207 push %ebp
@@ -299,10 +232,10 @@ core::arch::global_asm!(
299232 .cfi_adjust_cfa_offset -4
300233 ret
301234 .cfi_endproc
302- "
303- ) ,
304- options ( att_syntax )
305- ) ;
235+ " ,
236+ options ( att_syntax )
237+ )
238+ }
306239
307240#[ cfg( all( target_arch = "x86" , target_os = "uefi" ) ) ]
308241// UEFI target is windows like target. LLVM will do _chkstk things like windows.
@@ -318,8 +251,10 @@ core::arch::global_asm!(
318251// MSVC x32's _chkstk and cygwin/mingw's _alloca adjust %esp themselves.
319252// MSVC x64's __chkstk and cygwin/mingw's ___chkstk_ms do not adjust %rsp
320253// themselves.
321- core:: arch:: global_asm!(
322- define_rust_probestack!(
254+ #[ unsafe( naked) ]
255+ #[ rustc_std_internal_symbol]
256+ pub unsafe extern "C" fn __rust_probestack ( ) {
257+ core:: arch:: naked_asm!(
323258 "
324259 .cfi_startproc
325260 push %ebp
@@ -355,7 +290,7 @@ core::arch::global_asm!(
355290 .cfi_adjust_cfa_offset -4
356291 ret
357292 .cfi_endproc
358- "
359- ) ,
360- options ( att_syntax )
361- ) ;
293+ " ,
294+ options ( att_syntax )
295+ )
296+ }
0 commit comments