how does kernel get the "current" task struct?

From: Jun Sun (jsun@mvista.com)
Date: Wed Feb 02 2000 - 19:16:02 EST


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/



This archive was generated by hypermail 2b29 : Mon Feb 07 2000 - 21:00:08 EST