-/* crypto/async/arch/async_posix.c */
/*
* Written by Matt Caswell (matt@openssl.org) for the OpenSSL project.
*/
* ====================================================================
*/
+/* This must be the first #include file */
#include "../async_locl.h"
-#include <openssl/async.h>
-#ifdef ASYNC_SYSV
-# include <stddef.h>
-# include <ucontext.h>
-# include <openssl/crypto.h>
-# include <openssl/async.h>
+#ifdef ASYNC_POSIX
-__thread ASYNC_CTX *sysvctx;
+# include <stddef.h>
+# include <unistd.h>
#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