@@ -19,62 +19,66 @@ static GLOBAL_ALLOCATOR: rustix_dlmalloc::GlobalDlmalloc = rustix_dlmalloc::Glob
1919/// and start running the constructors but to immediately take over.
2020///
2121/// [here]: https://github.com/rust-lang/rfcs/pull/2735
22- #[ link_section = ".init_array.00000" ]
22+ #[ unsafe ( link_section = ".init_array.00000" ) ]
2323#[ used]
2424static EARLY_INIT_ARRAY : unsafe extern "C" fn ( i32 , * mut * mut u8 ) = {
2525 unsafe extern "C" fn function ( _argc : i32 , argv : * mut * mut u8 ) {
26- // Libc was calling constructors (we're one of them), but origin will
27- // be doing that now, so just exit when we're called a second time.
28- static FIRST : AtomicBool = AtomicBool :: new ( false ) ;
29- if FIRST
30- . compare_exchange ( false , true , Ordering :: Relaxed , Ordering :: Relaxed )
31- . is_err ( )
32- {
33- return ;
34- }
26+ unsafe {
27+ // Libc was calling constructors (we're one of them), but origin will
28+ // be doing that now, so just exit when we're called a second time.
29+ static FIRST : AtomicBool = AtomicBool :: new ( false ) ;
30+ if FIRST
31+ . compare_exchange ( false , true , Ordering :: Relaxed , Ordering :: Relaxed )
32+ . is_err ( )
33+ {
34+ return ;
35+ }
3536
36- // Compute the initial stack address provided by the kernel.
37- let mem = argv. sub ( 1 ) ;
37+ // Compute the initial stack address provided by the kernel.
38+ let mem = argv. sub ( 1 ) ;
3839
39- origin:: program:: start ( mem as _ ) ;
40+ origin:: program:: start ( mem as _ ) ;
41+ }
4042 }
4143 function
4244} ;
4345
44- #[ no_mangle]
46+ #[ unsafe ( no_mangle) ]
4547unsafe fn origin_main ( _argc : usize , _argv : * mut * mut u8 , _envp : * mut * mut u8 ) -> i32 {
46- eprintln ! ( "Hello from main thread" ) ;
48+ unsafe {
49+ eprintln ! ( "Hello from main thread" ) ;
4750
48- program:: at_exit ( Box :: new ( || {
49- eprintln ! ( "Hello from a `program::at_exit` handler" )
50- } ) ) ;
51- thread:: at_exit ( Box :: new ( || {
52- eprintln ! ( "Hello from a main-thread `thread::at_exit` handler" )
53- } ) ) ;
51+ program:: at_exit ( Box :: new ( || {
52+ eprintln ! ( "Hello from a `program::at_exit` handler" )
53+ } ) ) ;
54+ thread:: at_exit ( Box :: new ( || {
55+ eprintln ! ( "Hello from a main-thread `thread::at_exit` handler" )
56+ } ) ) ;
5457
55- let thread = thread:: create (
56- |_args| {
57- eprintln ! ( "Hello from child thread" ) ;
58- thread:: at_exit ( Box :: new ( || {
59- eprintln ! ( "Hello from child thread's `thread::at_exit` handler" )
60- } ) ) ;
61- None
62- } ,
63- & [ ] ,
64- thread:: default_stack_size ( ) ,
65- thread:: default_guard_size ( ) ,
66- )
67- . unwrap ( ) ;
58+ let thread = thread:: create (
59+ |_args| {
60+ eprintln ! ( "Hello from child thread" ) ;
61+ thread:: at_exit ( Box :: new ( || {
62+ eprintln ! ( "Hello from child thread's `thread::at_exit` handler" )
63+ } ) ) ;
64+ None
65+ } ,
66+ & [ ] ,
67+ thread:: default_stack_size ( ) ,
68+ thread:: default_guard_size ( ) ,
69+ )
70+ . unwrap ( ) ;
6871
69- thread:: join ( thread) ;
72+ thread:: join ( thread) ;
7073
71- eprintln ! ( "Goodbye from main" ) ;
72- program:: exit ( 0 ) ;
74+ eprintln ! ( "Goodbye from main" ) ;
75+ program:: exit ( 0 ) ;
76+ }
7377}
7478
7579// Libc calls `main` so we need to provide a definition to satisfy the
7680// linker, however origin gains control before libc can call this `main`.
77- #[ no_mangle]
81+ #[ unsafe ( no_mangle) ]
7882unsafe fn main ( _argc : i32 , _argv : * mut * mut u8 , _envp : * mut * mut u8 ) -> i32 {
7983 eprintln ! ( "Main was not supposed to be called!" ) ;
8084 program:: trap ( ) ;
0 commit comments