relibc: fix redox feature compile errors

This commit is contained in:
Red Bear OS
2026-07-09 13:08:39 +03:00
parent fa792c6231
commit 74367d1542
2 changed files with 20 additions and 21 deletions
+10 -11
View File
@@ -29,7 +29,7 @@ use crate::{
bits_timespec::timespec,
errno::{
EACCES, EBADF, EBADFD, EEXIST, EFAULT, EFBIG, EINTR, EINVAL, EIO, ENAMETOOLONG, ENOENT, ENOMEM,
ENOSYS, EOPNOTSUPP, EPERM,
EOPNOTSUPP, EPERM,
},
fcntl::{
self, AT_EACCESS, AT_EMPTY_PATH, AT_FDCWD, AT_REMOVEDIR, AT_SYMLINK_FOLLOW,
@@ -270,20 +270,17 @@ impl Pal for Sys {
if tp.is_null() {
return Err(Errno(EFAULT));
}
let ts = unsafe { *tp };
let ts = unsafe { (*tp).clone() };
let path = format!("/scheme/time/{}", clk_id as usize);
let fd = redox_rt::sys::open(
&path,
syscall::O_WRONLY | syscall::O_CLOEXEC,
0,
).map_err(|e| Errno(e.errno))?;
let bytes = redox_rt::sys::write(fd, unsafe {
let fd = redox_rt::sys::open(&path, syscall::O_WRONLY | syscall::O_CLOEXEC)
.map_err(|e| Errno(e.errno))?;
let bytes = syscall::write(fd, unsafe {
core::slice::from_raw_parts(
&ts as *const timespec as *const u8,
size_of::<timespec>(),
)
}).map_err(|e| Errno(e.errno))?;
let _ = redox_rt::sys::close(fd);
let _ = syscall::close(fd);
if bytes == size_of::<timespec>() {
Ok(())
} else {
@@ -1005,7 +1002,7 @@ impl Pal for Sys {
_args: *mut c_void,
) -> Result<*mut c_void> {
use crate::header::sys_mman::{MREMAP_MAYMOVE, PROT_READ, PROT_WRITE, MAP_PRIVATE, MAP_ANONYMOUS};
let page_size = platform::PAGE_SIZE;
let page_size = syscall::PAGE_SIZE;
let old_len = round_up_to_page_size(len).unwrap_or(len);
let new_page_len = round_up_to_page_size(new_len).unwrap_or(new_len);
@@ -1032,7 +1029,9 @@ impl Pal for Sys {
let map = syscall::Map {
offset: 0,
size: new_page_len,
flags: (PROT_READ | PROT_WRITE) as u32 | (MAP_PRIVATE | MAP_ANONYMOUS) as u32,
flags: syscall::MapFlags::from_bits_truncate(
((PROT_READ | PROT_WRITE) as usize) << 16 | ((MAP_PRIVATE | MAP_ANONYMOUS) as usize),
),
address: addr as usize, // hint only
};
let new_addr = unsafe { syscall::fmap(usize::MAX, &map)? } as *mut c_void;
+10 -10
View File
@@ -9,11 +9,12 @@ use crate::{
header::{
bits_sigset_t::sigset_t,
bits_timespec::timespec,
errno::{EINVAL, ENOSYS},
errno::EINVAL,
signal::{
SIG_BLOCK, SIG_DFL, SIG_IGN, SIG_SETMASK, SIG_UNBLOCK, SIGALRM, SIGEV_SIGNAL,
SS_DISABLE, SS_ONSTACK, sigaction, sigevent, siginfo_t, sigval, stack_t, ucontext_t,
},
sys_select::timeval,
time::{itimerspec, timer_internal_t},
},
out::Out,
@@ -109,12 +110,12 @@ impl PalSignal for Sys {
// implement ITIMER_REAL using /scheme/time for interval timers.
// ITIMER_VIRTUAL and ITIMER_PROF are not supported (no CPU time
// tracking). Cross-referenced with Linux 7.1 kernel/time/itimer.c.
use crate::header::sys_time::{ITIMER_REAL, ITIMER_VIRTUAL, ITIMER_PROF};
use crate::header::sys_time::ITIMER_REAL;
if which != ITIMER_REAL {
// ITIMER_VIRTUAL and ITIMER_PROF need per-process CPU time
// accounting which Red Bear does not implement.
return Err(Errno(ENOSYS));
return Err(Errno(EINVAL));
}
// Report old value if requested
@@ -131,28 +132,27 @@ impl PalSignal for Sys {
}
// Use timer_create + timer_settime for ITIMER_REAL
let mut timerid: crate::platform::types::timer_t = 0;
let mut timerid: crate::platform::types::timer_t = core::ptr::null_mut();
let sev = crate::header::signal::sigevent {
sigev_value: crate::header::signal::sigval { sival_int: 0 },
sigev_signo: crate::header::signal::SIGALRM as i32,
sigev_notify: crate::header::signal::SIGEV_SIGNAL,
sigev_notify_function: None,
sigev_notify_attributes: core::ptr::null_mut(),
sigev_notify_thread_id: 0,
};
Sys::timer_create(syscall::CLOCK_MONOTONIC, &sev, Out::from_mut(&mut timerid))?;
Sys::timer_create(syscall::CLOCK_MONOTONIC as clockid_t, &sev, Out::from_mut(&mut timerid))?;
let interval_ns = new.it_interval.tv_sec as i64 * 1_000_000_000
+ new.it_interval.tv_usec as i64 * 1000;
let value_ns = new.it_value.tv_sec as i64 * 1_000_000_000
+ new.it_value.tv_usec as i64 * 1000;
let new_setting = crate::header::time::itimerspec {
it_interval: syscall::TimeSpec { tv_sec: interval_ns / 1_000_000_000, tv_nsec: (interval_ns % 1_000_000_000) as i32 },
it_value: syscall::TimeSpec { tv_sec: value_ns / 1_000_000_000, tv_nsec: (value_ns % 1_000_000_000) as i32 },
let new_setting = itimerspec {
it_interval: timespec { tv_sec: interval_ns / 1_000_000_000, tv_nsec: (interval_ns % 1_000_000_000) as _ },
it_value: timespec { tv_sec: value_ns / 1_000_000_000, tv_nsec: (value_ns % 1_000_000_000) as _ },
};
let mut old_setting = crate::header::time::itimerspec::default();
Sys::timer_settime(timerid, 0, &new_setting, Out::from_mut(&mut old_setting))?;
Sys::timer_settime(timerid, 0, &new_setting, Some(Out::from_mut(&mut old_setting)))?;
Ok(())
}