系统调用时寄存器传参方法

 

 

X86-64下有16个64位寄存器:

其中%rdi、%rsi、%rdx,%rcx、%r8、%r9用作传递函数参数,分别对应第1个参数、第2个参数直到第6个参数

如果函数的参数个数超过6个,则超过的参数直接使用栈来传递。

在被调用函数执行前,会先将寄存器中的参数压入堆栈,之后的访问会通过栈寄存器加上偏移位置来访问

 

Usage during syscall/function call:

  • First six arguments are in rdi, rsi, rdx, rcx, r8d, r9d; remaining arguments are on the stack.
  • For syscalls, the syscall number is in rax.
  • Return value is in rax.
  • The called routine is expected to preserve rsp,rbp, rbx, r12, r13, r14, and r15 but may trample any other registers.

posted on 2017-04-18 16:01  utokyo  阅读(1232)  评论(0编辑  收藏  举报