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
+ <<<<<<< HEAD
52
53
// SAFETY: defined in this module.
53
54
// FIXME(extern_custom): the ABI is not correct.
54
55
unsafe extern "C" {
@@ -122,9 +123,13 @@ macro_rules! define_rust_probestack {
122
123
} ;
123
124
}
124
125
126
+ =======
127
+ >>>>>>> d6dd2696443 ( use `#[ naked] ` for `__rust_probestack`)
125
128
// Our goal here is to touch each page between %rsp+8 and %rsp+8-%rax,
126
129
// ensuring that if any pages are unmapped we'll make a page fault.
127
130
//
131
+ // This function is unsafe because it uses a custom ABI, it does not actually match `extern "C"`.
132
+ //
128
133
// The ABI here is that the stack frame size is located in `%rax`. Upon
129
134
// return we're not supposed to modify `%rsp` or `%rax`.
130
135
//
@@ -133,8 +138,10 @@ macro_rules! define_rust_probestack {
133
138
target_arch = "x86_64" ,
134
139
not( all( target_env = "sgx" , target_vendor = "fortanix" ) )
135
140
) ) ]
136
- core:: arch:: global_asm!(
137
- define_rust_probestack!(
141
+ #[ unsafe( naked) ]
142
+ #[ rustc_std_internal_symbol]
143
+ pub unsafe extern "C" fn __rust_probestack ( ) {
144
+ core:: arch:: naked_asm!(
138
145
"
139
146
.cfi_startproc
140
147
pushq %rbp
@@ -184,10 +191,10 @@ core::arch::global_asm!(
184
191
.cfi_adjust_cfa_offset -8
185
192
ret
186
193
.cfi_endproc
187
- "
188
- ) ,
189
- options ( att_syntax )
190
- ) ;
194
+ " ,
195
+ options ( att_syntax )
196
+ )
197
+ }
191
198
192
199
// This function is the same as above, except that some instructions are
193
200
// [manually patched for LVI].
@@ -197,8 +204,10 @@ core::arch::global_asm!(
197
204
target_arch = "x86_64" ,
198
205
all( target_env = "sgx" , target_vendor = "fortanix" )
199
206
) ) ]
200
- core:: arch:: global_asm!(
201
- define_rust_probestack!(
207
+ #[ unsafe( naked) ]
208
+ #[ no_mangle]
209
+ pub unsafe extern "C" fn __rust_probestack ( ) {
210
+ core:: arch:: naked_asm!(
202
211
"
203
212
.cfi_startproc
204
213
pushq %rbp
@@ -250,19 +259,23 @@ core::arch::global_asm!(
250
259
lfence
251
260
jmp *%r11
252
261
.cfi_endproc
253
- "
254
- ) ,
255
- options ( att_syntax )
256
- ) ;
262
+ " ,
263
+ options ( att_syntax )
264
+ )
265
+ }
257
266
258
267
#[ cfg( all( target_arch = "x86" , not( target_os = "uefi" ) ) ) ]
259
268
// This is the same as x86_64 above, only translated for 32-bit sizes. Note
260
269
// that on Unix we're expected to restore everything as it was, this
261
270
// function basically can't tamper with anything.
262
271
//
272
+ // This function is unsafe because it uses a custom ABI, it does not actually match `extern "C"`.
273
+ //
263
274
// The ABI here is the same as x86_64, except everything is 32-bits large.
264
- core:: arch:: global_asm!(
265
- define_rust_probestack!(
275
+ #[ unsafe( naked) ]
276
+ #[ rustc_std_internal_symbol]
277
+ pub unsafe extern "C" fn __rust_probestack ( ) {
278
+ core:: arch:: naked_asm!(
266
279
"
267
280
.cfi_startproc
268
281
push %ebp
@@ -293,24 +306,28 @@ core::arch::global_asm!(
293
306
.cfi_adjust_cfa_offset -4
294
307
ret
295
308
.cfi_endproc
296
- "
297
- ) ,
298
- options ( att_syntax )
299
- ) ;
309
+ " ,
310
+ options ( att_syntax )
311
+ )
312
+ }
300
313
301
314
#[ cfg( all( target_arch = "x86" , target_os = "uefi" ) ) ]
302
315
// UEFI target is windows like target. LLVM will do _chkstk things like windows.
303
316
// probestack function will also do things like _chkstk in MSVC.
304
317
// So we need to sub %ax %sp in probestack when arch is x86.
305
318
//
319
+ // This function is unsafe because it uses a custom ABI, it does not actually match `extern "C"`.
320
+ //
306
321
// REF: Rust commit(74e80468347)
307
322
// rust\src\llvm-project\llvm\lib\Target\X86\X86FrameLowering.cpp: 805
308
323
// Comments in LLVM:
309
324
// MSVC x32's _chkstk and cygwin/mingw's _alloca adjust %esp themselves.
310
325
// MSVC x64's __chkstk and cygwin/mingw's ___chkstk_ms do not adjust %rsp
311
326
// themselves.
312
- core:: arch:: global_asm!(
313
- define_rust_probestack!(
327
+ #[ unsafe( naked) ]
328
+ #[ rustc_std_internal_symbol]
329
+ pub unsafe extern "C" fn __rust_probestack ( ) {
330
+ core:: arch:: naked_asm!(
314
331
"
315
332
.cfi_startproc
316
333
push %ebp
@@ -346,7 +363,7 @@ core::arch::global_asm!(
346
363
.cfi_adjust_cfa_offset -4
347
364
ret
348
365
.cfi_endproc
349
- "
350
- ) ,
351
- options ( att_syntax )
352
- ) ;
366
+ " ,
367
+ options ( att_syntax )
368
+ )
369
+ }
0 commit comments