What is the difference between kernel stack and us

2019-03-08 21:55发布

What is the need of using two different stacks in same program? How does trap change the current stack of program from user stack to kernel stack? How does it come back to user stack after completing system call?

Does every process have a kernel and user stack?

7条回答
三岁会撩人
2楼-- · 2019-03-08 22:38

There are 2 stacks because there are 2 CPU execution contexts. The user mode stack will cater to your program with respect to creating stack frames for functions, local variables, return addresses etc. When the CPU switches context to kernel mode, for instance during system call execution, it needs access to kernel memory and data structures and so switches to using it's kernel stack. And yes, Unix I believe uses a per process kernel stack.

查看更多
登录 后发表回答