File tree 2 files changed +10
-6
lines changed
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(
28
28
use crate :: panic;
29
29
use crate :: sys_common;
30
30
31
- sys_common:: rt:: init ( argc, argv) ;
31
+ // SAFETY: Only called once during runtime initialization.
32
+ unsafe { sys_common:: rt:: init ( argc, argv) } ;
33
+
32
34
let exit_code = panic:: catch_unwind ( main) ;
35
+
33
36
sys_common:: rt:: cleanup ( ) ;
34
37
35
38
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
+
1
3
use crate :: sync:: Once ;
2
4
use crate :: sys;
3
5
use crate :: sys_common:: thread_info;
4
6
use crate :: thread:: Thread ;
5
7
6
8
// One-time runtime initialization.
7
9
// Runs before `main`.
10
+ // SAFETY: must be called only once during runtime initialization.
8
11
// NOTE: this is not guaranteed to run, for example when Rust code is called externally.
9
12
#[ 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 {
14
15
sys:: init ( argc, argv) ;
15
16
16
17
let main_guard = sys:: thread:: guard:: init ( ) ;
@@ -20,7 +21,7 @@ pub fn init(argc: isize, argv: *const *const u8) {
20
21
// info about the stack bounds.
21
22
let thread = Thread :: new ( Some ( "main" . to_owned ( ) ) ) ;
22
23
thread_info:: set ( main_guard, thread) ;
23
- } ) ;
24
+ }
24
25
}
25
26
26
27
// One-time runtime cleanup.
You can’t perform that action at this time.
0 commit comments