[lkml]   [2000]   [Feb]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Subjecthow does kernel get the "current" task struct?

I am looking at the source code of kernel v2.2.12, and get
totally confused by the "current" macro. Kernel uses "current"
to get a pointer to the task_struct of the current running process.

"current" is defined as a macro in include/asm-i386/current.h :

struct task_struct;

static inline struct task_struct * get_current(void)
struct task_struct *current;
__asm__("andl %%esp,%0; ":"=r" (current) : "0" (~8191UL));
return current;

#define current get_current()

Basically, the pointer to the current task_struct is the current stack
pointer(%esp) substracted by 8K.

How could this code possibly work correctly? For one thing, the %esp
will have varying values as the call stack moves up and down.

In addition, how can we have different "current" values for different
CPUs in
the SMP version?

any enlightment is appreciated.


To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
Please read the FAQ at

 \ /
  Last update: 2005-03-22 13:56    [W:0.078 / U:5.276 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site