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.
为什么这个打印垃圾而不是优雅地退出程序?我在BSD使用这种方式调用系统,我想知道我需要什么才能使它在Linux中工作。
int
main(int argc, char **argv)
{
__asm ("movq $1,%rax; movq $0,%rdi; syscall"); /* exit(0) ? */
return 0;
}
Thanks.
谢谢。
2 个解决方案
#1
13
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".
根据CESA-2009-001,“Syscall 1在i386上退出,但在x86_64上写入”。
what would I need to make it work in Linux
我需要什么使它在Linux中工作
Use the syscall ordinals from the current unistd_64.h
使用来自当前unistd_64.h的syscall序号。
Hope this helps!
希望这可以帮助!
#2
3
Syscall 1 is exit on i386 but write on x86-64 I believe.
Syscall 1在i386上退出,但我相信写在x86-64上。
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.
编辑:这似乎不准确:根据web,它似乎没有太多关于x86-64 Linux程序集的信息,这似乎是syscall指令之前预期的注册设置。
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??
#1
13
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".
根据CESA-2009-001,“Syscall 1在i386上退出,但在x86_64上写入”。
what would I need to make it work in Linux
我需要什么使它在Linux中工作
Use the syscall ordinals from the current unistd_64.h
使用来自当前unistd_64.h的syscall序号。
Hope this helps!
希望这可以帮助!
#2
3
Syscall 1 is exit on i386 but write on x86-64 I believe.
Syscall 1在i386上退出,但我相信写在x86-64上。
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.
编辑:这似乎不准确:根据web,它似乎没有太多关于x86-64 Linux程序集的信息,这似乎是syscall指令之前预期的注册设置。
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??