Function linux_api::signal::sigaction_restorer

source ·
pub unsafe extern "C" fn sigaction_restorer()
Expand description

Restorer suitable for use with sigaction.

Normally libc’s implementation of the sigaction function injects a similar restorer function.

From sigreturn(2):

If the Linux kernel determines that an unblocked signal is pending for a process, then, at the next transition back to user mode in that process (e.g., upon return from a system call or when the process is rescheduled onto the CPU), it creates a new frame on the user-space stack where it saves various pieces of process context (processor status word, registers, signal mask, and signal stack settings).

The kernel also arranges that, during the transition back to user mode, the signal handler is called, and that, upon return from the handler, control passes to a piece of user-space code com‐ monly called the “signal trampoline”. The signal trampoline code in turn calls sigreturn().

This sigreturn() call undoes everything that was done—changing the process’s signal mask, switching signal stacks (see sigaltstack(2))—in order to invoke the signal handler. Using the informa‐ tion that was earlier saved on the user-space stack sigreturn() restores the process’s signal mask, switches stacks, and restores the process’s context (processor flags and registers, including the stack pointer and instruction pointer), so that the process resumes execution at the point where it was interrupted by the signal.

§Safety

This function is only intended for use as a restorer in sigaction. Do not call this function directly.