Executing user-mode handlers

Recall from our discussion in the previous section that do_signal() invokes the handle_signal() routine for delivery of pending signals whose disposition is set to user handler. The user-mode signal handler resides in the process code segment and requires access to the user-mode stack of the process; therefore, the kernel needs to switch to the user-mode stack for executing the signal handler. Successful return from the signal handler requires a switch back to the kernel stack to restore the user context for normal user-mode execution, but such an operation would fail since the kernel stack would no longer contain the user context (struct pt_regs) since it is emptied on each entry of the process from user to kernel mode.

To ensure smooth transition of the process for its normal execution in user mode (on return from the signal handler), handle_signal() moves the user-mode hardware context (struct pt_regs) in the kernel stack into the user-mode stack (struct ucontext) and sets up the handler frame to invoke the _kernel_rt_sigreturn() routine during return; this function copies the hardware context back into the kernel stack and restores the user-mode context for resuming normal execution of the current process.

The following figure depicts the execution of a user-mode signal handler:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.14.1.136