diff options
author | Brent Cook <bcook@openbsd.org> | 2014-07-15 14:50:05 -0500 |
---|---|---|
committer | Brent Cook <bcook@openbsd.org> | 2014-07-15 14:50:05 -0500 |
commit | 32d9eeeecf4e951e1566d5f4a42b36ea37b60f35 (patch) | |
tree | 920b4122a61b5445894433e881424fac42d09b10 | |
parent | 7f2fab20bc1327d1b390cf5c44047da4ad3a599a (diff) | |
download | portable-32d9eeeecf4e951e1566d5f4a42b36ea37b60f35.tar.gz portable-32d9eeeecf4e951e1566d5f4a42b36ea37b60f35.tar.bz2 portable-32d9eeeecf4e951e1566d5f4a42b36ea37b60f35.zip |
register the atfork handler from arc4random
From kettenis@
People have suggested using pthread_atfork(3) before, but discarded
the idea because it involves linking with -lpthread, which has other
undesirable consequences. However:
* Most systems actually have pthread_atfork(3) in libc. I verified
this on OS X and Solaris. I believe this is the case on Linux
systems that use musl as well.
* On Linux systems that use glibc, this isn't the case. However,
those systems have __register_atfork(3), which is fully documented
in the "Linux Standard Base Core Specification".
ok kettenis@ deraadt@ beck@
-rw-r--r-- | crypto/compat/thread_private.h | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/crypto/compat/thread_private.h b/crypto/compat/thread_private.h index 3286a7c..c5b0daf 100644 --- a/crypto/compat/thread_private.h +++ b/crypto/compat/thread_private.h | |||
@@ -4,3 +4,11 @@ static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER; | |||
4 | 4 | ||
5 | #define _ARC4_LOCK() pthread_mutex_lock(&arc4random_mtx) | 5 | #define _ARC4_LOCK() pthread_mutex_lock(&arc4random_mtx) |
6 | #define _ARC4_UNLOCK() pthread_mutex_unlock(&arc4random_mtx) | 6 | #define _ARC4_UNLOCK() pthread_mutex_unlock(&arc4random_mtx) |
7 | |||
8 | #ifdef __GLIBC__ | ||
9 | extern void *__dso_handle; | ||
10 | extern int __register_atfork(void (*)(void), void(*)(void), void (*)(void), void *); | ||
11 | #define _ARC4_ATFORK(f) __register_atfork(NULL, NULL, (f), __dso_handle) | ||
12 | #else | ||
13 | #define _ARC4_ATFORK(f) pthread_atfork(NULL, NULL, (f)) | ||
14 | #endif | ||