kernel and user stack
2012-02-17 17:26
363 查看
进程创建的时候每个进程分配了8K的系统栈,除了一部分用来存放task_struct,
内核栈 用来 表示 进程 由于某种原因进入内核(比如系统调用/Exception)的时候用的。你想啊,进程进入内核后,执行一系列函数,保持函数的返回地址,传递参数啥的,就要用到这个内核栈了。 所以说,在内核中如果使用 较多的递归 会溢出内核栈的。oops
用户栈就是在用户空间指向函数调用的时候用的。 这个栈就大多了,因为其用 MMU映射,可以具有很大的虚拟空间的栈。
Linux下每个用户空间进程(不是kernel thread)都有两个堆栈,一个内核栈,一个系统栈。其中内核栈在创建进程或者线程(do_fork)是创建,在2.6内核中,他的内容如下:
union thread_union {
struct thread_info thread_info;
unsigned long stack[THREAD_SIZE/sizeof(long)];
};
由此可见,此内核栈的高端用于作为堆栈,底端用于存放thread_info(不是task_struct)。此堆栈用于存放进程在内核时的call frames或者接收到中断时的现场状态(pt_regs),在有些体系结构下,也存放同步上下文切换时的状态(switch_stack)。内核栈不能动态增长。
用户栈在进程调用execve的时候(参见fs/binfmt_*.c文件中的load_binary函数,大概是这个函数)创建,对于用clone创建的线程来说,它可以由用户来指定,用户栈和内核没有任何关系,它用于存放进程在用户空间时的call frames。用户堆栈可以动态增长。
内核栈 用来 表示 进程 由于某种原因进入内核(比如系统调用/Exception)的时候用的。你想啊,进程进入内核后,执行一系列函数,保持函数的返回地址,传递参数啥的,就要用到这个内核栈了。 所以说,在内核中如果使用 较多的递归 会溢出内核栈的。oops
用户栈就是在用户空间指向函数调用的时候用的。 这个栈就大多了,因为其用 MMU映射,可以具有很大的虚拟空间的栈。
Linux下每个用户空间进程(不是kernel thread)都有两个堆栈,一个内核栈,一个系统栈。其中内核栈在创建进程或者线程(do_fork)是创建,在2.6内核中,他的内容如下:
union thread_union {
struct thread_info thread_info;
unsigned long stack[THREAD_SIZE/sizeof(long)];
};
由此可见,此内核栈的高端用于作为堆栈,底端用于存放thread_info(不是task_struct)。此堆栈用于存放进程在内核时的call frames或者接收到中断时的现场状态(pt_regs),在有些体系结构下,也存放同步上下文切换时的状态(switch_stack)。内核栈不能动态增长。
用户栈在进程调用execve的时候(参见fs/binfmt_*.c文件中的load_binary函数,大概是这个函数)创建,对于用clone创建的线程来说,它可以由用户来指定,用户栈和内核没有任何关系,它用于存放进程在用户空间时的call frames。用户堆栈可以动态增长。
相关文章推荐
- the difference between kernel stack and user stack
- What is the difference between user mode and kernel mode, and real mode and protected mode?
- systemtap dump kernel function call stack and print function parameters
- What is the difference between user level threads and kernel level threads?
- Modules, User Space and Kernel Space
- Kernel space DMA and User space DMA
- User and kernel mode switching
- User mode and kernel mode
- Avoid memory copying between user space and kernel space
- Avoid memory copying between user space and kernel space
- kernel space and user space
- Kernel space DMA and User space DMA
- Linux kernel Process Management 1——Conparison and Contrast between linux 2.4 VS linux 2.6 in process kernel stack layout
- Communication Between User Mode and Kernel Mode 用户模式和内核模式间的通信
- linux i2c access in kernel and user space
- Execution Differences Between Kernel Modules and User Programs
- 1.6、Activity任务和返回堆栈3(Tasks and Back Stack)之LaunchMode
- How to Install Nvidia Kernel Module Cuda and Pyrit in Kali Linux
- Android kernel build from source code and from prebuilt
- RH133读书 笔记(5) - Lab 5 User and Group Administration