【问题标题】:x86 linux system call calling convention?x86 linux系统调用调用约定?
【发布时间】:2014-11-21 18:46:00
【问题描述】:

鉴于此代码:

section     .text
global      _start                              
_start:                                         ;tell linker entry point
    mov     edx,len                            ;message length
    mov     ecx,msg                             ;message to write
    mov     ebx,1                               ;file descriptor (stdout)
##  mov     eax,4                               ;system call number (sys_write)
    int     0x80                                ;call kernel
    mov     eax,1                               ;system call number (sys_exit)
    int     0x80                                ;call kernel

section     .data

msg     db  'Hello, world!',0xa                 ;our dear string
len     equ $ - msg                         ;length of our dear string

内核如何知道msgecx 中,lenedx 中等等?我们不向“内核”传递参数?

【问题讨论】:

    标签: assembly linux-kernel x86 system-calls calling-convention


    【解决方案1】:

    这就是你传递参数的方式。系统调用的调用约定说明了哪些寄存器保存了参数。内核期望它们在那里,你应该把它们放在那里。另见this reference

    虽然通常的 32 位 cdecl 约定使用堆栈来传递参数,但在用户模式下也有类似的约定(特别是 fastcall)也使用寄存器来传递参数。 x86-64 的标准约定也是如此。

    【讨论】:

      猜你喜欢
      • 2012-12-30
      • 1970-01-01
      • 2021-05-11
      • 2018-01-26
      • 1970-01-01
      • 1970-01-01
      • 2012-06-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多