summaryrefslogtreecommitdiff
path: root/src/lib/libc/stdlib/exit.c
diff options
context:
space:
mode:
authordhartmei <>2002-09-14 22:03:14 +0000
committerdhartmei <>2002-09-14 22:03:14 +0000
commit99933708b28d8f1a889e6109eb237499bf59eba2 (patch)
tree95adbcf0e9cc0d976e8e7b18bd1836b0faa0ecbf /src/lib/libc/stdlib/exit.c
parent3a3a489a756f2852d798376f20cc0d4ab609c866 (diff)
downloadopenbsd-99933708b28d8f1a889e6109eb237499bf59eba2.tar.gz
openbsd-99933708b28d8f1a889e6109eb237499bf59eba2.tar.bz2
openbsd-99933708b28d8f1a889e6109eb237499bf59eba2.zip
Move __cleanup into mprotect'ed page to prevent unintentional modifications
similar to the atexit handlers. Idea and help deraadt@, ok deraadt@
Diffstat (limited to 'src/lib/libc/stdlib/exit.c')
-rw-r--r--src/lib/libc/stdlib/exit.c10
1 files changed, 4 insertions, 6 deletions
diff --git a/src/lib/libc/stdlib/exit.c b/src/lib/libc/stdlib/exit.c
index c69639125e..e22bd5178e 100644
--- a/src/lib/libc/stdlib/exit.c
+++ b/src/lib/libc/stdlib/exit.c
@@ -32,7 +32,7 @@
32 */ 32 */
33 33
34#if defined(LIBC_SCCS) && !defined(lint) 34#if defined(LIBC_SCCS) && !defined(lint)
35static char *rcsid = "$OpenBSD: exit.c,v 1.7 2002/08/30 07:58:07 dhartmei Exp $"; 35static char *rcsid = "$OpenBSD: exit.c,v 1.8 2002/09/14 22:03:14 dhartmei Exp $";
36#endif /* LIBC_SCCS and not lint */ 36#endif /* LIBC_SCCS and not lint */
37 37
38#include <sys/types.h> 38#include <sys/types.h>
@@ -42,8 +42,6 @@ static char *rcsid = "$OpenBSD: exit.c,v 1.7 2002/08/30 07:58:07 dhartmei Exp $"
42#include "atexit.h" 42#include "atexit.h"
43#include "thread_private.h" 43#include "thread_private.h"
44 44
45void (*__cleanup)();
46
47/* 45/*
48 * This variable is zero until a process has created a thread. 46 * This variable is zero until a process has created a thread.
49 * It is used to avoid calling locking functions in libc when they 47 * It is used to avoid calling locking functions in libc when they
@@ -67,13 +65,13 @@ exit(status)
67 p = __atexit; 65 p = __atexit;
68 while (p != NULL) { 66 while (p != NULL) {
69 for (n = p->ind; --n >= 0;) 67 for (n = p->ind; --n >= 0;)
70 (*p->fns[n])(); 68 if (p->fns[n] != NULL)
69 (*p->fns[n])();
71 q = p; 70 q = p;
72 p = p->next; 71 p = p->next;
73 munmap(q, pgsize); 72 munmap(q, pgsize);
74 } 73 }
75 } 74 }
76 if (__cleanup) 75 /* cleanup, if registered, was called through fns[0] in the last page */
77 (*__cleanup)();
78 _exit(status); 76 _exit(status);
79} 77}