为什么打印垃圾而不是优雅地退出我的程序?我在BSD上以这种方式使用系统调用,我想知道在Linux中使用它需要什么。

int
main(int argc, char **argv)
{
    __asm ("movq $1,%rax; movq <*>,%rdi; syscall"); /* exit(0) ? */
    return 0;
}

感谢。

有帮助吗?

解决方案

  

为什么打印垃圾而不是优雅地退出程序?

根据 CESA-2009-001 ,“Syscall 1 is is退出i386但写在x86_64&quot;。

  

我需要什么才能让它在Linux中运行

使用当前 unistd_64.h

希望这有帮助!

其他提示

Syscall 1在i386上退出,但在x86-64上写道我相信。

编辑:这似乎不准确: 根据网站,似乎没有太多关于x86-64 Linux程序集的信息,这似乎是系统调用指令之前的预期寄存器设置。

 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??
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top