什么是 OpenSolaris 系统调用调用约定 (x86)?
什么是 OpenSolaris 系统调用调用约定 (x86)?
Fe 我想用 32 位程序集编写一个程序,在控制台上显示一个字符串。为此,我想使用“write”系统调用(第4号)。 write 的 C 定义是:
ssize_t write(int fildes, const void *buf, size_t nbyte)
哪些寄存器应该保存 fildes、buf 和 nbyte 参数?我应该调用哪个中断?
What is an OpenSolaris syscall calling convention (x86)?
F.e. I'd like to write a program in 32bit assembly which displays a string to the console. For this I'd like to use "write" syscall (no. 4). C definition for write is:
ssize_t write(int fildes, const void *buf, size_t nbyte)
what registers should hold fildes, buf and nbyte arguments? Which interrupt should I call?
您可以编写一个调用
write
的C程序,将其编译为汇编语言(使用-S
选项)。然后检查输出以了解编译器如何执行此操作。编辑:
OpenSolaris libc 是这样做的:
首先,当您调用 write 时,它会检查一些内容,然后调用 __write:
,然后 __write 看起来像:
它将 write 系统调用号放入 eax (4)、堆栈指针中ecx 中的返回地址和 edx 中的返回地址。 write 系统调用的参数已经被压入堆栈。
You could write a C program which calls
write
,compile it to assembly language (use-S
option). And then examine the output to see how the compiler does it.Edit:
OpenSolaris libc does it like this:
First when you call write it check some things and then calls __write:
and __write then looks like:
It puts the write syscall number in eax (4), stack pointer in ecx and the return address in edx. And the arguments to the write syscall have been already pushed on the stack.