asm中系统调用的引用
reference of syscall in asm
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
系统调用是在内核级别(OS 特定的)为每个 CPU 体系结构定义的。您提供的代码是 x86_64 程序集,因此这是您的目标 CPU 体系结构。根据您的示例,您使用的是 Linux 内核。 Linux 上 x86_64 的本机系统调用的详细列表可在此处找到:https://filippo.io/linux-syscall-table/
您实际上可以在您的系统上编辑此 table 以创建您自己的系统调用,但这样做时要非常小心!内核级编程可能非常危险。 linux 上的系统调用 table 存在于 arch/x86/syscalls 目录中,该目录位于存储内核源代码的目录中。
cat /kernel-src/arch/x86/syscalls/syscall_64.tbl
如@PeterCordes 所述,您还可以在 asm/unistd.h
中找到您机器上的系统调用编号,在我的机器中,它是在 /usr/include/x86_64-linux-gnu/asm/unistd_64.h
中找到的。如果您有兴趣,您应该能够在同一目录中找到 x86 调用。
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
系统调用是在内核级别(OS 特定的)为每个 CPU 体系结构定义的。您提供的代码是 x86_64 程序集,因此这是您的目标 CPU 体系结构。根据您的示例,您使用的是 Linux 内核。 Linux 上 x86_64 的本机系统调用的详细列表可在此处找到:https://filippo.io/linux-syscall-table/
您实际上可以在您的系统上编辑此 table 以创建您自己的系统调用,但这样做时要非常小心!内核级编程可能非常危险。 linux 上的系统调用 table 存在于 arch/x86/syscalls 目录中,该目录位于存储内核源代码的目录中。
cat /kernel-src/arch/x86/syscalls/syscall_64.tbl
如@PeterCordes 所述,您还可以在 asm/unistd.h
中找到您机器上的系统调用编号,在我的机器中,它是在 /usr/include/x86_64-linux-gnu/asm/unistd_64.h
中找到的。如果您有兴趣,您应该能够在同一目录中找到 x86 调用。