Chinaunix首页 | 论坛 | 博客
  • 博客访问: 150228
  • 博文数量: 34
  • 博客积分: 2000
  • 博客等级: 大尉
  • 技术积分: 410
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-03 09:44
文章分类

全部博文(34)

文章存档

2011年(1)

2008年(33)

我的朋友

分类: LINUX

2008-05-29 09:12:46

当一个进程在执行时,CPU的所有寄存器中的值、进程的状态以及堆栈中的内容被称为该进程的上下文。当内核需要切换到另一个进程时,它需要保存当前进程的所有状态,即保存当前进程的上下文,以便在再次执行该进程时,能够必得到切换时的状态执行下去。在LINUX中,当前进程上下文均保存在进程的任务数据结构中。在发生中断时,内核就在被中断进程的上下文中,在内核态下执行中断服务例程。但同时会保留所有需要用到的资源,以便中继服务结束时能恢复被中断进程的执行。

1:进程结构task_struct保存在内核空间中,在32位计算机中,即在3G-4G空间中。

2:进程结构task_struct的起始地址必须保证指针地址的低13位全为0,因为由于linux内核分配进程任务结构空间时,是以8KB(2个页面空间,即2^1*4KBlinux对物理内存空间和虚拟内存空间管理时,均规定其页面单位的尺寸为4KB)为单位来分配的,所以内存应用地址是8KB(2^13)的整数倍,即指针地址的低13位全为0。

3:当进程切换的时候,需要将CPU中的进程信息保存起来,其保存的位置在task_struct的thread_struct结构中:

struct thread_struct {
 unsigned long esp0;
 unsigned long eip;
 unsigned long esp;
 unsigned long fs;
 unsigned long gs;
/* Hardware debugging registers */
 unsigned long debugreg[8];  /* %%db0-7 debug registers */
/* fault info */
 unsigned long cr2, trap_no, error_code;
/* floating point info */
 union i387_union i387;
/* virtual 86 mode info */
 struct vm86_struct * vm86_info;
 unsigned long  screen_bitmap;
 unsigned long  v86flags, v86mask, saved_esp0;
/* IO permissions */
 int  ioperm;
 unsigned long io_bitmap[IO_BITMAP_SIZE+1];
};

4:其中的esp的指向我们在用户空间,如下图

阅读(1889) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~