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的地址。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值