current宏

current 
        是指当前进程

current宏
每个进程在内核态下都会开辟一个内核栈(8K或4K),一般大小为8KB,一般每个任务的thread_info结构在它的内核栈的尾端分配。这个thread_info结构是指向task_struct的。

thread_info的代码在<asm/thread_info.h>

  1. struct thread_info {
  2. struct task_struct *task; /* main task structure */
  3. struct exec_domain *exec_domain; /* execution domain */
  4. __u32 flags; /* low level flags */
  5. __u32 status; /* thread synchronous flags */
  6. __u32 cpu; /* current CPU */
  7. int preempt_count; /* 0 => preemptable, <0 => BUG */
  8. mm_segment_t addr_limit;
  9. struct restart_block restart_block;
  10. void __user *sysenter_return;
  11. #ifdef CONFIG_X86_32
  12. unsigned long previous_esp; /* ESP of the previous stack in case of nested (IRQ) stacks*/
  13. __u8 supervisor_stack[0];
  14. #endif
  15. int uaccess_err;
  16. };

current宏就是把栈指针的后13个有效位屏蔽掉来计算current_thread_info的地址(内核栈大小为8K时)
汇编代码
movl  $-8192,    %eax
andl    %esp,    %eax
这里栈大小为8K
然后通过current_thread_info()->task来获得task_struct的地址。