Discussion:
function stack frames in the kernel
Carter Cheng
2018-11-11 17:03:28 UTC
Permalink
Hello,

I am wondering how the compiler divines which stack to use for function
calls and placement of locals and arguments when a function call is made
inside the kernel since the kernel has multiple call stacks. Are function
calls handled manually inside kernel code or is there something special
inside the compiler for handling this?

Thanks,

Carter
Augusto Mecking Caringi
2018-11-11 17:55:10 UTC
Permalink
I am wondering how the compiler divines which stack to use for function calls and placement of locals and arguments when a function call is made inside the kernel since the kernel has multiple call stacks. Are function calls handled manually inside kernel code or is there something special inside the compiler for handling this?
I think this link can answer your question...

https://stackoverflow.com/questions/12911841/kernel-stack-and-user-space-stack
--
Augusto Mecking Caringi
Carter Cheng
2018-11-11 18:00:02 UTC
Permalink
Thanks for the reply but the link doesn't quite answer the question. I am
wondering how the pointer is handled so that there is one per thread by the
compiler. I perhaps was under the perhaps mistaken impression that the
stack pointer frame pointer management inside the compiler makes certain
assumptions in user space- but i am unsure how this applies to kernel space.

On Mon, Nov 12, 2018 at 1:55 AM Augusto Mecking Caringi <
Post by Carter Cheng
Post by Carter Cheng
I am wondering how the compiler divines which stack to use for function
calls and placement of locals and arguments when a function call is made
inside the kernel since the kernel has multiple call stacks. Are function
calls handled manually inside kernel code or is there something special
inside the compiler for handling this?
I think this link can answer your question...
https://stackoverflow.com/questions/12911841/kernel-stack-and-user-space-stack
--
Augusto Mecking Caringi
v***@vt.edu
2018-11-12 07:09:32 UTC
Permalink
Post by Carter Cheng
Thanks for the reply but the link doesn't quite answer the question. I am
wondering how the pointer is handled so that there is one per thread by the
compiler. I perhaps was under the perhaps mistaken impression that the
stack pointer frame pointer management inside the compiler makes certain
assumptions in user space- but i am unsure how this applies to kernel space.
For regular function calls, a kernel stack works exactly the same as a function
stack in userspace (remember, it's the same compiler, and other tools like the
linker and gdb need to be able to understand function calls).

Where things are different are what happens if an interrupt or a call to
schedule() or enter/exit the kernel (or a few other similar situations I can't
remember at 2AM) causes a different thread to start running - for those cases,
there's architecture-dependent shim code (usually involving at least a bit of
assembler) to do the register swapping needed.
Carter Cheng
2018-11-12 16:43:20 UTC
Permalink
Thanks for the clarification.
Post by Carter Cheng
Post by Carter Cheng
Thanks for the reply but the link doesn't quite answer the question. I am
wondering how the pointer is handled so that there is one per thread by
the
Post by Carter Cheng
compiler. I perhaps was under the perhaps mistaken impression that the
stack pointer frame pointer management inside the compiler makes certain
assumptions in user space- but i am unsure how this applies to kernel
space.
For regular function calls, a kernel stack works exactly the same as a function
stack in userspace (remember, it's the same compiler, and other tools like the
linker and gdb need to be able to understand function calls).
Where things are different are what happens if an interrupt or a call to
schedule() or enter/exit the kernel (or a few other similar situations I can't
remember at 2AM) causes a different thread to start running - for those cases,
there's architecture-dependent shim code (usually involving at least a bit of
assembler) to do the register swapping needed.
Continue reading on narkive:
Loading...