File tree Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -69,15 +69,25 @@ impl Thread {
6969 )
7070 . map_err ( |code| io:: Error :: from_raw_os_error ( code as i32 ) ) ?;
7171
72+ #[ inline( never) ]
73+ fn rust_main_thread_not_inlined ( init : Box < ThreadInit > ) {
74+ let rust_start = init. init ( ) ;
75+ rust_start ( ) ;
76+ }
77+
7278 extern "C" fn thread_start (
7379 data : * mut usize ,
7480 guard_page_pre : usize ,
7581 stack_size : usize ,
7682 ) -> ! {
7783 // SAFETY: we are simply recreating the box that was leaked earlier.
7884 let init = unsafe { Box :: from_raw ( data as * mut ThreadInit ) } ;
79- let rust_start = init. init ( ) ;
80- rust_start ( ) ;
85+
86+ // Run the main thread with an inline(never) barrier to prevent
87+ // dealloc calls from being reordered to after the TLS has been destroyed.
88+ // See https://github.com/rust-lang/rust/pull/144465#pullrequestreview-3289729950
89+ // for more context.
90+ run_main_thread_not_inlined ( init) ;
8191
8292 // Destroy TLS, which will free the TLS page and call the destructor for
8393 // any thread local storage (if any).
Original file line number Diff line number Diff line change @@ -186,6 +186,11 @@ pub unsafe fn destroy_tls() {
186186 } ;
187187}
188188
189+ // This is marked inline(never) to prevent dealloc calls from being reordered
190+ // to after the TLS has been destroyed.
191+ // See https://github.com/rust-lang/rust/pull/144465#pullrequestreview-3289729950
192+ // for more context.
193+ #[ inline( never) ]
189194unsafe fn run_dtors ( ) {
190195 let mut any_run = true ;
191196
You can’t perform that action at this time.
0 commit comments