Expand description
Signal delivery to user-space signal handlers
When a signal becomes pending for a process and the signal has a registered handler (not SIG_DFL or SIG_IGN), the kernel must arrange for the handler to execute in user space. This module implements the signal frame construction and restoration mechanism for all three supported architectures (x86_64, AArch64, RISC-V):
-
Delivery (
deliver_signal): Saves the current thread context into a signal frame on the user stack, sets up a trampoline return address that will invokesigreturn, and redirects execution to the signal handler. -
Restoration (
restore_signal_frame): Called fromsys_sigreturnto read the saved signal frame from the user stack, restore registers, and resume execution at the point where the signal interrupted the thread.
§Signal Nesting
Nested signals are supported. When a signal is delivered, the delivered
signal number is added to the process’s blocked signal mask (see
deliver_signal_x86_64 which sets saved_mask | (1 << signum)). This
prevents the same signal from interrupting its own handler. However,
different signals that are not blocked can still be delivered during
handler execution, producing a nested signal frame on the user stack.
Each signal delivery pushes a new frame (with its own saved context and
signal mask) onto the user stack. When the inner handler returns and
sigreturn restores the outer frame, the original signal mask is also
restored, re-enabling the previously blocked signal. This nesting is
bounded only by available user stack space.
Note: SIGKILL (9) and SIGSTOP (19) can never be blocked, caught, or ignored – the mask sanitization enforces this invariant.
Structs§
- Signal
Frame - Saved thread context pushed onto the user stack during signal delivery.
Functions§
- check_
pending_ signals - Check for and deliver any pending signals on the current process/thread.
- deliver_
signal - Deliver a signal to a user-space handler by constructing a signal frame on the user stack.
- restore_
signal_ frame - Restore the original thread context from a signal frame on the user stack.