asm 中 syscall 的参考

use*_*739 1 linux assembly x86-64 system-calls

https://www.cs.fsu.edu/~langley/CNT5605/2017-Summer/assembly-example/assembly.html

我看到如下示例。但是我没有找到系统调用的手册。例如,60 表示退出,1 表示写入。是否有所有系统调用的完整手册(包括调用号和参数的含义)?

    global  _start
    section .text

_start:

    ; ssize_t write(int fd, const void *buf, size_t count)
    mov rdi,1           ; fd
    mov rsi,hello_world     ; buffer
    mov rdx,hello_world_size    ; count
    mov rax,1           ; write(2)
    syscall

    ; exit(result)
    mov rdi,0           ; result
    mov rax,60          ; exit(2)
    syscall

hello_world:    db "Hello World!",10
hello_world_size EQU $ - hello_world
Run Code Online (Sandbox Code Playgroud)

Cai*_*ner 5

系统调用是在内核级别(特定于操作系统)为每个 CPU 架构定义的。您提供的代码是 x86_64 程序集,因此这是您的目标 CPU 架构。根据您的示例,您使用的是 Linux 内核。可以在此处找到 Linux 上 x86_64 的本机系统调用的详细列表:https : //filippo.io/linux-syscall-table/

您实际上可以在您的系统上编辑此表以创建您自己的系统调用,但这样做时要非常小心!内核级编程可能非常危险。linux 上的系统调用表存在于 arch/x86/syscalls 目录中,该目录位于存储内核源代码的目录中。

cat /kernel-src/arch/x86/syscalls/syscall_64.tbl
Run Code Online (Sandbox Code Playgroud)

正如@PeterCordes 所提到的,您还可以asm/unistd.h/usr/include/x86_64-linux-gnu/asm/unistd_64.h. 如果您有兴趣,您应该能够在同一目录中找到 x86 调用。