Chinaunix首页 | 论坛 | 博客
  • 博客访问: 65359
  • 博文数量: 12
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 22
  • 用 户 组: 普通用户
  • 注册时间: 2013-12-05 16:23
文章分类

全部博文(12)

文章存档

2014年(4)

2013年(8)

我的朋友

分类:

2014-11-17 16:55:00

进程描述符是指tast_struct结构,该结构中包含thread_info结构和内核栈,thread_info+内核栈一共是8K(2个页面)
union thread_union {
struct thread_info thread_info;
unsigned long stack[THREAD_SIZE/sizeof(long)];
};
thread_info位于低地址,内核栈位于高地址,栈的生长方向是从高地址向低地址生长,
CPU的esp寄存器保存的是当前运行上下文内核栈的栈顶,因为thread_union是8k对齐的,
所以根据esp的值即能计算出thread_union中thread_info的地址:
movl $0xffffe000,%ecx /* or 0xfffff000 for 4KB stacks */
andl %esp,%ecx
movl %ecx,p
得到thread_info的地址后,即能很快得到task_struct的地址:
movl $0xffffe000,%ecx /* or 0xfffff000 for 4KB stacks */
andl %esp,%ecx
movl (%ecx),p
因为task指针为thread_info结构的第一个分量。
使用CPU的esp寄存器定位当前进程描述符在多CPU的情况下显得特别重要,因为寄存器中的是最准确和最天然的。

打个书签:后面继续3.2.2.3节Doubly linked lists
阅读(1239) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~