diff options
author | Geoff Thorpe <geoff@openssl.org> | 2008-03-28 02:49:43 +0000 |
---|---|---|
committer | Geoff Thorpe <geoff@openssl.org> | 2008-03-28 02:49:43 +0000 |
commit | f7ccba3edf9f1f02d7bd3b019d7bc96f25a95718 (patch) | |
tree | 734b39872b1b8c3cee1db78ed5eb7e3214d6a0a7 /crypto/err | |
parent | eb77ebe26c5228a9a9688b33901e79968789b980 (diff) | |
download | openssl-new-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')
-rw-r--r-- | crypto/err/err.c | 42 | ||||
-rw-r--r-- | crypto/err/err.h | 7 | ||||
-rw-r--r-- | crypto/err/err_prn.c | 4 |
3 files changed, 28 insertions, 25 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++) diff --git a/crypto/err/err.h b/crypto/err/err.h index 9a6aecfce6..c56f5aadb2 100644 --- a/crypto/err/err.h +++ b/crypto/err/err.h @@ -147,8 +147,10 @@ extern "C" { #define ERR_NUM_ERRORS 16 typedef struct err_state_st { +#ifndef OPENSSL_NO_DEPRECATED unsigned long pid; - void *pidptr; /* new in OpenSSL 0.9.9 */ +#endif + CRYPTO_THREADID tid; int err_flags[ERR_NUM_ERRORS]; unsigned long err_buffer[ERR_NUM_ERRORS]; char *err_data[ERR_NUM_ERRORS]; @@ -349,7 +351,10 @@ void ERR_load_ERR_strings(void); void ERR_load_crypto_strings(void); void ERR_free_strings(void); +void ERR_remove_thread_state(CRYPTO_THREADID *tid); +#ifndef OPENSSL_NO_DEPRECATED void ERR_remove_state(unsigned long pid); /* if zero we look it up */ +#endif ERR_STATE *ERR_get_state(void); #ifndef OPENSSL_NO_LHASH diff --git a/crypto/err/err_prn.c b/crypto/err/err_prn.c index 2224a901e5..6515d10c07 100644 --- a/crypto/err/err_prn.c +++ b/crypto/err/err_prn.c @@ -72,8 +72,10 @@ void ERR_print_errors_cb(int (*cb)(const char *str, size_t len, void *u), const char *file,*data; int line,flags; unsigned long es; + CRYPTO_THREADID tid; - es=CRYPTO_thread_id(); + CRYPTO_THREADID_set(&tid); + es = CRYPTO_THREADID_hash(&tid); while ((l=ERR_get_error_line_data(&file,&line,&data,&flags)) != 0) { ERR_error_string_n(l, buf, sizeof buf); |