- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
课本中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
and
$0x80syscall
!). 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
andsyscall
. 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
orsyscall
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 $0x80
或 syscall
调用中断在内核空间:
eax
读取系统调用号eax
再次在用户空间:
eax
寄存器中找到中断结果关于linux - 在 Linux 的系统调用上下文中,EAX 寄存器有什么用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47692516/
这个问题在这里已经有了答案: Test whether a register is zero with CMP reg,0 vs OR reg,reg? (2 个回答) 3年前关闭。 or eax,e
test eax, eax 是否比 cmp eax, 0 更高效?是否存在需要 test eax, eax 而 cmp eax, 0 不满足要求的情况? 最佳答案 正如臧明杰在评论中已经说过的,tes
这个问题已经有答案了: 已关闭10 年前。 Possible Duplicate: x86 Assembly - ‘testl’ eax against eax? 我对汇编语言编程非常陌生,我目前正在
我有一些未知的 C++ 代码是在发布版本中编译的,因此对其进行了优化。我正在努力解决的问题是: xor al, al add esp, 8 cmp byte ptr [ebp+
GCC 给我做了一些汇编代码,里面有这个语句: lea eax, [ebx+eax] (英特尔语法) 只是好奇,这有什么区别,和: add eax, ebx 是? eax 和 ebx 包含函数的返回值
leal (%eax, %eax) 是什么意思做? %eax * 2 处的内容是否会相乘,因为它有括号? 最佳答案 它将使用 eax 的总和加载目标操作数和 eax , IOW, 2* eax . 关
我正在尝试理解一些汇编。 程序集如下,我对teSTL行感兴趣: 000319df 8b4508 movl 0x08(%ebp), %eax 000319e2 8b4004
LEA EAX, [EAX] 我在使用 Microsoft C 编译器编译的二进制文件中遇到了这条指令。它显然不能改变 EAX 的值。那它为什么在那里? 最佳答案 这是一个NOP。 以下通常用作NOP
我正在二进制文件中搜索特定指令,对于 xor eax,eax 指令,我有一个函数,如: int foo(){ return 0; } 如果我用 GCC 4.7.2 和 -O2 或 -O3 优化标志
我正在二进制文件中搜索特定指令,对于 xor eax,eax 指令,我有一个函数,如: int foo(){ return 0; } 如果我用 GCC 4.7.2 和 -O2 或 -O3 优化标志
什么是 0x01b55ee2 mov 0x40(%eax),%eax 是什么意思?我应该如何解释 0x40(),因为我的代码在该位置崩溃时遇到问题。 %eax寄存器的内容为0。 最佳答案
我知道 dword ptr 是一个 size 指令,它指示移动内容的大小,我知道 mov eax, eax 是一种 nop 代码形式,但这有什么作用? 我认为它将 eax 的地址与内部的十六进制值交换
这个问题已经有答案了: What is the meaning of MOV (%r11,%r12,1), %edx? (2 个回答) 已关闭 5 年前。 一直在从事 assembly 作业,并且在很
我在 GAS 源代码中定义了一个 MACRO。但是不是gcc编译的。 下面是我定义的MACRO。 #define MSGSCHEDULE0(index) \ movl (index*4)(%r
我在组装方面完全是个菜鸟,只是四处看看发生了什么。无论如何,我写了一个非常简单的函数: void multA(double *x,long size) { long i; for(i=0; i
GCC 4.4.3 生成了以下 x86_64 程序集。让我困惑的部分是 mov %eax,%eax .将寄存器移至自身?为什么? 23b6c: 31 c9
两条线有什么区别 push eax mov [esp], eax 不将 eax 压入堆栈(esp 所指向的位置与 mov [esp]、eax 一样?) 最佳答案 “push”会自动改变“esp”(你的
以下说明有何意义? xor eax,eax mov eax,[eax] 当您对 eax 进行 XOR 时,大多数情况下您会得到零,那么您可以取消引用地址 [eax] 中的内容(在本例中 eax 包含
我是一个初学者,正在编写汇编程序以使用以下代码打印从 1 到 9 的数字: section .text global _start _start:
Apparently ,现代处理器可以判断您是否做了一些愚蠢的事情,例如将寄存器移动到自身 ( mov %eax, %eax ) 并将其优化。为了验证该声明,我运行了以下程序: #include #
我是一名优秀的程序员,十分优秀!