5# deepwhite
我看的是深入理解Linux内核,然后在看Linux内核设计和实现里,有相似的表述,应该不会错吧!深入理解lLinux内核里是这么说的:
Figure 3-2 shows how the two data structures are stored in the 2-page (8 KB) memory area. The thread_info structure resides at the beginning of the memory area, and the stack grows downward from the end. The figure also shows that the tHRead_info structure and the task_struct structure are mutually linked by means of the fields task and tHRead_info, respectively.
Figure 3-2. Storing the thread_info structure and the process kernel stack in two page frames
[attach]31786[/attach]
……
The close association between the thread_info structure and the Kernel Mode stack just described offers a key benefit in terms of efficiency: the kernel can easily obtain the address of the thread_info structure of the process currently running on a CPU from the value of the esp register. In fact, if the thread_union structure is 8 KB (213 bytes) long, the kernel masks out the 13 least significant bits of esp to obtain the base address of the thread_info structure; on the other hand, if the thread_union structure is 4 KB long, the kernel masks out the 12 least significant bits of esp. This is done by the current_thread_info( ) function, which produces assembly language instructions like the following:
movl $0xffffe000,%ecx /* or 0xfffff000 for 4KB stacks */
andl %esp,%ecx
movl %ecx,p
After executing these three instructions, p contains the tHRead_info structure pointer of the process running on the CPU that executes the instruction.
这里面esp寄存器是存放着栈指针的,以那图做例子:在那图中的栈指针的位置是0x015fa878,而thread-info的位置是在于0x015fa000,它通过那段汇编指令,也就是0x015fa878减去0x00002000,得到的是0x015f8878啊,怎么都不可能是0x015fa000啊?所以我就疑惑嘛