current宏
current

是指当前进程
每个进程在内核态下都会开辟一个内核栈(8K或4K),一般大小为8KB,一般每个任务的thread_info结构在它的内核栈的尾端分配。这个thread_info结构是指向task_struct的。
thread_info的代码在<asm/thread_info.h>
struct thread_info {
struct task_struct *task; /* main task structure */
struct exec_domain *exec_domain; /* execution domain */
__u32 flags; /* low level flags */
__u32 status; /* thread synchronous flags */
__u32 cpu; /* current CPU */
int preempt_count; /* 0 => preemptable, <0 => BUG */
mm_segment_t addr_limit;
struct restart_block restart_block;
void __user *sysenter_return;
#ifdef CONFIG_X86_32
unsigned long previous_esp; /* ESP of the previous stack in case of nested (IRQ) stacks*/
__u8 supervisor_stack[0];
#endif
int uaccess_err;
};
current宏就是把栈指针的后13个有效位屏蔽掉来计算current_thread_info的地址(内核栈大小为8K时)
汇编代码
movl $-8192, %eax
andl %esp, %eax
这里栈大小为8K
然后通过current_thread_info()->task来获得task_struct的地址。