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.
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.
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.
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.
- 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
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.
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.
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.
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.