What is the difference between kernel stack and user stack?

前端 未结 7 506
忘了有多久
忘了有多久 2021-01-31 06:25

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

7条回答
  •  礼貌的吻别
    2021-01-31 06:56

    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.

提交回复
热议问题