Falsification for lane/hvf-spawn-destroy-gone (notes/job-mix/spawn-destroy-gone.md). Restores `user_mode_runtime::yield_now` as it was before 2026-10-05: its own `asm!` block on each architecture, declaring no output register. Expected with this applied: python3 helpers/system_call_asm.py fails, naming the three yield_now blocks script/job-mix --hvf --release --smp 4 refuses with -11 in a spawn job within a minute on patagonia (19 of 20 before the fix), because the spawn job's retry loop again loads DESTROY's arguments before the yield and traps with x0 = 0 after it (Re-cut on 2026-10-12 (UTC) against `crates/user_mode_runtime/src/process.rs`, where `yield_now` moved when the crate root was split; it had stopped applying to `lib.rs` before then.) Apply with `git apply`, revert with `git apply -R`. Only yield_now is restored: it is the wrapper the miscompiled loop crossed, so it is the one whose absence of a declaration this proves matters. diff --git a/crates/user_mode_runtime/src/process.rs b/crates/user_mode_runtime/src/process.rs index 125a93bd6..6846f93aa 100644 --- a/crates/user_mode_runtime/src/process.rs +++ b/crates/user_mode_runtime/src/process.rs @@ -11,14 +11,37 @@ use crate::system_call::trap6; /// Give up the CPU (`SYS_YIELD`). Returns when the scheduler runs this thread again; if another /// thread is ready, control goes there and back, which is one context-switch round trip. -/// -/// Not `nomem`: while this thread is away others write memory it shares with them, which a caller -/// spinning on a shared word with `yield_now` relies on. Through [`trap6`], because the kernel -/// writes its result into `x0`/`a0`/`rdi` on the way out of a yield too. +#[cfg(target_arch = "aarch64")] pub fn yield_now() { - // SAFETY: SYS_YIELD gives up the CPU and comes back; it reads no argument and touches no - // memory of this thread's own. - let _ = unsafe { trap6(abi::SYS_YIELD, [0; 6]) }; + // SAFETY: `svc`; SYS_YIELD gives up the CPU and returns with nothing to clean up. + unsafe { + core::arch::asm!("svc #0", in("x8") abi::SYS_YIELD, options(nostack, nomem)); + } +} + +/// Give up the CPU (RISC-V). `ecall`, `SYS_YIELD` in `a7`. +#[cfg(target_arch = "riscv64")] +pub fn yield_now() { + // SAFETY: `ecall`; SYS_YIELD gives up the CPU and returns with nothing to clean up. + unsafe { + core::arch::asm!("ecall", in("a7") abi::SYS_YIELD, options(nostack, nomem)); + } +} + +/// Give up the CPU (`x86_64`). `syscall`, `SYS_YIELD` in `rax`. `rcx` and `r11` are clobbered by the +/// instruction itself, and `nomem` survives that: neither is memory. +#[cfg(target_arch = "x86_64")] +pub fn yield_now() { + // SAFETY: `system_call`; SYS_YIELD gives up the CPU and returns with nothing to clean up. + unsafe { + core::arch::asm!( + "system call", + in("rax") abi::SYS_YIELD, + lateout("rcx") _, + lateout("r11") _, + options(nostack, nomem), + ); + } } /// Terminate this process. The kernel reaps the thread and frees its whole address space. Never