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.c45
1 files changed, 28 insertions, 17 deletions
diff --git a/src/lib/libc/stdlib/exit.c b/src/lib/libc/stdlib/exit.c
index b1412f42bb..a0960e83c4 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,30 +28,45 @@
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.10 2005/03/30 18:51:49 pat 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.
47 */ 52 */
48void 53void
49exit(status) 54exit(int status)
50 int status;
51{ 55{
52 register struct atexit *p; 56 struct atexit *p, *q;
53 register int n; 57 int n, pgsize = getpagesize();
54 58
55 for (p = __atexit; p; p = p->next) 59 if (!__atexit_invalid) {
56 for (n = p->ind; --n >= 0;) 60 p = __atexit;
57 (*p->fns[n])(); 61 while (p != NULL) {
58 if (__cleanup) 62 for (n = p->ind; --n >= 0;)
59 (*__cleanup)(); 63 if (p->fns[n] != NULL)
64 (*p->fns[n])();
65 q = p;
66 p = p->next;
67 munmap(q, pgsize);
68 }
69 }
70 /* cleanup, if registered, was called through fns[0] in the last page */
60 _exit(status); 71 _exit(status);
61} 72}