relibc: complete round-9 fixes and repair ifaddrs compilation
Builds ona41c5cb0(round-9 stub replacements) with three enhancements and a critical compilation fix: 1. getrusage (platform/redox/mod.rs): Extended ProcStatFields to parse minflt (field 7) and majflt (field 9) from the kernel proc scheme stat line. These fields are present in the Linux-compatible stat format but currently hardwired to zero by the kernel; relibc now parses and forwards them so they report real values automatically when the kernel starts tracking them. inblock/oublock/nvcsw/nivcsw remain zero (not present in the proc stat line). clock_settime stub (todo_skip!) replaced with real syscall::syscall2(SYS_CLOCK_SETTIME). 2. pthread_condattr_setclock (pthread/cond.rs): Added CLOCK_PROCESS_CPUTIME_ID (value 2, defined in constants.rs) to the accepted clock list alongside CLOCK_REALTIME and CLOCK_MONOTONIC. CLOCK_THREAD_CPUTIME_ID, CLOCK_REALTIME_COARSE, and CLOCK_MONOTONIC_COARSE are not defined on Redox so cannot be accepted. 3. ifaddrs (header/ifaddrs/mod.rs): Fixed 7 pre-existing compilation errors that blocked the entire relibc library from compiling. The module was introduced ind9760bdcbut never compiled: wrong imports (AF_INET from netinet_in instead of sys_socket, sa_family_t from sys_socket instead of bits_safamily_t, nonexistent AF_PACKET), missing Vec import, copy_nonoverlapping direction reversed (copied FROM zeroed sockaddr INTO source data), prefix validation inverted (rejected all valid 0-128 values), IPv6 address bytes never copied into sockaddr_in6, edition-2024 unsafe-block requirements.
This commit is contained in:
@@ -109,12 +109,17 @@ const fn default_rlimits() -> [rlimit; RLIM_COUNT] {
|
||||
|
||||
/// Fields parsed from the kernel proc scheme's Linux-compatible stat line,
|
||||
/// used by `getrusage`. The kernel reports `utime`/`stime` in whole seconds
|
||||
/// and `rss` in pages. Per-process fault and context-switch counters are
|
||||
/// currently hardwired to zero by the kernel proc scheme.
|
||||
/// and `rss` in pages. The kernel currently hardwires fault counters
|
||||
/// (`minflt`/`majflt`) to zero, but relibc parses them so they will be
|
||||
/// reported automatically once the kernel starts tracking real values.
|
||||
/// Context-switch and I/O counters (`inblock`, `oublock`, `nvcsw`,
|
||||
/// `nivcsw`) are not present in the proc stat line at all.
|
||||
struct ProcStatFields {
|
||||
utime_sec: u64,
|
||||
stime_sec: u64,
|
||||
rss_pages: u64,
|
||||
minflt: u64,
|
||||
majflt: u64,
|
||||
}
|
||||
|
||||
/// Read and parse `/scheme/proc/<pid>/stat` from the kernel proc scheme.
|
||||
@@ -156,6 +161,8 @@ fn read_proc_stat_fields(pid: usize) -> Option<ProcStatFields> {
|
||||
utime_sec: parse(11)?,
|
||||
stime_sec: parse(12)?,
|
||||
rss_pages: parse(21).unwrap_or(0),
|
||||
minflt: parse(7).unwrap_or(0),
|
||||
majflt: parse(9).unwrap_or(0),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -324,8 +331,20 @@ impl Pal for Sys {
|
||||
}
|
||||
|
||||
unsafe fn clock_settime(clk_id: clockid_t, tp: *const timespec) -> Result<()> {
|
||||
todo_skip!(0, "clock_settime({}, {:p}): not implemented", clk_id, tp);
|
||||
Err(Errno(ENOSYS))
|
||||
if tp.is_null() {
|
||||
return Err(Errno(EINVAL));
|
||||
}
|
||||
let relibc_ts = unsafe { &*tp };
|
||||
let redox_tp = syscall::TimeSpec {
|
||||
tv_sec: relibc_ts.tv_sec as i64,
|
||||
tv_nsec: relibc_ts.tv_nsec as i64,
|
||||
};
|
||||
syscall::syscall2(
|
||||
syscall::SYS_CLOCK_SETTIME,
|
||||
clk_id as usize,
|
||||
&redox_tp as *const _ as usize,
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn close(fd: c_int) -> Result<()> {
|
||||
@@ -886,6 +905,8 @@ impl Pal for Sys {
|
||||
utime_sec: 0,
|
||||
stime_sec: 0,
|
||||
rss_pages: 0,
|
||||
minflt: 0,
|
||||
majflt: 0,
|
||||
});
|
||||
|
||||
// ru_maxrss is in kilobytes (Linux convention); rss from the stat
|
||||
@@ -905,10 +926,12 @@ impl Pal for Sys {
|
||||
ru_ixrss: 0,
|
||||
ru_idrss: 0,
|
||||
ru_isrss: 0,
|
||||
// The kernel proc scheme hardwires fault counters to zero today.
|
||||
ru_minflt: 0,
|
||||
ru_majflt: 0,
|
||||
ru_minflt: stat.minflt as c_long,
|
||||
ru_majflt: stat.majflt as c_long,
|
||||
ru_nswap: 0,
|
||||
// The proc stat line does not include I/O or context-switch
|
||||
// counters; these require /proc/<pid>/io or /proc/<pid>/status
|
||||
// interfaces that the Redox proc scheme does not expose today.
|
||||
ru_inblock: 0,
|
||||
ru_oublock: 0,
|
||||
ru_msgsnd: 0,
|
||||
|
||||
Reference in New Issue
Block a user