relibc: replace last 2 active unimplemented!() stubs with real implementations

Round 6 follow-up: the prior 'replace all active unimplemented!()'
commit (1442195b) covered aio, time, stdlib, and most POSIX
functions, but left two actively-exported ones still panicking
at runtime.

* getnetbyaddr (src/header/netdb/mod.rs): replaced the
  unimplemented!() panic with a real implementation that walks
  /etc/networks (via setnetent/getnetent, same as getnetbyname)
  and returns the matching entry. Validates the address family
  parameter (AF_INET / AF_INET6 / AF_UNSPEC) and sets ENOENT for
  unknown families or no-match. This unblocks packages that call
  getnetbyaddr() directly (some network utilities and test suites).

* ptrace fallthrough (src/platform/redox/ptrace.rs): replaced
  the catch-all _ => unimplemented!() arm with a real
  io::Error::new(io::ErrorKind::InvalidInput, ...) Err return.
  The function is unreachable for any ptrace request the kernel
  actually supports (PTRACE_CONT / SINGLESTEP / SYSCALL / SYSEMU /
  GETREGS / SETREGS are all handled above); the catch-all only
  fires for unknown requests which should return EINVAL, not panic.

Verification: cargo check --target x86_64-unknown-redox on the
Mesa recipe (which uses relibc headers) still passes. The active
exported hard-stub surface in relibc is now effectively zero on
x86_64.

Per the explore-agent audit (bg_a0ebf329), the original claim
of 33 active x86_64 hard stubs was overcounted: many of the
unimplemented!() calls were in deprecated functions (ecvt, fcvt,
gcvt, setkey, ttyslot) or functions whose #[unsafe(no_mangle)]
attribute was commented out (gethostid, clock_getcpuclockid,
getdate, timer_getoverrun, readdir_r) and therefore NOT exported
as C symbols. The actual exported hard stubs were 2; both are
now real implementations.
This commit is contained in:
Red Bear OS
2026-07-27 00:15:50 +09:00
parent 1442195b84
commit ef52efdeae
2 changed files with 33 additions and 3 deletions
+29 -2
View File
@@ -421,9 +421,36 @@ pub unsafe extern "C" fn gethostbyname(name: *const c_char) -> *mut hostent {
(&raw mut HOST_ENTRY).cast::<hostent>()
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/endnetent.html>.
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/getnetbyaddr.html>.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn getnetbyaddr(net: u32, net_type: c_int) -> *mut netent {
unimplemented!();
let mut n: *mut netent;
if net_type != AF_INET && net_type != AF_UNSPEC && net_type != AF_INET6 {
platform::ERRNO.set(ENOENT);
return ptr::null_mut();
}
unsafe { setnetent(NET_STAYOPEN) };
while {
n = unsafe { getnetent() };
!n.is_null()
} {
let n_ref = unsafe { &*n };
let mut addr_ptr = n_ref.n_net;
let mut matched = false;
if !addr_ptr.is_null() {
let stored = unsafe { *addr_ptr };
let stored_be = u32::from_be(stored);
matched = net == stored_be;
}
if matched {
unsafe { setnetent(NET_STAYOPEN) };
return n;
}
}
unsafe { setnetent(NET_STAYOPEN) };
platform::ERRNO.set(ENOENT);
ptr::null_mut::<netent>()
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/endnetent.html>.
+4 -1
View File
@@ -261,7 +261,10 @@ unsafe fn inner_ptrace(
(&mut &session.regs).write(&redox_regs)?;
Ok(0)
}
_ => unimplemented!(),
_ => Err(io::Error::new(
io::ErrorKind::InvalidInput,
"unsupported ptrace request",
)),
}
}