mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
std: move exit out of PAL
This commit is contained in:
@@ -2464,7 +2464,7 @@ pub fn wait_with_output(mut self) -> io::Result<Output> {
|
||||
#[cfg_attr(not(test), rustc_diagnostic_item = "process_exit")]
|
||||
pub fn exit(code: i32) -> ! {
|
||||
crate::rt::cleanup();
|
||||
crate::sys::os::exit(code)
|
||||
crate::sys::exit::exit(code)
|
||||
}
|
||||
|
||||
/// Terminates the process in an abnormal fashion.
|
||||
|
||||
@@ -187,7 +187,7 @@ fn lang_start_internal(
|
||||
cleanup();
|
||||
// Guard against multiple threads calling `libc::exit` concurrently.
|
||||
// See the documentation for `unique_thread_exit` for more information.
|
||||
crate::sys::exit_guard::unique_thread_exit();
|
||||
crate::sys::exit::unique_thread_exit();
|
||||
|
||||
ret_code
|
||||
})
|
||||
|
||||
@@ -19,8 +19,7 @@
|
||||
/// * If it is called again on the same thread as the first call, it will abort.
|
||||
/// * If it is called again on a different thread, it will wait in a loop
|
||||
/// (waiting for the process to exit).
|
||||
#[cfg_attr(any(test, doctest), allow(dead_code))]
|
||||
pub(crate) fn unique_thread_exit() {
|
||||
pub fn unique_thread_exit() {
|
||||
use crate::ffi::c_int;
|
||||
use crate::ptr;
|
||||
use crate::sync::atomic::AtomicPtr;
|
||||
@@ -62,9 +61,83 @@ pub(crate) fn unique_thread_exit() {
|
||||
///
|
||||
/// Mitigation is ***NOT*** implemented on this platform, either because this platform
|
||||
/// is not affected, or because mitigation is not yet implemented for this platform.
|
||||
#[cfg_attr(any(test, doctest), allow(dead_code))]
|
||||
pub(crate) fn unique_thread_exit() {
|
||||
#[cfg_attr(any(test, doctest), expect(dead_code))]
|
||||
pub fn unique_thread_exit() {
|
||||
// Mitigation not required on platforms where `exit` is thread-safe.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn exit(code: i32) -> ! {
|
||||
cfg_select! {
|
||||
target_os = "hermit" => {
|
||||
unsafe { hermit_abi::exit(code) }
|
||||
}
|
||||
target_os = "linux" => {
|
||||
unsafe {
|
||||
unique_thread_exit();
|
||||
libc::exit(code)
|
||||
}
|
||||
}
|
||||
target_os = "motor" => {
|
||||
moto_rt::process::exit(code)
|
||||
}
|
||||
all(target_vendor = "fortanix", target_env = "sgx") => {
|
||||
crate::sys::pal::abi::exit_with_code(code as _)
|
||||
}
|
||||
target_os = "solid_asp3" => {
|
||||
rtabort!("exit({}) called", code)
|
||||
}
|
||||
target_os = "teeos" => {
|
||||
let _ = code;
|
||||
panic!("TA should not call `exit`")
|
||||
}
|
||||
target_os = "uefi" => {
|
||||
use r_efi::base::Status;
|
||||
|
||||
use crate::os::uefi::env;
|
||||
|
||||
if let (Some(boot_services), Some(handle)) =
|
||||
(env::boot_services(), env::try_image_handle())
|
||||
{
|
||||
let boot_services = boot_services.cast::<r_efi::efi::BootServices>();
|
||||
let _ = unsafe {
|
||||
((*boot_services.as_ptr()).exit)(
|
||||
handle.as_ptr(),
|
||||
Status::from_usize(code as usize),
|
||||
0,
|
||||
crate::ptr::null_mut(),
|
||||
)
|
||||
};
|
||||
}
|
||||
crate::intrinsics::abort()
|
||||
}
|
||||
any(
|
||||
target_family = "unix",
|
||||
target_os = "wasi",
|
||||
) => {
|
||||
unsafe { libc::exit(code as crate::ffi::c_int) }
|
||||
}
|
||||
target_os = "vexos" => {
|
||||
let _ = code;
|
||||
|
||||
unsafe {
|
||||
vex_sdk::vexSystemExitRequest();
|
||||
|
||||
loop {
|
||||
vex_sdk::vexTasksRun();
|
||||
}
|
||||
}
|
||||
}
|
||||
target_os = "windows" => {
|
||||
unsafe { crate::sys::pal::c::ExitProcess(code as u32) }
|
||||
}
|
||||
target_os = "xous" => {
|
||||
crate::os::xous::ffi::exit(code as u32)
|
||||
}
|
||||
_ => {
|
||||
let _ = code;
|
||||
crate::intrinsics::abort()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@
|
||||
pub mod cmath;
|
||||
pub mod env;
|
||||
pub mod env_consts;
|
||||
pub mod exit_guard;
|
||||
pub mod exit;
|
||||
pub mod fd;
|
||||
pub mod fs;
|
||||
pub mod io;
|
||||
|
||||
@@ -57,10 +57,6 @@ pub fn home_dir() -> Option<PathBuf> {
|
||||
None
|
||||
}
|
||||
|
||||
pub fn exit(code: i32) -> ! {
|
||||
unsafe { hermit_abi::exit(code) }
|
||||
}
|
||||
|
||||
pub fn getpid() -> u32 {
|
||||
unsafe { hermit_abi::getpid() as u32 }
|
||||
}
|
||||
|
||||
@@ -63,10 +63,6 @@ pub fn home_dir() -> Option<PathBuf> {
|
||||
None
|
||||
}
|
||||
|
||||
pub fn exit(code: i32) -> ! {
|
||||
moto_rt::process::exit(code)
|
||||
}
|
||||
|
||||
pub fn getpid() -> u32 {
|
||||
panic!("Pids on Motor OS are u64.")
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ extern "C" fn entry(p1: u64, p2: u64, p3: u64, secondary: bool, p4: u64, p5: u64
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn exit_with_code(code: isize) -> ! {
|
||||
pub fn exit_with_code(code: isize) -> ! {
|
||||
if code != 0 {
|
||||
if let Some(mut out) = panic::SgxPanicOutput::new() {
|
||||
let _ = write!(out, "Exited with status code {code}");
|
||||
|
||||
@@ -56,10 +56,6 @@ pub fn home_dir() -> Option<PathBuf> {
|
||||
None
|
||||
}
|
||||
|
||||
pub fn exit(code: i32) -> ! {
|
||||
super::abi::exit_with_code(code as _)
|
||||
}
|
||||
|
||||
pub fn getpid() -> u32 {
|
||||
panic!("no pids in SGX")
|
||||
}
|
||||
|
||||
@@ -63,10 +63,6 @@ pub fn home_dir() -> Option<PathBuf> {
|
||||
None
|
||||
}
|
||||
|
||||
pub fn exit(code: i32) -> ! {
|
||||
rtabort!("exit({}) called", code);
|
||||
}
|
||||
|
||||
pub fn getpid() -> u32 {
|
||||
panic!("no pids on this platform")
|
||||
}
|
||||
|
||||
@@ -67,10 +67,6 @@ pub fn home_dir() -> Option<PathBuf> {
|
||||
None
|
||||
}
|
||||
|
||||
pub fn exit(_code: i32) -> ! {
|
||||
panic!("TA should not call `exit`")
|
||||
}
|
||||
|
||||
pub fn getpid() -> u32 {
|
||||
panic!("no pids on this platform")
|
||||
}
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
use r_efi::efi::Status;
|
||||
use r_efi::efi::protocols::{device_path, loaded_image_device_path};
|
||||
|
||||
use super::{helpers, unsupported_err};
|
||||
use crate::ffi::{OsStr, OsString};
|
||||
use crate::marker::PhantomData;
|
||||
use crate::os::uefi;
|
||||
use crate::os::uefi::ffi::{OsStrExt, OsStringExt};
|
||||
use crate::path::{self, PathBuf};
|
||||
use crate::ptr::NonNull;
|
||||
use crate::{fmt, io};
|
||||
|
||||
const PATHS_SEP: u16 = b';' as u16;
|
||||
@@ -105,23 +102,6 @@ pub fn home_dir() -> Option<PathBuf> {
|
||||
None
|
||||
}
|
||||
|
||||
pub fn exit(code: i32) -> ! {
|
||||
if let (Some(boot_services), Some(handle)) =
|
||||
(uefi::env::boot_services(), uefi::env::try_image_handle())
|
||||
{
|
||||
let boot_services: NonNull<r_efi::efi::BootServices> = boot_services.cast();
|
||||
let _ = unsafe {
|
||||
((*boot_services.as_ptr()).exit)(
|
||||
handle.as_ptr(),
|
||||
Status::from_usize(code as usize),
|
||||
0,
|
||||
crate::ptr::null_mut(),
|
||||
)
|
||||
};
|
||||
}
|
||||
crate::intrinsics::abort()
|
||||
}
|
||||
|
||||
pub fn getpid() -> u32 {
|
||||
panic!("no pids on this platform")
|
||||
}
|
||||
|
||||
@@ -533,11 +533,6 @@ unsafe fn fallback() -> Option<OsString> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn exit(code: i32) -> ! {
|
||||
crate::sys::exit_guard::unique_thread_exit();
|
||||
unsafe { libc::exit(code as c_int) }
|
||||
}
|
||||
|
||||
pub fn getpid() -> u32 {
|
||||
unsafe { libc::getpid() as u32 }
|
||||
}
|
||||
|
||||
@@ -56,10 +56,6 @@ pub fn home_dir() -> Option<PathBuf> {
|
||||
None
|
||||
}
|
||||
|
||||
pub fn exit(_code: i32) -> ! {
|
||||
crate::intrinsics::abort()
|
||||
}
|
||||
|
||||
pub fn getpid() -> u32 {
|
||||
panic!("no pids on this platform")
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#[path = "../unsupported/os.rs"]
|
||||
pub mod os;
|
||||
|
||||
#[expect(dead_code)]
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
#[expect(dead_code)]
|
||||
#[path = "../unsupported/os.rs"]
|
||||
mod unsupported_os;
|
||||
pub use unsupported_os::{
|
||||
JoinPathsError, SplitPaths, chdir, current_exe, getcwd, getpid, home_dir, join_paths,
|
||||
split_paths, temp_dir,
|
||||
};
|
||||
|
||||
pub use super::unsupported;
|
||||
|
||||
pub fn exit(_code: i32) -> ! {
|
||||
unsafe {
|
||||
vex_sdk::vexSystemExitRequest();
|
||||
|
||||
loop {
|
||||
vex_sdk::vexTasksRun();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -102,10 +102,6 @@ pub fn home_dir() -> Option<PathBuf> {
|
||||
None
|
||||
}
|
||||
|
||||
pub fn exit(code: i32) -> ! {
|
||||
unsafe { libc::exit(code) }
|
||||
}
|
||||
|
||||
pub fn getpid() -> u32 {
|
||||
panic!("unsupported");
|
||||
}
|
||||
|
||||
@@ -189,10 +189,6 @@ pub fn home_dir() -> Option<PathBuf> {
|
||||
.or_else(home_dir_crt)
|
||||
}
|
||||
|
||||
pub fn exit(code: i32) -> ! {
|
||||
unsafe { c::ExitProcess(code as u32) }
|
||||
}
|
||||
|
||||
pub fn getpid() -> u32 {
|
||||
unsafe { c::GetCurrentProcessId() }
|
||||
}
|
||||
|
||||
@@ -119,10 +119,6 @@ pub fn home_dir() -> Option<PathBuf> {
|
||||
None
|
||||
}
|
||||
|
||||
pub fn exit(code: i32) -> ! {
|
||||
crate::os::xous::ffi::exit(code as u32);
|
||||
}
|
||||
|
||||
pub fn getpid() -> u32 {
|
||||
panic!("no pids on this platform")
|
||||
}
|
||||
|
||||
@@ -56,10 +56,6 @@ pub fn home_dir() -> Option<PathBuf> {
|
||||
None
|
||||
}
|
||||
|
||||
pub fn exit(_code: i32) -> ! {
|
||||
crate::intrinsics::abort()
|
||||
}
|
||||
|
||||
pub fn getpid() -> u32 {
|
||||
panic!("no pids on this platform")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user