diff options
| author | joboet <jonasboettiger@icloud.com> | 2023-10-03 23:13:55 +0200 |
|---|---|---|
| committer | joboet <jonasboettiger@icloud.com> | 2023-10-03 23:57:37 +0200 |
| commit | fd23276ca87b4b56918e4a87737859cfd77d657c (patch) | |
| tree | fdeeaca44c4aea4278560e6c1eac403f67e2d367 /library/std/src/sys/solid | |
| parent | 36aab8df0ab8a76f1c4f95ce8becefdd8a6fe526 (diff) | |
std: panic when the global allocator tries to register a TLS destructor
Diffstat (limited to 'library/std/src/sys/solid')
| -rw-r--r-- | library/std/src/sys/solid/thread_local_dtor.rs | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/library/std/src/sys/solid/thread_local_dtor.rs b/library/std/src/sys/solid/thread_local_dtor.rs index bad14bb37f7..d0fecede955 100644 --- a/library/std/src/sys/solid/thread_local_dtor.rs +++ b/library/std/src/sys/solid/thread_local_dtor.rs @@ -4,14 +4,13 @@ // Simplify dtor registration by using a list of destructors. use super::{abi, itron::task}; -use crate::cell::Cell; -use crate::mem; +use crate::cell::{Cell, RefCell}; #[thread_local] static REGISTERED: Cell<bool> = Cell::new(false); #[thread_local] -static mut DTORS: Vec<(*mut u8, unsafe extern "C" fn(*mut u8))> = Vec::new(); +static DTORS: RefCell<Vec<(*mut u8, unsafe extern "C" fn(*mut u8))>> = RefCell::new(Vec::new()); pub unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern "C" fn(*mut u8)) { if !REGISTERED.get() { @@ -22,18 +21,17 @@ pub unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern "C" fn(*mut u8)) { REGISTERED.set(true); } - let list = unsafe { &mut DTORS }; - list.push((t, dtor)); + DTORS.try_borrow_mut().expect("global allocator may not use TLS").push((t, dtor)); } pub unsafe fn run_dtors() { - let mut list = mem::take(unsafe { &mut DTORS }); + let mut list = DTORS.take(); while !list.is_empty() { for (ptr, dtor) in list { unsafe { dtor(ptr) }; } - list = mem::take(unsafe { &mut DTORS }); + list = DTORS.take(); } } |
