Linux syscall 是 x86_64 上的指令吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10583891/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 06:18:39  来源:igfitidea点击:

Is syscall an instruction on x86_64?

clinuxgccx86-64machine-instruction

提问by pythonic

I wanted to check the code for performing system calls in glibc. I found something like this.

我想检查在 glibc 中执行系统调用的代码。我发现了这样的东西。

ENTRY (syscall)
    movq %rdi, %rax     /* Syscall number -> rax.  */
    movq %rsi, %rdi     /* shift arg1 - arg5.  */
    movq %rdx, %rsi
    movq %rcx, %rdx
    movq %r8, %r10
    movq %r9, %r8
    movq 8(%rsp),%r9    /* arg6 is on the stack.  */
    syscall         /* Do the system call.  */
    cmpq $-4095, %rax   /* Check %rax for error.  */
    jae SYSCALL_ERROR_LABEL /* Jump to error handler if error.  */
L(pseudo_end):
    ret         /* Return to caller.  */

Now my question is if the syscall (before the cmpqinstruction) is an instruction? Secondly, if it is an instruction, what is the meaning of ENTRY (syscall)? The same name for an ENTRY (I don't know what an ENTRY is) and instruction? Secondly, what is L(pseudo_end)?

现在我的问题是系统调用(在cmpq指令之前)是否是一条指令?其次,如果是指令,ENTRY(系统调用)是什么意思?条目(我不知道条目是什么)和指令的名称相同?其次,什么是L(pseudo_end)?

回答by jpalecek

Yes, syscallis an instruction on x86-64. There is a similar instruction sysenteron i686.

是的,syscall是关于 x86-64 的指令。sysenteri686 上也有类似的说明。

ENTRY(syscall)would be a macro. Probably expands to the symbol definition, you have to grep for that.

ENTRY(syscall)将是一个宏。可能会扩展到符号定义,您必须为此进行 grep。

回答by flolo

syscallis an instruction in x86-64, and is used as part of the ABI for making system calls. (The 32-bit ABI uses int 80hor sysenter, and is also available in 64-bit mode, but using the 32-bit ABI from 64-bit code is a bad idea, especially for calls with pointer arguments.)

syscall是 x86-64 中的一条指令,用作进行系统调用ABI 的一部分。(32 位 ABI 使用int 80hsysenter,并且也可以在 64 位模式下使用,但是从 64 位代码使用 32 位 ABI 是一个坏主意,尤其是对于带有指针参数的调用。)

But there is also a C library function named syscall(2), a generic wrapper for the system-call ABI. Your code shows the dump of that function, including its decoding of the return value into errno-setting. ENTRY(syscall)just means that the function starts there.

但是还有一个名为syscall(2)C 库函数,它是系统调用 ABI 的通用包装器。您的代码显示了该函数的转储,包括将返回值解码为errno-setting。ENTRY(syscall)只是意味着该功能从那里开始。

L()and ENTRY()are CPP macros.

L()ENTRY()是 CPP 宏。

L(pseudo_end)is just a Label that can be a jump target. Maybe the code at SYSCALL_ERROR_LABELjumps back to there, although it would be more efficient for that block of code to just ret, so maybe it's a relic from a former version, or used for something else.

L(pseudo_end)只是一个可以作为跳转目标的标签。也许 at 的代码会SYSCALL_ERROR_LABEL跳回到那里,尽管将该代码块改为 just 会更有效ret,所以它可能是以前版本的遗物,或者用于其他东西。