aboutsummaryrefslogtreecommitdiff
path: root/crypto/async/arch
diff options
context:
space:
mode:
authorViktor Dukhovni <openssl-users@dukhovni.org>2015-11-21 20:14:43 -0500
committerViktor Dukhovni <openssl-users@dukhovni.org>2015-11-22 16:54:43 -0500
commit6e8ac5087061350a5a98ddc24dad6ceef9baf991 (patch)
tree35d5c7c7d42f03ccf97e67066b70a58e209667db /crypto/async/arch
parent3d32218812e87221344f2985512e42e4aaa88745 (diff)
downloadopenssl-6e8ac5087061350a5a98ddc24dad6ceef9baf991.zip
openssl-6e8ac5087061350a5a98ddc24dad6ceef9baf991.tar.gz
openssl-6e8ac5087061350a5a98ddc24dad6ceef9baf991.tar.bz2
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/arch')
-rw-r--r--crypto/async/arch/async_null.c2
-rw-r--r--crypto/async/arch/async_posix.c36
-rw-r--r--crypto/async/arch/async_posix.h17
-rw-r--r--crypto/async/arch/async_win.c1
-rw-r--r--crypto/async/arch/async_win.h3
5 files changed, 24 insertions, 35 deletions
diff --git a/crypto/async/arch/async_null.c b/crypto/async/arch/async_null.c
index b2dbfee..baed884 100644
--- a/crypto/async/arch/async_null.c
+++ b/crypto/async/arch/async_null.c
@@ -51,8 +51,8 @@
* ====================================================================
*/
+/* This must be the first #include file */
#include "../async_locl.h"
-#include <openssl/async.h>
#ifdef ASYNC_NULL
diff --git a/crypto/async/arch/async_posix.c b/crypto/async/arch/async_posix.c
index 77a2c33..3007581 100644
--- a/crypto/async/arch/async_posix.c
+++ b/crypto/async/arch/async_posix.c
@@ -51,15 +51,13 @@
* ====================================================================
*/
+/* This must be the first #include file */
#include "../async_locl.h"
-#include <openssl/async.h>
#ifdef ASYNC_POSIX
+
# include <stddef.h>
-# include <ucontext.h>
# include <unistd.h>
-# include <openssl/crypto.h>
-# include <openssl/async.h>
pthread_key_t posixctx;
pthread_key_t posixpool;
@@ -91,27 +89,27 @@ void async_global_cleanup(void)
{
}
-int async_fibre_init(async_fibre *fibre)
+int async_fibre_makecontext(async_fibre *fibre)
{
- void *stack = NULL;
-
- stack = OPENSSL_malloc(STACKSIZE);
- if (stack == NULL) {
- return 0;
- }
-
- fibre->fibre.uc_stack.ss_sp = stack;
- fibre->fibre.uc_stack.ss_size = STACKSIZE;
- fibre->fibre.uc_link = NULL;
fibre->env_init = 0;
-
- return 1;
+ 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)
{
- 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;
}
int async_pipe(OSSL_ASYNC_FD *pipefds)
diff --git a/crypto/async/arch/async_posix.h b/crypto/async/arch/async_posix.h
index 36fae24..c247888 100644
--- a/crypto/async/arch/async_posix.h
+++ b/crypto/async/arch/async_posix.h
@@ -50,6 +50,8 @@
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*/
+#ifndef OPENSSL_ASYNC_ARCH_ASYNC_POSIX_H
+#define OPENSSL_ASYNC_ARCH_ASYNC_POSIX_H
#include <openssl/e_os2.h>
#if defined(OPENSSL_SYS_UNIX) && defined(OPENSSL_THREADS)
@@ -63,14 +65,6 @@
# define ASYNC_POSIX
# define ASYNC_ARCH
-/*
- * Some platforms complain (e.g. OS-X) that setcontext/getcontext/makecontext
- * are deprecated without the following defined. We know its deprecated but
- * there is no alternative.
- */
-# define _XOPEN_SOURCE
-# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
-
# include <ucontext.h>
# include <setjmp.h>
# include "e_os.h"
@@ -103,14 +97,11 @@ static inline int async_fibre_swapcontext(async_fibre *o, async_fibre *n, int r)
return 1;
}
-# define async_fibre_makecontext(c) \
- (!getcontext(&(c)->fibre) \
- && async_fibre_init(c) \
- && (makecontext(&(c)->fibre, async_start_func, 0), 1))
# define async_fibre_init_dispatcher(d)
-int async_fibre_init(async_fibre *fibre);
+int async_fibre_makecontext(async_fibre *fibre);
void async_fibre_free(async_fibre *fibre);
# endif
#endif
+#endif /* OPENSSL_ASYNC_ARCH_ASYNC_POSIX_H */
diff --git a/crypto/async/arch/async_win.c b/crypto/async/arch/async_win.c
index 20c8a09..519476c 100644
--- a/crypto/async/arch/async_win.c
+++ b/crypto/async/arch/async_win.c
@@ -51,6 +51,7 @@
* ====================================================================
*/
+/* This must be the first #include file */
#include "../async_locl.h"
#ifdef ASYNC_WIN
diff --git a/crypto/async/arch/async_win.h b/crypto/async/arch/async_win.h
index 77e41e4..b247f59 100644
--- a/crypto/async/arch/async_win.h
+++ b/crypto/async/arch/async_win.h
@@ -51,13 +51,12 @@
* ====================================================================
*/
-#include <openssl/async.h>
-
/*
* This is the same detection used in cryptlib to set up the thread local
* storage that we depend on, so just copy that
*/
#if defined(_WIN32) || defined(__CYGWIN__)
+#include <openssl/async.h>
# define ASYNC_WIN
# define ASYNC_ARCH