summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdlib/atexit.c
diff options
context:
space:
mode:
authorkettenis <kettenis@openbsd.org>2014-07-11 09:51:37 +0000
committerkettenis <kettenis@openbsd.org>2014-07-11 09:51:37 +0000
commit43de99abf1f072136c0d3b4a26cef9c8e95a87dd (patch)
tree746f35d6e861b88a75403853f584beaa197e2816 /lib/libc/stdlib/atexit.c
parentRemove the commentary about the majority of this code being under (diff)
downloadwireguard-openbsd-43de99abf1f072136c0d3b4a26cef9c8e95a87dd.tar.xz
wireguard-openbsd-43de99abf1f072136c0d3b4a26cef9c8e95a87dd.zip
Add locking for __cxa_finalize() as it modifies the page permissions of the
__atexit tables and touches global variables. From Srinavasa Nagaraju through Android/Elliott Hughes. ok tedu@, guenther@
Diffstat (limited to 'lib/libc/stdlib/atexit.c')
-rw-r--r--lib/libc/stdlib/atexit.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/libc/stdlib/atexit.c b/lib/libc/stdlib/atexit.c
index 34f76bb7d3a..6532b382eab 100644
--- a/lib/libc/stdlib/atexit.c
+++ b/lib/libc/stdlib/atexit.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: atexit.c,v 1.19 2014/07/10 21:14:22 tedu Exp $ */
+/* $OpenBSD: atexit.c,v 1.20 2014/07/11 09:51:37 kettenis Exp $ */
/*
* Copyright (c) 2002 Daniel Hartmeier
* All rights reserved.
@@ -116,6 +116,7 @@ __cxa_finalize(void *dso)
int n, pgsize = getpagesize();
static int call_depth;
+ _ATEXIT_LOCK();
call_depth++;
restart:
@@ -136,7 +137,9 @@ restart:
p->fns[n].fn_ptr = NULL;
mprotect(p, pgsize, PROT_READ);
}
+ _ATEXIT_UNLOCK();
(*fn.fn_ptr)(fn.fn_arg);
+ _ATEXIT_LOCK();
if (restartloop)
goto restart;
}
@@ -157,6 +160,7 @@ restart:
}
__atexit = NULL;
}
+ _ATEXIT_UNLOCK();
}
/*