summaryrefslogtreecommitdiffstats
path: root/crypto/rand/md_rand.c
diff options
context:
space:
mode:
authorGeoff Thorpe <geoff@openssl.org>2008-03-28 02:49:43 +0000
committerGeoff Thorpe <geoff@openssl.org>2008-03-28 02:49:43 +0000
commitf7ccba3edf9f1f02d7bd3b019d7bc96f25a95718 (patch)
tree734b39872b1b8c3cee1db78ed5eb7e3214d6a0a7 /crypto/rand/md_rand.c
parenteb77ebe26c5228a9a9688b33901e79968789b980 (diff)
There was a need to support thread ID types that couldn't be reliably cast
to 'unsigned long' (ie. odd platforms/compilers), so a pointer-typed version was added but it required portable code to check *both* modes to determine equality. This commit maintains the availability of both thread ID types, but deprecates the type-specific accessor APIs that invoke the callbacks - instead a single type-independent API is used. This simplifies software that calls into this interface, and should also make it less error-prone - as forgetting to call and compare *both* thread ID accessors could have led to hard-to-debug/infrequent bugs (that might only affect certain platforms or thread implementations). As the CHANGES note says, there were corresponding deprecations and replacements in the thread-related functions for BN_BLINDING and ERR too.
Diffstat (limited to 'crypto/rand/md_rand.c')
-rw-r--r--crypto/rand/md_rand.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/crypto/rand/md_rand.c b/crypto/rand/md_rand.c
index cfc78774f7..59535b9e70 100644
--- a/crypto/rand/md_rand.c
+++ b/crypto/rand/md_rand.c
@@ -145,8 +145,7 @@ static unsigned int crypto_lock_rand = 0; /* may be set only when a thread
* holds CRYPTO_LOCK_RAND
* (to prevent double locking) */
/* access to lockin_thread is synchronized by CRYPTO_LOCK_RAND2 */
-static unsigned long locking_thread_id = 0; /* valid iff crypto_lock_rand is set */
-static void *locking_thread_idptr = NULL; /* valid iff crypto_lock_rand is set */
+static CRYPTO_THREADID locking_tid;
#ifdef PREDICT
@@ -214,8 +213,10 @@ static void ssleay_rand_add(const void *buf, int num, double add)
/* check if we already have the lock */
if (crypto_lock_rand)
{
+ CRYPTO_THREADID tid;
+ CRYPTO_THREADID_set(&tid);
CRYPTO_r_lock(CRYPTO_LOCK_RAND2);
- do_not_lock = (locking_thread_id == CRYPTO_thread_id()) && (locking_thread_idptr == CRYPTO_thread_idptr());
+ do_not_lock = !CRYPTO_THREADID_cmp(&locking_tid, &tid);
CRYPTO_r_unlock(CRYPTO_LOCK_RAND2);
}
else
@@ -373,8 +374,7 @@ static int ssleay_rand_bytes(unsigned char *buf, int num)
/* prevent ssleay_rand_bytes() from trying to obtain the lock again */
CRYPTO_w_lock(CRYPTO_LOCK_RAND2);
- locking_thread_id = CRYPTO_thread_id();
- locking_thread_idptr = CRYPTO_thread_idptr();
+ CRYPTO_THREADID_set(&locking_tid);
CRYPTO_w_unlock(CRYPTO_LOCK_RAND2);
crypto_lock_rand = 1;
@@ -536,8 +536,10 @@ static int ssleay_rand_status(void)
* (could happen if a RAND_poll() implementation calls RAND_status()) */
if (crypto_lock_rand)
{
+ CRYPTO_THREADID tid;
+ CRYPTO_THREADID_set(&tid);
CRYPTO_r_lock(CRYPTO_LOCK_RAND2);
- do_not_lock = (locking_thread_id == CRYPTO_thread_id()) && (locking_thread_idptr == CRYPTO_thread_idptr());
+ do_not_lock = !CRYPTO_THREADID_cmp(&locking_tid, &tid);
CRYPTO_r_unlock(CRYPTO_LOCK_RAND2);
}
else
@@ -549,8 +551,7 @@ static int ssleay_rand_status(void)
/* prevent ssleay_rand_bytes() from trying to obtain the lock again */
CRYPTO_w_lock(CRYPTO_LOCK_RAND2);
- locking_thread_id = CRYPTO_thread_id();
- locking_thread_idptr = CRYPTO_thread_idptr();
+ CRYPTO_THREADID_set(&locking_tid);
CRYPTO_w_unlock(CRYPTO_LOCK_RAND2);
crypto_lock_rand = 1;
}