lkml.org 
[lkml]   [2000]   [Feb]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
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
register
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.


Jun

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

\
 
 \ /
  Last update: 2005-03-22 13:56    [from the cache]
©2003-2011 Jasper Spaans. Advertise on this site