什么是 OpenSolaris 系统调用调用约定 (x86)?

发布于 2024-09-13 10:42:51 字数 306 浏览 1 评论 0原文

什么是 OpenSolaris 系统调用调用约定 (x86)?

Fe 我想用 32 位程序集编写一个程序,在控制台上显示一个字符串。为此,我想使用“write”系统调用(第4号)。 write 的 C 定义是:

ssize_t write(int fildes, const void *buf, size_t nbyte)

哪些寄存器应该保存 fildesbufnbyte 参数?我应该调用哪个中断?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

み青杉依旧 2024-09-20 10:42:51

您可以编写一个调用write的C程序,将其编译为汇编语言(使用-S选项)。然后检查输出以了解编译器如何执行此操作。

编辑:

OpenSolaris libc 是这样做的:

首先,当您调用 write 时,它​​会检查一些内容,然后调用 __write:

pushl  0x10(%ebp)
pushl  0xc(%ebp)
pushl  0x8(%ebp)
call   c2730 <__write>

,然后 __write 看起来像:

<__write>:
call c2735 <__write+0x5>
pop    %edx
mov    $0x4,%eax
mov    %esp,%ecx
add    $0x10,%edx
sysenter
jae    c2751 <__write+0x21>
cmp    $0x5b,%eax
je     c2730 <__write>
jmp    2e0d0 <__cerror>
ret

它将 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:

pushl  0x10(%ebp)
pushl  0xc(%ebp)
pushl  0x8(%ebp)
call   c2730 <__write>

and __write then looks like:

<__write>:
call c2735 <__write+0x5>
pop    %edx
mov    $0x4,%eax
mov    %esp,%ecx
add    $0x10,%edx
sysenter
jae    c2751 <__write+0x21>
cmp    $0x5b,%eax
je     c2730 <__write>
jmp    2e0d0 <__cerror>
ret

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文