Browse Source

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
OPENBSD_5_4
matthew 11 years ago
parent
commit
541be88fbc
2 changed files with 5 additions and 12 deletions
  1. +4
    -10
      src/lib/libc/stdlib/atexit.c
  2. +1
    -2
      src/lib/libc/stdlib/atexit.h

+ 4
- 10
src/lib/libc/stdlib/atexit.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: atexit.c,v 1.15 2011/03/02 18:34:05 matthew Exp $ */
/* $OpenBSD: atexit.c,v 1.16 2013/06/02 21:08:36 matthew Exp $ */
/* /*
* Copyright (c) 2002 Daniel Hartmeier * Copyright (c) 2002 Daniel Hartmeier
* All rights reserved. * All rights reserved.
@ -37,7 +37,6 @@
#include "atexit.h" #include "atexit.h"
#include "thread_private.h" #include "thread_private.h"
int __atexit_invalid = 1;
struct atexit *__atexit; struct atexit *__atexit;
/* /*
@ -89,8 +88,6 @@ __cxa_atexit(void (*func)(void *), void *arg, void *dso)
sizeof(p->fns[0]); sizeof(p->fns[0]);
p->next = __atexit; p->next = __atexit;
__atexit = p; __atexit = p;
if (__atexit_invalid)
__atexit_invalid = 0;
} }
fnp = &p->fns[p->ind++]; fnp = &p->fns[p->ind++];
fnp->fn_ptr.cxa_func = func; fnp->fn_ptr.cxa_func = func;
@ -126,9 +123,6 @@ __cxa_finalize(void *dso)
int n, pgsize = getpagesize(); int n, pgsize = getpagesize();
static int call_depth; static int call_depth;
if (__atexit_invalid)
return;
call_depth++; call_depth++;
for (p = __atexit; p != NULL; p = p->next) { for (p = __atexit; p != NULL; p = p->next) {
@ -154,12 +148,14 @@ __cxa_finalize(void *dso)
} }
} }
call_depth--;
/* /*
* If called via exit(), unmap the pages since we have now run * If called via exit(), unmap the pages since we have now run
* all the handlers. We defer this until calldepth == 0 so that * all the handlers. We defer this until calldepth == 0 so that
* we don't unmap things prematurely if called recursively. * we don't unmap things prematurely if called recursively.
*/ */
if (dso == NULL && --call_depth == 0) {
if (dso == NULL && call_depth == 0) {
for (p = __atexit; p != NULL; ) { for (p = __atexit; p != NULL; ) {
q = p; q = p;
p = p->next; p = p->next;
@ -194,8 +190,6 @@ __atexit_register_cleanup(void (*func)(void))
sizeof(p->fns[0]); sizeof(p->fns[0]);
p->next = NULL; p->next = NULL;
__atexit = p; __atexit = p;
if (__atexit_invalid)
__atexit_invalid = 0;
} else { } else {
if (mprotect(p, pgsize, PROT_READ | PROT_WRITE)) if (mprotect(p, pgsize, PROT_READ | PROT_WRITE))
goto unlock; goto unlock;


+ 1
- 2
src/lib/libc/stdlib/atexit.h View File

@ -1,4 +1,4 @@
/* $OpenBSD: atexit.h,v 1.7 2007/09/03 14:40:16 millert Exp $ */
/* $OpenBSD: atexit.h,v 1.8 2013/06/02 21:08:36 matthew Exp $ */
/* /*
* Copyright (c) 2002 Daniel Hartmeier * Copyright (c) 2002 Daniel Hartmeier
@ -44,7 +44,6 @@ struct atexit {
} fns[1]; /* the table itself */ } fns[1]; /* the table itself */
}; };
extern int __atexit_invalid;
extern struct atexit *__atexit; /* points to head of LIFO stack */ extern struct atexit *__atexit; /* points to head of LIFO stack */
int __cxa_atexit(void (*)(void *), void *, void *); int __cxa_atexit(void (*)(void *), void *, void *);


Loading…
Cancel
Save