Linux内核开发
我目前正在阅读 Robert Love 写的《Linux 内核开发》,我不明白这段汇编代码在做什么。
基本上,在每个进程内核堆栈中,都有一个位于堆栈末尾的 struct thread_info 。现在,在 x86 架构上,我们显然可以通过使用以下程序集来获取它(假设堆栈大小为 8KB),
movl $-8192, %eax
andl %esp, %eax
所以基本上将堆栈指针与 0xffffe000 进行 AND 运算。我很困惑这里发生了什么?我不明白为什么屏蔽 %esp
的最低有效 13 位会将我们带到结构体。我知道一旦解释清楚我会觉得自己很愚蠢,但这让我很烦恼。
谢谢。
I am currently reading 'Linux Kernel Development' by Robert Love and I do not understand what this bit of assembly is doing.
Basically, in each process kernel stack, there is a struct thread_info
which resides at the end of the stack. Now, on the x86 architecture, we can apparently grab this (assuming 8KB stack size) by using the following assembly
movl $-8192, %eax
andl %esp, %eax
So basically ANDing the stack pointer by 0xffffe000. I'm confused as to what is going on here? I don't see why masking the least significant 13 bits of %esp
takes us to the struct. I know I'll feel stupid once it is explained, but it is bugging me.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
堆栈向下增长,因此堆栈的末尾是堆栈中的最低地址,也是结构的起始地址。堆栈以 8KB 的倍数存储。因此,擦除 13 个最低有效位即可获得堆栈的最低地址,从而获得结构的开始位置。这有道理吗?
The stack grows downwards, so the end of the stack is the lowest address in the stack, and the structure's starting address. And stacks are stored at multiples of 8KB. Therefore, erasing the 13 least significant bits gets the lowest address of the stack and therefore the start of the structure. Does this make sense?