File tree Expand file tree Collapse file tree 2 files changed +10
-6
lines changed Expand file tree Collapse file tree 2 files changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -28,8 +28,11 @@ fn lang_start_internal(
2828 use crate :: panic;
2929 use crate :: sys_common;
3030
31- sys_common:: rt:: init ( argc, argv) ;
31+ // SAFETY: Only called once during runtime initialization.
32+ unsafe { sys_common:: rt:: init ( argc, argv) } ;
33+
3234 let exit_code = panic:: catch_unwind ( main) ;
35+
3336 sys_common:: rt:: cleanup ( ) ;
3437
3538 exit_code. unwrap_or ( 101 ) as isize
Original file line number Diff line number Diff line change 1+ #![ deny( unsafe_op_in_unsafe_fn) ]
2+
13use crate :: sync:: Once ;
24use crate :: sys;
35use crate :: sys_common:: thread_info;
46use crate :: thread:: Thread ;
57
68// One-time runtime initialization.
79// Runs before `main`.
10+ // SAFETY: must be called only once during runtime initialization.
811// NOTE: this is not guaranteed to run, for example when Rust code is called externally.
912#[ cfg_attr( test, allow( dead_code) ) ]
10- pub fn init ( argc : isize , argv : * const * const u8 ) {
11- static INIT : Once = Once :: new ( ) ;
12- INIT . call_once ( || unsafe {
13- // SAFETY: Only called once during runtime initialization.
13+ pub unsafe fn init ( argc : isize , argv : * const * const u8 ) {
14+ unsafe {
1415 sys:: init ( argc, argv) ;
1516
1617 let main_guard = sys:: thread:: guard:: init ( ) ;
@@ -20,7 +21,7 @@ pub fn init(argc: isize, argv: *const *const u8) {
2021 // info about the stack bounds.
2122 let thread = Thread :: new ( Some ( "main" . to_owned ( ) ) ) ;
2223 thread_info:: set ( main_guard, thread) ;
23- } ) ;
24+ }
2425}
2526
2627// One-time runtime cleanup.
You can’t perform that action at this time.
0 commit comments