From 5907c14c4e35ff6acc9cd571f71a091909d38f5f Mon Sep 17 00:00:00 2001 From: vasilito Date: Thu, 2 Jul 2026 07:55:28 +0300 Subject: [PATCH] relibc: fix Sys::open calls to use NulStr (not String/&path) The cross-compile to x86_64-unknown-redox caught what host cargo check missed: Sys::open takes NulStr<'_, Thin>, not String or *const c_char. Five call sites in src/header/pthread/ mod.rs and src/pthread/mod.rs were using the wrong types: - pthread_setaffinity_np / pthread_getaffinity_np (redox_get_thread_affinity / redox_set_thread_affinity) - pthread_setname_np - pthread_getname_np - mutex_owner_id_is_live (the new Phase 1 robust mutex helper) All five now construct a Nul-terminated path via format!("...\0") and convert via CStr::from_bytes_with_nul(). Also: Sys::close returns Result, not i32; the mutex_owner_id_is_live helper now matches the return type of close() correctly (the previous code passed the Result directly to fd >= 0 comparison which the cross-compile correctly rejected as a type error). --- src/header/pthread/mod.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/header/pthread/mod.rs b/src/header/pthread/mod.rs index a6c3801398..1e3f6c52fc 100644 --- a/src/header/pthread/mod.rs +++ b/src/header/pthread/mod.rs @@ -108,8 +108,8 @@ fn copy_u64_to_cpuset(mask: u64, cpusetsize: size_t, cpuset: *mut cpu_set_t) -> #[cfg(target_os = "redox")] fn redox_get_thread_affinity(thread: &crate::pthread::Pthread) -> Result { let os_tid = unsafe { thread.os_tid.get().read() }; - let path = alloc::format!("proc:{}/sched-affinity", os_tid.thread_fd); - let fd = Sys::open(&path, crate::header::fcntl::O_RDONLY, 0)?; + let path = alloc::format!("proc:{}/sched-affinity\0", os_tid.thread_fd); + let fd = Sys::open(crate::c_str::CStr::from_bytes_with_nul(path.as_bytes()).unwrap(), crate::header::fcntl::O_RDONLY, 0)?; let mut buf = [0u8; RLCT_AFFINITY_BYTES]; let read = Sys::read(fd, &mut buf)?; @@ -123,8 +123,8 @@ fn redox_get_thread_affinity(thread: &crate::pthread::Pthread) -> Result Result<(), Errno> { let os_tid = unsafe { thread.os_tid.get().read() }; - let path = alloc::format!("proc:{}/sched-affinity", os_tid.thread_fd); - let fd = Sys::open(&path, crate::header::fcntl::O_WRONLY, 0)?; + let path = alloc::format!("proc:{}/sched-affinity\0", os_tid.thread_fd); + let fd = Sys::open(crate::c_str::CStr::from_bytes_with_nul(path.as_bytes()).unwrap(), crate::header::fcntl::O_WRONLY, 0)?; let bytes = mask.to_ne_bytes(); let written = Sys::write(fd, &bytes)?; @@ -554,8 +554,8 @@ pub unsafe extern "C" fn pthread_setname_np(thread: pthread_t, name: *const c_ch { let thread = unsafe { &*thread.cast::() }; let os_tid = unsafe { thread.os_tid.get().read() }; - let path = alloc::format!("proc:{}/name", os_tid.thread_fd); - let fd = match Sys::open(&path, crate::header::fcntl::O_WRONLY, 0) { + let path = alloc::format!("proc:{}/name\0", os_tid.thread_fd); + let fd = match Sys::open(crate::c_str::CStr::from_bytes_with_nul(path.as_bytes()).unwrap(), crate::header::fcntl::O_WRONLY, 0) { Ok(fd) => fd, Err(Errno(code)) => return code, }; @@ -592,8 +592,8 @@ pub unsafe extern "C" fn pthread_getname_np( { let thread = unsafe { &*thread.cast::() }; let os_tid = unsafe { thread.os_tid.get().read() }; - let path = alloc::format!("proc:{}/name", os_tid.thread_fd); - let fd = match Sys::open(&path, crate::header::fcntl::O_RDONLY, 0) { + let path = alloc::format!("proc:{}/name\0", os_tid.thread_fd); + let fd = match Sys::open(crate::c_str::CStr::from_bytes_with_nul(path.as_bytes()).unwrap(), crate::header::fcntl::O_RDONLY, 0) { Ok(fd) => fd, Err(Errno(code)) => return code, };