📄 err_def.c
字号:
CRYPTO_w_unlock(CRYPTO_LOCK_ERR); return p; }static LHASH *int_thread_get(int create) { LHASH *ret = NULL; CRYPTO_w_lock(CRYPTO_LOCK_ERR); if (!int_thread_hash && create) { CRYPTO_push_info("int_thread_get (err.c)"); int_thread_hash = lh_new(pid_hash, pid_cmp); CRYPTO_pop_info(); } if (int_thread_hash) { int_thread_hash_references++; ret = int_thread_hash; } CRYPTO_w_unlock(CRYPTO_LOCK_ERR); return ret; }static void int_thread_release(LHASH **hash) { int i; if (hash == NULL || *hash == NULL) return; i = CRYPTO_add(&int_thread_hash_references, -1, CRYPTO_LOCK_ERR);#ifdef REF_PRINT fprintf(stderr,"%4d:%s\n",int_thread_hash_references,"ERR");#endif if (i > 0) return;#ifdef REF_CHECK if (i < 0) { fprintf(stderr,"int_thread_release, bad reference count\n"); abort(); /* ok */ }#endif *hash = NULL; }static ERR_STATE *int_thread_get_item(const ERR_STATE *d) { ERR_STATE *p; LHASH *hash; err_fns_check(); hash = ERRFN(thread_get)(0); if (!hash) return NULL; CRYPTO_r_lock(CRYPTO_LOCK_ERR); p = (ERR_STATE *)lh_retrieve(hash, d); CRYPTO_r_unlock(CRYPTO_LOCK_ERR); ERRFN(thread_release)(&hash); return p; }static ERR_STATE *int_thread_set_item(ERR_STATE *d) { ERR_STATE *p; LHASH *hash; err_fns_check(); hash = ERRFN(thread_get)(1); if (!hash) return NULL; CRYPTO_w_lock(CRYPTO_LOCK_ERR); p = (ERR_STATE *)lh_insert(hash, d); CRYPTO_w_unlock(CRYPTO_LOCK_ERR); ERRFN(thread_release)(&hash); return p; }static void int_thread_del_item(const ERR_STATE *d) { ERR_STATE *p; LHASH *hash; err_fns_check(); hash = ERRFN(thread_get)(0); if (!hash) return; CRYPTO_w_lock(CRYPTO_LOCK_ERR); p = (ERR_STATE *)lh_delete(hash, d); /* make sure we don't leak memory */ if (int_thread_hash_references == 1 && int_thread_hash && (lh_num_items(int_thread_hash) == 0)) { lh_free(int_thread_hash); int_thread_hash = NULL; } CRYPTO_w_unlock(CRYPTO_LOCK_ERR); ERRFN(thread_release)(&hash); if (p) ERR_STATE_free(p); }static int int_err_get_next_lib(void) { int ret; CRYPTO_w_lock(CRYPTO_LOCK_ERR); ret = int_err_library_number++; CRYPTO_w_unlock(CRYPTO_LOCK_ERR); return ret; }static void ERR_STATE_free(ERR_STATE *s) { int i; if (s == NULL) return; for (i=0; i<ERR_NUM_ERRORS; i++) { err_clear_data(s,i); } OPENSSL_free(s); }static void err_load_strings(int lib, ERR_STRING_DATA *str) { while (str->error) { if (lib) str->error|=ERR_PACK(lib,0,0); ERRFN(err_set_item)(str); str++; } }void ERR_load_strings(int lib, ERR_STRING_DATA *str) { err_fns_check(); err_load_strings(lib, str); }void ERR_unload_strings(int lib, ERR_STRING_DATA *str) { while (str->error) { if (lib) str->error|=ERR_PACK(lib,0,0); ERRFN(err_del_item)(str); str++; } }void ERR_free_strings(void) { err_fns_check(); ERRFN(err_del)(); }LHASH *ERR_get_string_table(void) { err_fns_check(); return ERRFN(err_get)(0); }LHASH *ERR_get_err_state_table(void) { err_fns_check(); return ERRFN(thread_get)(0); }void ERR_release_err_state_table(LHASH **hash) { err_fns_check(); ERRFN(thread_release)(hash); }const char *ERR_lib_error_string(unsigned long e) { ERR_STRING_DATA d,*p; unsigned long l; err_fns_check(); l=ERR_GET_LIB(e); d.error=ERR_PACK(l,0,0); p=ERRFN(err_get_item)(&d); return((p == NULL)?NULL:p->string); }const char *ERR_func_error_string(unsigned long e) { ERR_STRING_DATA d,*p; unsigned long l,f; err_fns_check(); l=ERR_GET_LIB(e); f=ERR_GET_FUNC(e); d.error=ERR_PACK(l,f,0); p=ERRFN(err_get_item)(&d); return((p == NULL)?NULL:p->string); }const char *ERR_reason_error_string(unsigned long e) { ERR_STRING_DATA d,*p=NULL; unsigned long l,r; err_fns_check(); l=ERR_GET_LIB(e); r=ERR_GET_REASON(e); d.error=ERR_PACK(l,0,r); p=ERRFN(err_get_item)(&d); if (!p) { d.error=ERR_PACK(0,0,r); p=ERRFN(err_get_item)(&d); } return((p == NULL)?NULL:p->string); }/* static unsigned long err_hash(ERR_STRING_DATA *a) */static unsigned long err_hash(const void *a_void) { unsigned long ret,l; l=((const ERR_STRING_DATA *)a_void)->error; ret=l^ERR_GET_LIB(l)^ERR_GET_FUNC(l); return(ret^ret%19*13); }/* static int err_cmp(ERR_STRING_DATA *a, ERR_STRING_DATA *b) */static int err_cmp(const void *a_void, const void *b_void) { return((int)(((const ERR_STRING_DATA *)a_void)->error - ((const ERR_STRING_DATA *)b_void)->error)); }/* static unsigned long pid_hash(ERR_STATE *a) */static unsigned long pid_hash(const void *a_void) { return(((const ERR_STATE *)a_void)->pid*13); }/* static int pid_cmp(ERR_STATE *a, ERR_STATE *b) */static int pid_cmp(const void *a_void, const void *b_void) { return((int)((long)((const ERR_STATE *)a_void)->pid - (long)((const ERR_STATE *)b_void)->pid)); }#ifdef OPENSSL_FIPSstatic void int_err_remove_state(unsigned long pid)#elsevoid ERR_remove_state(unsigned long pid)#endif { ERR_STATE tmp; err_fns_check(); if (pid == 0) pid=(unsigned long)CRYPTO_thread_id(); tmp.pid=pid; /* thread_del_item automatically destroys the LHASH if the number of * items reaches zero. */ ERRFN(thread_del_item)(&tmp); }#ifdef OPENSSL_FIPS static ERR_STATE *int_err_get_state(void)#elseERR_STATE *ERR_get_state(void)#endif { static ERR_STATE fallback; ERR_STATE *ret,tmp,*tmpp=NULL; int i; unsigned long pid; err_fns_check(); pid=(unsigned long)CRYPTO_thread_id(); tmp.pid=pid; ret=ERRFN(thread_get_item)(&tmp); /* ret == the error state, if NULL, make a new one */ if (ret == NULL) { ret=(ERR_STATE *)OPENSSL_malloc(sizeof(ERR_STATE)); if (ret == NULL) return(&fallback); ret->pid=pid; ret->top=0; ret->bottom=0; for (i=0; i<ERR_NUM_ERRORS; i++) { ret->err_data[i]=NULL; ret->err_data_flags[i]=0; } tmpp = ERRFN(thread_set_item)(ret); /* To check if insertion failed, do a get. */ if (ERRFN(thread_get_item)(ret) != ret) { ERR_STATE_free(ret); /* could not insert it */ return(&fallback); } /* If a race occured in this function and we came second, tmpp * is the first one that we just replaced. */ if (tmpp) ERR_STATE_free(tmpp); } return ret; }#ifdef OPENSSL_FIPSvoid int_ERR_lib_init(void) { int_ERR_set_state_func(int_err_get_state, int_err_remove_state); }#endifint ERR_get_next_error_library(void) { err_fns_check(); return ERRFN(get_next_lib)(); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -