Skip to content

Commit b18990b

Browse files
committed
std: abort instead of panicking if the global allocator uses TLS
1 parent fd23276 commit b18990b

File tree

5 files changed

+21
-5
lines changed

5 files changed

+21
-5
lines changed

library/std/src/sys/hermit/thread_local_dtor.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ use crate::cell::RefCell;
1111
static DTORS: RefCell<Vec<(*mut u8, unsafe extern "C" fn(*mut u8))>> = RefCell::new(Vec::new());
1212

1313
pub unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern "C" fn(*mut u8)) {
14-
DTORS.try_borrow_mut().expect("global allocator may not use TLS").push((t, dtor));
14+
match DTORS.try_borrow_mut() {
15+
Ok(mut dtors) => dtors.push((t, dtor)),
16+
Err(_) => rtabort!("global allocator may not use TLS"),
17+
}
1518
}
1619

1720
// every thread call this function to run through all possible destructors

library/std/src/sys/solid/thread_local_dtor.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ pub unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern "C" fn(*mut u8)) {
2121
REGISTERED.set(true);
2222
}
2323

24-
DTORS.try_borrow_mut().expect("global allocator may not use TLS").push((t, dtor));
24+
match DTORS.try_borrow_mut() {
25+
Ok(mut dtors) => dtors.push((t, dtor)),
26+
Err(_) => rtabort!("global allocator may not use TLS"),
27+
}
2528
}
2629

2730
pub unsafe fn run_dtors() {

library/std/src/sys/unix/thread_local_dtor.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,10 @@ pub unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern "C" fn(*mut u8)) {
6868
fn _tlv_atexit(dtor: unsafe extern "C" fn(*mut u8), arg: *mut u8);
6969
}
7070

71-
DTORS.try_borrow_mut().expect("global allocator may not use TLS").push((t, dtor));
71+
match DTORS.try_borrow_mut() {
72+
Ok(mut dtors) => dtors.push((t, dtor)),
73+
Err(_) => rtabort!("global allocator may not use TLS"),
74+
}
7275

7376
unsafe extern "C" fn run_dtors(_: *mut u8) {
7477
let mut list = DTORS.take();

library/std/src/sys/windows/thread_local_key.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ static DESTRUCTORS: crate::cell::RefCell<Vec<(*mut u8, unsafe extern "C" fn(*mut
2424
#[inline(never)]
2525
#[cfg(target_thread_local)]
2626
pub unsafe fn register_keyless_dtor(t: *mut u8, dtor: unsafe extern "C" fn(*mut u8)) {
27-
DESTRUCTORS.try_borrow_mut().expect("global allocator may not use TLS").push((t, dtor));
27+
match DESTRUCTORS.try_borrow_mut() {
28+
Ok(mut dtors) => dtors.push((t, dtor)),
29+
Err(_) => rtabort!("global allocator may not use TLS"),
30+
}
31+
2832
HAS_DTORS.store(true, Relaxed);
2933
}
3034

library/std/src/sys_common/thread_local_dtor.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ pub unsafe fn register_dtor_fallback(t: *mut u8, dtor: unsafe extern "C" fn(*mut
3838
DTORS.set(Box::into_raw(v) as *mut u8);
3939
}
4040
let list = &*(DTORS.get() as *const List);
41-
list.try_borrow_mut().expect("global allocator may not use TLS").push((t, dtor));
41+
match list.try_borrow_mut() {
42+
Ok(mut dtors) => dtors.push((t, dtor)),
43+
Err(_) => rtabort!("global allocator may not use TLS"),
44+
}
4245

4346
unsafe extern "C" fn run_dtors(mut ptr: *mut u8) {
4447
while !ptr.is_null() {

0 commit comments

Comments
 (0)