mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
std: abort instead of panicking if the global allocator uses TLS
This commit is contained in:
parent
fd23276ca8
commit
b18990b1e9
@ -11,7 +11,10 @@ use crate::cell::RefCell;
|
||||
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)) {
|
||||
DTORS.try_borrow_mut().expect("global allocator may not use TLS").push((t, dtor));
|
||||
match DTORS.try_borrow_mut() {
|
||||
Ok(mut dtors) => dtors.push((t, dtor)),
|
||||
Err(_) => rtabort!("global allocator may not use TLS"),
|
||||
}
|
||||
}
|
||||
|
||||
// every thread call this function to run through all possible destructors
|
||||
|
@ -21,7 +21,10 @@ pub unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern "C" fn(*mut u8)) {
|
||||
REGISTERED.set(true);
|
||||
}
|
||||
|
||||
DTORS.try_borrow_mut().expect("global allocator may not use TLS").push((t, dtor));
|
||||
match DTORS.try_borrow_mut() {
|
||||
Ok(mut dtors) => dtors.push((t, dtor)),
|
||||
Err(_) => rtabort!("global allocator may not use TLS"),
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe fn run_dtors() {
|
||||
|
@ -68,7 +68,10 @@ pub unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern "C" fn(*mut u8)) {
|
||||
fn _tlv_atexit(dtor: unsafe extern "C" fn(*mut u8), arg: *mut u8);
|
||||
}
|
||||
|
||||
DTORS.try_borrow_mut().expect("global allocator may not use TLS").push((t, dtor));
|
||||
match DTORS.try_borrow_mut() {
|
||||
Ok(mut dtors) => dtors.push((t, dtor)),
|
||||
Err(_) => rtabort!("global allocator may not use TLS"),
|
||||
}
|
||||
|
||||
unsafe extern "C" fn run_dtors(_: *mut u8) {
|
||||
let mut list = DTORS.take();
|
||||
|
@ -24,7 +24,11 @@ static DESTRUCTORS: crate::cell::RefCell<Vec<(*mut u8, unsafe extern "C" fn(*mut
|
||||
#[inline(never)]
|
||||
#[cfg(target_thread_local)]
|
||||
pub unsafe fn register_keyless_dtor(t: *mut u8, dtor: unsafe extern "C" fn(*mut u8)) {
|
||||
DESTRUCTORS.try_borrow_mut().expect("global allocator may not use TLS").push((t, dtor));
|
||||
match DESTRUCTORS.try_borrow_mut() {
|
||||
Ok(mut dtors) => dtors.push((t, dtor)),
|
||||
Err(_) => rtabort!("global allocator may not use TLS"),
|
||||
}
|
||||
|
||||
HAS_DTORS.store(true, Relaxed);
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,10 @@ pub unsafe fn register_dtor_fallback(t: *mut u8, dtor: unsafe extern "C" fn(*mut
|
||||
DTORS.set(Box::into_raw(v) as *mut u8);
|
||||
}
|
||||
let list = &*(DTORS.get() as *const List);
|
||||
list.try_borrow_mut().expect("global allocator may not use TLS").push((t, dtor));
|
||||
match list.try_borrow_mut() {
|
||||
Ok(mut dtors) => dtors.push((t, dtor)),
|
||||
Err(_) => rtabort!("global allocator may not use TLS"),
|
||||
}
|
||||
|
||||
unsafe extern "C" fn run_dtors(mut ptr: *mut u8) {
|
||||
while !ptr.is_null() {
|
||||
|
Loading…
Reference in New Issue
Block a user