Computer Science 822 Quiz 5 Name_______________________ 1. Which signals is a process NOT allowed to specify a handler for? SIGSTOP SIGKILL 2. Each task struct contains: struct signal_struct *sig; Describe the contents of this table and how it is used in signal processing. The table contains an entry for each signal type. The entries dictate the action to be taken when the signal is received. There are 3 elements to each entry: Handler = user handler, IGNORE, or DEFAULT Mask = signals to be blocked during user handling Flags = special handling options such as do / don't restart interrupted signal calls, or whether or not the handler should be a ONESHOT or reestablished. Two bit maps in the task_struct identify the signals that are presently "pending" and presently "blocked". 3. Describe how a signal becomes "pending" and subsequently "unpending" Pending - Pending bit is set in response to a "kill()" system call. Unpending - Pending is reset collect_signal() called by dequeue_signal() from do_signal() before the signal is actually handled 4. Describe how a signal becomes "blocked" and subsequently "unblocked" Blocked - Signals become blocked while another signal is being handled if they appear in the mask field of the sigaction structure associated with the signal being handled. These are copied into the blocked mask in handle_signal(); Unblocked - Blocked signals are reset in sys_sigreturn() 5. The kill(pid, signal) system call is used to send a signal. For each of the following pid values identify the target process(es) a. -n (!= -1) The process group of process n b. -1 All processes c. 0 No processes (although some front ends (e.g. the kill command use 0 as an alias for the current process group) d. n Process n 6. Signals are actually delivered to the recipient: a. Whenever the recipient enters b. At the time the signal is kernel mode sent c c. Just prior to return to the recipient from kernel mode. 7. A user level signal handler is actually invoked by the kernel via: a. iret (interrupt return) b. a procedure call a c. software interrupt 8. The stack frame for a user level signal handler that is setup by setup_frame() resides: a. on the user stack b. on the kernel stack a c. in some kmalloc'ed memory d. in some malloc'ed user memory 9. When a user level signal handler actually runs, a copy of contents of the processes kernel stack is saved (in the default case): a. on the user stack b. on the kernel stack a c. in some kmalloc'ed memory d. in some malloc'ed user memory 10. Exactly why is it necessary to save the contents of the kernel stack before activating a user signal handler? Signals are always handled after an interrupt has caused the main thread to enter kernel mode and save its context on the kernel stack. The signal handler is allowed to make system calls. In fact, the exit from a signal handler is a system call! Such calls DO reuse the kernel stack and would thus wipe out the user context of the main thread of the process. 11. Describe the user level signal handler return mechanism. When the handler executes the "ret" instruction to exit. IP is popped. The value to be popped has been preset by the kernel to point a sequence of instructions that issues the sys_sigreturn system call. 12. Describe the mechanism used to restart system calls that are interrupted by a signal. The value of EIP associated with the user context and saved on the kernel stack is decremented by 2 (the length of int 0x80). The value to be restored in register EAX is also modified so that it is the value that was in EAX at the time the kernel was originally entered will be restored into register EAX. Thus when the iret occurs the int 0x80 will be the next instruction executed.