diff options
author | Jakob Kaivo <jkk@ung.org> | 2023-11-14 14:58:44 -0500 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2023-11-14 14:58:44 -0500 |
commit | 30226c2f0959ef4a74f67de4ed762cdc4dffb82f (patch) | |
tree | 7b89f46d01bf5057c5bdd428397dbe3cdbced25c | |
parent | 83990426c98ed9f75494535b9bb29151f8c3fd08 (diff) |
enable multiple-exit() detection
-rw-r--r-- | src/stdlib/_stdlib.h | 2 | ||||
-rw-r--r-- | src/stdlib/atexit.c | 5 | ||||
-rw-r--r-- | src/stdlib/exit.c | 13 |
3 files changed, 10 insertions, 10 deletions
diff --git a/src/stdlib/_stdlib.h b/src/stdlib/_stdlib.h index 4d456594..82b7943d 100644 --- a/src/stdlib/_stdlib.h +++ b/src/stdlib/_stdlib.h @@ -19,6 +19,8 @@ struct __stdlib { struct atexit *next; struct atexit *prev; } atexit; + int exit_called; + int quick_exit_called; unsigned int rand; char **environ; constraint_handler_t constraint_handler; diff --git a/src/stdlib/atexit.c b/src/stdlib/atexit.c index d48b9d0e..79b486d0 100644 --- a/src/stdlib/atexit.c +++ b/src/stdlib/atexit.c @@ -1,5 +1,3 @@ -#if 0 - #include <errno.h> #include <stdlib.h> #include "_stdlib.h" @@ -38,6 +36,3 @@ RETURN_FAILURE(NONZERO) RETURN_SUCCESS(0) STDC(1) */ - - -#endif diff --git a/src/stdlib/exit.c b/src/stdlib/exit.c index 55800ace..60a933b8 100644 --- a/src/stdlib/exit.c +++ b/src/stdlib/exit.c @@ -1,5 +1,3 @@ -#if 0 - #include <stdlib.h> #include <stdio.h> #include "_stdlib.h" @@ -11,6 +9,14 @@ _Noreturn void exit(int status) long scno = __syscall_lookup(exit); struct atexit *ae = &(__stdlib.atexit); + if (__stdlib.quick_exit_called) { + __stdlib.constraint_handler("Undefined behavior: exit() called after quick_exit()", NULL, 0); + } + if (__stdlib.exit_called) { + __stdlib.constraint_handler("Undefined behavior: exit() called twice", NULL, 0); + } + __stdlib.exit_called = 1; + /* execute all atexit() registered functions in reverse order */ while (ae) { int i = ae->nfns; @@ -47,6 +53,3 @@ IMPLEMENTATION(The unsuccessful termination value returned to the host environme /* STDC(1) */ - - -#endif |