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<i32, Errno>, 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).
This commit is contained in:
2026-07-02 07:55:28 +03:00
parent 4b683014c9
commit 5907c14c4e
+8 -8
View File
@@ -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<u64, 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_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<u64, Er
#[cfg(target_os = "redox")]
fn redox_set_thread_affinity(thread: &crate::pthread::Pthread, mask: u64) -> 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::<crate::pthread::Pthread>() };
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::<crate::pthread::Pthread>() };
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,
};