X-Git-Url: https://git.openssl.org/?p=openssl.git;a=blobdiff_plain;f=crypto%2Fasync%2Farch%2Fasync_posix.c;h=33f2a3fa1ea21f7f42237c589e088bca19904676;hp=bb799e54f8f32bb30b0b1c9473f772c739309ee7;hb=c521edc3a12042701b2dda93e6bb9855e351c929;hpb=7070e5ca2fa41940d56599bf016a45cb1c0e03f0 diff --git a/crypto/async/arch/async_posix.c b/crypto/async/arch/async_posix.c index bb799e54f8..33f2a3fa1e 100644 --- a/crypto/async/arch/async_posix.c +++ b/crypto/async/arch/async_posix.c @@ -1,4 +1,3 @@ -/* crypto/async/arch/async_posix.c */ /* * Written by Matt Caswell (matt@openssl.org) for the OpenSSL project. */ @@ -51,38 +50,52 @@ * ==================================================================== */ +/* This must be the first #include file */ #include "../async_locl.h" -#include -#ifdef ASYNC_SYSV -# include -# include -# include -# include +#ifdef ASYNC_POSIX -__thread ASYNC_CTX *sysvctx; +# include +# include #define STACKSIZE 32768 -int ASYNC_FIBRE_init(ASYNC_FIBRE *fibre) +int ASYNC_is_capable(void) { - void *stack = NULL; + ucontext_t ctx; - if (!(stack = OPENSSL_malloc(STACKSIZE))) { - return 0; - } + /* + * Some platforms provide getcontext() but it does not work (notably + * MacOSX PPC64). Check for a working getcontext(); + */ + return getcontext(&ctx) == 0; +} - fibre->fibre.uc_stack.ss_sp = stack; - fibre->fibre.uc_stack.ss_size = STACKSIZE; - fibre->fibre.uc_link = NULL; - fibre->env_init = 0; +void async_local_cleanup(void) +{ +} - return 1; +int async_fibre_makecontext(async_fibre *fibre) +{ + fibre->env_init = 0; + if (getcontext(&fibre->fibre) == 0) { + fibre->fibre.uc_stack.ss_sp = OPENSSL_malloc(STACKSIZE); + if (fibre->fibre.uc_stack.ss_sp != NULL) { + fibre->fibre.uc_stack.ss_size = STACKSIZE; + fibre->fibre.uc_link = NULL; + makecontext(&fibre->fibre, async_start_func, 0); + return 1; + } + } else { + fibre->fibre.uc_stack.ss_sp = NULL; + } + return 0; } -void ASYNC_FIBRE_free(ASYNC_FIBRE *fibre) +void async_fibre_free(async_fibre *fibre) { - if (fibre->fibre.uc_stack.ss_sp) - OPENSSL_free(fibre->fibre.uc_stack.ss_sp); + OPENSSL_free(fibre->fibre.uc_stack.ss_sp); + fibre->fibre.uc_stack.ss_sp = NULL; } + #endif