Files
RedBear-OS/local/recovered-stashes/relibc--getnetbyaddr+semaphore.patch
T
vasilito 6fc0366abb build system: remove working-tree stashing (data-loss risk); pre-cook CI=1; target-scoped diagnostics
Remove the stash-and-restore machinery entirely. It manipulated the operator's
working tree and had a fatal bug: modern git's 'stash push' does not print the
stash SHA on stdout, so the SHA was never recorded, the stash was never restored,
and with REDBEAR_ALLOW_DIRTY=1 the operator's dirty-fork WIP was silently
stranded in 'git stash list' on every build (base had accumulated 25 strands).
The build now cooks committed HEAD, or the working tree AS-IS under
REDBEAR_ALLOW_DIRTY=1 — it never touches the tree. A read-only startup advisory
surfaces any leftover redbear-build-* strands from the old code.

Recovered the valuable stranded work to local/recovered-stashes/ (netstack
proptest, relibc get_dns_server daemon-path + getnetbyaddr impl); originals
remain in each fork's git stash list. See local/recovered-stashes/README.md.

Also: pre-cook now runs 'repo cook' with CI=1 (matches make live), fixing the
'Entering raw terminal mode ... Inappropriate ioctl' noise; and the failure
diagnostics per-recipe dump is scoped to THIS build's artifacts (mtime >= build
start) so a bare/mini build no longer lists graphical packages left over from a
prior redbear-full build.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-27 12:59:08 +09:00

177 lines
6.4 KiB
Diff

diff --git a/src/header/netdb/mod.rs b/src/header/netdb/mod.rs
index 36681613..9c0804a8 100644
--- a/src/header/netdb/mod.rs
+++ b/src/header/netdb/mod.rs
@@ -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>.
diff --git a/src/header/semaphore/cbindgen.toml b/src/header/semaphore/cbindgen.toml
index 30f09127..bce68ad1 100644
--- a/src/header/semaphore/cbindgen.toml
+++ b/src/header/semaphore/cbindgen.toml
@@ -11,6 +11,9 @@ include_guard = "_RELIBC_SEMAPHORE_H"
after_includes = """
#include <bits/clockid-t.h> // for clockid_t from sys/types.h
#include <bits/timespec.h> // for timespec from time.h
+#include <bits/valist.h> // for va_list from stdarg.h for sem_open variadic args
+
+#define SEM_FAILED ((sem_t *)0)
"""
language = "C"
style = "Type"
diff --git a/src/header/semaphore/mod.rs b/src/header/semaphore/mod.rs
index c8ed7f53..19adea2a 100644
--- a/src/header/semaphore/mod.rs
+++ b/src/header/semaphore/mod.rs
@@ -6,11 +6,12 @@ use crate::{
error::ResultExt,
header::{
errno,
+ fcntl::O_CREAT,
time::{self, timespec},
},
platform::{
self,
- types::{c_char, c_int, c_long, c_uint, clockid_t},
+ types::{c_char, c_int, c_long, c_uint, clockid_t, mode_t},
},
};
@@ -25,9 +26,26 @@ pub union sem_t {
pub type RlctSempahore = crate::sync::Semaphore;
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sem_close.html>.
-// #[unsafe(no_mangle)]
+///
+/// Releases the calling process's reference to the named semaphore indicated
+/// by `sem`. Redox does not yet provide a kernel-backed named-semaphore
+/// facility (no `nsem:` scheme or equivalent), so named semaphores cannot be
+/// created via [`sem_open`]. For an unnamed semaphore this function is a no-op
+/// per POSIX ("If the sem argument refers to an unnamed semaphore, the
+/// sem_close() function shall have no effect").
+///
+/// Upon success, returns `0`. Upon failure, returns `-1` and sets `errno` to
+/// `EINVAL` if `sem` is a null pointer.
+#[unsafe(no_mangle)]
pub unsafe extern "C" fn sem_close(sem: *mut sem_t) -> c_int {
- todo!("named semaphores")
+ if sem.is_null() {
+ platform::ERRNO.set(errno::EINVAL);
+ -1
+ } else {
+ // Named semaphores are unsupported on Redox; for unnamed semaphores
+ // sem_close is defined to be a no-op that returns 0.
+ 0
+ }
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sem_destroy.html>.
@@ -54,13 +72,31 @@ pub unsafe extern "C" fn sem_init(sem: *mut sem_t, _pshared: c_int, value: c_uin
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sem_open.html>.
-// TODO: va_list
-// #[unsafe(no_mangle)]
+///
+/// Creates or opens a named semaphore identified by `name`. A real
+/// implementation requires a kernel-backed facility that Redox does not yet
+/// provide (for example a `nsem:` scheme serving semaphore objects under a
+/// well-known path). Per POSIX, when the implementation does not support
+/// named semaphores the correct response is to fail and set `errno` to
+/// `ENOSYS` rather than panic.
+///
+/// Upon failure, returns [`SEM_FAILED`] (a null pointer) and sets `errno` to
+/// `ENOSYS`. [`SEM_FAILED`] is defined in the generated `semaphore.h`.
+#[unsafe(no_mangle)]
pub unsafe extern "C" fn sem_open(
name: *const c_char,
- oflag: c_int, /* (va_list) value: c_uint */
+ oflag: c_int,
+ mut __valist: ...
) -> *mut sem_t {
- todo!("named semaphores")
+ let _ = name;
+ if oflag & O_CREAT == O_CREAT {
+ // Drain the mandatory `mode` (mode_t) and `value` (unsigned) varargs
+ // so the caller's va_list stays consistent, even though we fail.
+ let _ = unsafe { __valist.next_arg::<mode_t>() };
+ let _ = unsafe { __valist.next_arg::<c_uint>() };
+ }
+ platform::ERRNO.set(errno::ENOSYS);
+ core::ptr::null_mut()
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sem_post.html>.
@@ -83,9 +119,17 @@ pub unsafe extern "C" fn sem_trywait(sem: *mut sem_t) -> c_int {
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sem_unlink.html>.
-// #[unsafe(no_mangle)]
+///
+/// Removes a named semaphore identified by `name`. Like [`sem_open`], this
+/// requires the kernel-backed named-semaphore facility that Redox does not
+/// yet provide. Per POSIX, the correct response is to fail with `ENOSYS`.
+///
+/// Upon failure, returns `-1` and sets `errno` to `ENOSYS`.
+#[unsafe(no_mangle)]
pub unsafe extern "C" fn sem_unlink(name: *const c_char) -> c_int {
- todo!("named semaphores")
+ let _ = name;
+ platform::ERRNO.set(errno::ENOSYS);
+ -1
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/sem_trywait.html>.
diff --git a/src/platform/redox/ptrace.rs b/src/platform/redox/ptrace.rs
index 51cb7646..4ac81a00 100644
--- a/src/platform/redox/ptrace.rs
+++ b/src/platform/redox/ptrace.rs
@@ -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",
+ )),
}
}