Commit Graph

30 Commits

Author SHA1 Message Date
vasilito dfd687e3cf relibc: P5-robust-mutexes — apply Phase 0e patch
Re-apply P5-robust-mutexes.patch from local/patches/relibc/ to the local fork.
Multi-threading plan Phase 0e.
2026-07-02 07:03:53 +03:00
vasilito d00a02c791 relibc: P3-barrier-smp-futex — apply Phase 0e patch
Re-apply P3-barrier-smp-futex.patch from local/patches/relibc/ to the local fork.
Multi-threading plan Phase 0e.
2026-07-02 07:03:53 +03:00
vasilito 83a5c11e21 relibc: P3-pthread-yield — sched_yield via proc scheme
Re-apply P3-pthread-yield.patch from local/patches/relibc/ to the
local fork. Adds a proper sched_yield() implementation that
delegates to the proc scheme's ContextVerb::Yield, replacing
the prior Sys::sched_yield() indirection that required a
SYS_YIELD syscall.

Multi-threading plan Phase 0e, plan order 1 of 16.
2026-07-02 07:03:41 +03:00
vasilito 6caad3a538 relibc: fix pthread_cond_signal POSIX semantics bug
src/sync/cond.rs:signal() was calling self.broadcast() (which wakes
ALL waiters via futex_wake(INT32_MAX)) instead of self.wake(1) (which
wakes exactly one).

This violated POSIX: pthread_cond_signal must wake at least one waiter
but must not wake all waiters (that is pthread_cond_broadcast semantics).

The pre-existing code also had a commented-out self.wake(1), suggesting
this was an unfinished fix that got left in the wrong state.

Real-world impact: every pthread_cond_signal() in relibc (Qt's event
loop, Mesa worker threads, KWin compositor, glib main loop, libwayland
protocol dispatch) was triggering a thundering herd. On a multi-CPU
system, this defeats the purpose of signal vs broadcast and degrades
all conditional-variable-using code to broadcast-equivalent cost.

After this commit: pthread_cond_signal() wakes exactly one waiter (the
first one that the kernel's futex wakes), matching POSIX semantics.

Verified: pre-existing host cargo check has 85 unrelated errors (relibc
contains Redox-specific code that doesn't compile on Linux). The change
in cond.rs introduces zero new errors. Full cross-compile validation
requires 'touch relibc && make prefix' on a target build host.

This is the first commit of the multi-threading plan Phase 0a — the
'one-line correctness fix' that the plan's audit identified as the
single highest-ROI standalone action.
2026-07-02 06:23:13 +03:00
Red Bear OS a725e6ac8c relibc: guard size_t typedef against C++ name collision
When a C++ translation unit transitively includes this header (e.g.
via <string> pulling in <bits/basic_string.h>), the unqualified
'size_t' references inside libstdc++'s internal templates resolved
to this typedef instead of std::size_t, producing
'unterminated #ifndef' template parse errors during hosted-mode C++
compilation.

Mirror the pattern already used in bits/wchar-t.h: wrap the typedef
in '#ifndef __cplusplus / #endif' so C compilation sees the typedef
and C++ falls back to the libstdc++/libc++-provided std::size_t via
the standard type machinery.
2026-06-29 19:35:07 +03:00
Red Bear OS a31138efe9 fix: document strtold cbindgen trailer (no Rust impl needed)
strtold is declared via cbindgen trailer section as 'long double'.
No Rust implementation required — linker resolves via compat lib.
2026-06-29 02:57:37 +03:00
Red Bear OS 4eabdf2016 relibc: integrate upstream wchar.h include ordering + stdbool.h POSIX fix
Two upstream improvements integrated:

1. wchar.h cbindgen.toml — adopt upstream include ordering:
   - Remove redundant wchar_t redefinition (now provided by bits/wchar-t.h)
   - Define wint_t BEFORE #include <stddef.h> (conflict with GCC __need_wint_t)
   - Drop sys_includes, use no_includes=true (all includes in after_includes)
   - Cleaner circular-dependency breaking (wchar.h → stdio.h → inttypes.h → wchar.h)

2. stdbool.h — fix to POSIX standard:
   - Change 'typedef _Bool bool' to '#define bool _Bool' (C mode)
   - Remove 'typedef bool _Bool' (C++ mode, not in POSIX)
   - Only emit bool/true/false defines in C++ when __cplusplus < 201103L
2026-06-29 01:34:09 +03:00
Red Bear OS 826a984fdb relibc: move stddef header from C to cbindgen (integrate upstream 3be84f4b)
Cherry-pick upstream commit 3be84f4b (auronandace, 2026-06-24):
- Delete hand-written include/stddef.h
- Create src/header/stddef/ with cbindgen.toml + mod.rs
- Create src/header/bits_wchar-t/ with cbindgen.toml + mod.rs
- Create src/header/bits_size-t/ with cbindgen.toml + mod.rs
- Create src/header/bits_null/ with cbindgen.toml + mod.rs
- Update src/header/mod.rs: add bits_* modules, uncomment stddef

The generated stddef.h now includes modular bits_* sub-headers:
  #include <bits/wchar-t.h>  — wchar_t with _WCHAR_T guard + __WCHAR_TYPE__
  #include <bits/size-t.h>   — size_t from Rust usize via cbindgen [export]
  #include <bits/null.h>     — NULL: nullptr (C++11), 0L (C++), (void*)0 (C)

This fixes the wchar_t circular include issue structurally.
2026-06-29 01:28:57 +03:00
Red Bear OS 08cf1e6e0a fix: add wchar_t definition to stddef.h (C mode only, C++ has it as keyword)
POSIX requires stddef.h to define wchar_t. Previously it was missing,
which broke inttypes.h (wcstoimax/strtoimax use wchar_t). Fixed by
adding  guarded by  since
C++ has wchar_t as a built-in keyword.
2026-06-29 01:00:35 +03:00
Red Bear OS 2f320c1ea0 fix: suppress cbindgen stderr warnings (types resolved by C #include chain) 2026-06-28 19:28:59 +03:00
Red Bear OS bae5afa1b4 fix: set no_includes=false in 21 cbindgen.toml for auto type resolution 2026-06-28 19:26:25 +03:00
Red Bear OS ae99d15bfa fix: add missing sys_includes to reduce cbindgen type warnings
- wchar.h: add stddef.h (wint_t/wchar_t), stdarg.h (va_list), stdio.h (FILE)
- ctype.h: add stddef.h (wint_t)
- string.h: add features.h, strings.h
- sys_wait.h: add stdint.h (siginfo_t types)
- sys_socket.h: add sys/un.h (sockaddr_un)
2026-06-28 19:24:17 +03:00
Red Bear OS e25fd20708 fix: define eventfd_t locally instead of re-export (cbindgen cross-module) 2026-06-28 16:21:45 +03:00
Red Bear OS 0c5f21d297 relibc: apply full eventfd implementation from P3 patches
- eventfd(), eventfd_read(), eventfd_write() functions
- uses kernel event scheme at /scheme/event/eventfd/
- eventfd_t type via bits_eventfd + after_includes in cbindgen
- EFD_SEMAPHORE, EFD_CLOEXEC, EFD_NONBLOCK constants
2026-06-28 11:31:27 +03:00
Red Bear OS 2ae6ef9a67 fix: add eventfd_t typedef in trailer for cbindgen 2026-06-28 11:19:01 +03:00
Red Bear OS ba2e6555af relibc: add sys/eventfd.h cbindgen config and eventfd_t type
libwayland and other users need sys/eventfd.h with:
- eventfd_t typedef (uint64_t)
- EFD_SEMAPHORE, EFD_CLOEXEC, EFD_NONBLOCK constants
- eventfd(), eventfd_read(), eventfd_write() prototypes
2026-06-28 10:35:49 +03:00
Red Bear OS c1b8c3b4cf abort: fix unsafe-op-in-unsafe-fn, signal path, unused imports
- abort() body: use signal::sys::SIGABRT (the platform-independent name
  the signal module uses for both linux and redox submodules)
- call sites: wrap abort() in unsafe { } blocks (Rust 2024 edition's
  unsafe_op_in_unsafe_fn lint makes this mandatory inside unsafe fns)
- stdlib/mod.rs, start.rs: drop now-unused 'intrinsics' import
2026-06-28 04:17:35 +03:00
Red Bear OS 4e40dc538c abort: raise(SIGABRT) + _Exit instead of ud2
Previously abort() called core::intrinsics::abort() which compiles to
the ud2 instruction, generating an Invalid Opcode fault. The kernel
logs this as 'UNHANDLED EXCEPTION' and kills the process, but the
fault message is alarming and doesn't reflect the actual intent
(SIGABRT from process self-termination).

This change uses the POSIX-compliant abort sequence: raise(SIGABRT)
first (default handler terminates the process), then _Exit(134) as
fallback if the signal handler returns. Six sites updated:
stdlib abort, assert __assert_fail, lib.rs relibc_panic/oom/_Unwind_Resume,
start.rs relibc_verify_host.

The proc-manager-fallback in redox-rt/src/sys.rs retains
core::intrinsics::abort() — that path is a true 'system unreachable'
last resort where raise/_Exit cannot succeed.
2026-06-28 04:00:30 +03:00
Red Bear OS fc8f0ec4fd Fix sched.h: use style=Both so sched_param has typedef (needed by spawn.h) 2026-06-27 23:53:21 +03:00
Red Bear OS f00e969b82 Fix: remove unnecessary unsafe block for safe sched_setscheduler call 2026-06-27 23:50:21 +03:00
Red Bear OS 3cb57fbc7f Add posix_spawnattr_{get,set}schedpolicy and schedparam functions 2026-06-27 23:45:14 +03:00
Red Bear OS a500cd9e6c Fix spawn.h: use style=Both for typedef-compatible posix_spawn types 2026-06-27 23:34:18 +03:00
Red Bear OS 32e402087f Fix sigaction.sa_flags type: c_int -> c_ulong
nix 0.30.1 expects SaFlags_t = c_ulong for target_os = "redox"
(see nix-0.30.1/src/sys/signal.rs:430). Our relibc had c_int,
causing type mismatch errors in uutils and any nix-dependent crate.
Align with nix's expectation.
2026-06-27 22:26:56 +03:00
Red Bear OS 2cd334a1f9 Fix cpuid unsafe wrapper for Rust 1.98 compatibility
__cpuid is unsafe in Rust 1.92 but safe in 1.98. Wrap with
#[allow(unused_unsafe)] and explicit unsafe block for both versions.
2026-06-27 22:03:51 +03:00
Red Bear OS ae6549251b Implement spawn.h + fix VaList API for Rust 1.98 + signal.h stdint.h
spawn.h: Implement posix_spawn/posix_spawnp with file actions and
spawn attributes (flags, pgroup, sigmask, sigdefault). Uses fork+exec.

signal/cbindgen.toml: Add stdint.h to sys_includes for signalfd_siginfo
fixed-width integer types (uint32_t, int32_t, etc.).

VaList API migration for Rust 1.98.0-dev toolchain:
- VaListImpl merged into VaList (core::ffi::VaList)
- .arg()/.arg::<T>() renamed to .next_arg()/.next_arg::<T>()
- .as_va_list() removed (parameter is already VaList)
- .with_copy() replaced with .clone()
- printf.rs: Fix double-dereference cast for inline VaListInner

redox-rt/signal.rs: Remove unnecessary unsafe around __cpuid (safe in
new nightly).
2026-06-27 21:47:37 +03:00
Red Bear OS 31ee8b3bf9 signal/cbindgen.toml: add stdint.h to sys_includes for signalfd_siginfo types
The signalfd_siginfo struct uses uint32_t, int32_t, uint64_t, uint16_t
which require <stdint.h>. Without it, gnulib-based packages (m4, bison,
flex) fail configure's sigset_t test because signal.h doesn't compile.
2026-06-27 21:10:13 +03:00
Red Bear OS a2e4cd27fe Fix inttypes.h circular include: use stdint.h+stddef.h instead of wchar.h
inttypes.h included wchar.h for wchar_t and stdint.h, but this created
a circular dependency: wchar.h → stdint.h → gnulib inttypes.h →
inttypes.h → wchar.h. When gnulib's wchar.h wrapper was re-entered
during this cycle, wint_t and mbstate_t were not yet defined.

POSIX spec says inttypes.h should include stdint.h directly and
wchar_t comes from stddef.h. Using stdint.h + stddef.h breaks the
circular chain at its source.
2026-06-27 14:31:34 +03:00
Red Bear OS d28963d88e Fix wchar.h circular include: define types before stdio.h
relibc's wchar.h included <stdio.h> before defining wint_t and
mbstate_t. The circular chain wchar.h → stdio.h → inttypes.h →
wchar.h caused gnulib's wchar.h wrapper (used by m4, bison, etc.)
to see 'unknown type name wint_t' and 'unknown type name mbstate_t'.

Fix: Move stdio.h and time.h from sys_includes (which cbindgen
emits before type definitions) into after_includes, after wchar_t,
wint_t, and mbstate_t are defined. Also define mbstate_t manually
in after_includes with a guard, and exclude it from cbindgen export
to prevent duplicate definitions.
2026-06-27 14:22:45 +03:00
Red Bear OS 047e7c09da Add __fseterr and __freadahead to stdio ext (P3-stdio-fseterr patch) 2026-06-27 09:22:51 +03:00
Red Bear OS 1b3e94a20d Red Bear OS relibc baseline
From release 0.1.0 pre-patched archive.
This includes all Red Bear modifications previously maintained
as patches in local/patches/relibc/.
2026-06-27 09:19:26 +03:00