Syscall from inline asm in x86_64 Linux?

和自甴很熟 提交于 2019-11-30 06:54:58

Why does this print garbage instead of exiting my program gracefully?

Per CESA-2009-001, "Syscall 1 is exit on i386 but write on x86_64".

what would I need to make it work in Linux

Use the syscall ordinals from the current unistd_64.h

Hope this helps!

Syscall 1 is exit on i386 but write on x86-64 I believe.

EDIT: this seems inaccurate: According to the web, which does not seem to have too much information about x86-64 Linux assembly this seems to be the expected register setup before the syscall instruction.

 rax  system call number
 rbx  arg0
 rcx  return address from syscall
 rdx  arg2
 rsi  arg3
 rdi  arg4
 r8   arg5
 r9   arg1    (expected by gcc in %rcx)
 r10-r15  should be saved/restored by C code
 rbp  dito What is dito??
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!