summaryrefslogtreecommitdiff
path: root/src/lib/libc/stdlib/exit.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libc/stdlib/exit.c')
-rw-r--r--src/lib/libc/stdlib/exit.c36
1 files changed, 26 insertions, 10 deletions
diff --git a/src/lib/libc/stdlib/exit.c b/src/lib/libc/stdlib/exit.c
index b1412f42bb..e22bd5178e 100644
--- a/src/lib/libc/stdlib/exit.c
+++ b/src/lib/libc/stdlib/exit.c
@@ -32,15 +32,24 @@
32 */ 32 */
33 33
34#if defined(LIBC_SCCS) && !defined(lint) 34#if defined(LIBC_SCCS) && !defined(lint)
35/*static char *sccsid = "from: @(#)exit.c 5.4 (Berkeley) 2/23/91";*/ 35static char *rcsid = "$OpenBSD: exit.c,v 1.8 2002/09/14 22:03:14 dhartmei Exp $";
36static char *rcsid = "$Id: exit.c,v 1.1.1.1 1995/10/18 08:42:17 deraadt Exp $";
37#endif /* LIBC_SCCS and not lint */ 36#endif /* LIBC_SCCS and not lint */
38 37
38#include <sys/types.h>
39#include <sys/mman.h>
39#include <stdlib.h> 40#include <stdlib.h>
40#include <unistd.h> 41#include <unistd.h>
41#include "atexit.h" 42#include "atexit.h"
43#include "thread_private.h"
42 44
43void (*__cleanup)(); 45/*
46 * This variable is zero until a process has created a thread.
47 * It is used to avoid calling locking functions in libc when they
48 * are not required. By default, libc is intended to be(come)
49 * thread-safe, but without a (significant) penalty to non-threaded
50 * processes.
51 */
52int __isthreaded = 0;
44 53
45/* 54/*
46 * Exit, flushing stdio buffers if necessary. 55 * Exit, flushing stdio buffers if necessary.
@@ -49,13 +58,20 @@ void
49exit(status) 58exit(status)
50 int status; 59 int status;
51{ 60{
52 register struct atexit *p; 61 register struct atexit *p, *q;
53 register int n; 62 register int n, pgsize = getpagesize();
54 63
55 for (p = __atexit; p; p = p->next) 64 if (!__atexit_invalid) {
56 for (n = p->ind; --n >= 0;) 65 p = __atexit;
57 (*p->fns[n])(); 66 while (p != NULL) {
58 if (__cleanup) 67 for (n = p->ind; --n >= 0;)
59 (*__cleanup)(); 68 if (p->fns[n] != NULL)
69 (*p->fns[n])();
70 q = p;
71 p = p->next;
72 munmap(q, pgsize);
73 }
74 }
75 /* cleanup, if registered, was called through fns[0] in the last page */
60 _exit(status); 76 _exit(status);
61} 77}