diff options
author | Viktor Dukhovni <openssl-users@dukhovni.org> | 2015-11-21 20:14:43 -0500 |
---|---|---|
committer | Viktor Dukhovni <openssl-users@dukhovni.org> | 2015-11-22 16:54:43 -0500 |
commit | 6e8ac5087061350a5a98ddc24dad6ceef9baf991 (patch) | |
tree | 35d5c7c7d42f03ccf97e67066b70a58e209667db /crypto/async/async.c | |
parent | 3d32218812e87221344f2985512e42e4aaa88745 (diff) |
Async error handling and MacOS/X fixes
In the async code for MacOS/X define _XOPEN_SOURCE (if not already
defined) as early as possible. We must do this before including
any header files, because on MacOS/X <stlib.h> includes <signal.h>
which includes <ucontext.h>. If we delay defining _XOPEN_SOURCE
and include <ucontext.h> after various system headers are included,
we are very likely to end up with the wrong (truncated) definition
of ucontext_t.
Also, better error handling and some code cleanup in POSIX fibre
construction and destruction. We make sure that async_fibre_makecontext()
always initializes the fibre to a state that can be freed.
For all implementations, check for error returns from
async_fibre_makecontext().
Reviewed-by: Matt Caswell <matt@openssl.org>
Diffstat (limited to 'crypto/async/async.c')
-rw-r--r-- | crypto/async/async.c | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/crypto/async/async.c b/crypto/async/async.c index 5664d990b6..031ca039e4 100644 --- a/crypto/async/async.c +++ b/crypto/async/async.c @@ -59,10 +59,11 @@ */ #undef _FORTIFY_SOURCE +/* This must be the first #include file */ +#include "async_locl.h" + #include <openssl/err.h> -#include <openssl/async.h> #include <string.h> -#include "async_locl.h" #define ASYNC_JOB_RUNNING 0 #define ASYNC_JOB_PAUSING 1 @@ -168,8 +169,11 @@ static ASYNC_JOB *async_get_pool_job(void) { return NULL; job = async_job_new(); - if (job) { - async_fibre_makecontext(&job->fibrectx); + if (job != NULL) { + if (! async_fibre_makecontext(&job->fibrectx)) { + async_job_free(job); + return NULL; + } pool->curr_size++; } } @@ -369,22 +373,20 @@ int ASYNC_init_thread(size_t max_size, size_t init_size) pool->max_size = max_size; /* Pre-create jobs as required */ - while (init_size) { + while (init_size--) { ASYNC_JOB *job; job = async_job_new(); - if (job) { - async_fibre_makecontext(&job->fibrectx); - job->funcargs = NULL; - sk_ASYNC_JOB_push(pool->jobs, job); - curr_size++; - init_size--; - } else { + if (job == NULL || !async_fibre_makecontext(&job->fibrectx)) { /* - * Not actually fatal because we already created the pool, just skip - * creation of any more jobs + * Not actually fatal because we already created the pool, just + * skip creation of any more jobs */ - init_size = 0; + async_job_free(job); + break; } + job->funcargs = NULL; + sk_ASYNC_JOB_push(pool->jobs, job); + curr_size++; } pool->curr_size = curr_size; if (!async_set_pool(pool)) { |