From 951e9dd1eb91f89c00391b1dd85b5ff25e31cd0b Mon Sep 17 00:00:00 2001 From: 4lDO2 <4lDO2@protonmail.com> Date: Fri, 12 May 2023 13:59:07 +0200 Subject: [PATCH 1/2] Define sem_t as typedef, not union. --- src/header/semaphore/cbindgen.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/header/semaphore/cbindgen.toml b/src/header/semaphore/cbindgen.toml index 0c01194989..213064b7ac 100644 --- a/src/header/semaphore/cbindgen.toml +++ b/src/header/semaphore/cbindgen.toml @@ -1,7 +1,7 @@ sys_includes = [] include_guard = "_RELIBC_SEMAPHORE_H" language = "C" -style = "Tag" +style = "Type" no_includes = true cpp_compat = true From 89429f26c032303d292d65d74298c635d843b82f Mon Sep 17 00:00:00 2001 From: 4lDO2 <4lDO2@protonmail.com> Date: Fri, 12 May 2023 18:09:22 +0200 Subject: [PATCH 2/2] Follow POSIX by allowing NULL pthread_key_t dtors. --- src/header/pthread/tls.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/header/pthread/tls.rs b/src/header/pthread/tls.rs index 6a064f971b..57c7c35458 100644 --- a/src/header/pthread/tls.rs +++ b/src/header/pthread/tls.rs @@ -30,7 +30,7 @@ pub unsafe extern "C" fn pthread_getspecific(key: pthread_key_t) -> *mut c_void data } #[no_mangle] -pub unsafe extern "C" fn pthread_key_create(key_ptr: *mut pthread_key_t, destructor: extern "C" fn(value: *mut c_void)) -> c_int { +pub unsafe extern "C" fn pthread_key_create(key_ptr: *mut pthread_key_t, destructor: Option) -> c_int { let key = NEXTKEY.get(); NEXTKEY.set(key + 1); //println!("pthread_key_create new key {:#0x}, dtor {:p}", key, destructor); @@ -82,7 +82,7 @@ pub unsafe extern "C" fn pthread_setspecific(key: pthread_key_t, value: *const c static KEYS: Mutex> = Mutex::new(BTreeMap::new()); struct Dtor { - destructor: extern "C" fn(value: *mut c_void) + destructor: Option, } #[thread_local] @@ -97,8 +97,8 @@ static NEXTKEY: Cell = Cell::new(1); pub(crate) unsafe fn run_all_destructors() { for (key, Record { data }) in VALUES.take() { - let Some(&Dtor { destructor }) = KEYS.lock().get(&key) else { continue }; + let Some(&Dtor { destructor: Some(dtor) }) = KEYS.lock().get(&key) else { continue }; - destructor(data); + dtor(data); } }