I am using the esp value of kernel stack to calculate the process descriptor pointer value.
According to ULK book, I just need to mask 13 least significant bits of esp to obtain the base address of the thread_info structure.
My test is:
- write a kernel module because I need to get value of kernel stack
- In the kernel init function, get the value of kernel stack
- use following formula to get the process descriptor pointer of the process running on the CPU:
*((unsigned int*) esp & 0xffffe000) - use the current macro, print out its value.
I think the value of step3 should be same as the value of step 4.
But my experiment results shows: sometimes they are same, and sometimes they are different. Could any explain why? Or am I missing anything?
current()works that might be helpful. - sarnold