【INT的内核笔记】Linux信号递达过程详解

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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值