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.c42
1 files changed, 27 insertions, 15 deletions
diff --git a/src/lib/libc/stdlib/exit.c b/src/lib/libc/stdlib/exit.c
index b1412f42bb..a75b32abeb 100644
--- a/src/lib/libc/stdlib/exit.c
+++ b/src/lib/libc/stdlib/exit.c
@@ -10,11 +10,7 @@
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the 11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution. 12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software 13 * 3. Neither the name of the University nor the names of its contributors
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software 14 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission. 15 * without specific prior written permission.
20 * 16 *
@@ -32,15 +28,24 @@
32 */ 28 */
33 29
34#if defined(LIBC_SCCS) && !defined(lint) 30#if defined(LIBC_SCCS) && !defined(lint)
35/*static char *sccsid = "from: @(#)exit.c 5.4 (Berkeley) 2/23/91";*/ 31static char *rcsid = "$OpenBSD: exit.c,v 1.9 2003/06/02 20:18:37 millert 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 */ 32#endif /* LIBC_SCCS and not lint */
38 33
34#include <sys/types.h>
35#include <sys/mman.h>
39#include <stdlib.h> 36#include <stdlib.h>
40#include <unistd.h> 37#include <unistd.h>
41#include "atexit.h" 38#include "atexit.h"
39#include "thread_private.h"
42 40
43void (*__cleanup)(); 41/*
42 * This variable is zero until a process has created a thread.
43 * It is used to avoid calling locking functions in libc when they
44 * are not required. By default, libc is intended to be(come)
45 * thread-safe, but without a (significant) penalty to non-threaded
46 * processes.
47 */
48int __isthreaded = 0;
44 49
45/* 50/*
46 * Exit, flushing stdio buffers if necessary. 51 * Exit, flushing stdio buffers if necessary.
@@ -49,13 +54,20 @@ void
49exit(status) 54exit(status)
50 int status; 55 int status;
51{ 56{
52 register struct atexit *p; 57 register struct atexit *p, *q;
53 register int n; 58 register int n, pgsize = getpagesize();
54 59
55 for (p = __atexit; p; p = p->next) 60 if (!__atexit_invalid) {
56 for (n = p->ind; --n >= 0;) 61 p = __atexit;
57 (*p->fns[n])(); 62 while (p != NULL) {
58 if (__cleanup) 63 for (n = p->ind; --n >= 0;)
59 (*__cleanup)(); 64 if (p->fns[n] != NULL)
65 (*p->fns[n])();
66 q = p;
67 p = p->next;
68 munmap(q, pgsize);
69 }
70 }
71 /* cleanup, if registered, was called through fns[0] in the last page */
60 _exit(status); 72 _exit(status);
61} 73}