1. 什么时候执行信号递达
书上是叫递达的,但我个人比较喜欢叫信号处理吧,毕竟明明就是信号的接收进程处理信号的过程╮(╯▽╰)╭,所以文中可能会多处出现信号处理。
一般在从中断或系统调用返回到用户态前,会执行一段逻辑检查TIF_SIGPENDING位,
如果被置位了的话则会经由:–> do_notify_resume --> do_signal,进入到do_signal执行信号处理。
中断/系统调用返回的大致情况,可以参考下图:
中断返回用户态的相关代码:
/**
*返回用户空间,只需要检查need_resched
*
*可能从中断返回,也可能从系统调用返回。
*/
ENTRY(resume_userspace) #返回用户空间,中断或异常发生时,任务处于用户空间
cli # make sure we don't miss an interrupt
# setting need_resched or sigpending
# between sampling and the iret
movl TI_flags(%ebp), %ecx
andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
# int/exception return?
jne work_pending #还有其它工作要做
jmp restore_all #所有工作都做完,则恢复处理器状态
#恢复处理器状态
restore_all:
RESTORE_ALL
# perform work that needs to be done immediately before resumption
ALIGN
#完成其它工作
work_pending:
testb $_TIF_NEED_RESCHED, %cl #检查是否需要重新调度
jz work_notifysig #不需要重新调度
#需要重新调度
work_resched:
call schedule #调度进程
cli # make sure we don't miss an interrupt
# setting need_resched or sigpending
# between sampling and the iret
movl TI_flags(%ebp), %ecx
/*检查是否还有其它的事要做*/
andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
# than syscall tracing?
jz restore_all #没有其它的事,则恢复处理器状态
testb $_TIF_NEED_RESCHED, %cl
jnz work_resched #如果need_resched再次置位,则继续调度
#VM和信号检测
work_notifysig: # deal with pending signals and
# notify-resume requests
testl $VM_MASK, EFLAGS(%esp) #检查是否是VM模式
movl %esp, %eax
jne work_notifysig_v86 # returning to kernel-space or
# vm8