Stack frame for signal handling in the Linux Kernel

孤街醉人 提交于 2019-12-11 08:44:52

问题


I see that the stack frame the process needs to handle signals is allocated in the function setup_rt_frame().

My question is: where it is de-allocated?

Thank you!


回答1:


setup_rt_frame() sets stack for Real-time signals (see man 7 signal). It does 2 main things:

  1. Saves CPU context of user process (before it was interrupted) from kernel stack to user stack.
    For ARM architecture it's done in setup_sigframe().
  2. Saves return address (where signal handler returns) to user stack.
    Return address will point to rt_sigreturn() syscall (see man 2 sigreturn for details).
    For ARM architecture it's done in setup_return().

As you can see, once signal handler is finished, it will automatically return to sys_rt_sigreturn() function in kernel. This function will restore kernel stack from user stack and get back to interrupted user-space process.

So, answering your question:

where it is de-allocated?

It's being restored in sys_rt_sigreturn() function.

See also:

[1] How signals work internally?

[2] Who uses POSIX realtime signals and why?

[3] Implementation of signal handling (see sections "Delivering Signals (7)" to "Delivering Signals (12)")



来源:https://stackoverflow.com/questions/39517375/stack-frame-for-signal-handling-in-the-linux-kernel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!