Chinaunix

标题: 对do_page_fault中current宏的一点疑惑 [打印本页]

作者: mournjust    时间: 2011-04-26 16:52
标题: 对do_page_fault中current宏的一点疑惑
今天再次读到了《情景分析》中的do_page_fault函数。对其中的一些代码感到比较疑惑。
struct task_struct *tsk;
tsk = current;
对于上面的这句代码感到不解。do_page_fault是由系统产生一个异常的时候调用的一个服务程序,显然操作系统处于内核态。
current最终会调用到下面的current_thread_info函数
static inline struct thread_info *current_thread_info(void)
{
    register unsigned long sp asm ("sp");
    return (struct thread_info *)(sp & ~(THREAD_SIZE - 1));
}
具体是根据当前的栈针来获得task_struct结构体的。
但是当处理异常服务程序的时候,内核在内核态,获得不应该是造成异常的用户程序的task_struct呀,我到底是哪儿理解错了。。。。
作者: 瀚海书香    时间: 2011-04-26 17:27
回复 1# mournjust
不管是内核线程还是用户进程,所有的task_struct都是由内核来管理的。
当发生缺页异常的用户进程陷入内核态处理的时候,current就是用户进程的task_struct。
作者: mournjust    时间: 2011-04-26 18:51
回复 2# 瀚海书香
[javascript:;img]http://my.chinaunix.net/attachment/photo/113198_100709193746.jpg[/img]

    明白了。我还以为系统堆栈是公用的呢,原来每一个进程都有相应的系统堆栈。
谢谢

截图00.png (24.4 KB, 下载次数: 20)

截图00.png





欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2