Fixed two critical disguised stubs found by comprehensive audit:
1. listen(): updated misleading 'Redox has no need to listen'
comment. TCP sockets enter LISTEN state during bind() via
smoltcp's tcp_handle.listen(), making POSIX listen() a no-op.
The backlog is handled internally via scheme event mechanism.
2. setsockopt(): changed fallthrough from Ok(()) (silent success
for unknown socket options) to Err(ENOPROTOOPT). Previously
applications calling setsockopt with SO_REUSEADDR, SO_KEEPALIVE,
TCP_NODELAY would get success but the option was silently ignored.
Now returns the POSIX-correct error for unsupported options.
Replaced ENOSYS stub with real implementation for ITIMER_REAL.
Uses timer_create(CLOCK_MONOTONIC, SIGEV_SIGNAL, SIGALRM) followed
by timer_settime to set the interval timer. ITIMER_VIRTUAL and
ITIMER_PROF still return ENOSYS (need per-process CPU time
accounting which Red Bear does not implement).
Cross-referenced with Linux 7.1 kernel/time/itimer.c which
implements setitimer via do_setitimer → hrtimer.
This fixes ualarm() and any legacy code that still uses setitimer(2).
Replaced ENOSYS stub with real implementation using
syscall::funmap + syscall::fmap + copy_nonoverlapping.
Algorithm (cross-referenced with Linux 7.1 mm/mremap.c):
1. Same size → no-op
2. Smaller (shrink) → funmap excess pages
3. Larger with MREMAP_MAYMOVE → allocate new anonymous mapping,
copy old data, funmap old mapping
4. Larger without MREMAP_MAYMOVE → ENOMEM (can't grow in place)
This fixes realloc() for large allocations that use mremap
via the platform allocator (platform/allocator/sys.rs).
Replaced ENOSYS stub with real implementation: opens
/scheme/time/{clk_id} for writing and writes the timespec.
Cross-referenced with Linux 7.1 kernel/time/posix-clock.c
pc_clock_settime().
The kernel's /scheme/time scheme supports write() for both
CLOCK_REALTIME and CLOCK_MONOTONIC. Writing a TimeSpec sets
the clock value. Returns EIO if fewer bytes written than
expected.
Previously only SOL_SOCKET and IPPROTO_TCP levels were handled by
the socket scheme. Now IPPROTO_IP and IPPROTO_IPV6 levels also
forward to the socket scheme via SocketCall::GetSockOpt, removing
the ENOSYS fallthrough for these common socket option levels.
Cross-referenced with Linux 7.1 net/ipv4/ip_sockglue.c and
net/ipv6/ipv6_sockglue.c which implement IP/UDP/ICMP level
getsockopt handlers.
Opens /scheme/sys/proc/{pid}/groups for writing, converts
the gid_t array to little-endian u32 bytes, and writes to the
procfs handle. The kernel's Groups writer (proc.rs:1600) reads
the bytes and updates the context's groups list.
Cross-referenced with Linux 7.1 kernel/groups.c setgroups().
Validation:
- size=0, list=NULL: clear all groups (per Linux man page)
- size>0, list=NULL: return EFAULT
- size>NGROUPS_MAX: return EINVAL
- File open/write errors: return EIO/EACCES
gtty(): set errno=ENOTTY instead of silently logging TODO. The
function always fails on Red Bear (no terminal ioctl subsystem).
Modern equivalent is tcgetattr(3) in <termios.h>.
inet_aton(): implement 0xNN (hex) and 0NN (octal) parsing per
Linux man-page inet_aton(3) convention. Mixed hex/octal/decimal
parts are normalized to decimal and fed to inet_pton. Previous
behavior logged TODO and returned 0 for any non-decimal part.
Replaced ENOSYS stub with proper POSIX madvise() implementation
cross-referenced from Linux 7.1 mm/madvise.c.
Flag validation: MADV_NORMAL, RANDOM, SEQUENTIAL, WILLNEED, DONTNEED.
Address must be page-aligned. Unknown flags → EINVAL.
Red Bear has no page cache, swap, or lazy allocation. All MADV_*
flags are no-ops: the hints are advisory and the kernel is free to
ignore them. MADV_DONTNEED would need page table teardown support
which is not implemented.
Replaced ENOSYS stub with proper POSIX msync() implementation
cross-referenced from Linux 7.1 mm/msync.c:42-55.
Flag validation: MS_ASYNC|MS_INVALIDATE|MS_SYNC, rejects unknown
flags and MS_ASYNC|MS_SYNC combination. Address page-aligned check.
Length rounded to page boundary with overflow check.
Red Bear filesystem I/O is synchronous (no writeback cache).
MS_SYNC/MS_ASYNC are no-ops. MS_INVALIDATE not implemented (needs
kernel cache invalidation), but stale cache is not a concern
with direct filesystem reads.
This function is used to set the orientation of a stream to either
byte-oriented or wchar-oriented.
More info on this function is here:
https://man7.org/linux/man-pages/man3/fwide.3p.html
This implementation only impmlemnts the manual switching and does
not yet guard against using a byte-oriented stream with wchar
functions and vice versa. Those step will come in additional
commits.
Signed-off-by: Wren Turkal <wt@penguintechs.org>
As with the previous commit, accept() was calling inner_get_name() and
assuming only "tcp:" or "udp:" addresses would be received. Thus, in
order to support AF_UNIX sockets, inner_get_name() was split into two,
inner_af_inet() and inner_af_unix() - where the former keeps the
previous logic, dealing with "tcp:" and "udp:" addresses, and the latter
deals now with "chan:" addresses and filling in the sockaddr_un
appropriately.
Previously, domain AF_INET was assumed while processing bind() /
connect(), which end up calling bind_or_connect!. Instead, match on the
domain type and process the path for AF_UNIX domains.
To add support for UNIX sockets (AF_UNIX), of SOCK_STREAM type, the
"chan:" scheme is used, which will be supportedby the ipcd running in
userspace.
Later commits add similar AF_UNIX support for the rest of the methods in
impl PalSocket.