简体   繁体   English

linux内核开发

[英]linux kernel development

I am currently reading 'Linux Kernel Development' by Robert Love and I do not understand what this bit of assembly is doing. 我目前正在阅读Robert Love的“Linux内核开发”,我不明白这个程序集正在做什么。

Basically, in each process kernel stack, there is a struct thread_info which resides at the end of the stack. 基本上,在每个进程内核堆栈中,都​​有一个struct thread_info ,它位于堆栈的末尾。 Now, on the x86 architecture, we can apparently grab this (assuming 8KB stack size) by using the following assembly 现在,在x86架构上,我们可以通过使用以下程序集来抓住这个(假设8KB堆栈大小)

movl $-8192, %eax
andl %esp, %eax

So basically ANDing the stack pointer by 0xffffe000. 所以基本上通过0xffffe000对堆栈指针进行AND运算。 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. 我不明白为什么掩盖%esp的最不重要的13位将我们带到结构。 I know I'll feel stupid once it is explained, but it is bugging me. 我知道一旦得到解释我就会感到愚蠢,但这让我烦恼。

Thanks. 谢谢。

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. 堆栈以8KB的倍数存储。 Therefore, erasing the 13 least significant bits gets the lowest address of the stack and therefore the start of the structure. 因此,擦除13个最低有效位得到堆栈的最低地址,因此得到结构的开始。 Does this make sense? 这有意义吗?

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

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