Tuesday, 8 January 2013

x86 and linux process kernel Stack

I even had this as doubt until I figured it out and as of I tried to google the solution on net found non so this could help others to find the solution if they have similar doubts.
x86 have few registers to store data so efficient ways are implemented to consume less of available registers, one is to find the current process running .Many RISC arch processors store the address of current process running in a register but for x86 Linux does maps struct thread_info which has task_struct which points to process being running .
I read in book Linux Kernel Development in topic "Storing the process descriptor" page 26 in new edition about this but I did not got it.
I understood that when process block is made in RAM it is allocated to any physical address in RAM and so there is no perfect knowledge of the starting point or so. Thus we can't even say any thing about the stack's address. So I did not got how could masking just 13 bits of address of stack point of kernel process stack gives the address of current_thread_info.
This was wrong as right now I have no knowledge of how paging in done in physical address space. 
But then I tried to find out that how that happens and I had some idea that if it is at a predefined location than be can have such conditions.
I found the good explanation is Understanding linux Kernel in topic 3.2.2.1 "Process descriptor handling" page 4 of chapter 3.
Its simple, 2 pages are assigned to Kernel stack and current_thread_info struct which are aligned to multiple of 2 power 13. And this is the point I was not knowing. Rest all you can understand by diagram fro m the book.

Every process( ) has memory reserved for kernel function when those processes call the system calls .This kernel stack are used. 

No comments:

Post a Comment