Commit Graph

1585 Commits

Author SHA1 Message Date
Red Bear OS 0b5d0aca97 fix(netdb): use relibc types in freeaddrinfo fallback 2026-07-08 21:29:56 +03:00
Red Bear OS 277944a91c relibc: implement gethostid() — uncomment and add real implementation
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.
2026-07-08 21:24:40 +03:00
Red Bear OS a3981d1d7f fix(netdb): remove stray closing brace in freeaddrinfo 2026-07-08 21:21:04 +03:00
Red Bear OS 285eedfab8 relibc: fix freeaddrinfo memory leak for unknown address lengths
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.
2026-07-08 21:15:31 +03:00
Red Bear OS f704b67f25 build(relibc): remove check_against_libc_crate from default features; fix cond import
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.
2026-07-08 20:03:25 +03:00
Red Bear OS 202e3eb500 relibc: implement pthread_cond_init with monotonic clock
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.
2026-07-08 19:58:46 +03:00
Red Bear OS 68d43106eb fix(pthread_mutex): store prioceiling in u8 to keep 12-byte layout matching libc crate 2026-07-08 19:54:05 +03:00
Red Bear OS 7f42a9fb20 relibc: implement pthread mutex prioceiling get/replace
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.
2026-07-08 19:46:46 +03:00
Red Bear OS 2347017649 fix(pthread_mutex): add missing prioceiling_value field for mutex priority ceiling 2026-07-08 19:44:19 +03:00
Red Bear OS 6c56264396 fix(socket): avoid casts in match patterns for IPPROTO_IP/IPPROTO_IPV6 2026-07-08 19:39:11 +03:00
Red Bear OS 93afedade5 relibc: extend getsockopt to handle IPPROTO_IP and IPPROTO_IPV6
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.
2026-07-08 19:24:43 +03:00
Red Bear OS 5638058b48 relibc: fix setgroups and unused ENOSYS import 2026-07-08 18:45:05 +03:00
Red Bear OS 5c8fe1c51a relibc: implement setgroups() via kernel proc Groups handle
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
2026-07-08 18:40:06 +03:00
Red Bear OS e90086dc67 relibc: implement gtty() and inet_aton() hex/octal parsing
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.
2026-07-08 18:30:51 +03:00
Red Bear OS 871078c4d9 relibc: implement vswprintf() — wide-char printf to string
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.
2026-07-08 18:25:33 +03:00
Red Bear OS 3b28c27e00 relibc: implement wcsxfrm() — identity transformation
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)
2026-07-08 18:15:21 +03:00
Red Bear OS 8d8c9c9bfd relibc: implement wcsftime() — remove todo_skip stub
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.
2026-07-08 18:14:05 +03:00
Red Bear OS 01807f6fa7 relibc: implement madvise() — remove ENOSYS stub
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.
2026-07-08 18:00:15 +03:00
Red Bear OS fc158b3611 relibc: implement msync() — remove ENOSYS stub
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.
2026-07-08 17:58:47 +03:00
Red Bear OS c1e4c1d53d relibc: use /scheme/proc/{pid}/ctx for ptrace GETREGS/SETREGS 2026-07-08 17:58:11 +03:00
Red Bear OS 628d5c2a51 0.3.0: add dual-toolchain VaList ABI probe and macros (relibc check passes) 2026-07-06 20:33:17 +03:00
vasilito 5004e94d1d 0.3.0: fix relibc build for Rust 2024 + VaList API (cargo check passes) 2026-07-06 19:37:02 +03:00
vasilito 4ef7e57571 0.3.0: converge relibc to upstream 0.6.0 + Red Bear patches 2026-07-06 19:13:57 +03:00
Jeremy Soller 1a0edd8eeb Add program_invocation_short_name 2020-12-23 20:24:04 -07:00
Jeremy Soller 2f3987dd88 Add _SC_GETPW_R_SIZE_MAX 2020-12-23 19:47:53 -07:00
Jeremy Soller d1ee653b5c Add dirfd 2020-12-23 19:47:44 -07:00
Jeremy Soller 928b18b306 Add sysexits.h 2020-12-23 13:45:25 -07:00
Jeremy Soller 5ae7b7efe7 Use new semaphore to prevent spinning 2020-12-23 12:20:19 -07:00
Jeremy Soller 2f69f0e7f1 Add simple semaphore implementation using futex 2020-12-23 12:18:17 -07:00
Jeremy Soller 79452dbd80 Remove warnings in elf.h 2020-12-23 12:18:02 -07:00
Jeremy Soller bddd69d0c1 Print when abort is called 2020-12-23 11:20:07 -07:00
Jeremy Soller 5efaffe0f9 Ensure that nul test is passed after last commit and failed before 2020-12-23 08:25:44 -07:00
Jeremy Soller 94a6da9116 Fix lookahead buffer reading nul's 2020-12-23 08:20:11 -07:00
Jeremy Soller 07ec3b6591 Merge branch 'mk-subs' into 'master'
Add submodules target to main makefile

See merge request redox-os/relibc!323
2020-10-18 19:48:03 +00:00
hasheddan e5539a570f Add submodules target to main makefile
Adds a submodules convenience target to main makefile. Submodules must
be initialized before other targets can run successfully.

Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
2020-10-18 13:45:29 -05:00
Jeremy Soller 9529e09568 Force overwrite of libc.so.6 if it exists 2020-10-06 11:12:42 -06:00
Jeremy Soller 29e2f29231 Merge branch 'fmt' into 'master'
Fix formatiing issues

See merge request redox-os/relibc!316
2020-10-02 03:22:42 +00:00
Jeremy Soller 3e49323a3a Merge branch 'dlopen' into 'master'
Add support for dlopen(NULL, ...)

See merge request redox-os/relibc!315
2020-10-02 03:21:42 +00:00
Jeremy Soller 21e72cafc6 Merge branch 'tls' into 'master'
Fix tls tests for dynamic linker

See merge request redox-os/relibc!317
2020-10-02 03:20:50 +00:00
Mateusz Tabaka eee9a80baa Fix tls tests for dynamic linker
* load TLS segment for executable - while we can skip PT_LOAD for executable,
  we still have to load TLS segment.
* set TCB address based on if elf is position independent
2020-10-01 15:45:55 +02:00
Mateusz Tabaka 79643c293b Fix formatiing issues 2020-09-30 11:40:38 +02:00
Mateusz Tabaka c11aad71b8 Add support for dlopen(NULL, ...) 2020-09-30 11:04:10 +02:00
Jeremy Soller 687f4d4923 Merge branch 'dynamic' into 'master'
Add tests for ld_so

See merge request redox-os/relibc!314
2020-09-30 00:42:45 +00:00
Mateusz Tabaka 675101ac0e Add tests for dynamic linker 2020-09-29 23:01:52 +02:00
Mateusz Tabaka 7829a7ade9 Add support for RUNPATH 2020-09-29 23:01:48 +02:00
Mateusz Tabaka 58cc9efbc0 Call pthread_init in libc's init_array 2020-09-29 19:20:24 +02:00
Mateusz Tabaka 42acd32ac0 Fix TCB master address 2020-09-29 19:15:21 +02:00
Mateusz Tabaka b05d8df5f8 Restore previous load address for ld_so
Current value gives us 0x1234000 - 0x400000 ~ 14 MB for executable,
which is too low for certain programs.
2020-09-29 18:58:35 +02:00
Mateusz Tabaka c000373a08 Add symlink from libc.so to libc.so.6
Typically it's the other way around, but we can't have shared library named libc.so.6 in target/release directory.
cargo includes 'target/release' in LD_LIBRARY_PATH for build script, so even if clean build runs fine,
every subsquent run will make build script link with relibc.
2020-09-29 00:08:11 +02:00
Jeremy Soller 2c6114be75 Merge branch 'asctime-ub-asserts' into 'master'
Catch UB in asctime_r()

See merge request redox-os/relibc!312
2020-09-17 23:19:08 +00:00