diff options
| author | matthew <> | 2013-06-02 21:08:36 +0000 | 
|---|---|---|
| committer | matthew <> | 2013-06-02 21:08:36 +0000 | 
| commit | 9e156cde788e5f63a85c507c8176b609be234528 (patch) | |
| tree | e26182b2ca2e8d39107cf5e87e5ebc882fdd0e4f /src/lib/libc | |
| parent | 6b0e941c80638e4ce54c2988f71cb15a0ee4d42f (diff) | |
| download | openbsd-9e156cde788e5f63a85c507c8176b609be234528.tar.gz openbsd-9e156cde788e5f63a85c507c8176b609be234528.tar.bz2 openbsd-9e156cde788e5f63a85c507c8176b609be234528.zip  | |
Two small cleanups to atexit: remove unneeded __atexit_invalid, and
move the call_depth decrement so it happens unconditionally and can
still return to 0 when called with dso!=NULL.
ok millert
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libc/stdlib/atexit.c | 14 | ||||
| -rw-r--r-- | src/lib/libc/stdlib/atexit.h | 3 | 
2 files changed, 5 insertions, 12 deletions
diff --git a/src/lib/libc/stdlib/atexit.c b/src/lib/libc/stdlib/atexit.c index e28ccf29d0..52f1cf3c5c 100644 --- a/src/lib/libc/stdlib/atexit.c +++ b/src/lib/libc/stdlib/atexit.c  | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: atexit.c,v 1.15 2011/03/02 18:34:05 matthew Exp $ */ | 1 | /* $OpenBSD: atexit.c,v 1.16 2013/06/02 21:08:36 matthew Exp $ */ | 
| 2 | /* | 2 | /* | 
| 3 | * Copyright (c) 2002 Daniel Hartmeier | 3 | * Copyright (c) 2002 Daniel Hartmeier | 
| 4 | * All rights reserved. | 4 | * All rights reserved. | 
| @@ -37,7 +37,6 @@ | |||
| 37 | #include "atexit.h" | 37 | #include "atexit.h" | 
| 38 | #include "thread_private.h" | 38 | #include "thread_private.h" | 
| 39 | 39 | ||
| 40 | int __atexit_invalid = 1; | ||
| 41 | struct atexit *__atexit; | 40 | struct atexit *__atexit; | 
| 42 | 41 | ||
| 43 | /* | 42 | /* | 
| @@ -89,8 +88,6 @@ __cxa_atexit(void (*func)(void *), void *arg, void *dso) | |||
| 89 | sizeof(p->fns[0]); | 88 | sizeof(p->fns[0]); | 
| 90 | p->next = __atexit; | 89 | p->next = __atexit; | 
| 91 | __atexit = p; | 90 | __atexit = p; | 
| 92 | if (__atexit_invalid) | ||
| 93 | __atexit_invalid = 0; | ||
| 94 | } | 91 | } | 
| 95 | fnp = &p->fns[p->ind++]; | 92 | fnp = &p->fns[p->ind++]; | 
| 96 | fnp->fn_ptr.cxa_func = func; | 93 | fnp->fn_ptr.cxa_func = func; | 
| @@ -126,9 +123,6 @@ __cxa_finalize(void *dso) | |||
| 126 | int n, pgsize = getpagesize(); | 123 | int n, pgsize = getpagesize(); | 
| 127 | static int call_depth; | 124 | static int call_depth; | 
| 128 | 125 | ||
| 129 | if (__atexit_invalid) | ||
| 130 | return; | ||
| 131 | |||
| 132 | call_depth++; | 126 | call_depth++; | 
| 133 | 127 | ||
| 134 | for (p = __atexit; p != NULL; p = p->next) { | 128 | for (p = __atexit; p != NULL; p = p->next) { | 
| @@ -154,12 +148,14 @@ __cxa_finalize(void *dso) | |||
| 154 | } | 148 | } | 
| 155 | } | 149 | } | 
| 156 | 150 | ||
| 151 | call_depth--; | ||
| 152 | |||
| 157 | /* | 153 | /* | 
| 158 | * If called via exit(), unmap the pages since we have now run | 154 | * If called via exit(), unmap the pages since we have now run | 
| 159 | * all the handlers. We defer this until calldepth == 0 so that | 155 | * all the handlers. We defer this until calldepth == 0 so that | 
| 160 | * we don't unmap things prematurely if called recursively. | 156 | * we don't unmap things prematurely if called recursively. | 
| 161 | */ | 157 | */ | 
| 162 | if (dso == NULL && --call_depth == 0) { | 158 | if (dso == NULL && call_depth == 0) { | 
| 163 | for (p = __atexit; p != NULL; ) { | 159 | for (p = __atexit; p != NULL; ) { | 
| 164 | q = p; | 160 | q = p; | 
| 165 | p = p->next; | 161 | p = p->next; | 
| @@ -194,8 +190,6 @@ __atexit_register_cleanup(void (*func)(void)) | |||
| 194 | sizeof(p->fns[0]); | 190 | sizeof(p->fns[0]); | 
| 195 | p->next = NULL; | 191 | p->next = NULL; | 
| 196 | __atexit = p; | 192 | __atexit = p; | 
| 197 | if (__atexit_invalid) | ||
| 198 | __atexit_invalid = 0; | ||
| 199 | } else { | 193 | } else { | 
| 200 | if (mprotect(p, pgsize, PROT_READ | PROT_WRITE)) | 194 | if (mprotect(p, pgsize, PROT_READ | PROT_WRITE)) | 
| 201 | goto unlock; | 195 | goto unlock; | 
diff --git a/src/lib/libc/stdlib/atexit.h b/src/lib/libc/stdlib/atexit.h index 1b23565dd0..c44005deda 100644 --- a/src/lib/libc/stdlib/atexit.h +++ b/src/lib/libc/stdlib/atexit.h  | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: atexit.h,v 1.7 2007/09/03 14:40:16 millert Exp $ */ | 1 | /* $OpenBSD: atexit.h,v 1.8 2013/06/02 21:08:36 matthew Exp $ */ | 
| 2 | 2 | ||
| 3 | /* | 3 | /* | 
| 4 | * Copyright (c) 2002 Daniel Hartmeier | 4 | * Copyright (c) 2002 Daniel Hartmeier | 
| @@ -44,7 +44,6 @@ struct atexit { | |||
| 44 | } fns[1]; /* the table itself */ | 44 | } fns[1]; /* the table itself */ | 
| 45 | }; | 45 | }; | 
| 46 | 46 | ||
| 47 | extern int __atexit_invalid; | ||
| 48 | extern struct atexit *__atexit; /* points to head of LIFO stack */ | 47 | extern struct atexit *__atexit; /* points to head of LIFO stack */ | 
| 49 | 48 | ||
| 50 | int __cxa_atexit(void (*)(void *), void *, void *); | 49 | int __cxa_atexit(void (*)(void *), void *, void *); | 
