summaryrefslogtreecommitdiffstats
path: root/lib/librthread/rthread_libc.c
diff options
context:
space:
mode:
authorkurt <kurt@openbsd.org>2008-01-01 00:43:39 +0000
committerkurt <kurt@openbsd.org>2008-01-01 00:43:39 +0000
commit229f4f6ee4c7ecffe38220a1baa321e3465d69d6 (patch)
tree8958250da2db5f655350d351427431e7df1af2e8 /lib/librthread/rthread_libc.c
parentfix name (diff)
downloadwireguard-openbsd-229f4f6ee4c7ecffe38220a1baa321e3465d69d6.tar.xz
wireguard-openbsd-229f4f6ee4c7ecffe38220a1baa321e3465d69d6.zip
- make arc4random*() functions thread safe. Use a custom spinlock function
instead of the generic pthread macros since free(3) uses __arc4_getbyte() when freeing small sized allocations and the generic pthread macros call malloc(3). - eliminate passing pointers to a static variable with global scope (rs) for additional code clarity and reduction. - shlib minor bumps for libc and libpthread due to new functions. From andreas@ with some bits from me. okay tedu@ marc@ w/some spot checking from millert@
Diffstat (limited to 'lib/librthread/rthread_libc.c')
-rw-r--r--lib/librthread/rthread_libc.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/lib/librthread/rthread_libc.c b/lib/librthread/rthread_libc.c
index bf3c057d874..da0d92f8da5 100644
--- a/lib/librthread/rthread_libc.c
+++ b/lib/librthread/rthread_libc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rthread_libc.c,v 1.4 2007/06/05 18:11:49 kurt Exp $ */
+/* $OpenBSD: rthread_libc.c,v 1.5 2008/01/01 00:43:39 kurt Exp $ */
/* $snafu: libc_tag.c,v 1.4 2004/11/30 07:00:06 marc Exp $ */
/* PUBLIC DOMAIN: No Rights Reserved. Marco S Hyman <marc@snafu.org> */
@@ -175,6 +175,23 @@ _thread_malloc_init(void)
{
}
+/*
+ * arc4random lock
+ */
+static _spinlock_lock_t arc4_lock = _SPINLOCK_UNLOCKED;
+
+void
+_thread_arc4_lock(void)
+{
+ _spinlock(&arc4_lock);
+}
+
+void
+_thread_arc4_unlock(void)
+{
+ _spinunlock(&arc4_lock);
+}
+
#if 0
/*
* miscellaneous libc exported symbols we want to override