diff options
author | Matt Caswell <matt@openssl.org> | 2015-10-06 14:47:00 +0100 |
---|---|---|
committer | Matt Caswell <matt@openssl.org> | 2015-11-20 23:34:35 +0000 |
commit | 079a1a9014b89661f0a612a5a9724ad9c77f21a3 (patch) | |
tree | 2e04061d51e78ff7c6e53bdd2440497c9cbcc0c6 /crypto/async | |
parent | 9c8dc051d0a1293279bbf289b5f324824a02405b (diff) |
Add ASYNC error codes
Add ASYNCerr support to give some meaningful error message in the event of
a failure.
Reviewed-by: Rich Salz <rsalz@openssl.org>
Diffstat (limited to 'crypto/async')
-rw-r--r-- | crypto/async/Makefile | 4 | ||||
-rw-r--r-- | crypto/async/async.c | 36 | ||||
-rw-r--r-- | crypto/async/async_err.c | 101 |
3 files changed, 131 insertions, 10 deletions
diff --git a/crypto/async/Makefile b/crypto/async/Makefile index 886873257b..1c9482f12e 100644 --- a/crypto/async/Makefile +++ b/crypto/async/Makefile @@ -17,8 +17,8 @@ TEST= APPS= LIB=$(TOP)/libcrypto.a -LIBSRC=async.c arch/async_posix.c arch/async_win.c arch/async_null.c -LIBOBJ=async.o arch/async_posix.o arch/async_win.o arch/async_null.o +LIBSRC=async.c async_err.c arch/async_posix.c arch/async_win.c arch/async_null.c +LIBOBJ=async.o async_err.o arch/async_posix.o arch/async_win.o arch/async_null.o SRC= $(LIBSRC) diff --git a/crypto/async/async.c b/crypto/async/async.c index c3fe3e15c7..e0ff110e33 100644 --- a/crypto/async/async.c +++ b/crypto/async/async.c @@ -51,6 +51,7 @@ * ==================================================================== */ +#include <openssl/err.h> #include <openssl/async.h> #include <string.h> #include "async_locl.h" @@ -65,7 +66,7 @@ static async_ctx *async_ctx_new(void) async_ctx *nctx = NULL; if(!(nctx = OPENSSL_malloc(sizeof (async_ctx)))) { - /* Error here */ + ASYNCerr(ASYNC_F_ASYNC_CTX_NEW, ERR_R_MALLOC_FAILURE); goto err; } @@ -101,11 +102,13 @@ static ASYNC_JOB *async_job_new(void) int pipefds[2]; if(!(job = OPENSSL_malloc(sizeof (ASYNC_JOB)))) { + ASYNCerr(ASYNC_F_ASYNC_JOB_NEW, ERR_R_MALLOC_FAILURE); return NULL; } if(!async_pipe(pipefds)) { OPENSSL_free(job); + ASYNCerr(ASYNC_F_ASYNC_JOB_NEW, ASYNC_R_CANNOT_CREATE_WAIT_PIPE); return NULL; } @@ -181,9 +184,10 @@ void async_start_func(void) if(!async_fibre_swapcontext(&job->fibrectx, &async_get_ctx()->dispatcher, 1)) { /* - * Should not happen. Getting here will close the thread...can't do much - * about it + * Should not happen. Getting here will close the thread...can't do + * much about it */ + ASYNCerr(ASYNC_F_ASYNC_START_FUNC, ASYNC_R_FAILED_TO_SWAP_CONTEXT); } } } @@ -220,12 +224,16 @@ int ASYNC_start_job(ASYNC_JOB **job, int *ret, int (*func)(void *), async_get_ctx()->currjob = *job; /* Resume previous job */ if(!async_fibre_swapcontext(&async_get_ctx()->dispatcher, - &async_get_ctx()->currjob->fibrectx, 1)) + &async_get_ctx()->currjob->fibrectx, 1)) { + ASYNCerr(ASYNC_F_ASYNC_START_JOB, + ASYNC_R_FAILED_TO_SWAP_CONTEXT); goto err; + } continue; } /* Should not happen */ + ASYNCerr(ASYNC_F_ASYNC_START_JOB, ERR_R_INTERNAL_ERROR); async_release_job(async_get_ctx()->currjob); async_get_ctx()->currjob = NULL; *job = NULL; @@ -240,6 +248,7 @@ int ASYNC_start_job(ASYNC_JOB **job, int *ret, int (*func)(void *), if(args != NULL) { async_get_ctx()->currjob->funcargs = OPENSSL_malloc(size); if(!async_get_ctx()->currjob->funcargs) { + ASYNCerr(ASYNC_F_ASYNC_START_JOB, ERR_R_MALLOC_FAILURE); async_release_job(async_get_ctx()->currjob); async_get_ctx()->currjob = NULL; return ASYNC_ERR; @@ -251,8 +260,10 @@ int ASYNC_start_job(ASYNC_JOB **job, int *ret, int (*func)(void *), async_get_ctx()->currjob->func = func; if(!async_fibre_swapcontext(&async_get_ctx()->dispatcher, - &async_get_ctx()->currjob->fibrectx, 1)) + &async_get_ctx()->currjob->fibrectx, 1)) { + ASYNCerr(ASYNC_F_ASYNC_START_JOB, ASYNC_R_FAILED_TO_SWAP_CONTEXT); goto err; + } } err: @@ -267,15 +278,20 @@ int ASYNC_pause_job(void) { ASYNC_JOB *job; - if(!async_get_ctx() || !async_get_ctx()->currjob) + if(!async_get_ctx() || !async_get_ctx()->currjob) { + /* + * Could be we've deliberately not been started within a job so we + * don't put an error on the error queue here. + */ return 0; + } job = async_get_ctx()->currjob; job->status = ASYNC_JOB_PAUSING; if(!async_fibre_swapcontext(&job->fibrectx, &async_get_ctx()->dispatcher, 1)) { - /* Error */ + ASYNCerr(ASYNC_F_ASYNC_PAUSE_JOB, ASYNC_R_FAILED_TO_SWAP_CONTEXT); return 0; } @@ -297,11 +313,14 @@ int ASYNC_init_pool(size_t max_size, size_t init_size) STACK_OF(ASYNC_JOB) *pool; size_t curr_size = 0; - if (init_size > max_size) + if (init_size > max_size) { + ASYNCerr(ASYNC_F_ASYNC_INIT_POOL, ASYNC_R_INVALID_POOL_SIZE); return 0; + } pool = sk_ASYNC_JOB_new_null(); if (pool == NULL) { + ASYNCerr(ASYNC_F_ASYNC_INIT_POOL, ERR_R_MALLOC_FAILURE); return 0; } /* Pre-create jobs as required */ @@ -324,6 +343,7 @@ int ASYNC_init_pool(size_t max_size, size_t init_size) } if (!async_set_pool(pool, curr_size, max_size)) { + ASYNCerr(ASYNC_F_ASYNC_INIT_POOL, ASYNC_R_FAILED_TO_SET_POOL); async_empty_pool(pool); sk_ASYNC_JOB_free(pool); return 0; diff --git a/crypto/async/async_err.c b/crypto/async/async_err.c new file mode 100644 index 0000000000..1391c0f3d5 --- /dev/null +++ b/crypto/async/async_err.c @@ -0,0 +1,101 @@ +/* crypto/async/async_err.c */ +/* ==================================================================== + * Copyright (c) 1999-2015 The OpenSSL Project. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * openssl-core@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ + +/* + * NOTE: this file was auto generated by the mkerr.pl script: any changes + * made to it will be overwritten when the script next updates this file, + * only reason strings will be preserved. + */ + +#include <stdio.h> +#include <openssl/err.h> +#include <openssl/async.h> + +/* BEGIN ERROR CODES */ +#ifndef OPENSSL_NO_ERR + +# define ERR_FUNC(func) ERR_PACK(ERR_LIB_ASYNC,func,0) +# define ERR_REASON(reason) ERR_PACK(ERR_LIB_ASYNC,0,reason) + +static ERR_STRING_DATA ASYNC_str_functs[] = { + {ERR_FUNC(ASYNC_F_ASYNC_CTX_NEW), "ASYNC_CTX_NEW"}, + {ERR_FUNC(ASYNC_F_ASYNC_INIT_POOL), "ASYNC_init_pool"}, + {ERR_FUNC(ASYNC_F_ASYNC_JOB_NEW), "ASYNC_JOB_NEW"}, + {ERR_FUNC(ASYNC_F_ASYNC_PAUSE_JOB), "ASYNC_pause_job"}, + {ERR_FUNC(ASYNC_F_ASYNC_START_FUNC), "ASYNC_START_FUNC"}, + {ERR_FUNC(ASYNC_F_ASYNC_START_JOB), "ASYNC_start_job"}, + {0, NULL} +}; + +static ERR_STRING_DATA ASYNC_str_reasons[] = { + {ERR_REASON(ASYNC_R_CANNOT_CREATE_WAIT_PIPE), "cannot create wait pipe"}, + {ERR_REASON(ASYNC_R_FAILED_TO_SET_POOL), "failed to set pool"}, + {ERR_REASON(ASYNC_R_FAILED_TO_SWAP_CONTEXT), "failed to swap context"}, + {ERR_REASON(ASYNC_R_INVALID_POOL_SIZE), "invalid pool size"}, + {0, NULL} +}; + +#endif + +void ERR_load_ASYNC_strings(void) +{ +#ifndef OPENSSL_NO_ERR + + if (ERR_func_error_string(ASYNC_str_functs[0].error) == NULL) { + ERR_load_strings(0, ASYNC_str_functs); + ERR_load_strings(0, ASYNC_str_reasons); + } +#endif +} |