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@
This commit is contained in:
Brent Cook 2014-07-15 14:50:05 -05:00
parent 7f2fab20bc
commit 32d9eeeecf

View File

@ -4,3 +4,11 @@ static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER;
#define _ARC4_LOCK() pthread_mutex_lock(&arc4random_mtx) #define _ARC4_LOCK() pthread_mutex_lock(&arc4random_mtx)
#define _ARC4_UNLOCK() pthread_mutex_unlock(&arc4random_mtx) #define _ARC4_UNLOCK() pthread_mutex_unlock(&arc4random_mtx)
#ifdef __GLIBC__
extern void *__dso_handle;
extern int __register_atfork(void (*)(void), void(*)(void), void (*)(void), void *);
#define _ARC4_ATFORK(f) __register_atfork(NULL, NULL, (f), __dso_handle)
#else
#define _ARC4_ATFORK(f) pthread_atfork(NULL, NULL, (f))
#endif