From d82240f228d9f64bbb1d7b5846ea5c53674175ef Mon Sep 17 00:00:00 2001 From: Anhad Singh Date: Tue, 27 Jan 2026 19:31:14 +1100 Subject: [PATCH] fix(pthread/mutex): broken `pthread_mutexattr_*` Regression of https://gitlab.redox-os.org/redox-os/relibc/-/merge_requests/890 * The unsafe block needs to be moved *outside* to make sure the `attr` is mutated. * `RlctMutexAttr` was `Copy` which is not required. Signed-off-by: Anhad Singh --- src/header/pthread/mutex.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/header/pthread/mutex.rs b/src/header/pthread/mutex.rs index 32daa1e937..3c6b4ae4a0 100644 --- a/src/header/pthread/mutex.rs +++ b/src/header/pthread/mutex.rs @@ -41,7 +41,7 @@ pub unsafe extern "C" fn pthread_mutex_init( attr: *const pthread_mutexattr_t, ) -> c_int { let attr = unsafe { attr.cast::().as_ref() } - .copied() + .cloned() .unwrap_or_default(); match RlctMutex::new(&attr) { @@ -156,7 +156,7 @@ pub unsafe extern "C" fn pthread_mutexattr_setprioceiling( attr: *mut pthread_mutexattr_t, prioceiling: c_int, ) -> c_int { - (unsafe { *attr.cast::() }).prioceiling = prioceiling; + unsafe { (*attr.cast::()).prioceiling = prioceiling }; 0 } @@ -165,7 +165,7 @@ pub unsafe extern "C" fn pthread_mutexattr_setprotocol( attr: *mut pthread_mutexattr_t, protocol: c_int, ) -> c_int { - (unsafe { *attr.cast::() }).protocol = protocol; + unsafe { (*attr.cast::()).protocol = protocol }; 0 } @@ -174,7 +174,7 @@ pub unsafe extern "C" fn pthread_mutexattr_setpshared( attr: *mut pthread_mutexattr_t, pshared: c_int, ) -> c_int { - (unsafe { *attr.cast::() }).pshared = pshared; + unsafe { (*attr.cast::()).pshared = pshared }; 0 } @@ -183,7 +183,7 @@ pub unsafe extern "C" fn pthread_mutexattr_setrobust( attr: *mut pthread_mutexattr_t, robust: c_int, ) -> c_int { - (unsafe { *attr.cast::() }).robust = robust; + unsafe { (*attr.cast::()).robust = robust }; 0 } #[unsafe(no_mangle)] @@ -191,14 +191,14 @@ pub unsafe extern "C" fn pthread_mutexattr_settype( attr: *mut pthread_mutexattr_t, ty: c_int, ) -> c_int { - (unsafe { *attr.cast::() }).ty = ty; + unsafe { (*attr.cast::()).ty = ty }; 0 } pub use crate::sync::pthread_mutex::RlctMutex; #[repr(C)] -#[derive(Clone, Copy)] +#[derive(Clone)] pub(crate) struct RlctMutexAttr { pub prioceiling: c_int, pub protocol: c_int, @@ -206,6 +206,7 @@ pub(crate) struct RlctMutexAttr { pub robust: c_int, pub ty: c_int, } + impl Default for RlctMutexAttr { fn default() -> Self { Self {