Skip to content

Commit f9a5ab4

Browse files
committed
add note about why this function is unsafe
1 parent fc33c57 commit f9a5ab4

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

compiler-builtins/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#![feature(linkage)]
99
#![feature(naked_functions)]
1010
#![feature(repr_simd)]
11+
#![feature(rustc_attrs)]
1112
#![cfg_attr(f16_enabled, feature(f16))]
1213
#![cfg_attr(f128_enabled, feature(f128))]
1314
#![no_builtins]

compiler-builtins/src/probestack.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,13 @@
5252
// Our goal here is to touch each page between %rsp+8 and %rsp+8-%rax,
5353
// ensuring that if any pages are unmapped we'll make a page fault.
5454
//
55+
// This function is unsafe because it uses a custom ABI, it does not actually match `extern "C"`.
56+
//
5557
// The ABI here is that the stack frame size is located in `%rax`. Upon
5658
// return we're not supposed to modify `%rsp` or `%rax`.
5759
#[cfg(target_arch = "x86_64")]
5860
#[unsafe(naked)]
59-
#[no_mangle]
61+
#[rustc_std_internal_symbol]
6062
pub unsafe extern "C" fn __rust_probestack() {
6163
#[cfg(not(all(target_env = "sgx", target_vendor = "fortanix")))]
6264
macro_rules! ret {
@@ -141,9 +143,11 @@ pub unsafe extern "C" fn __rust_probestack() {
141143
// that on Unix we're expected to restore everything as it was, this
142144
// function basically can't tamper with anything.
143145
//
146+
// This function is unsafe because it uses a custom ABI, it does not actually match `extern "C"`.
147+
//
144148
// The ABI here is the same as x86_64, except everything is 32-bits large.
145149
#[unsafe(naked)]
146-
#[no_mangle]
150+
#[rustc_std_internal_symbol]
147151
pub unsafe extern "C" fn __rust_probestack() {
148152
core::arch::naked_asm!(
149153
"
@@ -186,14 +190,16 @@ pub unsafe extern "C" fn __rust_probestack() {
186190
// probestack function will also do things like _chkstk in MSVC.
187191
// So we need to sub %ax %sp in probestack when arch is x86.
188192
//
193+
// This function is unsafe because it uses a custom ABI, it does not actually match `extern "C"`.
194+
//
189195
// REF: Rust commit(74e80468347)
190196
// rust\src\llvm-project\llvm\lib\Target\X86\X86FrameLowering.cpp: 805
191197
// Comments in LLVM:
192198
// MSVC x32's _chkstk and cygwin/mingw's _alloca adjust %esp themselves.
193199
// MSVC x64's __chkstk and cygwin/mingw's ___chkstk_ms do not adjust %rsp
194200
// themselves.
195201
#[unsafe(naked)]
196-
#[no_mangle]
202+
#[rustc_std_internal_symbol]
197203
pub unsafe extern "C" fn __rust_probestack() {
198204
core::arch::naked_asm!(
199205
"

0 commit comments

Comments
 (0)