From 541be88fbc6e4114340a2ae0bc4dfec6bb9f8b3e Mon Sep 17 00:00:00 2001 From: matthew <> Date: Sun, 2 Jun 2013 21:08:36 +0000 Subject: [PATCH] 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 --- src/lib/libc/stdlib/atexit.c | 14 ++++---------- 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 e28ccf29..52f1cf3c 100644 --- a/src/lib/libc/stdlib/atexit.c +++ b/src/lib/libc/stdlib/atexit.c @@ -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 * All rights reserved. @@ -37,7 +37,6 @@ #include "atexit.h" #include "thread_private.h" -int __atexit_invalid = 1; struct atexit *__atexit; /* @@ -89,8 +88,6 @@ __cxa_atexit(void (*func)(void *), void *arg, void *dso) sizeof(p->fns[0]); p->next = __atexit; __atexit = p; - if (__atexit_invalid) - __atexit_invalid = 0; } fnp = &p->fns[p->ind++]; fnp->fn_ptr.cxa_func = func; @@ -126,9 +123,6 @@ __cxa_finalize(void *dso) int n, pgsize = getpagesize(); static int call_depth; - if (__atexit_invalid) - return; - call_depth++; 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 * all the handlers. We defer this until calldepth == 0 so that * 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; ) { q = p; p = p->next; @@ -194,8 +190,6 @@ __atexit_register_cleanup(void (*func)(void)) sizeof(p->fns[0]); p->next = NULL; __atexit = p; - if (__atexit_invalid) - __atexit_invalid = 0; } else { if (mprotect(p, pgsize, PROT_READ | PROT_WRITE)) goto unlock; diff --git a/src/lib/libc/stdlib/atexit.h b/src/lib/libc/stdlib/atexit.h index 1b23565d..c44005de 100644 --- a/src/lib/libc/stdlib/atexit.h +++ b/src/lib/libc/stdlib/atexit.h @@ -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 @@ -44,7 +44,6 @@ struct atexit { } fns[1]; /* the table itself */ }; -extern int __atexit_invalid; extern struct atexit *__atexit; /* points to head of LIFO stack */ int __cxa_atexit(void (*)(void *), void *, void *);