Skip to main content

Module wait

Module wait 

Source
Expand description

Wait-family syscall handlers: waitpid, getpid, getppid.

§Design notes

The blocking loop follows the Aero / Maestro pattern:

loop {
    try_wait_child()       ← O(log n) scan under scheduler lock
    StillRunning → block_current_task()
                            ↑ woken by exit_current_task → wake_task_locked(parent)
}

Lost-wakeup race: if the child exits between try_wait_child returning StillRunning and block_current_task() reaching the scheduler lock, exit_current_task will have already called wake_task_locked(parent), which sets task.wake_pending = true. block_current_task() checks this flag and aborts the block, so the parent re-runs the loop immediately without sleeping.

Signal interruption: after each sleep the pending-signal flag is checked; if a signal is queued the syscall returns -EINTR so userspace can handle it before retrying.

§Plan 9 flavour

sys_waitpid encodes the exit status using the standard Linux W_EXITCODE macro (status << 8), which musl/glibc decode correctly. A separate Plan 9-style Waitmsg structure (pid + exit_code + msg[64]) is written to an optional second output pointer when the caller provides one (via the waitmsg_ptr variant:SYS_PROC_WAIT).

Structs§

Waitmsg
Plan 9-inspired exit message written to userspace by SYS_PROC_WAIT.

Constants§

WNOHANG
Do not block if no child has exited yet.

Functions§

encode_wstatus 🔒
Encode exit_code as a Linux wstatus word: W_EXITCODE(code, 0).
resolve_cow_for_range 🔒
Performs the resolve cow for range operation.
sys_getpid
SYS_PROC_GETPID (308): return the current task’s ID.
sys_getppid
SYS_PROC_GETPPID (309): return the parent task’s ID, or 0 if none.
sys_wait
SYS_PROC_WAIT (311): Plan 9-style wait : any child, writes full Waitmsg.
sys_waitpid
SYS_PROC_WAITPID (310): wait for a child process to exit.
wait_blocking 🔒
Block until a matching child becomes a zombie, checking signals each cycle.
write_decimal 🔒
Write the decimal representation of n into buf, null-terminated.
write_user_with_cow 🔒
Writes user with cow.
write_wstatus 🔒
Write the Linux-encoded wait status to a nullable userspace pointer.