Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Signal Stack

Tags:

c

signals

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 ?

like image 607
Thunderboltz Avatar asked May 08 '09 20:05

Thunderboltz


People also ask

What is a signal stack?

A signal stack is a special area of memory to be used as the execution stack during signal handlers. It should be fairly large, to avoid any danger that it will overflow in turn; the macro SIGSTKSZ is defined to a canonical size for signal stacks. You can use malloc to allocate the space for the stack.

How do signal handlers work?

A signal handler is a function which is called by the target environment when the corresponding signal occurs. The target environment suspends execution of the program until the signal handler returns or calls longjmp() . Signal handlers can be set with signal() or sigaction() .


1 Answers

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.

like image 67
Zifre Avatar answered Oct 25 '22 14:10

Zifre