/*
 * $Header: /smsa/bsd:include/setjmp.h:bsd  1.21  $
 * $Source: /smsa/bsd:include/setjmp.h: $
 *
 * Copyright (c) 1988 Acorn Computers Ltd., Cambridge, England
 */
#ifndef __setjmp_h
#define __setjmp_h

/**********************************************************************************
 **********************************************************************************
 **                                                                              **
 **         ***    ***  ********  ********** ******  ********  **********        **
 **         ****    ** ****  **** ** **** ** * ** * ***    *** ***    ***        **
 **         ** **   ** **      **     **       **   **       * **       *        **
 **         **  **  ** **      **     **       **   **         *******           **
 **         **   ** ** **      **     **       **   **       * **       *        **
 **         **    **** ****  ****     **     * ** * ***    *** ***    ***        **
 **         ***    ***  ********     ****    ******  ********  **********        **
 **                                                                              **
 **********************************************************************************
 **********************************************************************************/

/*
 * The compiler understands the semantics of the setjmp() function call.  Any
 * procedure which calls setjmp() is assumed to have unpredictable control flow
 * around procedure calls.  Before a procedure call is made any automatic variables
 * in registers are forced to their correct place on the stack - including variables
 * declared with the ``register'' directive.  The longjmp() implementation restores
 * all register values to the values they had at the time of the setjmp() call.
 *
 * The _setjmp() function is not supported - the compiler does not currently 
 * recognise it.  setjmp() must be used instead.  _longjmp() is supported - it
 * restores the registers but does not restore the signal block state or move
 * the execution of the signal stack (if the stack pointer points to a different
 * stack as a result of the register restoration the code will fail).  To allow
 * programs which call _setjmp to be linked it is defined in terms of setjmp here.
 *
 * Indirect calls to setjmp via a function pointer will compile incorrect code.
 */

#define _JMP_SIZE 44		/* sizeof (struct sigcontext)/sizeof (int) + 1 */
#define _JMP_MASK 43		/* index of extra element in jmp_buf */

typedef int jmp_buf[_JMP_SIZE];

extern int *_setsigsave(jmp_buf, int /*savesigs*/);
extern int (setjmp) (int */*env*/);
#if	defined (_BSD_C)
#define setjmp(e)  ((setjmp) (_setsigsave(e, 1)))
#define _setjmp(e) ((setjmp) (_setsigsave(e, 0)))
#else
/* X/Open and ANSI don't require signal context to be saved */
#define setjmp(e)  ((setjmp) (_setsigsave(e, 0)))
#endif

extern void longjmp(jmp_buf /*env*/, int /*val*/);
#ifdef	_BSD_C
extern void _longjmp(jmp_buf /*env*/, int /*val*/);
#endif

#if defined (_XOPEN_C)
typedef jmp_buf sigjmp_buf;
#define sigsetjmp(e, m) ((setjmp) (_setsigsave(e, m)))
#define siglongjmp(e, v) (longjmp ((e), (v)))
#endif

#endif

