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
- extern "C" {
53
- pub fn __rust_probestack ( ) ;
54
- }
55
-
56
- // A wrapper for our implementation of __rust_probestack, which allows us to
57
- // keep the assembly inline while controlling all CFI directives in the assembly
58
- // emitted for the function.
59
- //
60
- // This is the ELF version.
61
- #[ cfg( not( any( target_vendor = "apple" , target_os = "uefi" ) ) ) ]
62
- macro_rules! define_rust_probestack {
63
- ( $body: expr) => {
64
- concat!(
65
- "
66
- .pushsection .text.__rust_probestack
67
- .globl __rust_probestack
68
- .type __rust_probestack, @function
69
- .hidden __rust_probestack
70
- __rust_probestack:
71
- " ,
72
- $body,
73
- "
74
- .size __rust_probestack, . - __rust_probestack
75
- .popsection
76
- "
77
- )
78
- } ;
79
- }
80
-
81
- #[ cfg( all( target_os = "uefi" , target_arch = "x86_64" ) ) ]
82
- macro_rules! define_rust_probestack {
83
- ( $body: expr) => {
84
- concat!(
85
- "
86
- .globl __rust_probestack
87
- __rust_probestack:
88
- " ,
89
- $body
90
- )
91
- } ;
92
- }
93
-
94
- // Same as above, but for Mach-O. Note that the triple underscore
95
- // is deliberate
96
- #[ cfg( target_vendor = "apple" ) ]
97
- macro_rules! define_rust_probestack {
98
- ( $body: expr) => {
99
- concat!(
100
- "
101
- .globl ___rust_probestack
102
- ___rust_probestack:
103
- " ,
104
- $body
105
- )
106
- } ;
107
- }
108
-
109
- // In UEFI x86 arch, triple underscore is deliberate.
110
- #[ cfg( all( target_os = "uefi" , target_arch = "x86" ) ) ]
111
- macro_rules! define_rust_probestack {
112
- ( $body: expr) => {
113
- concat!(
114
- "
115
- .globl ___rust_probestack
116
- ___rust_probestack:
117
- " ,
118
- $body
119
- )
120
- } ;
121
- }
122
-
123
52
// Our goal here is to touch each page between %rsp+8 and %rsp+8-%rax,
124
53
// ensuring that if any pages are unmapped we'll make a page fault.
125
54
//
@@ -131,8 +60,10 @@ macro_rules! define_rust_probestack {
131
60
target_arch = "x86_64" ,
132
61
not( all( target_env = "sgx" , target_vendor = "fortanix" ) )
133
62
) ) ]
134
- core:: arch:: global_asm!(
135
- define_rust_probestack!(
63
+ #[ unsafe( naked) ]
64
+ #[ no_mangle]
65
+ pub unsafe extern "C" fn __rust_probestack ( ) {
66
+ core:: arch:: naked_asm!(
136
67
"
137
68
.cfi_startproc
138
69
pushq %rbp
@@ -182,10 +113,10 @@ core::arch::global_asm!(
182
113
.cfi_adjust_cfa_offset -8
183
114
ret
184
115
.cfi_endproc
185
- "
186
- ) ,
187
- options ( att_syntax )
188
- ) ;
116
+ " ,
117
+ options ( att_syntax )
118
+ )
119
+ }
189
120
190
121
// This function is the same as above, except that some instructions are
191
122
// [manually patched for LVI].
@@ -195,8 +126,10 @@ core::arch::global_asm!(
195
126
target_arch = "x86_64" ,
196
127
all( target_env = "sgx" , target_vendor = "fortanix" )
197
128
) ) ]
198
- core:: arch:: global_asm!(
199
- define_rust_probestack!(
129
+ #[ unsafe( naked) ]
130
+ #[ no_mangle]
131
+ pub unsafe extern "C" fn __rust_probestack ( ) {
132
+ core:: arch:: naked_asm!(
200
133
"
201
134
.cfi_startproc
202
135
pushq %rbp
@@ -248,19 +181,21 @@ core::arch::global_asm!(
248
181
lfence
249
182
jmp *%r11
250
183
.cfi_endproc
251
- "
252
- ) ,
253
- options ( att_syntax )
254
- ) ;
184
+ " ,
185
+ options ( att_syntax )
186
+ )
187
+ }
255
188
256
189
#[ cfg( all( target_arch = "x86" , not( target_os = "uefi" ) ) ) ]
257
190
// This is the same as x86_64 above, only translated for 32-bit sizes. Note
258
191
// that on Unix we're expected to restore everything as it was, this
259
192
// function basically can't tamper with anything.
260
193
//
261
194
// The ABI here is the same as x86_64, except everything is 32-bits large.
262
- core:: arch:: global_asm!(
263
- define_rust_probestack!(
195
+ #[ unsafe( naked) ]
196
+ #[ no_mangle]
197
+ pub unsafe extern "C" fn __rust_probestack ( ) {
198
+ core:: arch:: naked_asm!(
264
199
"
265
200
.cfi_startproc
266
201
push %ebp
@@ -291,10 +226,10 @@ core::arch::global_asm!(
291
226
.cfi_adjust_cfa_offset -4
292
227
ret
293
228
.cfi_endproc
294
- "
295
- ) ,
296
- options ( att_syntax )
297
- ) ;
229
+ " ,
230
+ options ( att_syntax )
231
+ )
232
+ }
298
233
299
234
#[ cfg( all( target_arch = "x86" , target_os = "uefi" ) ) ]
300
235
// UEFI target is windows like target. LLVM will do _chkstk things like windows.
@@ -307,8 +242,10 @@ core::arch::global_asm!(
307
242
// MSVC x32's _chkstk and cygwin/mingw's _alloca adjust %esp themselves.
308
243
// MSVC x64's __chkstk and cygwin/mingw's ___chkstk_ms do not adjust %rsp
309
244
// themselves.
310
- core:: arch:: global_asm!(
311
- define_rust_probestack!(
245
+ #[ unsafe( naked) ]
246
+ #[ no_mangle]
247
+ pub unsafe extern "C" fn __rust_probestack ( ) {
248
+ core:: arch:: naked_asm!(
312
249
"
313
250
.cfi_startproc
314
251
push %ebp
@@ -344,7 +281,7 @@ core::arch::global_asm!(
344
281
.cfi_adjust_cfa_offset -4
345
282
ret
346
283
.cfi_endproc
347
- "
348
- ) ,
349
- options ( att_syntax )
350
- ) ;
284
+ " ,
285
+ options ( att_syntax )
286
+ )
287
+ }
0 commit comments