process descriptor address in kernel stack

, Samuel samuel at
Thu Mar 19 04:53:32 EDT 2020

In this book (understanding Linux kernel),

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 struc-
ture 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

Why is *"stack pointer(esp) & 0xffffe000"* equal to the process descriptor
base address?

That means the base address of process descriptor is always *0xXYZ...000*,
right? It is weird.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Kernelnewbies mailing list