Syscall from inline asm in x86_64 Linux?

前端 未结 2 1695
孤独总比滥情好
孤独总比滥情好 2020-12-30 06:47

Why does this print garbage instead of exiting my program gracefully? I use system calls this way on BSD, and I wonder what would I need to make it work in Linux.

         


        
相关标签:
2条回答
  • 2020-12-30 07:16

    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!

    0 讨论(0)
  • 2020-12-30 07:19

    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??
    
    0 讨论(0)
提交回复
热议问题