altstack: Restore alternate signal stack state
authorDavid Gibson <david@gibson.dropbear.id.au>
Fri, 3 Jun 2016 08:42:00 +0000 (18:42 +1000)
committerDan Good <dan@dancancode.com>
Thu, 16 Jun 2016 20:18:52 +0000 (20:18 +0000)
commit15c555b335126e5210c2847048f85dd078e71cf7
tree6e9b36bbee477cfa3f91863ec1378994f43d9d27
parent2da0271f9700ecb1bd402918e5f7ae7b27c2b142
altstack: Restore alternate signal stack state

altstack relies on catching a SIGSEGV caused when overrunning the stack.
This means that the SEGV handler itself can't use the already overflowed
stack, and so we use sigaltstack() to assign the signal handler a different
stack.  On completion, altstack() clears the alternate signal stack.

However, it's possible that the calling program could be using
sigaltstack() for its own reasons, so it's more correct to restore the
sigaltstack() state to that from the beginning of the altstack() call.
This patch implements this behaviour.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
ccan/altstack/altstack.c