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 {
69
69
)
70
70
. map_err ( |code| io:: Error :: from_raw_os_error ( code as i32 ) ) ?;
71
71
72
+ #[ inline( never) ]
73
+ fn rust_main_thread_not_inlined ( init : Box < ThreadInit > ) {
74
+ let rust_start = init. init ( ) ;
75
+ rust_start ( ) ;
76
+ }
77
+
72
78
extern "C" fn thread_start (
73
79
data : * mut usize ,
74
80
guard_page_pre : usize ,
75
81
stack_size : usize ,
76
82
) -> ! {
77
83
// SAFETY: we are simply recreating the box that was leaked earlier.
78
84
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) ;
81
91
82
92
// Destroy TLS, which will free the TLS page and call the destructor for
83
93
// 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() {
186
186
} ;
187
187
}
188
188
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) ]
189
194
unsafe fn run_dtors ( ) {
190
195
let mut any_run = true ;
191
196
You can’t perform that action at this time.
0 commit comments