@@ -26,38 +26,6 @@ use crate::sys;
2626use crate :: sys_common:: thread_info;
2727use crate :: thread:: Thread ;
2828
29- // One-time runtime initialization.
30- // Runs before `main`.
31- // SAFETY: must be called only once during runtime initialization.
32- // NOTE: this is not guaranteed to run, for example when Rust code is called externally.
33- #[ cfg_attr( test, allow( dead_code) ) ]
34- unsafe fn init ( argc : isize , argv : * const * const u8 ) {
35- unsafe {
36- sys:: init ( argc, argv) ;
37-
38- let main_guard = sys:: thread:: guard:: init ( ) ;
39- // Next, set up the current Thread with the guard information we just
40- // created. Note that this isn't necessary in general for new threads,
41- // but we just do this to name the main thread and to give it correct
42- // info about the stack bounds.
43- let thread = Thread :: new ( Some ( CString :: new ( "main" ) . unwrap ( ) ) ) ;
44- thread_info:: set ( main_guard, thread) ;
45- }
46- }
47-
48- // One-time runtime cleanup.
49- // Runs after `main` or at program exit.
50- // NOTE: this is not guaranteed to run, for example when the program aborts.
51- pub ( crate ) fn cleanup ( ) {
52- static CLEANUP : Once = Once :: new ( ) ;
53- CLEANUP . call_once ( || unsafe {
54- // Flush stdout and disable buffering.
55- crate :: io:: cleanup ( ) ;
56- // SAFETY: Only called once during runtime cleanup.
57- sys:: cleanup ( ) ;
58- } ) ;
59- }
60-
6129// Prints to the "panic output", depending on the platform this may be:
6230// - the standard error output
6331// - some dedicated platform specific output
@@ -99,6 +67,38 @@ macro_rules! rtunwrap {
9967 } ;
10068}
10169
70+ // One-time runtime initialization.
71+ // Runs before `main`.
72+ // SAFETY: must be called only once during runtime initialization.
73+ // NOTE: this is not guaranteed to run, for example when Rust code is called externally.
74+ #[ cfg_attr( test, allow( dead_code) ) ]
75+ unsafe fn init ( argc : isize , argv : * const * const u8 ) {
76+ unsafe {
77+ sys:: init ( argc, argv) ;
78+
79+ let main_guard = sys:: thread:: guard:: init ( ) ;
80+ // Next, set up the current Thread with the guard information we just
81+ // created. Note that this isn't necessary in general for new threads,
82+ // but we just do this to name the main thread and to give it correct
83+ // info about the stack bounds.
84+ let thread = Thread :: new ( Some ( rtunwrap ! ( Ok , CString :: new( "main" ) ) ) ) ;
85+ thread_info:: set ( main_guard, thread) ;
86+ }
87+ }
88+
89+ // One-time runtime cleanup.
90+ // Runs after `main` or at program exit.
91+ // NOTE: this is not guaranteed to run, for example when the program aborts.
92+ pub ( crate ) fn cleanup ( ) {
93+ static CLEANUP : Once = Once :: new ( ) ;
94+ CLEANUP . call_once ( || unsafe {
95+ // Flush stdout and disable buffering.
96+ crate :: io:: cleanup ( ) ;
97+ // SAFETY: Only called once during runtime cleanup.
98+ sys:: cleanup ( ) ;
99+ } ) ;
100+ }
101+
102102// To reduce the generated code of the new `lang_start`, this function is doing
103103// the real work.
104104#[ cfg( not( test) ) ]
0 commit comments