diff options
Diffstat (limited to 'crypto/async')
| -rw-r--r-- | crypto/async/arch/async_null.c | 1 | ||||
| -rw-r--r-- | crypto/async/arch/async_null.h | 13 | ||||
| -rw-r--r-- | crypto/async/arch/async_posix.c | 6 | ||||
| -rw-r--r-- | crypto/async/arch/async_posix.h | 51 | ||||
| -rw-r--r-- | crypto/async/arch/async_win.c | 10 | ||||
| -rw-r--r-- | crypto/async/arch/async_win.h | 30 | ||||
| -rw-r--r-- | crypto/async/async.c | 29 | ||||
| -rw-r--r-- | crypto/async/async_err.c | 16 | ||||
| -rw-r--r-- | crypto/async/async_local.h | 9 | ||||
| -rw-r--r-- | crypto/async/async_wait.c | 48 |
10 files changed, 107 insertions, 106 deletions
diff --git a/crypto/async/arch/async_null.c b/crypto/async/arch/async_null.c index 675c1d35bf0c..652ea28d1d7c 100644 --- a/crypto/async/arch/async_null.c +++ b/crypto/async/arch/async_null.c @@ -20,4 +20,3 @@ void async_local_cleanup(void) { } #endif - diff --git a/crypto/async/arch/async_null.h b/crypto/async/arch/async_null.h index c62aba69a874..422748df48a0 100644 --- a/crypto/async/arch/async_null.h +++ b/crypto/async/arch/async_null.h @@ -14,17 +14,16 @@ * to NULL. */ #ifndef ASYNC_ARCH -# define ASYNC_NULL -# define ASYNC_ARCH +#define ASYNC_NULL +#define ASYNC_ARCH typedef struct async_fibre_st { int dummy; } async_fibre; - -# define async_fibre_swapcontext(o,n,r) 0 -# define async_fibre_makecontext(c) 0 -# define async_fibre_free(f) -# define async_fibre_init_dispatcher(f) +#define async_fibre_swapcontext(o, n, r) 0 +#define async_fibre_makecontext(c) 0 +#define async_fibre_free(f) +#define async_fibre_init_dispatcher(f) #endif diff --git a/crypto/async/arch/async_posix.c b/crypto/async/arch/async_posix.c index e107e09a352f..235e34ad45a8 100644 --- a/crypto/async/arch/async_posix.c +++ b/crypto/async/arch/async_posix.c @@ -12,10 +12,10 @@ #ifdef ASYNC_POSIX -# include <stddef.h> -# include <unistd.h> +#include <stddef.h> +#include <unistd.h> -#define STACKSIZE 32768 +#define STACKSIZE 32768 int ASYNC_is_capable(void) { diff --git a/crypto/async/arch/async_posix.h b/crypto/async/arch/async_posix.h index a17c6b8e68af..08772e1a9eda 100644 --- a/crypto/async/arch/async_posix.h +++ b/crypto/async/arch/async_posix.h @@ -11,21 +11,22 @@ #define OSSL_CRYPTO_ASYNC_POSIX_H #include <openssl/e_os2.h> -#if defined(OPENSSL_SYS_UNIX) \ +#if defined(OPENSSL_SYS_UNIX) \ && defined(OPENSSL_THREADS) && !defined(OPENSSL_NO_ASYNC) \ - && !defined(__ANDROID__) && !defined(__OpenBSD__) + && !defined(__ANDROID__) && !defined(__OpenBSD__) \ + && !defined(OPENSSL_SYS_TANDEM) -# include <unistd.h> +#include <unistd.h> -# if _POSIX_VERSION >= 200112L \ - && (_POSIX_VERSION < 200809L || defined(__GLIBC__)) +#if _POSIX_VERSION >= 200112L \ + && (_POSIX_VERSION < 200809L || defined(__GLIBC__)) -# include <pthread.h> +#include <pthread.h> -# define ASYNC_POSIX -# define ASYNC_ARCH +#define ASYNC_POSIX +#define ASYNC_ARCH -# if defined(__CET__) || defined(__ia64__) +#if defined(__CET__) || defined(__ia64__) /* * When Intel CET is enabled, makecontext will create a different * shadow stack for each context. async_fibre_swapcontext cannot @@ -34,9 +35,9 @@ * On IA64 the register stack engine is not saved across setjmp/longjmp. Here * swapcontext() performs correctly. */ -# define USE_SWAPCONTEXT -# endif -# if defined(__aarch64__) && defined(__clang__) \ +#define USE_SWAPCONTEXT +#endif +#if defined(__aarch64__) && defined(__clang__) \ && defined(__ARM_FEATURE_BTI_DEFAULT) && __ARM_FEATURE_BTI_DEFAULT == 1 /* * setjmp/longjmp don't currently work with BTI on all libc implementations @@ -46,26 +47,26 @@ * So use the swapcontext implementation, which does work. * See https://github.com/llvm/llvm-project/issues/48888. */ -# define USE_SWAPCONTEXT -# endif -# include <ucontext.h> -# ifndef USE_SWAPCONTEXT -# include <setjmp.h> -# endif +#define USE_SWAPCONTEXT +#endif +#include <ucontext.h> +#ifndef USE_SWAPCONTEXT +#include <setjmp.h> +#endif typedef struct async_fibre_st { ucontext_t fibre; -# ifndef USE_SWAPCONTEXT +#ifndef USE_SWAPCONTEXT jmp_buf env; int env_init; -# endif +#endif } async_fibre; static ossl_inline int async_fibre_swapcontext(async_fibre *o, async_fibre *n, int r) { -# ifdef USE_SWAPCONTEXT +#ifdef USE_SWAPCONTEXT swapcontext(&o->fibre, &n->fibre); -# else +#else o->env_init = 1; if (!r || !_setjmp(o->env)) { @@ -74,16 +75,16 @@ static ossl_inline int async_fibre_swapcontext(async_fibre *o, async_fibre *n, i else setcontext(&n->fibre); } -# endif +#endif return 1; } -# define async_fibre_init_dispatcher(d) +#define async_fibre_init_dispatcher(d) int async_fibre_makecontext(async_fibre *fibre); void async_fibre_free(async_fibre *fibre); -# endif +#endif #endif #endif /* OSSL_CRYPTO_ASYNC_POSIX_H */ diff --git a/crypto/async/arch/async_win.c b/crypto/async/arch/async_win.c index 0b276fd504d8..00959ea71da1 100644 --- a/crypto/async/arch/async_win.c +++ b/crypto/async/arch/async_win.c @@ -12,8 +12,8 @@ #ifdef ASYNC_WIN -# include <windows.h> -# include "internal/cryptlib.h" +#include <windows.h> +#include "internal/cryptlib.h" int ASYNC_is_capable(void) { @@ -34,11 +34,11 @@ void async_local_cleanup(void) int async_fibre_init_dispatcher(async_fibre *fibre) { -# if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x600 +#if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x600 fibre->fibre = ConvertThreadToFiberEx(NULL, FIBER_FLAG_FLOAT_SWITCH); -# else +#else fibre->fibre = ConvertThreadToFiber(NULL); -# endif +#endif if (fibre->fibre == NULL) { fibre->converted = 0; fibre->fibre = GetCurrentFiber(); diff --git a/crypto/async/arch/async_win.h b/crypto/async/arch/async_win.h index 0fab95996e27..96abb00ce2ff 100644 --- a/crypto/async/arch/async_win.h +++ b/crypto/async/arch/async_win.h @@ -13,30 +13,30 @@ */ #if defined(_WIN32) && !defined(OPENSSL_NO_ASYNC) #include <openssl/async.h> -# define ASYNC_WIN -# define ASYNC_ARCH +#define ASYNC_WIN +#define ASYNC_ARCH -# include <windows.h> -# include "internal/cryptlib.h" +#include <windows.h> +#include "internal/cryptlib.h" typedef struct async_fibre_st { LPVOID fibre; int converted; } async_fibre; -# define async_fibre_swapcontext(o,n,r) \ - (SwitchToFiber((n)->fibre), 1) +#define async_fibre_swapcontext(o, n, r) \ + (SwitchToFiber((n)->fibre), 1) -# if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x600 -# define async_fibre_makecontext(c) \ - ((c)->fibre = CreateFiberEx(0, 0, FIBER_FLAG_FLOAT_SWITCH, \ - async_start_func_win, 0)) -# else -# define async_fibre_makecontext(c) \ - ((c)->fibre = CreateFiber(0, async_start_func_win, 0)) -# endif +#if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x600 +#define async_fibre_makecontext(c) \ + ((c)->fibre = CreateFiberEx(0, 0, FIBER_FLAG_FLOAT_SWITCH, \ + async_start_func_win, 0)) +#else +#define async_fibre_makecontext(c) \ + ((c)->fibre = CreateFiber(0, async_start_func_win, 0)) +#endif -# define async_fibre_free(f) (DeleteFiber((f)->fibre)) +#define async_fibre_free(f) (DeleteFiber((f)->fibre)) int async_fibre_init_dispatcher(async_fibre *fibre); VOID CALLBACK async_start_func_win(PVOID unused); diff --git a/crypto/async/async.c b/crypto/async/async.c index a320d455b7bb..0e5dec3c4c3b 100644 --- a/crypto/async/async.c +++ b/crypto/async/async.c @@ -22,10 +22,10 @@ #include "crypto/cryptlib.h" #include <string.h> -#define ASYNC_JOB_RUNNING 0 -#define ASYNC_JOB_PAUSING 1 -#define ASYNC_JOB_PAUSED 2 -#define ASYNC_JOB_STOPPING 3 +#define ASYNC_JOB_RUNNING 0 +#define ASYNC_JOB_PAUSING 1 +#define ASYNC_JOB_PAUSED 2 +#define ASYNC_JOB_STOPPING 3 static CRYPTO_THREAD_LOCAL ctxkey; static CRYPTO_THREAD_LOCAL poolkey; @@ -101,7 +101,8 @@ static void async_job_free(ASYNC_JOB *job) } } -static ASYNC_JOB *async_get_pool_job(void) { +static ASYNC_JOB *async_get_pool_job(void) +{ ASYNC_JOB *job; async_pool *pool; @@ -124,7 +125,7 @@ static ASYNC_JOB *async_get_pool_job(void) { job = async_job_new(); if (job != NULL) { - if (! async_fibre_makecontext(&job->fibrectx)) { + if (!async_fibre_makecontext(&job->fibrectx)) { async_job_free(job); return NULL; } @@ -134,7 +135,8 @@ static ASYNC_JOB *async_get_pool_job(void) { return job; } -static void async_release_job(ASYNC_JOB *job) { +static void async_release_job(ASYNC_JOB *job) +{ async_pool *pool; pool = (async_pool *)CRYPTO_THREAD_get_local(&poolkey); @@ -164,7 +166,7 @@ void async_start_func(void) /* Stop the job */ job->status = ASYNC_JOB_STOPPING; if (!async_fibre_swapcontext(&job->fibrectx, - &ctx->dispatcher, 1)) { + &ctx->dispatcher, 1)) { /* * Should not happen. Getting here will close the thread...can't do * much about it @@ -175,7 +177,7 @@ void async_start_func(void) } int ASYNC_start_job(ASYNC_JOB **job, ASYNC_WAIT_CTX *wctx, int *ret, - int (*func)(void *), void *args, size_t size) + int (*func)(void *), void *args, size_t size) { async_ctx *ctx; OSSL_LIB_CTX *libctx; @@ -253,7 +255,8 @@ int ASYNC_start_job(ASYNC_JOB **job, ASYNC_WAIT_CTX *wctx, int *ret, if ((ctx->currjob = async_get_pool_job()) == NULL) return ASYNC_NO_JOBS; - if (args != NULL) { + /* Check for size > 0 to avoid malloc(0) */ + if (args != NULL && size > 0) { ctx->currjob->funcargs = OPENSSL_malloc(size); if (ctx->currjob->funcargs == NULL) { ERR_raise(ERR_LIB_ASYNC, ERR_R_MALLOC_FAILURE); @@ -294,8 +297,8 @@ int ASYNC_pause_job(void) async_ctx *ctx = async_get_ctx(); if (ctx == NULL - || ctx->currjob == NULL - || ctx->blocked) { + || ctx->currjob == NULL + || ctx->blocked) { /* * Could be we've deliberately not been started within a job so this is * counted as success. @@ -307,7 +310,7 @@ int ASYNC_pause_job(void) job->status = ASYNC_JOB_PAUSING; if (!async_fibre_swapcontext(&job->fibrectx, - &ctx->dispatcher, 1)) { + &ctx->dispatcher, 1)) { ERR_raise(ERR_LIB_ASYNC, ASYNC_R_FAILED_TO_SWAP_CONTEXT); return 0; } diff --git a/crypto/async/async_err.c b/crypto/async/async_err.c index 34db12fb969c..1e28eb78234b 100644 --- a/crypto/async/async_err.c +++ b/crypto/async/async_err.c @@ -15,14 +15,14 @@ #ifndef OPENSSL_NO_ERR static const ERR_STRING_DATA ASYNC_str_reasons[] = { - {ERR_PACK(ERR_LIB_ASYNC, 0, ASYNC_R_FAILED_TO_SET_POOL), - "failed to set pool"}, - {ERR_PACK(ERR_LIB_ASYNC, 0, ASYNC_R_FAILED_TO_SWAP_CONTEXT), - "failed to swap context"}, - {ERR_PACK(ERR_LIB_ASYNC, 0, ASYNC_R_INIT_FAILED), "init failed"}, - {ERR_PACK(ERR_LIB_ASYNC, 0, ASYNC_R_INVALID_POOL_SIZE), - "invalid pool size"}, - {0, NULL} + { ERR_PACK(ERR_LIB_ASYNC, 0, ASYNC_R_FAILED_TO_SET_POOL), + "failed to set pool" }, + { ERR_PACK(ERR_LIB_ASYNC, 0, ASYNC_R_FAILED_TO_SWAP_CONTEXT), + "failed to swap context" }, + { ERR_PACK(ERR_LIB_ASYNC, 0, ASYNC_R_INIT_FAILED), "init failed" }, + { ERR_PACK(ERR_LIB_ASYNC, 0, ASYNC_R_INVALID_POOL_SIZE), + "invalid pool size" }, + { 0, NULL } }; #endif diff --git a/crypto/async/async_local.h b/crypto/async/async_local.h index c06f413cf604..9690adbb1e95 100644 --- a/crypto/async/async_local.h +++ b/crypto/async/async_local.h @@ -12,12 +12,12 @@ * includes <signal.h> which includes <ucontext.h> */ #if defined(__APPLE__) && defined(__MACH__) && !defined(_XOPEN_SOURCE) -# define _XOPEN_SOURCE /* Otherwise incomplete ucontext_t structure */ -# pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#define _XOPEN_SOURCE /* Otherwise incomplete ucontext_t structure */ +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" #endif #if defined(_WIN32) -# include <windows.h> +#include <windows.h> #endif #include "crypto/async.h" @@ -38,7 +38,7 @@ struct async_ctx_st { struct async_job_st { async_fibre fibrectx; - int (*func) (void *); + int (*func)(void *); void *funcargs; int ret; int status; @@ -78,4 +78,3 @@ void async_start_func(void); async_ctx *async_get_ctx(void); void async_wait_ctx_reset_counts(ASYNC_WAIT_CTX *ctx); - diff --git a/crypto/async/async_wait.c b/crypto/async/async_wait.c index df7d29302182..a433a1ba96ac 100644 --- a/crypto/async/async_wait.c +++ b/crypto/async/async_wait.c @@ -41,9 +41,9 @@ void ASYNC_WAIT_CTX_free(ASYNC_WAIT_CTX *ctx) OPENSSL_free(ctx); } int ASYNC_WAIT_CTX_set_wait_fd(ASYNC_WAIT_CTX *ctx, const void *key, - OSSL_ASYNC_FD fd, void *custom_data, - void (*cleanup)(ASYNC_WAIT_CTX *, const void *, - OSSL_ASYNC_FD, void *)) + OSSL_ASYNC_FD fd, void *custom_data, + void (*cleanup)(ASYNC_WAIT_CTX *, const void *, + OSSL_ASYNC_FD, void *)) { struct fd_lookup_st *fdlookup; @@ -64,7 +64,7 @@ int ASYNC_WAIT_CTX_set_wait_fd(ASYNC_WAIT_CTX *ctx, const void *key, } int ASYNC_WAIT_CTX_get_fd(ASYNC_WAIT_CTX *ctx, const void *key, - OSSL_ASYNC_FD *fd, void **custom_data) + OSSL_ASYNC_FD *fd, void **custom_data) { struct fd_lookup_st *curr; @@ -86,7 +86,7 @@ int ASYNC_WAIT_CTX_get_fd(ASYNC_WAIT_CTX *ctx, const void *key, } int ASYNC_WAIT_CTX_get_all_fds(ASYNC_WAIT_CTX *ctx, OSSL_ASYNC_FD *fd, - size_t *numfds) + size_t *numfds) { struct fd_lookup_st *curr; @@ -109,8 +109,8 @@ int ASYNC_WAIT_CTX_get_all_fds(ASYNC_WAIT_CTX *ctx, OSSL_ASYNC_FD *fd, } int ASYNC_WAIT_CTX_get_changed_fds(ASYNC_WAIT_CTX *ctx, OSSL_ASYNC_FD *addfd, - size_t *numaddfds, OSSL_ASYNC_FD *delfd, - size_t *numdelfds) + size_t *numaddfds, OSSL_ASYNC_FD *delfd, + size_t *numdelfds) { struct fd_lookup_st *curr; @@ -183,38 +183,38 @@ int ASYNC_WAIT_CTX_clear_fd(ASYNC_WAIT_CTX *ctx, const void *key) } int ASYNC_WAIT_CTX_set_callback(ASYNC_WAIT_CTX *ctx, - ASYNC_callback_fn callback, - void *callback_arg) + ASYNC_callback_fn callback, + void *callback_arg) { - if (ctx == NULL) - return 0; + if (ctx == NULL) + return 0; - ctx->callback = callback; - ctx->callback_arg = callback_arg; - return 1; + ctx->callback = callback; + ctx->callback_arg = callback_arg; + return 1; } int ASYNC_WAIT_CTX_get_callback(ASYNC_WAIT_CTX *ctx, - ASYNC_callback_fn *callback, - void **callback_arg) + ASYNC_callback_fn *callback, + void **callback_arg) { - if (ctx->callback == NULL) - return 0; + if (ctx->callback == NULL) + return 0; - *callback = ctx->callback; - *callback_arg = ctx->callback_arg; - return 1; + *callback = ctx->callback; + *callback_arg = ctx->callback_arg; + return 1; } int ASYNC_WAIT_CTX_set_status(ASYNC_WAIT_CTX *ctx, int status) { - ctx->status = status; - return 1; + ctx->status = status; + return 1; } int ASYNC_WAIT_CTX_get_status(ASYNC_WAIT_CTX *ctx) { - return ctx->status; + return ctx->status; } void async_wait_ctx_reset_counts(ASYNC_WAIT_CTX *ctx) |
