写入系统调用参数寄存器
Write System Call Argument Registers
我有一段汇编代码通过
执行write system call(正确吗?)
call write@plt
这样做之前,rax
、地址rsp
、edi
、rsi
和rdx
的值为set/modified。
我怎么知道哪些寄存器通常用作写入或系统函数调用的参数?
我的猜测是,对于写入,它是 rsp
、edi
和 rsi
,因为在 C
中它需要 3 个参数:
ssize_t write(int fd, const void *buf, size_t nbytes);
当你 call write@plt
时,你不会 直接 调用 write(2) 系统调用,而是围绕它的一个小包装器(一个小的 C 函数系统调用并在失败时设置 errno
)。
所以这个 write
函数使用的是标准 C calling convention, defined in the ABI (application binary interface). For Linux x86-64 read the SysV ABI interface for x86-64
另请阅读 vdso(7) to find out a bit more about how some syscalls are actually done. Others might use the SYSENTER
machine instruction, etc... Some details are given in the ABI spec (stricto sensu, the real syscall is not using any stack and passes arguments & results thru registers). Read also the Linux Assembly HowTo(更侧重于 32 位 x86)。
此外,C standard libraries for Linux are free software, generally GNU glibc or perhaps musl-libc,等等...因此请研究他们的源代码以了解 write
的具体实现方式。
我有一段汇编代码通过
执行write system call(正确吗?)call write@plt
这样做之前,rax
、地址rsp
、edi
、rsi
和rdx
的值为set/modified。
我怎么知道哪些寄存器通常用作写入或系统函数调用的参数?
我的猜测是,对于写入,它是 rsp
、edi
和 rsi
,因为在 C
中它需要 3 个参数:
ssize_t write(int fd, const void *buf, size_t nbytes);
当你 call write@plt
时,你不会 直接 调用 write(2) 系统调用,而是围绕它的一个小包装器(一个小的 C 函数系统调用并在失败时设置 errno
)。
所以这个 write
函数使用的是标准 C calling convention, defined in the ABI (application binary interface). For Linux x86-64 read the SysV ABI interface for x86-64
另请阅读 vdso(7) to find out a bit more about how some syscalls are actually done. Others might use the SYSENTER
machine instruction, etc... Some details are given in the ABI spec (stricto sensu, the real syscall is not using any stack and passes arguments & results thru registers). Read also the Linux Assembly HowTo(更侧重于 32 位 x86)。
此外,C standard libraries for Linux are free software, generally GNU glibc or perhaps musl-libc,等等...因此请研究他们的源代码以了解 write
的具体实现方式。