lkml.org 
[lkml]   [2001]   [Jun]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: Reg:current a pointer to task_struct
"SATHISH.J" wrote:
>
> Hi,
>
> Please help me with the following:
>
> I tried to go through get_current function which is in assembly.
>
> static inline struct task_struct * get_current(void) {
> struct task_struct *current;
> __asm__("andl %%esp,%0; ":"=r" (current) : "0" (~8191UL));
> return current;
> }
>
> Please tell me what is done here. Does current refer to process onproc.

Actually the code returns the stack pointer (esp) anded with ~8191
(FFFE000).

The trick is that kernel task structures are allocated at the low end of
the kernel stack for each task. The stack is a the high end of the
address range and works down. (Kernel stack overflow will "eat" the
task structure.)

current is (struct tast_struct *) and points to the task_struc for the
current task (how could it be otherwise, given that it comes from the
tasks stack pointer).

George
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 12:55    [W:0.118 / U:1.788 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site