简体   繁体   English

syscall 是 x86_64 上的指令吗?

[英]Is syscall an instruction on x86_64?

I wanted to check the code for performing system calls in glibc.我想检查在 glibc 中执行系统调用的代码。 I found something like this:我发现了这样的事情:

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 questions are:现在我的问题是:

  1. Is syscall (before the cmpq instruction) an instruction? syscall (在cmpq指令之前)是指令吗?
  2. If it is an instruction, what is the meaning of ENTRY (syscall) ?如果是指令,那么ENTRY (syscall)是什么意思? The same name for an ENTRY (I don't know what an ENTRY is) and instruction? ENTRY(我不知道 ENTRY 是什么)和指令的名称相同?
  3. What is L(pseudo_end) ?什么是L(pseudo_end)

syscall is an instruction in x86-64, and is used as part of the ABI for making system calls . syscall是 x86-64 中的指令,用作进行系统调用的 ABI 的一部分。 (The 32-bit ABI uses int 80h or 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.) (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.但是还有一个名为syscall(2)的 C 库函数,它是系统调用 ABI 的通用包装器。 Your code shows the dump of that function, including its decoding of the return value into errno -setting.您的代码显示了该函数的转储,包括将返回值解码为errno设置。 ENTRY(syscall) just means that the function starts there. ENTRY(syscall)只是意味着函数从那里开始。

L() and ENTRY() are CPP macros. L()ENTRY()是 CPP 宏。

L(pseudo_end) is just a Label that can be a jump target. L(pseudo_end)只是一个可以作为跳转目标的标签。 Maybe the code at SYSCALL_ERROR_LABEL jumps 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.也许SYSCALL_ERROR_LABEL处的代码会跳回到那里,尽管该代码块只ret会更有效,所以它可能是以前版本的遗物,或者用于其他用途。

Yes, syscall is an instruction on x86-64.是的, syscall是 x86-64 上的指令。 There is a similar instruction sysenter on i686. i686 上有类似的指令sysenter

ENTRY(syscall) would be a macro. ENTRY(syscall)将是一个宏。 Probably expands to the symbol definition, you have to grep for that.可能会扩展到符号定义,您必须为此使用 grep。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM