123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- /*++
- Copyright (c) 2013 Minoca Corp.
- This file is licensed under the terms of the GNU General Public License
- version 3. Alternative licensing terms are available. Contact
- info@minocacorp.com for details. See the LICENSE file at the root of this
- project for complete licensing information.
- Module Name:
- setjmp.h
- Abstract:
- This header contains definitions for the setjmp and longjmp functions,
- which provide non-local goto support.
- Author:
- Evan Green 22-Jul-2013
- --*/
- #ifndef _SETJMP_H
- #define _SETJMP_H
- //
- // ------------------------------------------------------------------- Includes
- //
- #include <libcbase.h>
- #include <stddef.h>
- //
- // ---------------------------------------------------------------- Definitions
- //
- #ifdef __cplusplus
- extern "C" {
- #endif
- //
- // ------------------------------------------------------ Data Type Definitions
- //
- //
- // Define the mystery jump buffer type, which is a platform-depenent structure,
- // usually used to hold non-volatile variables.
- //
- typedef long jmp_buf[16];
- typedef long sigjmp_buf[16];
- //
- // -------------------------------------------------------------------- Globals
- //
- //
- // -------------------------------------------------------- Function Prototypes
- //
- LIBC_API
- int
- setjmp (
- jmp_buf Environment
- );
- /*++
- Routine Description:
- This routine saves the calling environment into the given buffer for
- later use by longjmp.
- Arguments:
- Environment - Supplies the pointer to the environment to save the
- application context in.
- Return Value:
- 0 if this was the direct call to setjmp.
- Non-zero if this was a call from longjmp.
- --*/
- LIBC_API
- int
- _setjmp (
- jmp_buf Environment
- );
- /*++
- Routine Description:
- This routine saves the calling environment into the given buffer for
- later use by longjmp.
- Arguments:
- Environment - Supplies the pointer to the environment to save the
- application context in.
- Return Value:
- 0 if this was the direct call to setjmp.
- Non-zero if this was a call from longjmp.
- --*/
- LIBC_API
- int
- sigsetjmp (
- sigjmp_buf Environment,
- int SaveMask
- );
- /*++
- Routine Description:
- This routine saves the calling environment into the given buffer for
- later use by longjmp.
- Arguments:
- Environment - Supplies the pointer to the environment to save the
- application context in.
- SaveMask - Supplies a value indicating if the caller would like the
- current signal mask to be saved in the environment as well.
- Return Value:
- 0 if this was the direct call to setjmp.
- Non-zero if this was a call from longjmp.
- --*/
- LIBC_API
- void
- longjmp (
- jmp_buf Environment,
- int Value
- );
- /*++
- Routine Description:
- This routine restores the environment saved by the most recent invocation
- of setjmp with the given environment buffer. If there is no such invocation,
- or if the function containing the invocation of setjmp has terminated in
- the interim, the behavior is undefined. Most likely, the app will crash
- spectacularly.
- Arguments:
- Environment - Supplies the pointer to the previously saved environment to
- restore.
- Value - Supplies the value to set as the return value from the setjmp
- function. If this value is 0, it will be set to 1.
- Return Value:
- None, this routine does not return.
- --*/
- LIBC_API
- void
- _longjmp (
- jmp_buf Environment,
- int Value
- );
- /*++
- Routine Description:
- This routine restores the environment saved by the most recent invocation
- of setjmp with the given environment buffer. If there is no such invocation,
- or if the function containing the invocation of setjmp has terminated in
- the interim, the behavior is undefined. Most likely, the app will crash
- spectacularly.
- Arguments:
- Environment - Supplies the pointer to the previously saved environment to
- restore.
- Value - Supplies the value to set as the return value from the setjmp
- function. If this value is 0, it will be set to 1.
- Return Value:
- None, this routine does not return.
- --*/
- LIBC_API
- void
- siglongjmp (
- sigjmp_buf Environment,
- int Value
- );
- /*++
- Routine Description:
- This routine restores the environment saved by the most recent invocation
- of setjmp with the given environment buffer. It works just like the longjmp
- function, except it also restores the signal mask if the given environment
- buffer was initialized with sigsetjmp with a non-zero save mask value.
- Arguments:
- Environment - Supplies the pointer to the previously saved environment to
- restore.
- Value - Supplies the value to set as the return value from the setjmp
- function. If this value is 0, it will be set to 1.
- Return Value:
- None, this routine does not return.
- --*/
- #ifdef __cplusplus
- }
- #endif
- #endif
|