提交 079a1a90 编写于 作者: M Matt Caswell

Add ASYNC error codes

Add ASYNCerr support to give some meaningful error message in the event of
a failure.
Reviewed-by: NRich Salz <rsalz@openssl.org>
上级 9c8dc051
...@@ -17,8 +17,8 @@ TEST= ...@@ -17,8 +17,8 @@ TEST=
APPS= APPS=
LIB=$(TOP)/libcrypto.a LIB=$(TOP)/libcrypto.a
LIBSRC=async.c arch/async_posix.c arch/async_win.c arch/async_null.c LIBSRC=async.c async_err.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 LIBOBJ=async.o async_err.o arch/async_posix.o arch/async_win.o arch/async_null.o
SRC= $(LIBSRC) SRC= $(LIBSRC)
......
...@@ -51,6 +51,7 @@ ...@@ -51,6 +51,7 @@
* ==================================================================== * ====================================================================
*/ */
#include <openssl/err.h>
#include <openssl/async.h> #include <openssl/async.h>
#include <string.h> #include <string.h>
#include "async_locl.h" #include "async_locl.h"
...@@ -65,7 +66,7 @@ static async_ctx *async_ctx_new(void) ...@@ -65,7 +66,7 @@ static async_ctx *async_ctx_new(void)
async_ctx *nctx = NULL; async_ctx *nctx = NULL;
if(!(nctx = OPENSSL_malloc(sizeof (async_ctx)))) { if(!(nctx = OPENSSL_malloc(sizeof (async_ctx)))) {
/* Error here */ ASYNCerr(ASYNC_F_ASYNC_CTX_NEW, ERR_R_MALLOC_FAILURE);
goto err; goto err;
} }
...@@ -101,11 +102,13 @@ static ASYNC_JOB *async_job_new(void) ...@@ -101,11 +102,13 @@ static ASYNC_JOB *async_job_new(void)
int pipefds[2]; int pipefds[2];
if(!(job = OPENSSL_malloc(sizeof (ASYNC_JOB)))) { if(!(job = OPENSSL_malloc(sizeof (ASYNC_JOB)))) {
ASYNCerr(ASYNC_F_ASYNC_JOB_NEW, ERR_R_MALLOC_FAILURE);
return NULL; return NULL;
} }
if(!async_pipe(pipefds)) { if(!async_pipe(pipefds)) {
OPENSSL_free(job); OPENSSL_free(job);
ASYNCerr(ASYNC_F_ASYNC_JOB_NEW, ASYNC_R_CANNOT_CREATE_WAIT_PIPE);
return NULL; return NULL;
} }
...@@ -181,9 +184,10 @@ void async_start_func(void) ...@@ -181,9 +184,10 @@ void async_start_func(void)
if(!async_fibre_swapcontext(&job->fibrectx, if(!async_fibre_swapcontext(&job->fibrectx,
&async_get_ctx()->dispatcher, 1)) { &async_get_ctx()->dispatcher, 1)) {
/* /*
* Should not happen. Getting here will close the thread...can't do much * Should not happen. Getting here will close the thread...can't do
* about it * 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 *), ...@@ -220,12 +224,16 @@ int ASYNC_start_job(ASYNC_JOB **job, int *ret, int (*func)(void *),
async_get_ctx()->currjob = *job; async_get_ctx()->currjob = *job;
/* Resume previous job */ /* Resume previous job */
if(!async_fibre_swapcontext(&async_get_ctx()->dispatcher, 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; goto err;
}
continue; continue;
} }
/* Should not happen */ /* Should not happen */
ASYNCerr(ASYNC_F_ASYNC_START_JOB, ERR_R_INTERNAL_ERROR);
async_release_job(async_get_ctx()->currjob); async_release_job(async_get_ctx()->currjob);
async_get_ctx()->currjob = NULL; async_get_ctx()->currjob = NULL;
*job = NULL; *job = NULL;
...@@ -240,6 +248,7 @@ int ASYNC_start_job(ASYNC_JOB **job, int *ret, int (*func)(void *), ...@@ -240,6 +248,7 @@ int ASYNC_start_job(ASYNC_JOB **job, int *ret, int (*func)(void *),
if(args != NULL) { if(args != NULL) {
async_get_ctx()->currjob->funcargs = OPENSSL_malloc(size); async_get_ctx()->currjob->funcargs = OPENSSL_malloc(size);
if(!async_get_ctx()->currjob->funcargs) { if(!async_get_ctx()->currjob->funcargs) {
ASYNCerr(ASYNC_F_ASYNC_START_JOB, ERR_R_MALLOC_FAILURE);
async_release_job(async_get_ctx()->currjob); async_release_job(async_get_ctx()->currjob);
async_get_ctx()->currjob = NULL; async_get_ctx()->currjob = NULL;
return ASYNC_ERR; return ASYNC_ERR;
...@@ -251,9 +260,11 @@ int ASYNC_start_job(ASYNC_JOB **job, int *ret, int (*func)(void *), ...@@ -251,9 +260,11 @@ int ASYNC_start_job(ASYNC_JOB **job, int *ret, int (*func)(void *),
async_get_ctx()->currjob->func = func; async_get_ctx()->currjob->func = func;
if(!async_fibre_swapcontext(&async_get_ctx()->dispatcher, 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; goto err;
} }
}
err: err:
async_release_job(async_get_ctx()->currjob); async_release_job(async_get_ctx()->currjob);
...@@ -267,15 +278,20 @@ int ASYNC_pause_job(void) ...@@ -267,15 +278,20 @@ int ASYNC_pause_job(void)
{ {
ASYNC_JOB *job; 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; return 0;
}
job = async_get_ctx()->currjob; job = async_get_ctx()->currjob;
job->status = ASYNC_JOB_PAUSING; job->status = ASYNC_JOB_PAUSING;
if(!async_fibre_swapcontext(&job->fibrectx, if(!async_fibre_swapcontext(&job->fibrectx,
&async_get_ctx()->dispatcher, 1)) { &async_get_ctx()->dispatcher, 1)) {
/* Error */ ASYNCerr(ASYNC_F_ASYNC_PAUSE_JOB, ASYNC_R_FAILED_TO_SWAP_CONTEXT);
return 0; return 0;
} }
...@@ -297,11 +313,14 @@ int ASYNC_init_pool(size_t max_size, size_t init_size) ...@@ -297,11 +313,14 @@ int ASYNC_init_pool(size_t max_size, size_t init_size)
STACK_OF(ASYNC_JOB) *pool; STACK_OF(ASYNC_JOB) *pool;
size_t curr_size = 0; 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; return 0;
}
pool = sk_ASYNC_JOB_new_null(); pool = sk_ASYNC_JOB_new_null();
if (pool == NULL) { if (pool == NULL) {
ASYNCerr(ASYNC_F_ASYNC_INIT_POOL, ERR_R_MALLOC_FAILURE);
return 0; return 0;
} }
/* Pre-create jobs as required */ /* Pre-create jobs as required */
...@@ -324,6 +343,7 @@ int ASYNC_init_pool(size_t max_size, size_t init_size) ...@@ -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)) { 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); async_empty_pool(pool);
sk_ASYNC_JOB_free(pool); sk_ASYNC_JOB_free(pool);
return 0; return 0;
......
/* 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
}
...@@ -157,6 +157,7 @@ static ERR_STRING_DATA ERR_str_libraries[] = { ...@@ -157,6 +157,7 @@ static ERR_STRING_DATA ERR_str_libraries[] = {
{ERR_PACK(ERR_LIB_FIPS, 0, 0), "FIPS routines"}, {ERR_PACK(ERR_LIB_FIPS, 0, 0), "FIPS routines"},
{ERR_PACK(ERR_LIB_CMS, 0, 0), "CMS routines"}, {ERR_PACK(ERR_LIB_CMS, 0, 0), "CMS routines"},
{ERR_PACK(ERR_LIB_HMAC, 0, 0), "HMAC routines"}, {ERR_PACK(ERR_LIB_HMAC, 0, 0), "HMAC routines"},
{ERR_PACK(ERR_LIB_ASYNC, 0, 0), "ASYNC routines"},
{0, NULL}, {0, NULL},
}; };
......
...@@ -106,6 +106,7 @@ ...@@ -106,6 +106,7 @@
# include <openssl/jpake.h> # include <openssl/jpake.h>
#endif #endif
#include <internal/ct_int.h> #include <internal/ct_int.h>
#include <openssl/async.h>
void ERR_load_crypto_strings(void) void ERR_load_crypto_strings(void)
{ {
...@@ -165,5 +166,6 @@ void ERR_load_crypto_strings(void) ...@@ -165,5 +166,6 @@ void ERR_load_crypto_strings(void)
# ifndef OPENSSL_NO_CT # ifndef OPENSSL_NO_CT
ERR_load_CT_strings(); ERR_load_CT_strings();
# endif # endif
ERR_load_ASYNC_strings();
#endif #endif
} }
...@@ -36,6 +36,7 @@ L HMAC include/openssl/hmac.h crypto/hmac/hmac_err.c ...@@ -36,6 +36,7 @@ L HMAC include/openssl/hmac.h crypto/hmac/hmac_err.c
L CMS include/openssl/cms.h crypto/cms/cms_err.c L CMS include/openssl/cms.h crypto/cms/cms_err.c
L JPAKE include/openssl/jpake.h crypto/jpake/jpake_err.c L JPAKE include/openssl/jpake.h crypto/jpake/jpake_err.c
L FIPS include/openssl/fips.h crypto/fips_err.h L FIPS include/openssl/fips.h crypto/fips_err.h
L ASYNC include/openssl/async.h crypto/async/async_err.c
# additional header files to be scanned for function names # additional header files to be scanned for function names
L NONE crypto/x509/x509_vfy.h NONE L NONE crypto/x509/x509_vfy.h NONE
......
...@@ -79,8 +79,30 @@ ASYNC_JOB *ASYNC_get_current_job(void); ...@@ -79,8 +79,30 @@ ASYNC_JOB *ASYNC_get_current_job(void);
void ASYNC_wake(ASYNC_JOB *job); void ASYNC_wake(ASYNC_JOB *job);
void ASYNC_clear_wake(ASYNC_JOB *job); void ASYNC_clear_wake(ASYNC_JOB *job);
# ifdef __cplusplus /* BEGIN ERROR CODES */
} /*
# endif * The following lines are auto generated by the script mkerr.pl. Any changes
* made after this point may be overwritten when the script is next run.
*/
void ERR_load_ASYNC_strings(void);
/* Error codes for the ASYNC functions. */
/* Function codes. */
# define ASYNC_F_ASYNC_CTX_NEW 100
# define ASYNC_F_ASYNC_INIT_POOL 101
# define ASYNC_F_ASYNC_JOB_NEW 102
# define ASYNC_F_ASYNC_PAUSE_JOB 103
# define ASYNC_F_ASYNC_START_FUNC 104
# define ASYNC_F_ASYNC_START_JOB 105
/* Reason codes. */
# define ASYNC_R_CANNOT_CREATE_WAIT_PIPE 100
# define ASYNC_R_FAILED_TO_SET_POOL 101
# define ASYNC_R_FAILED_TO_SWAP_CONTEXT 102
# define ASYNC_R_INVALID_POOL_SIZE 103
#ifdef __cplusplus
}
#endif
#endif #endif
...@@ -194,6 +194,7 @@ typedef struct err_state_st { ...@@ -194,6 +194,7 @@ typedef struct err_state_st {
# define ERR_LIB_HMAC 48 # define ERR_LIB_HMAC 48
# define ERR_LIB_JPAKE 49 # define ERR_LIB_JPAKE 49
# define ERR_LIB_CT 50 # define ERR_LIB_CT 50
# define ERR_LIB_ASYNC 51
# define ERR_LIB_USER 128 # define ERR_LIB_USER 128
...@@ -231,6 +232,7 @@ typedef struct err_state_st { ...@@ -231,6 +232,7 @@ typedef struct err_state_st {
# define HMACerr(f,r) ERR_PUT_error(ERR_LIB_HMAC,(f),(r),__FILE__,__LINE__) # define HMACerr(f,r) ERR_PUT_error(ERR_LIB_HMAC,(f),(r),__FILE__,__LINE__)
# define JPAKEerr(f,r) ERR_PUT_error(ERR_LIB_JPAKE,(f),(r),__FILE__,__LINE__) # define JPAKEerr(f,r) ERR_PUT_error(ERR_LIB_JPAKE,(f),(r),__FILE__,__LINE__)
# define CTerr(f,r) ERR_PUT_error(ERR_LIB_CT,(f),(r),__FILE__,__LINE__) # define CTerr(f,r) ERR_PUT_error(ERR_LIB_CT,(f),(r),__FILE__,__LINE__)
# define ASYNCerr(f,r) ERR_PUT_error(ERR_LIB_ASYNC,(f),(r),__FILE__,__LINE__)
/* /*
* Borland C seems too stupid to be able to shift and do longs in the * Borland C seems too stupid to be able to shift and do longs in the
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册