Hi, On Tue, Sep 14, 2010 at 10:47 AM, mohit verma <mohit89mlnc@xxxxxxxxx> wrote: > hi , > i am goin through get_current() function as follows: > http://kernelnewbies.org/FAQ/get_current > ........... >>>Basically, the task's task_struct and a task's kernel stack occupy an 8KB >>> block that is 8KB aligned, with the task_struct at the beginning and the >>> stack growing from the end downwards. So you can find the task_struct by >>> clearing the bottom 13 bits of the stack pointer value.<< > > here how can we say that masking only 13 bits we'll get the address of > task_struct? It's simple. You have a 8K aligned chunk of memory which contains at it's top the task_struct. The stack pointer will hold a value inside this memory. SP will always have a value equal with base + offset. (sizeof(task_struct) <= offset < 8K) base is a 8K aligned address, this means that it's last 13 bits ( 2^3 * 2^10) are zero. I hope that now everything makes sense. Nevertheless, this is true for older kernels. Nowadays, there is a struct called thread_info stored at the beginning of kernel stack [1] thanks, Daniel. [1] http://lxr.linux.no/#linux+v2.6.35/arch/x86/include/asm/thread_info.h#L26 -- To unsubscribe from this list: send an email with "unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx Please read the FAQ at http://kernelnewbies.org/FAQ