Linux内核中的信号机制??信号处理
作者:网络转载 发布时间:[ 2013/2/25 10:12:12 ] 推荐标签:
下面具体看看sys_sigreturn()的定义:
asmlinkage int sys_sigreturn(struct pt_regs *regs)
{
struct sigframe __user *frame;
sigset_t set;
/* Always make any pending restarted system calls return -EINTR */
current_thread_info()->restart_block.fn = do_no_restart_syscall;
/*
* Since we stacked the signal on a 64-bit boundary,
* then 'sp' should be word aligned here. If it's
* not, then the user is trying to mess with us.
*/
if (regs->ARM_sp & 7)
goto badframe;
frame = (struct sigframe __user *)regs->ARM_sp;
if (!access_ok(VERIFY_READ, frame, sizeof (*frame)))
goto badframe;
if (__get_user(set.sig[0], &frame->sc.oldmask)
|| (_NSIG_WORDS > 1
&& __copy_from_user(&set.sig[1], &frame->extramask,
sizeof(frame->extramask))))
goto badframe;
sigdelsetmask(&set, ~_BLOCKABLE);
spin_lock_irq(¤t->sighand->siglock);
current->blocked = set;
recalc_sigpending();
spin_unlock_irq(¤tt->sighand->siglock);
if (restore_sigcontext(regs, &frame->sc, &frame->aux))
goto badframe;
/* Send SIGTRAP if we're single-stepping */
if (current->ptrace & PT_SINGLESTEP) {
ptrace_cancel_bpt(current);
send_sig(SIGTRAP, current, 1);
}
return regs->ARM_r0;
badframe:
force_sig(SIGSEGV, current);
return 0;
}
这个函数主要调用restore_sigcontext()根据用户态态堆栈上的sigframe备份还原pt_regs。
static int
restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc,
struct aux_sigframe __user *aux)
{
int err = 0;
__get_user_error(regs->ARM_r0, &sc->arm_r0, err);
__get_user_error(regs->ARM_r1, &sc->arm_r1, err);
__get_user_error(regs->ARM_r2, &sc->arm_r2, err);
__get_user_error(regs->ARM_r3, &sc->arm_r3, err);
__get_user_error(regs->ARM_r4, &sc->arm_r4, err);
__get_user_error(regs->ARM_r5, &sc->arm_r5, err);
__get_user_error(regs->ARM_r6, &sc->arm_r6, err);
__get_user_error(regs->ARM_r7, &sc->arm_r7, err);
__get_user_error(regs->ARM_r8, &sc->arm_r8, err);
__get_user_error(regs->ARM_r9, &sc->arm_r9, err);
__get_user_error(regs->ARM_r10, &sc->arm_r10, err);
__get_user_error(regs->ARM_fp, &sc->arm_fp, err);
__get_user_error(regs->ARM_ip, &sc->arm_ip, err);
__get_user_error(regs->ARM_sp, &sc->arm_sp, err);
__get_user_error(regs->ARM_lr, &sc->arm_lr, err);
__get_user_error(regs->ARM_pc, &sc->arm_pc, err);
__get_user_error(regs->ARM_cpsr, &sc->arm_cpsr, err);
err |= !valid_user_regs(regs);
#ifdef CONFIG_IWMMXT
if (err == 0 && test_thread_flag(TIF_USING_IWMMXT))
err |= restore_iwmmxt_context(&aux->iwmmxt);
#endif
#ifdef CONFIG_VFP
// if (err == 0)
// err |= vfp_restore_state(&aux->vfp);
#endif
return err;
}
restore_sigcontext()很简单,当它返回后,通过sys_sigreturn()在内核态堆栈建立的pt_regs已经变为调用信号处理函数之前的pt_regs。这样,sys_sigreturn()返回用户态时,顺利地过渡到处理之前的状态了。
相关推荐
更新发布
功能测试和接口测试的区别
2023/3/23 14:23:39如何写好测试用例文档
2023/3/22 16:17:39常用的选择回归测试的方式有哪些?
2022/6/14 16:14:27测试流程中需要重点把关几个过程?
2021/10/18 15:37:44性能测试的七种方法
2021/9/17 15:19:29全链路压测优化思路
2021/9/14 15:42:25性能测试流程浅谈
2021/5/28 17:25:47常见的APP性能测试指标
2021/5/8 17:01:11