进入内核态的方式
中断,包括软中断和硬中断,其中软中断包括系统调用(int 80)和各种异常(segmentfatel 信号11),硬中断包括网卡收包,usb插入等等。
内核栈
- 每个进程独有一个内核栈
- 各cpu架构有不同的异常栈,中断栈,有的是使用的是被打断的程序的内核栈,有的有独有的空间
内核栈结构体
union thread_union {
struct thread_info thread_info;
unsigned long stack[THREAD_SIZE/sizeof(long)];
};
其中thread_info保存在进程的重要信息,最重要的是指针task,其中包含了进程的所有信息。
该结构体的大小就表示了整个内核栈的大小,即THREAD_SIZE,一般都是4k或者8k。所以thread_info保存在低地址,内核栈从该地址空间的尾部向内增长。
/*
* low level task data that entry.S needs immediate access to.
* __switch_to() assumes cpu_context follows immediately after cpu_domain.
*/
struct thread_info {
unsigned long flags; /* low level flags */
int preempt_count; /* 0 => preemptable, <0 => bug */