From 86c27653ed5a2c179e4e4cd6d825ee50e1cb354f Mon Sep 17 00:00:00 2001 From: vasilito Date: Thu, 2 Jul 2026 07:57:51 +0300 Subject: [PATCH] relibc: fix mutex_owner_id_is_live Sys::open/close return type Sys::open returns Result (not i32), and Sys::close returns Result as well. The previous version of mutex_owner_id_is_live used the cstr.as_ptr() pattern (which the cross-compile correctly rejected because Sys::open expects NulStr<'_, Thin> not *const c_char) and treated the Result as a raw fd (which the type system rejected). Fix: pass the CStr directly (it converts to NulStr via Deref) and match on the Result<>'s Ok/Err variants instead of doing fd >= 0 comparison on a non-i32 type. --- src/pthread/mod.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/pthread/mod.rs b/src/pthread/mod.rs index 0cd5d1d088..7755f7153f 100644 --- a/src/pthread/mod.rs +++ b/src/pthread/mod.rs @@ -481,17 +481,18 @@ pub fn mutex_owner_id_is_live(owner: u32) -> bool { // For Redox, attempt to open the thread's "name" handle via // the proc scheme. If the thread is alive, the open succeeds; // if it has exited and been reaped, the open returns ENOENT. - let path = format!("proc:{}/name", owner); + let path = alloc::format!("proc:{}/name\0", owner); let cstr = match crate::c_str::CStr::from_bytes_with_nul(path.as_bytes()) { Ok(c) => c, Err(_) => return false, }; - let fd = crate::platform::Sys::open(cstr.as_ptr(), crate::header::fcntl::O_RDONLY, 0); - if fd >= 0 { - let _ = crate::platform::Sys::close(fd); - true - } else { - false + let fd = crate::platform::Sys::open(cstr, crate::header::fcntl::O_RDONLY, 0); + match fd { + Ok(fd) => { + let _ = crate::platform::Sys::close(fd); + true + } + Err(_) => false, } } #[cfg(target_os = "linux")]