aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/err/err.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/err/err.c
parenteb77ebe26c5228a9a9688b33901e79968789b980 (diff)
downloadopenssl-f7ccba3edf9f1f02d7bd3b019d7bc96f25a95718.tar.gz
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/err/err.c')
-rw-r--r--crypto/err/err.c42
1 files changed, 19 insertions, 23 deletions
diff --git a/crypto/err/err.c b/crypto/err/err.c
index 09b9812b7e..8adcd9f96d 100644
--- a/crypto/err/err.c
+++ b/crypto/err/err.c
@@ -975,50 +975,47 @@ static int err_cmp(const void *a_void, const void *b_void)
/* static unsigned long pid_hash(ERR_STATE *a) */
static unsigned long pid_hash(const void *a_void)
{
- return((((const ERR_STATE *)a_void)->pid + (unsigned long)((const ERR_STATE *)a_void)->pidptr)*13);
+ return CRYPTO_THREADID_hash(&((const ERR_STATE *)a_void)->tid);
}
/* static int pid_cmp(ERR_STATE *a, ERR_STATE *b) */
static int pid_cmp(const void *a_void, const void *b_void)
{
- return (((const ERR_STATE *)a_void)->pid != ((const ERR_STATE *)b_void)->pid)
- || (((const ERR_STATE *)a_void)->pidptr != ((const ERR_STATE *)b_void)->pidptr);
+ return CRYPTO_THREADID_cmp(&((const ERR_STATE *)a_void)->tid,
+ &((const ERR_STATE *)b_void)->tid);
}
-void ERR_remove_state(unsigned long pid)
+void ERR_remove_thread_state(CRYPTO_THREADID *tid)
{
ERR_STATE tmp;
- void *pidptr;
- err_fns_check();
- if (pid != 0)
- pidptr = &errno;
+ if (tid)
+ CRYPTO_THREADID_cpy(&tmp.tid, tid);
else
- {
- pid = CRYPTO_thread_id();
- pidptr = CRYPTO_thread_idptr();
- }
-
- tmp.pid=pid;
- tmp.pidptr=pidptr;
+ CRYPTO_THREADID_set(&tmp.tid);
+ err_fns_check();
/* thread_del_item automatically destroys the LHASH if the number of
* items reaches zero. */
ERRFN(thread_del_item)(&tmp);
}
+#ifndef OPENSSL_NO_DEPRECATED
+void ERR_remove_state(unsigned long pid)
+ {
+ ERR_remove_thread_state(NULL);
+ }
+#endif
+
ERR_STATE *ERR_get_state(void)
{
static ERR_STATE fallback;
+ CRYPTO_THREADID tid;
ERR_STATE *ret,tmp,*tmpp=NULL;
int i;
- unsigned long pid;
- void *pidptr;
err_fns_check();
- pid = CRYPTO_thread_id();
- pidptr = CRYPTO_thread_idptr();
- tmp.pid = pid;
- tmp.pidptr = pidptr;
+ CRYPTO_THREADID_set(&tid);
+ CRYPTO_THREADID_cpy(&tmp.tid, &tid);
ret=ERRFN(thread_get_item)(&tmp);
/* ret == the error state, if NULL, make a new one */
@@ -1026,8 +1023,7 @@ ERR_STATE *ERR_get_state(void)
{
ret=(ERR_STATE *)OPENSSL_malloc(sizeof(ERR_STATE));
if (ret == NULL) return(&fallback);
- ret->pid=pid;
- ret->pidptr=pidptr;
+ CRYPTO_THREADID_cpy(&ret->tid, &tid);
ret->top=0;
ret->bottom=0;
for (i=0; i<ERR_NUM_ERRORS; i++)