@@ -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,83 @@ 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+ let _ = code;
93+ panic!( "TA should not call `exit`" )
94+ }
95+ target_os = "uefi" => {
96+ use r_efi:: base:: Status ;
97+
98+ use crate :: os:: uefi:: env;
99+
100+ if let ( Some ( boot_services) , Some ( handle) ) =
101+ ( env:: boot_services( ) , env:: try_image_handle( ) )
102+ {
103+ let boot_services = boot_services. cast:: <r_efi:: efi:: BootServices >( ) ;
104+ let _ = unsafe {
105+ ( ( * boot_services. as_ptr( ) ) . exit) (
106+ handle. as_ptr( ) ,
107+ Status :: from_usize( code as usize ) ,
108+ 0 ,
109+ crate :: ptr:: null_mut( ) ,
110+ )
111+ } ;
112+ }
113+ crate :: intrinsics:: abort( )
114+ }
115+ any(
116+ target_family = "unix" ,
117+ target_os = "wasi" ,
118+ ) => {
119+ unsafe { libc:: exit( code as crate :: ffi:: c_int) }
120+ }
121+ target_os = "vexos" => {
122+ let _ = code;
123+
124+ unsafe {
125+ vex_sdk:: vexSystemExitRequest( ) ;
126+
127+ loop {
128+ vex_sdk:: vexTasksRun( ) ;
129+ }
130+ }
131+ }
132+ target_os = "windows" => {
133+ unsafe { crate :: sys:: pal:: c:: ExitProcess ( code as u32 ) }
134+ }
135+ target_os = "xous" => {
136+ crate :: os:: xous:: ffi:: exit( code as u32 )
137+ }
138+ _ => {
139+ let _ = code;
140+ crate :: intrinsics:: abort( )
141+ }
142+ }
143+ }
0 commit comments