49
49
// We only define stack probing for these architectures today.
50
50
#![ cfg( any( target_arch = "x86_64" , target_arch = "x86" ) ) ]
51
51
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
-
125
52
// Our goal here is to touch each page between %rsp+8 and %rsp+8-%rax,
126
53
// ensuring that if any pages are unmapped we'll make a page fault.
127
54
//
@@ -136,8 +63,10 @@ macro_rules! define_rust_probestack {
136
63
target_arch = "x86_64" ,
137
64
not( all( target_env = "sgx" , target_vendor = "fortanix" ) )
138
65
) ) ]
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!(
141
70
"
142
71
.cfi_startproc
143
72
pushq %rbp
@@ -187,10 +116,10 @@ core::arch::global_asm!(
187
116
.cfi_adjust_cfa_offset -8
188
117
ret
189
118
.cfi_endproc
190
- "
191
- ) ,
192
- options ( att_syntax )
193
- ) ;
119
+ " ,
120
+ options ( att_syntax )
121
+ )
122
+ }
194
123
195
124
// This function is the same as above, except that some instructions are
196
125
// [manually patched for LVI].
@@ -200,8 +129,10 @@ core::arch::global_asm!(
200
129
target_arch = "x86_64" ,
201
130
all( target_env = "sgx" , target_vendor = "fortanix" )
202
131
) ) ]
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!(
205
136
"
206
137
.cfi_startproc
207
138
pushq %rbp
@@ -253,10 +184,10 @@ core::arch::global_asm!(
253
184
lfence
254
185
jmp *%r11
255
186
.cfi_endproc
256
- "
257
- ) ,
258
- options ( att_syntax )
259
- ) ;
187
+ " ,
188
+ options ( att_syntax )
189
+ )
190
+ }
260
191
261
192
#[ cfg( all( target_arch = "x86" , not( target_os = "uefi" ) ) ) ]
262
193
// This is the same as x86_64 above, only translated for 32-bit sizes. Note
@@ -267,8 +198,10 @@ core::arch::global_asm!(
267
198
// it does not actually match `extern "C"`.
268
199
//
269
200
// 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!(
272
205
"
273
206
.cfi_startproc
274
207
push %ebp
@@ -299,10 +232,10 @@ core::arch::global_asm!(
299
232
.cfi_adjust_cfa_offset -4
300
233
ret
301
234
.cfi_endproc
302
- "
303
- ) ,
304
- options ( att_syntax )
305
- ) ;
235
+ " ,
236
+ options ( att_syntax )
237
+ )
238
+ }
306
239
307
240
#[ cfg( all( target_arch = "x86" , target_os = "uefi" ) ) ]
308
241
// UEFI target is windows like target. LLVM will do _chkstk things like windows.
@@ -318,8 +251,10 @@ core::arch::global_asm!(
318
251
// MSVC x32's _chkstk and cygwin/mingw's _alloca adjust %esp themselves.
319
252
// MSVC x64's __chkstk and cygwin/mingw's ___chkstk_ms do not adjust %rsp
320
253
// 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!(
323
258
"
324
259
.cfi_startproc
325
260
push %ebp
@@ -355,7 +290,7 @@ core::arch::global_asm!(
355
290
.cfi_adjust_cfa_offset -4
356
291
ret
357
292
.cfi_endproc
358
- "
359
- ) ,
360
- options ( att_syntax )
361
- ) ;
293
+ " ,
294
+ options ( att_syntax )
295
+ )
296
+ }
0 commit comments