为什么忽略SIGTRAP不能与asm一起使用?

编程入门 行业动态 更新时间:2024-10-28 16:30:36
本文介绍了为什么忽略SIGTRAP不能与asm一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正试图忽略SIGTRAP.我有以下概念验证代码:

I'm trying to ignore SIGTRAP. I have the following proof-of-concept code:

#include <signal.h> #include <stdlib.h> int main(){ signal(SIGTRAP, SIG_IGN); write(1, "A", 1); asm("int3"); write(1, "B", 1); return 0; }

运行它时,我希望看到"AB",但是看到

When I run it, I expect to see "AB", but I see

ATrace/breakpoint trap (core dumped)

为什么我的程序尽管忽略了SIGTRAP还是终止了?

Why does my program terminate despite it ignoring SIGTRAP?

推荐答案

根据此站点被阻止/忽略的信号在引发时会在内核代码中自动解除阻止.因此,如果反复发出相同的信号,则不会发生无限循环.相反,至少在Linux内核实现中,应用程序在第二次信号上升时终止.

According to this site a blocked/ignored signal is automatically unblocked inside the kernel code when it is raised. So if the same signal is raised repeatedly, an infinite loop will not happen. Instead the application is terminated on the second signal raise, at least in the Linux kernel implementation.

因此,当使用raise()时,SIGTRAP仅会被升起一次,不会造成任何问题.但是使用asm("int3")时,处理器将重新执行引发信号的指令.围绕此第二次导致进程终止.

So when using raise(), the SIGTRAP will only be raised once, causing no problems. But with asm("int3") the processor will re-execute the instruction which raised the signal. The second time around this causes process termination.

相关的内核源代码(对于旧版2.6.27)在此处(函数force_sig_info):

The relevant kernel source (for the old 2.6.27) is here (function force_sig_info):

939 if (blocked || ignored) { 940 action->sa.sa_handler = SIG_DFL; 941 if (blocked) { 942 sigdelset(&t->blocked, sig); 943 recalc_sigpending_and_wake(t); 944 } 945 }

更多推荐

为什么忽略SIGTRAP不能与asm一起使用?

本文发布于:2023-07-25 16:06:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1210740.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:能与   SIGTRAP   asm

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!