diff options
Diffstat (limited to 'src/setjmp')
-rw-r--r-- | src/setjmp/jmp_buf.c | 16 | ||||
-rw-r--r-- | src/setjmp/longjmp.c | 35 | ||||
-rw-r--r-- | src/setjmp/setjmp.c | 32 |
3 files changed, 83 insertions, 0 deletions
diff --git a/src/setjmp/jmp_buf.c b/src/setjmp/jmp_buf.c new file mode 100644 index 00000000..6ea7efff --- /dev/null +++ b/src/setjmp/jmp_buf.c @@ -0,0 +1,16 @@ +#include <setjmp.h> +typedef unsigned long int jmp_buf[32]; + +/** program environment **/ + +/*** +is used to hold all the information needed to restore a a calling +environment. +***/ + +/* +TYPEDEF(an array type) +*/ +/* +STDC(1) +*/ diff --git a/src/setjmp/longjmp.c b/src/setjmp/longjmp.c new file mode 100644 index 00000000..bcb97410 --- /dev/null +++ b/src/setjmp/longjmp.c @@ -0,0 +1,35 @@ +#include <setjmp.h> + +/** restore calling environment **/ +_Noreturn void longjmp(jmp_buf env, int val) +{ + (void)env; + if (val == 0) { + val = 1; + } + /* Set env.return_register to val */ + /* Load all registers from env */ + for (;;); /* silence _Noreturn function returns warning */ +} + +/*** +THIS() restores the environment of a previous call to FUNCTION(setjmp) +and continues execution at the location of the call to FUNCTION(setjmp). + +All objects previously accessible at the time of the call to FUNCTION(setjmp) +have the same values. Non-TYPE(volatile) objects of automatic storage duration +that have changed since the call to FUNCTION(setjmp) have intederminate values. + +When execution resumes at the point of the original call to FUNCTION(setjmp), +the value specified by ARGUMENT(val) is returned. If 0 is specified, then the return +value is 1. +***/ + +/* +UNDEFINED(There was no previous call to FUNCTION(setjmp)) +UNDEFINED(The function containing the previous call to FUNCTION(setjmp) is no longer executing) +UNDEFINED(THIS() is called from a nested signal handler) +*/ +/* +STDC(1) +*/ diff --git a/src/setjmp/setjmp.c b/src/setjmp/setjmp.c new file mode 100644 index 00000000..c578d2a9 --- /dev/null +++ b/src/setjmp/setjmp.c @@ -0,0 +1,32 @@ +#include <setjmp.h> + +int setjmp(jmp_buf env) +{ + extern int __setjmp(jmp_buf); + /* + RETURN(0, the environment has been saved by THIS()) + RETURN(NONZERO, the environment has been restored by FUNCTION(longjmp)) + */ + return __setjmp(env); +} + +/** save program state **/ + +/*** +saves the current state of the calling environment +in the TYPEDEF(jmp_buf) ARGUMENT(env). +***/ + +/* CONSTRAINT: entire controlling expression of a selection or iteration statement */ +/* CONSTRAINT: one operand of a relational or equality operator which is the entire controlling expression of a selction or iteration statement */ +/* CONSTRAINT: the operand of a unary ! as the entire controlling expression of a selection or iteration statement */ +/* CONSTRAINT: an entire expression statement */ + +/* +UNSPECIFIED(Whether THIS() is a macro or identifier with external linkage) +UNDEFINED(A macro definition of THIS() is suppressed in order to access an actual function) +UNDEFINED(A program defines an external identifier named LITERAL(setjmp)) +*/ +/* +STDC(1) +*/ |