Skip to content

Commit 969b741

Browse files
committed
protect creation of destructors by a mutex
add on HermizCore an additional lock to protect static data
1 parent 3a1b3b3 commit 969b741

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/libstd/sys/hermit/thread_local.rs

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use crate::collections::BTreeMap;
44
use crate::ptr;
55
use crate::sync::atomic::{AtomicUsize, Ordering};
6+
use crate::sys_common::mutex::Mutex;
67

78
pub type Key = usize;
89

@@ -11,6 +12,7 @@ type Dtor = unsafe extern fn(*mut u8);
1112
static NEXT_KEY: AtomicUsize = AtomicUsize::new(0);
1213

1314
static mut KEYS: *mut BTreeMap<Key, Option<Dtor>> = ptr::null_mut();
15+
static KEYS_LOCK: Mutex = Mutex::new();
1416

1517
#[thread_local]
1618
static mut LOCALS: *mut BTreeMap<Key, *mut u8> = ptr::null_mut();
@@ -32,6 +34,7 @@ unsafe fn locals() -> &'static mut BTreeMap<Key, *mut u8> {
3234
#[inline]
3335
pub unsafe fn create(dtor: Option<Dtor>) -> Key {
3436
let key = NEXT_KEY.fetch_add(1, Ordering::SeqCst);
37+
let _guard = KEYS_LOCK.lock();
3538
keys().insert(key, dtor);
3639
key
3740
}

0 commit comments

Comments
 (0)