Previously returned 0 unconditionally, breaking ELF programs that
rely on the auxiliary vector. Now returns real values for the
most common entries:
- AT_PAGESZ: actual page size (typically 4096)
- AT_CLKTCK: standard POSIX clock tick (100)
- AT_PLATFORM: 0 (string address — not yet supported)
- AT_NULL/AT_IGNORE: 0 (terminator/ignore)
Cross-referenced with Linux 7.1 fs/binfmt_elf.c create_elf_tables().
getpagesize() and dynamic linker initialization now work correctly.
Implements the three POSIX pseudoterminal functions required by
upstream getty commit 2834434 and other callers that use the
standard C API.
- grantpt(fd): no-op on Redox. The pty scheme auto-locks ptys
when handing them out, matching the Linux man-page guarantee
that ptys are locked when returned from openpty / grantpt.
- unlockpt(fd): no-op on Redox. Same rationale as grantpt.
- ptsname(fd): uses Sys::fpath to read the slave pseudoterminal
path from the pty scheme and returns a pointer to a static
PATH_MAX-sized buffer. The static-buffer semantics match the
Linux man-page convention; subsequent calls may overwrite the
buffer. Returns NULL on error (fpath failure).
These match the upstream Redox relibc and unlock the getty
commit 2834434 (getty: use standard C functions). Reference:
Linux 7.x man-pages/man3/{grantpt,unlockpt,ptsname}.3.html and
drivers/tty/pty.c.
Previously nice() was commented out with #[unsafe(no_mangle)]
disabled. Now exported and implemented:
1. Get current nice value via getpriority(PRIO_PROCESS, 0)
2. Add incr, clamp to [0, 39] (NZERO range)
3. Set via setpriority(PRIO_PROCESS, 0, new_value)
4. Return the new nice value
Cross-referenced with Linux 7.1 kernel/sched/core.c:set_one_prio()
and glibc posix/nice.c.
Previously gethostid() was commented out with #[unsafe(no_mangle)]
disabled. Now exported and implemented with three-tier fallback:
1. Read /etc/hostid file (hex value) if present
2. Compute djb2 hash from uname fields (nodename + sysname + machine)
3. Fallback to getrandom bytes
This is the standard glibc/BSD behavior. Cross-referenced with
glibc sysdeps/unix/gethostid.c.
Previously when getaddrinfo returned an addrinfo with an
ai_addrlen that didn't match sockaddr_in or sockaddr_in6, the
allocation was leaked (the function logged a TODO and returned
without freeing the address).
Now handles:
- sockaddr_un (Unix domain socket addresses)
- ai_addrlen=0 (no address to free)
- Unknown sizes (free as raw allocation to prevent leak)
The raw dealloc uses the address length as the size with
sa_family_t alignment, which is sufficient for any address
family's alignment requirements.
The libc crate's pthread type layouts do not match Redox's relibc
layouts (e.g. pthread_cond_t 8 vs 12 bytes). Redox is its own libc,
so comparing against a foreign Linux libc crate is not meaningful.
Disable the feature by default and keep relibc types internally
consistent via assert_equal_size! checks against our own Rlct* types.
Added clock: u8 field to Cond struct that stores the clock
setting (CLOCK_REALTIME or CLOCK_MONOTONIC) per pthread_condattr.
pthread_cond_init now properly sets the clock attribute.
timedwait uses the stored clock instead of hardcoding CLOCK_REALTIME.
Previously pthread_cond_init with CLOCK_MONOTONIC would log TODO
and use the wrong clock, causing condition variable timeouts to
behave incorrectly.
pthread_cond_t size updated from 8 to 12 bytes to accommodate
the new field. Cross-referenced with POSIX pthread_cond_init(3)
and Linux glibc nptl pthread_cond_init.c.
Added prioceiling: c_int field to RlctMutex struct and real
implementations for prioceiling() and replace_prioceiling()
methods. Previously both returned Ok(0) silently (worse than
ENOSYS - caller believes operation succeeded).
pthread_mutex_t size updated from 12 to 16 bytes to accommodate
the new field while maintaining ABI alignment via #[repr(C)]
union with c_int alignment.
Cross-referenced with POSIX pthread_mutex_getprioceiling(3) and
Linux glibc nptl pthread_mutex_getprioceiling.c.
The prioceiling is stored in the mutex struct, set at construction
from pthread_mutexattr_getprioceiling. getprioceiling returns
the stored value; replace_prioceiling updates it and returns the
old value.
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 todo_skip stub with vswprintf() that writes to a wchar_t buffer.
WcharWriter implements relibc's io::Write trait: each input byte
is written as a wchar_t to the output buffer. The wprintf::wprintf
function handles all format parsing; the writer adapter captures
the output. This matches the POSIX spec: wchar_t output array.
Note: output is byte-by-byte cast to wchar_t, not full UTF-16/UTF-32
encoding. This is a known limitation of the current wprintf pipeline
which outputs UTF-8 bytes even in Wide mode.
Replaced todo_skip stub with proper wcsxfrm() implementation.
The wide-char string transformation uses the current locale's
collation. Red Bear has no locale support, so the transformation
is the identity (same as C/POSIX locale). Cross-referenced with
Linux 7.1 time/wcsxfrm.c.
Behavior:
- n=0: count length of ws2 (excluding null terminator)
- n>0: copy ws2 to ws1 with null terminator, cap at n-1 chars
- Returns number of wide chars written (excluding null terminator)
Implemented wcsftime() as wide-char variant of strftime.
Cross-referenced from Linux 7.1 time/wcsftime.c.
Algorithm: convert wchar format to UTF-8 byte string (non-ASCII
chars replaced with '?'), call strftime::strftime with byte format
to format into a byte buffer, then convert each output byte to
a wchar_t in the output buffer (maxsize-1 chars + null terminator).
Also exposed time::strftime module as pub for cross-module access.
It seams that stdout of ld.so is not that much of an issue but actually
it unfortunately is. The major problem here is that sometimes programs
generate header files in stdout (./getmy_custom_headers > header.h) and
we need to keep that cleen. and this is very very popular in gcc.
struct flock is posix defined locking mechanism on *nix platform
Example usage (copied from https://gavv.github.io/articles/file-locks/) :
#include <fcntl.h>
struct flock fl;
memset(&fl, 0, sizeof(fl));
// lock in shared mode
fl.l_type = F_RDLCK;
// lock entire file
fl.l_whence = SEEK_SET; // offset base is start of the file
fl.l_start = 0; // starting offset is zero
fl.l_len = 0; // len is zero, which is a special value representing end
// of file (no matter how large the file grows in future)
fl.l_pid = 0; // F_SETLK(W) ignores it; F_OFD_SETLK(W) requires it to be zero
// F_SETLKW specifies blocking mode
if (fcntl(fd, F_SETLKW, &fl) == -1) {
exit(1);
}
// atomically upgrade shared lock to exclusive lock, but only
// for bytes in range [10; 15)
//
// after this call, the process will hold three lock regions:
// [0; 10) - shared lock
// [10; 15) - exclusive lock
// [15; SEEK_END) - shared lock
fl.l_type = F_WRLCK;
fl.l_start = 10;
fl.l_len = 5;
// F_SETLKW specifies non-blocking mode
if (fcntl(fd, F_SETLK, &fl) == -1) {
exit(1);
}
// release lock for bytes in range [10; 15)
fl.l_type = F_UNLCK;
if (fcntl(fd, F_SETLK, &fl) == -1) {
exit(1);
}
// close file and release locks for all regions
// remember that locks are released when process calls close()
// on any descriptor for a lock file
close(fd);
When a byte-oriented stream function touches a stream, that stream
should be set to byte-oriented mode if it hasn't been set yet. If
it has been set, the opertion should only succeed if the stream is
already in byte-oriented mode.
Signed-off-by: Wren Turkal <wt@penguintechs.org>
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>