gpt4 book ai didi

linux - 在 Linux 的系统调用上下文中,EAX 寄存器有什么用?

转载 作者:太空狗 更新时间:2023-10-29 12:09:59 26 4
gpt4 key购买 nike

课本中Linux Kernel Development by Robert Love , 提到 (pg no. 101):

The return value is sent to user-space also via register. On x86, it is written into the eax register.

并在课本中The Linux Programming Interface by Michael Kerrisk , 提到 (pg no. 88):

Since all system calls enter the kernel in the same way, the kernel needs some method of identifying the system call. To permit this, the wrapper function copies the system call number into a specific CPU register (%eax).

那么,我可以从 EAX 寄存器在系统调用中的效用得出什么结论?

当内核遇到系统调用时,它会将系统调用号复制到 EAX 寄存器,在系统调用返回时,寄存器中的值将被系统调用的返回值替换。这个结论正确吗?

最佳答案

X86 Assembly/Interfacing with Linux

Making a syscall

For making a syscall using an interrupt, you have to pass all required information to the kernel by copying them into general purpose registers.

Each syscall has a fixed number (note: the numbers differ between int
$0x80
and syscall!). You specify the syscall by writing the number into the eax/rax register.

Most syscalls take parameters to perform their task. Those parameters are passed by writing them in the appropriate registers before making the actual call. Each parameter index has a specific register. See the tables in the subsections as the mapping differs between int $0x80 and syscall. Parameters are passed in the order they appear in the function signature of the corresponding C wrapper function. You may find syscall functions and their signatures in every Linux API documentation, like the reference manual (type man 2 open to see the signature of the open syscall).

After everything is set up correctly, you call the interrupt using int $0x80 or syscall and the kernel performs the task.

The return / error value of a syscall is written to eax/rax.

The kernel uses its own stack to perform the actions. The user stack is not touched in any way.

总结一下:

在用户空间:

  • 通过将参数写入指定的寄存器来准备系统调用
  • 将系统调用号放入eax
  • 通过 int $0x80syscall 调用中断

在内核空间:

  • 内核从eax读取系统调用号
  • 从特定寄存器中读取参数
  • 执行任务(在它自己的堆栈上)
  • 将结果写入eax
  • 将控制权交还给用户空间

再次在用户空间:

  • 可以在eax寄存器中找到中断结果

关于linux - 在 Linux 的系统调用上下文中,EAX 寄存器有什么用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47692516/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com