tags:

views:

206

answers:

2
+3  Q: 

Signal Stack

I did read that signals need to have a separate stack, why and how do you think it is implemented ?

Are they dynamically allocated or statically allocated ? How is memory allocation done ? Is it the same for all signals ?

+2  A: 

The reason that signals need a separate stack is that, if the normal stack gets corrupted or overflows, the signal can still execute. I think the signal stack is usually allocated dynamically, but it could implemented be either way. You can set a new signal stack with sigaltstack. It is the same for all signals.

Zifre
So as I understand we have all default handlers onto the separate signal stack, is it true ?What happens when we decide to use a different signal handler ? How is this special case taken care of ?
Thunderboltz
Non-default signal handlers are also executed on the same signal stack.
Zifre
How could that be possible ? Non-default signal handlers would not be executed onto the same signal stack. Non-default signal handlers would be defined in the user program and would be using the normal user stack and not the special signal stack. I think we pass the pointer to the non-default signal handler which is later on used with the BSD signal API.
Thunderboltz
No, this is incorrect. Just because non-default signal handlers are defined in the user program doesn't mean that they have to execute on the user stack. I think you are not understanding how the stack actually works. Basically, the stack pointer is a register on the CPU, so if I change that register to another location, any functions I call will use stack space there. It doesn't matter where the function was defined.
Zifre
+1  A: 

Another, more esoteric reason is to create user-level threads. See the paper, "Portable Multithreading" by Ralf Engelschall: http://www.gnu.org/software/pth/rse-pmt.ps. It describes how the "signal stack trampoline trick" is used to effect userspace threading.

nick black
Completely off-topic to this question (unfortunately), but very cool link :-)
Mecki