Home | History | Annotate | Line # | Download | only in async
      1 /*
      2  * Copyright 2015-2020 The OpenSSL Project Authors. All Rights Reserved.
      3  *
      4  * Licensed under the Apache License 2.0 (the "License").  You may not use
      5  * this file except in compliance with the License.  You can obtain a copy
      6  * in the file LICENSE in the source distribution or at
      7  * https://www.openssl.org/source/license.html
      8  */
      9 
     10 /*
     11  * Must do this before including any header files, because on MacOS/X <stlib.h>
     12  * includes <signal.h> which includes <ucontext.h>
     13  */
     14 #if defined(__APPLE__) && defined(__MACH__) && !defined(_XOPEN_SOURCE)
     15 #define _XOPEN_SOURCE /* Otherwise incomplete ucontext_t structure */
     16 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
     17 #endif
     18 
     19 #if defined(_WIN32)
     20 #include <windows.h>
     21 #endif
     22 
     23 #include "crypto/async.h"
     24 #include <openssl/crypto.h>
     25 
     26 typedef struct async_ctx_st async_ctx;
     27 typedef struct async_pool_st async_pool;
     28 
     29 #include "arch/async_win.h"
     30 #include "arch/async_posix.h"
     31 #include "arch/async_null.h"
     32 
     33 struct async_ctx_st {
     34     async_fibre dispatcher;
     35     ASYNC_JOB *currjob;
     36     unsigned int blocked;
     37 };
     38 
     39 struct async_job_st {
     40     async_fibre fibrectx;
     41     int (*func)(void *);
     42     void *funcargs;
     43     int ret;
     44     int status;
     45     ASYNC_WAIT_CTX *waitctx;
     46     OSSL_LIB_CTX *libctx;
     47 };
     48 
     49 struct fd_lookup_st {
     50     const void *key;
     51     OSSL_ASYNC_FD fd;
     52     void *custom_data;
     53     void (*cleanup)(ASYNC_WAIT_CTX *, const void *, OSSL_ASYNC_FD, void *);
     54     int add;
     55     int del;
     56     struct fd_lookup_st *next;
     57 };
     58 
     59 struct async_wait_ctx_st {
     60     struct fd_lookup_st *fds;
     61     size_t numadd;
     62     size_t numdel;
     63     ASYNC_callback_fn callback;
     64     void *callback_arg;
     65     int status;
     66 };
     67 
     68 DEFINE_STACK_OF(ASYNC_JOB)
     69 
     70 struct async_pool_st {
     71     STACK_OF(ASYNC_JOB) *jobs;
     72     size_t curr_size;
     73     size_t max_size;
     74 };
     75 
     76 void async_local_cleanup(void);
     77 void async_start_func(void);
     78 async_ctx *async_get_ctx(void);
     79 
     80 void async_wait_ctx_reset_counts(ASYNC_WAIT_CTX *ctx);
     81