Stack frame for signal handling in the Linux Kerne

2019-07-29 03:49发布

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条回答
\"骚年 ilove
2楼-- · 2019-07-29 04:37

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)")

查看更多
登录 后发表回答