Skip to content

Commit 7742e99

Browse files
committed
Auto merge of #152657 - joboet:move_pal_exit, r=<try>
std: move `exit` out of PAL try-job: test-various
2 parents 8387095 + c8156bd commit 7742e99

File tree

18 files changed

+76
-88
lines changed

18 files changed

+76
-88
lines changed

library/std/src/process.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2464,7 +2464,7 @@ impl Child {
24642464
#[cfg_attr(not(test), rustc_diagnostic_item = "process_exit")]
24652465
pub fn exit(code: i32) -> ! {
24662466
crate::rt::cleanup();
2467-
crate::sys::os::exit(code)
2467+
crate::sys::exit::exit(code)
24682468
}
24692469

24702470
/// Terminates the process in an abnormal fashion.

library/std/src/rt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ fn lang_start_internal(
187187
cleanup();
188188
// Guard against multiple threads calling `libc::exit` concurrently.
189189
// See the documentation for `unique_thread_exit` for more information.
190-
crate::sys::exit_guard::unique_thread_exit();
190+
crate::sys::exit::unique_thread_exit();
191191

192192
ret_code
193193
})
Lines changed: 72 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ cfg_select! {
1919
/// * If it is called again on the same thread as the first call, it will abort.
2020
/// * If it is called again on a different thread, it will wait in a loop
2121
/// (waiting for the process to exit).
22-
#[cfg_attr(any(test, doctest), allow(dead_code))]
23-
pub(crate) fn unique_thread_exit() {
22+
pub fn unique_thread_exit() {
2423
use crate::ffi::c_int;
2524
use crate::ptr;
2625
use crate::sync::atomic::AtomicPtr;
@@ -62,9 +61,78 @@ cfg_select! {
6261
///
6362
/// Mitigation is ***NOT*** implemented on this platform, either because this platform
6463
/// is not affected, or because mitigation is not yet implemented for this platform.
65-
#[cfg_attr(any(test, doctest), allow(dead_code))]
66-
pub(crate) fn unique_thread_exit() {
64+
#[cfg_attr(any(test, doctest), expect(dead_code))]
65+
pub fn unique_thread_exit() {
6766
// Mitigation not required on platforms where `exit` is thread-safe.
6867
}
6968
}
7069
}
70+
71+
pub fn exit(code: i32) -> ! {
72+
cfg_select! {
73+
target_os = "hermit" => {
74+
unsafe { hermit_abi::exit(code) }
75+
}
76+
target_os = "linux" => {
77+
unsafe {
78+
unique_thread_exit();
79+
libc::exit(code)
80+
}
81+
}
82+
target_os = "motor" => {
83+
moto_rt::process::exit(code)
84+
}
85+
all(target_vendor = "fortanix", target_env = "sgx") => {
86+
crate::sys::pal::abi::exit_with_code(code as _)
87+
}
88+
target_os = "solid_asp3" => {
89+
rtabort!("exit({}) called", code)
90+
}
91+
target_os = "teeos" => {
92+
panic!("TA should not call `exit`")
93+
}
94+
target_os = "uefi" => {
95+
if let (Some(boot_services), Some(handle)) =
96+
(uefi::env::boot_services(), uefi::env::try_image_handle())
97+
{
98+
let boot_services: NonNull<r_efi::efi::BootServices> = boot_services.cast();
99+
let _ = unsafe {
100+
((*boot_services.as_ptr()).exit)(
101+
handle.as_ptr(),
102+
Status::from_usize(code as usize),
103+
0,
104+
crate::ptr::null_mut(),
105+
)
106+
};
107+
}
108+
crate::intrinsics::abort()
109+
}
110+
any(
111+
target_family = "unix",
112+
target_os = "wasi",
113+
) => {
114+
unsafe { libc::exit(code as crate::ffi::c_int) }
115+
}
116+
target_os = "vexos" => {
117+
drop(code);
118+
119+
unsafe {
120+
vex_sdk::vexSystemExitRequest();
121+
122+
loop {
123+
vex_sdk::vexTasksRun();
124+
}
125+
}
126+
}
127+
target_os = "windows" => {
128+
unsafe { crate::sys::pal::c::ExitProcess(code as u32) }
129+
}
130+
target_os = "xous" => {
131+
crate::os::xous::ffi::exit(code as u32)
132+
}
133+
_ => {
134+
drop(code);
135+
crate::intrinsics::abort()
136+
}
137+
}
138+
}

library/std/src/sys/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub mod backtrace;
1111
pub mod cmath;
1212
pub mod env;
1313
pub mod env_consts;
14-
pub mod exit_guard;
14+
pub mod exit;
1515
pub mod fd;
1616
pub mod fs;
1717
pub mod io;

library/std/src/sys/pal/hermit/os.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,6 @@ pub fn home_dir() -> Option<PathBuf> {
5757
None
5858
}
5959

60-
pub fn exit(code: i32) -> ! {
61-
unsafe { hermit_abi::exit(code) }
62-
}
63-
6460
pub fn getpid() -> u32 {
6561
unsafe { hermit_abi::getpid() as u32 }
6662
}

library/std/src/sys/pal/motor/os.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,6 @@ pub fn home_dir() -> Option<PathBuf> {
6363
None
6464
}
6565

66-
pub fn exit(code: i32) -> ! {
67-
moto_rt::process::exit(code)
68-
}
69-
7066
pub fn getpid() -> u32 {
7167
panic!("Pids on Motor OS are u64.")
7268
}

library/std/src/sys/pal/sgx/os.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,6 @@ pub fn home_dir() -> Option<PathBuf> {
5656
None
5757
}
5858

59-
pub fn exit(code: i32) -> ! {
60-
super::abi::exit_with_code(code as _)
61-
}
62-
6359
pub fn getpid() -> u32 {
6460
panic!("no pids in SGX")
6561
}

library/std/src/sys/pal/solid/os.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,6 @@ pub fn home_dir() -> Option<PathBuf> {
6363
None
6464
}
6565

66-
pub fn exit(code: i32) -> ! {
67-
rtabort!("exit({}) called", code);
68-
}
69-
7066
pub fn getpid() -> u32 {
7167
panic!("no pids on this platform")
7268
}

library/std/src/sys/pal/teeos/os.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,6 @@ pub fn home_dir() -> Option<PathBuf> {
6767
None
6868
}
6969

70-
pub fn exit(_code: i32) -> ! {
71-
panic!("TA should not call `exit`")
72-
}
73-
7470
pub fn getpid() -> u32 {
7571
panic!("no pids on this platform")
7672
}

library/std/src/sys/pal/uefi/os.rs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -105,23 +105,6 @@ pub fn home_dir() -> Option<PathBuf> {
105105
None
106106
}
107107

108-
pub fn exit(code: i32) -> ! {
109-
if let (Some(boot_services), Some(handle)) =
110-
(uefi::env::boot_services(), uefi::env::try_image_handle())
111-
{
112-
let boot_services: NonNull<r_efi::efi::BootServices> = boot_services.cast();
113-
let _ = unsafe {
114-
((*boot_services.as_ptr()).exit)(
115-
handle.as_ptr(),
116-
Status::from_usize(code as usize),
117-
0,
118-
crate::ptr::null_mut(),
119-
)
120-
};
121-
}
122-
crate::intrinsics::abort()
123-
}
124-
125108
pub fn getpid() -> u32 {
126109
panic!("no pids on this platform")
127110
}

0 commit comments

Comments
 (0)