linux中的一个问题,请大侠们帮忙解释一下,谢谢!
linux内核源代码情景分析的进程与进程调度一章中有如下一段代码:
获取当前进程的task_struct结构
static inline struct task_struct * get_current(void)
{
struct task_struct *current;
__asm__("andl %%esp,%0; ":"=r" (current) : "0" (~8191UL));
return current;
}
书中说这行汇编代码是将当前的堆栈指针寄存器ESP的内容与8191UL相“与”而得到当前进程task_struct结构的起始地址。
进程的task_struct结构与进程系统空间堆栈的关系如下:
------------------ --
| | |
| | |
| | |
| | |
| |
| | 7K 系统空间堆栈
两个连续的物理页面 8K ------------------
| | |
| | |
| | |
| | |
------------------ --
| | 1K task_struct结构
------------------
我的理解是:
将当前的堆栈指针寄存器ESP的内容 + 8191 就得到当前进程task_struct结构的起始地址。
请帮忙解释下,谢谢!