ymc4444 发表于 2016-08-30 19:58

chengxta 发表于 2016-08-31 14:56

这个首先要搞清楚current是怎么取得当前进程描述符的:
每个进程使用独立的栈空间,栈底存放thread_info结构;
union thread_union {
        struct thread_info thread_info;
        unsigned long stack;
};

那么通过cpu的堆栈指针(sp)就可以很容易计算出thread_info的地址,并进一步找到当前进程的描述符:
static inline struct thread_info *current_thread_info(void)
{
        return (struct thread_info *)
                (current_stack_pointer & ~(THREAD_SIZE - 1));
}

#define get_current() (current_thread_info()->task)

延迟函数都是通过软中断实现的,运行在中断上下文,sp寄存器已经发生变化,所以通过sp是没法取得当前进程信息的;

nswcfd 发表于 2016-08-31 17:32

可以得到,但是这个结果是不确定的,比如这次是sshd,下次可能是apache。

ymc4444 发表于 2016-09-02 07:05

ymc4444 发表于 2016-09-02 07:10

zhanglong71 发表于 2016-09-02 09:27

chengxta 发表于 2016-08-31 14:56
这个首先要搞清楚current是怎么取得当前进程描述符的:
每个进程使用独立的栈空间,栈底存放thread_info结 ...

中断或异常会借用当前进程的内核态栈空间,所以可以通过current确定哪个进程在中断或异常之前运行。不过current进程与此时发生的中断的关系是不确定的。或者说,此时的中断所要服务的对象不一定是current进程。而异常是同步的,其所服务的对象就是current进程。

页: [1]
查看完整版本: ULK3上中断章节的一段话,不是很懂。。。