处理x86_64程序集中的信号

时间:2017-10-08 11:34:38

标签: assembly signals x86-64

我想建立一个基本的信号陷阱。

global _start
%define stdout 1
%define sys_signal 48
%define SIGINT 2
%define SIGSEGV 11

section .text
exit:
    mov eax, 60
    mov rdi, 0
    syscall
catch:
    mov eax, 1
    mov rdi, stdout
    lea rsi, [message]
    mov rdx, 15
    syscall
    jmp exit

_start:
    ; jmp catch
    mov eax, sys_signal
    mov ebx, SIGINT
    mov ecx, catch
    int 80h
loop:
    jmp loop

section .data
    message: db "Signal caught!", 10

按下Control-C会中断程序而不是打印“Signal caught!”的段错误。消息。

以上是this example的简化版本。 (我也不知道传递什么选项来运行该示例。)

这是在使用nasm的linux x86_64上。但我的系统似乎支持int 80h,但理想情况下,我希望syscall执行此操作。

我的问题是:有人可以在不使用C的情况下使用nasm在x86_64上为我提供SIGINT或SIGSEGV信号处理的最小示例吗?

谢谢。

0 个答案:

没有答案