home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************
- *
- * $Source: /unixb/home/unixlib/source/unixlib37/src/signal/c/RCS/sigstack,v $
- * $Date: 1996/10/30 22:04:51 $
- * $Revision: 1.1 $
- * $State: Rel $
- * $Author: unixlib $
- *
- * $Log: sigstack,v $
- * Revision 1.1 1996/10/30 22:04:51 unixlib
- * Initial revision
- *
- ***************************************************************************/
-
- static const char rcs_id[] = "$Id: sigstack,v 1.1 1996/10/30 22:04:51 unixlib Rel $";
-
- /* sigstack.c: Written by Nick Burrett, 27 August 1996.
- This is the BSD version of the POSIX function sigaltstack. */
-
- #include <signal.h>
- #include <errno.h>
- #include <unixlib/sigstate.h>
- #include <sys/unix.h>
-
- /* Specifies an alternate stack for use during signal handling.
- When a signal is received by the process and its action
- indicates that the signal stack is used, the system arranges
- a switch to the currently installed signal stack while the
- handler for that signal is executed. */
-
- int
- sigstack (const struct sigstack *stack, struct sigstack *oldstack)
- {
- struct unixlib_sigstate *ss = &__u->sigstate;
- if (ss->signalstack.ss_flags & SA_ONSTACK)
- {
- /* Trying to disable a stack that is currently in use. */
- errno = EINVAL;
- return -1;
- }
-
- if (oldstack != NULL)
- {
- oldstack->ss_sp = ss->signalstack.ss_sp;
- oldstack->ss_onstack = ss->signalstack.ss_flags & SA_ONSTACK;
- }
- /* Converting between a sigstack and a sigaltstack. With sigstack,
- ss_sp points to the top of the buffer because we have a downwards
- growing stack. Since we don't have a size parameter, we'll set
- size to -1 to tell the signal handler that ss_sp points to the
- top of the buffer, instead of the bottom. */
-
- ss->signalstack.ss_sp = stack->ss_sp;
- ss->signalstack.ss_size = -1;
- ss->signalstack.ss_flags = stack->ss_onstack;
-
- return 0;
- }
-