简体   繁体   English

linux x86_64 nasm 程序集系统调用

[英]linux x86_64 nasm assembly syscalls

I have found charts online showing various syscalls for x86_64 linux nasm assembly and there appears to be 380ish total syscalls, however every book or tutorial I can find only "how a few of the syscalls work and what they do?"我在网上找到了一些图表,显示了 x86_64 linux nasm 程序集的各种系统调用,并且系统调用总数似乎为 380 左右,但是每本书或教程我只能找到“一些系统调用如何工作以及它们做什么?” Does anyone know where I can find information on every single syscall for x86_64 linux assembly using the nasm assembler?有谁知道我在哪里可以找到有关使用 nasm 汇编程序的 x86_64 linux 程序集的每个系统调用的信息?

Any help would be great.任何帮助都会很棒。

Look at the Linux man pages (section 2).查看 Linux 手册页(第 2 部分)。 http://man7.org/linux/man-pages/dir_section_2.html http://man7.org/linux/man-pages/dir_section_2.html

It doesn't matter what assembler (or C compiler) you use to create x86-64 machine code, the system calls you can make are the same.无论您使用什么汇编程序(或 C 编译器)来创建 x86-64 机器代码,您可以进行的系统调用都是相同的。 (Put a call number in RAX and run the syscall instruction; inside the kernel it uses that number to index a table of function pointers. Or returns -ENOSYS if it's out of range.) (在 RAX 中放入一个调用号并运行syscall指令;在内核中,它使用该编号来索引函数指针表。如果超出范围,则返回-ENOSYS 。)

Debug your program with strace ./my_program to trace the system calls it makes.使用strace ./my_program调试您的程序以跟踪它进行的系统调用。 This decodes the args and return values into meaningful stuff on a per-call basis, so you can easily see if you passed a bad pointer making the syscall return -EFAULT for example.这会在每次调用的基础上将 args 和返回值解码为有意义的内容,因此您可以轻松查看是否传递了一个错误的指针,使系统调用返回-EFAULT (System calls don't raise SIGSEGV / segfault, they just return an error.) (系统调用不会引发 SIGSEGV / segfault,它们只是返回一个错误。)


/usr/include/asm/unistd_64.h has the actual numbers. /usr/include/asm/unistd_64.h有实际数字。 (Included by <asm/unistd.h> when compiling for 64-bit). (编译 64 位时包含在<asm/unistd.h> )。 The man pages will document the args in terms of C syntax.手册页将根据 C 语法记录参数。 Given the C prototype, you can work out the asm ABI according to the x86-64 System V ABI .给定 C 原型,您可以根据 x86-64 System V ABI 计算出 asm ABI (Same as the function-call ABI except with R10 instead of RCX for the 4th arg, if present.) What are the calling conventions for UNIX & Linux system calls on i386 and x86-64 (与函数调用 ABI 相同,除了第 4 个参数的 R10 而不是 RCX(如果存在)。) i386 和 x86-64 上的 UNIX 和 Linux 系统调用的调用约定是什么

syscall(2) is a glibc wrapper function for system calls, and the syscall man page also documents is asm ABI for various Linux platforms (x86-64, SPARC, ARM, etc.), including registers for the call number and ret val, and the instruction for entering the kernel. syscall(2)是一个用于系统调用的 glibc 包装函数,并且syscall 手册页还记录了各种 Linux 平台(x86-64、SPARC、ARM 等)的 asm ABI,包括调用号和 ret val 的寄存器,以及进入内核的指令。 Note that the function name being the same as the x86-64 syscall instruction is just a coincidence.请注意,函数名称与 x86-64 syscall指令相同只是巧合。


Nobody bothers to make exhaustive documentation for every system call for every different flavour of asm syntax - the information is all there in the man pages plus the calling convention doc;没有人会费心为每种不同风格的 asm 语法的每个系统调用制作详尽的文档——信息都在手册页和调用约定文档中; the NOTES section of the Linux man pages document differences between the C library wrapper API vs. the underlying asm system call. Linux 手册页的 NOTES 部分记录了 C 库包装器 API 与底层 asm 系统调用之间的差异。

See also https://blog.packagecloud.io/eng/2016/04/05/the-definitive-guide-to-linux-system-calls/ for more including VDSO stuff for efficient getpid / clock_gettime without even entering the kernel.另请参阅https://blog.packagecloud.io/eng/2016/04/05/the-definitive-guide-to-linux-system-calls/了解更多包括 VDSO 内容以实现高效getpid / clock_gettime甚至无需进入内核。

However, some people do compile tables of system call name and Linux x86-64 call number and arg registers.但是,有些人确实编译了系统调用名称和 Linux x86-64 调用号和 arg 寄存器的表。 I've never found that useful (the syscall calling convention is so close to the function calling convention that it's easy to remember), but https://blog.rchapman.org/posts/Linux_System_Call_Table_for_x86_64/ is there if you want it.我从来没有发现它很有用(系统调用调用约定非常接近函数调用约定,很容易记住),但是https://blog.rchapman.org/posts/Linux_System_Call_Table_for_x86_64/如果你想要它就在那里。


Notable differences between the POSIX function and the raw Linux system call exist for a couple calls: For example brk / sbrk , and also getpriority where the "nice" level return values are biased so they're not in the -4095..-1 range of error codes. POSIX 函数和原始 Linux 系统调用之间存在显着差异,有几个调用:例如brk / sbrk ,以及getpriority其中“nice”级别的返回值有偏差,因此它们不在-4095..-1错误代码的范围。 But most system calls have an ABI that exactly matches the C library wrapper prototype in which case the NOTES section doesn't mention anything.但是大多数系统调用都有一个与 C 库包装器原型完全匹配的 ABI,在这种情况下,NOTES 部分没有提及任何内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM