Lines Matching +full:mx +full:- +full:specific

2  * Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved.
21 global->ex_data_lock = CRYPTO_THREAD_lock_new(); in ossl_do_ex_data_init()
22 return global->ex_data_lock != NULL; in ossl_do_ex_data_init()
41 if (global->ex_data_lock == NULL) { in get_and_lock()
50 if (!CRYPTO_THREAD_read_lock(global->ex_data_lock)) in get_and_lock()
53 if (!CRYPTO_THREAD_write_lock(global->ex_data_lock)) in get_and_lock()
57 ip = &global->ex_data[class_index]; in get_and_lock()
68 * thread-safe without overhauling a lot of stuff, and shouldn't really be
69 * called under potential race-conditions anyway (it's for program shutdown
81 EX_CALLBACKS *ip = &global->ex_data[i]; in ossl_crypto_cleanup_all_ex_data_int()
83 sk_EX_CALLBACK_pop_free(ip->meth, cleanup_cb); in ossl_crypto_cleanup_all_ex_data_int()
84 ip->meth = NULL; in ossl_crypto_cleanup_all_ex_data_int()
87 CRYPTO_THREAD_lock_free(global->ex_data_lock); in ossl_crypto_cleanup_all_ex_data_int()
88 global->ex_data_lock = NULL; in ossl_crypto_cleanup_all_ex_data_int()
93 * Unregister a new index by replacing the callbacks with no-ops.
94 * Any in-use instances are leaked.
127 if (idx < 0 || idx >= sk_EX_CALLBACK_num(ip->meth)) in ossl_crypto_free_ex_index_ex()
129 a = sk_EX_CALLBACK_value(ip->meth, idx); in ossl_crypto_free_ex_index_ex()
132 a->new_func = dummy_new; in ossl_crypto_free_ex_index_ex()
133 a->dup_func = dummy_dup; in ossl_crypto_free_ex_index_ex()
134 a->free_func = dummy_free; in ossl_crypto_free_ex_index_ex()
137 CRYPTO_THREAD_unlock(global->ex_data_lock); in ossl_crypto_free_ex_index_ex()
156 int toret = -1; in ossl_crypto_get_ex_new_index_ex()
162 return -1; in ossl_crypto_get_ex_new_index_ex()
166 return -1; in ossl_crypto_get_ex_new_index_ex()
168 if (ip->meth == NULL) { in ossl_crypto_get_ex_new_index_ex()
169 ip->meth = sk_EX_CALLBACK_new_null(); in ossl_crypto_get_ex_new_index_ex()
172 if (ip->meth == NULL in ossl_crypto_get_ex_new_index_ex()
173 || !sk_EX_CALLBACK_push(ip->meth, NULL)) { in ossl_crypto_get_ex_new_index_ex()
174 sk_EX_CALLBACK_free(ip->meth); in ossl_crypto_get_ex_new_index_ex()
175 ip->meth = NULL; in ossl_crypto_get_ex_new_index_ex()
184 a->argl = argl; in ossl_crypto_get_ex_new_index_ex()
185 a->argp = argp; in ossl_crypto_get_ex_new_index_ex()
186 a->new_func = new_func; in ossl_crypto_get_ex_new_index_ex()
187 a->dup_func = dup_func; in ossl_crypto_get_ex_new_index_ex()
188 a->free_func = free_func; in ossl_crypto_get_ex_new_index_ex()
189 a->priority = priority; in ossl_crypto_get_ex_new_index_ex()
191 if (!sk_EX_CALLBACK_push(ip->meth, NULL)) { in ossl_crypto_get_ex_new_index_ex()
196 toret = sk_EX_CALLBACK_num(ip->meth) - 1; in ossl_crypto_get_ex_new_index_ex()
197 (void)sk_EX_CALLBACK_set(ip->meth, toret, a); in ossl_crypto_get_ex_new_index_ex()
200 CRYPTO_THREAD_unlock(global->ex_data_lock); in ossl_crypto_get_ex_new_index_ex()
213 * Initialise a new CRYPTO_EX_DATA for use in a particular class - including
215 * Thread-safe by copying a class's array of "EX_CALLBACK" entries
222 int mx, i; in ossl_crypto_new_ex_data_ex() local
236 ad->ctx = ctx; in ossl_crypto_new_ex_data_ex()
237 ad->sk = NULL; in ossl_crypto_new_ex_data_ex()
238 mx = sk_EX_CALLBACK_num(ip->meth); in ossl_crypto_new_ex_data_ex()
239 if (mx > 0) { in ossl_crypto_new_ex_data_ex()
240 if (mx < (int)OSSL_NELEM(stack)) in ossl_crypto_new_ex_data_ex()
243 storage = OPENSSL_malloc(sizeof(*storage) * mx); in ossl_crypto_new_ex_data_ex()
245 for (i = 0; i < mx; i++) in ossl_crypto_new_ex_data_ex()
246 storage[i] = sk_EX_CALLBACK_value(ip->meth, i); in ossl_crypto_new_ex_data_ex()
248 CRYPTO_THREAD_unlock(global->ex_data_lock); in ossl_crypto_new_ex_data_ex()
250 if (mx > 0 && storage == NULL) in ossl_crypto_new_ex_data_ex()
252 for (i = 0; i < mx; i++) { in ossl_crypto_new_ex_data_ex()
253 if (storage[i] != NULL && storage[i]->new_func != NULL) { in ossl_crypto_new_ex_data_ex()
255 storage[i]->new_func(obj, ptr, ad, i, in ossl_crypto_new_ex_data_ex()
256 storage[i]->argl, storage[i]->argp); in ossl_crypto_new_ex_data_ex()
270 * Duplicate a CRYPTO_EX_DATA variable - including calling dup() callbacks
276 int mx, j, i; in CRYPTO_dup_ex_data() local
284 to->ctx = from->ctx; in CRYPTO_dup_ex_data()
285 if (from->sk == NULL) in CRYPTO_dup_ex_data()
289 global = ossl_lib_ctx_get_ex_data_global(from->ctx); in CRYPTO_dup_ex_data()
297 mx = sk_EX_CALLBACK_num(ip->meth); in CRYPTO_dup_ex_data()
298 j = sk_void_num(from->sk); in CRYPTO_dup_ex_data()
299 if (j < mx) in CRYPTO_dup_ex_data()
300 mx = j; in CRYPTO_dup_ex_data()
301 if (mx > 0) { in CRYPTO_dup_ex_data()
302 if (mx < (int)OSSL_NELEM(stack)) in CRYPTO_dup_ex_data()
305 storage = OPENSSL_malloc(sizeof(*storage) * mx); in CRYPTO_dup_ex_data()
307 for (i = 0; i < mx; i++) in CRYPTO_dup_ex_data()
308 storage[i] = sk_EX_CALLBACK_value(ip->meth, i); in CRYPTO_dup_ex_data()
310 CRYPTO_THREAD_unlock(global->ex_data_lock); in CRYPTO_dup_ex_data()
312 if (mx == 0) in CRYPTO_dup_ex_data()
317 * Make sure the ex_data stack is at least |mx| elements long to avoid in CRYPTO_dup_ex_data()
318 * issues in the for loop that follows; so go get the |mx|'th element in CRYPTO_dup_ex_data()
320 * to itself. This is normally a no-op; but ensures the stack is the in CRYPTO_dup_ex_data()
323 if (!CRYPTO_set_ex_data(to, mx - 1, CRYPTO_get_ex_data(to, mx - 1))) in CRYPTO_dup_ex_data()
326 for (i = 0; i < mx; i++) { in CRYPTO_dup_ex_data()
328 if (storage[i] != NULL && storage[i]->dup_func != NULL) in CRYPTO_dup_ex_data()
329 if (!storage[i]->dup_func(to, from, &ptr, i, in CRYPTO_dup_ex_data()
330 storage[i]->argl, storage[i]->argp)) in CRYPTO_dup_ex_data()
351 if (ap->excb == bp->excb) in ex_callback_compare()
354 if (ap->excb == NULL) in ex_callback_compare()
356 if (bp->excb == NULL) in ex_callback_compare()
357 return -1; in ex_callback_compare()
358 if (ap->excb->priority == bp->excb->priority) in ex_callback_compare()
360 return ap->excb->priority > bp->excb->priority ? -1 : 1; in ex_callback_compare()
364 * Cleanup a CRYPTO_EX_DATA variable - including calling free() callbacks for
369 int mx, i; in CRYPTO_free_ex_data() local
375 OSSL_EX_DATA_GLOBAL *global = ossl_lib_ctx_get_ex_data_global(ad->ctx); in CRYPTO_free_ex_data()
384 mx = sk_EX_CALLBACK_num(ip->meth); in CRYPTO_free_ex_data()
385 if (mx > 0) { in CRYPTO_free_ex_data()
386 if (mx < (int)OSSL_NELEM(stack)) in CRYPTO_free_ex_data()
389 storage = OPENSSL_malloc(sizeof(*storage) * mx); in CRYPTO_free_ex_data()
391 for (i = 0; i < mx; i++) { in CRYPTO_free_ex_data()
392 storage[i].excb = sk_EX_CALLBACK_value(ip->meth, i); in CRYPTO_free_ex_data()
396 CRYPTO_THREAD_unlock(global->ex_data_lock); in CRYPTO_free_ex_data()
400 qsort(storage, mx, sizeof(*storage), ex_callback_compare); in CRYPTO_free_ex_data()
401 for (i = 0; i < mx; i++) { in CRYPTO_free_ex_data()
404 if (f != NULL && f->free_func != NULL) { in CRYPTO_free_ex_data()
406 f->free_func(obj, ptr, ad, storage[i].index, f->argl, f->argp); in CRYPTO_free_ex_data()
414 sk_void_free(ad->sk); in CRYPTO_free_ex_data()
415 ad->sk = NULL; in CRYPTO_free_ex_data()
416 ad->ctx = NULL; in CRYPTO_free_ex_data()
420 * Allocate a given CRYPTO_EX_DATA item using the class specific allocation
443 global = ossl_lib_ctx_get_ex_data_global(ad->ctx); in ossl_crypto_alloc_ex_data_intern()
450 f = sk_EX_CALLBACK_value(ip->meth, idx); in ossl_crypto_alloc_ex_data_intern()
451 CRYPTO_THREAD_unlock(global->ex_data_lock); in ossl_crypto_alloc_ex_data_intern()
457 if (f->new_func == NULL) in ossl_crypto_alloc_ex_data_intern()
460 f->new_func(obj, NULL, ad, idx, f->argl, f->argp); in ossl_crypto_alloc_ex_data_intern()
473 if (ad->sk == NULL) { in CRYPTO_set_ex_data()
474 if ((ad->sk = sk_void_new_null()) == NULL) { in CRYPTO_set_ex_data()
480 for (i = sk_void_num(ad->sk); i <= idx; ++i) { in CRYPTO_set_ex_data()
481 if (!sk_void_push(ad->sk, NULL)) { in CRYPTO_set_ex_data()
486 if (sk_void_set(ad->sk, idx, val) != val) { in CRYPTO_set_ex_data()
500 if (ad->sk == NULL || idx >= sk_void_num(ad->sk)) in CRYPTO_get_ex_data()
502 return sk_void_value(ad->sk, idx); in CRYPTO_get_ex_data()
507 return ad->ctx; in ossl_crypto_ex_data_get_ossl_lib_ctx()