| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/async/async.c |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /* | - | ||||||||||||
| 2 | * Copyright 2015-2018 The OpenSSL Project Authors. All Rights Reserved. | - | ||||||||||||
| 3 | * | - | ||||||||||||
| 4 | * Licensed under the OpenSSL license (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 | * Without this we start getting longjmp crashes because it thinks we're jumping | - | ||||||||||||
| 12 | * up the stack when in fact we are jumping to an entirely different stack. The | - | ||||||||||||
| 13 | * cost of this is not having certain buffer overrun/underrun checks etc for | - | ||||||||||||
| 14 | * this source file :-( | - | ||||||||||||
| 15 | */ | - | ||||||||||||
| 16 | #undef _FORTIFY_SOURCE | - | ||||||||||||
| 17 | - | |||||||||||||
| 18 | /* This must be the first #include file */ | - | ||||||||||||
| 19 | #include "async_locl.h" | - | ||||||||||||
| 20 | - | |||||||||||||
| 21 | #include <openssl/err.h> | - | ||||||||||||
| 22 | #include "internal/cryptlib_int.h" | - | ||||||||||||
| 23 | #include <string.h> | - | ||||||||||||
| 24 | - | |||||||||||||
| 25 | #define ASYNC_JOB_RUNNING 0 | - | ||||||||||||
| 26 | #define ASYNC_JOB_PAUSING 1 | - | ||||||||||||
| 27 | #define ASYNC_JOB_PAUSED 2 | - | ||||||||||||
| 28 | #define ASYNC_JOB_STOPPING 3 | - | ||||||||||||
| 29 | - | |||||||||||||
| 30 | static CRYPTO_THREAD_LOCAL ctxkey; | - | ||||||||||||
| 31 | static CRYPTO_THREAD_LOCAL poolkey; | - | ||||||||||||
| 32 | - | |||||||||||||
| 33 | static async_ctx *async_ctx_new(void) | - | ||||||||||||
| 34 | { | - | ||||||||||||
| 35 | async_ctx *nctx; | - | ||||||||||||
| 36 | - | |||||||||||||
| 37 | if (!ossl_init_thread_start(OPENSSL_INIT_THREAD_ASYNC))
| 0-5 | ||||||||||||
| 38 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||
| 39 | - | |||||||||||||
| 40 | nctx = OPENSSL_malloc(sizeof(*nctx)); | - | ||||||||||||
| 41 | if (nctx == NULL) {
| 0-5 | ||||||||||||
| 42 | ASYNCerr(ASYNC_F_ASYNC_CTX_NEW, ERR_R_MALLOC_FAILURE); | - | ||||||||||||
| 43 | goto err; never executed: goto err; | 0 | ||||||||||||
| 44 | } | - | ||||||||||||
| 45 | - | |||||||||||||
| 46 | async_fibre_init_dispatcher(&nctx->dispatcher); | - | ||||||||||||
| 47 | nctx->currjob = NULL; | - | ||||||||||||
| 48 | nctx->blocked = 0; | - | ||||||||||||
| 49 | if (!CRYPTO_THREAD_set_local(&ctxkey, nctx))
| 0-5 | ||||||||||||
| 50 | goto err; never executed: goto err; | 0 | ||||||||||||
| 51 | - | |||||||||||||
| 52 | return nctx; executed 5 times by 1 test: return nctx;Executed by:
| 5 | ||||||||||||
| 53 | err: | - | ||||||||||||
| 54 | OPENSSL_free(nctx); | - | ||||||||||||
| 55 | - | |||||||||||||
| 56 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||
| 57 | } | - | ||||||||||||
| 58 | - | |||||||||||||
| 59 | async_ctx *async_get_ctx(void) | - | ||||||||||||
| 60 | { | - | ||||||||||||
| 61 | return (async_ctx *)CRYPTO_THREAD_get_local(&ctxkey); executed 58 times by 1 test: return (async_ctx *)CRYPTO_THREAD_get_local(&ctxkey);Executed by:
| 58 | ||||||||||||
| 62 | } | - | ||||||||||||
| 63 | - | |||||||||||||
| 64 | static int async_ctx_free(void) | - | ||||||||||||
| 65 | { | - | ||||||||||||
| 66 | async_ctx *ctx; | - | ||||||||||||
| 67 | - | |||||||||||||
| 68 | ctx = async_get_ctx(); | - | ||||||||||||
| 69 | - | |||||||||||||
| 70 | if (!CRYPTO_THREAD_set_local(&ctxkey, NULL))
| 0-6 | ||||||||||||
| 71 | return 0; never executed: return 0; | 0 | ||||||||||||
| 72 | - | |||||||||||||
| 73 | OPENSSL_free(ctx); | - | ||||||||||||
| 74 | - | |||||||||||||
| 75 | return 1; executed 6 times by 1 test: return 1;Executed by:
| 6 | ||||||||||||
| 76 | } | - | ||||||||||||
| 77 | - | |||||||||||||
| 78 | static ASYNC_JOB *async_job_new(void) | - | ||||||||||||
| 79 | { | - | ||||||||||||
| 80 | ASYNC_JOB *job = NULL; | - | ||||||||||||
| 81 | - | |||||||||||||
| 82 | job = OPENSSL_zalloc(sizeof(*job)); | - | ||||||||||||
| 83 | if (job == NULL) {
| 0-6 | ||||||||||||
| 84 | ASYNCerr(ASYNC_F_ASYNC_JOB_NEW, ERR_R_MALLOC_FAILURE); | - | ||||||||||||
| 85 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||
| 86 | } | - | ||||||||||||
| 87 | - | |||||||||||||
| 88 | job->status = ASYNC_JOB_RUNNING; | - | ||||||||||||
| 89 | - | |||||||||||||
| 90 | return job; executed 6 times by 1 test: return job;Executed by:
| 6 | ||||||||||||
| 91 | } | - | ||||||||||||
| 92 | - | |||||||||||||
| 93 | static void async_job_free(ASYNC_JOB *job) | - | ||||||||||||
| 94 | { | - | ||||||||||||
| 95 | if (job != NULL) {
| 5-6 | ||||||||||||
| 96 | OPENSSL_free(job->funcargs); | - | ||||||||||||
| 97 | async_fibre_free(&job->fibrectx); | - | ||||||||||||
| 98 | OPENSSL_free(job); | - | ||||||||||||
| 99 | } executed 6 times by 1 test: end of blockExecuted by:
| 6 | ||||||||||||
| 100 | } executed 11 times by 1 test: end of blockExecuted by:
| 11 | ||||||||||||
| 101 | - | |||||||||||||
| 102 | static ASYNC_JOB *async_get_pool_job(void) { | - | ||||||||||||
| 103 | ASYNC_JOB *job; | - | ||||||||||||
| 104 | async_pool *pool; | - | ||||||||||||
| 105 | - | |||||||||||||
| 106 | pool = (async_pool *)CRYPTO_THREAD_get_local(&poolkey); | - | ||||||||||||
| 107 | if (pool == NULL) {
| 0-8 | ||||||||||||
| 108 | /* | - | ||||||||||||
| 109 | * Pool has not been initialised, so init with the defaults, i.e. | - | ||||||||||||
| 110 | * no max size and no pre-created jobs | - | ||||||||||||
| 111 | */ | - | ||||||||||||
| 112 | if (ASYNC_init_thread(0, 0) == 0)
| 0 | ||||||||||||
| 113 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||
| 114 | pool = (async_pool *)CRYPTO_THREAD_get_local(&poolkey); | - | ||||||||||||
| 115 | } never executed: end of block | 0 | ||||||||||||
| 116 | - | |||||||||||||
| 117 | job = sk_ASYNC_JOB_pop(pool->jobs); | - | ||||||||||||
| 118 | if (job == NULL) {
| 1-7 | ||||||||||||
| 119 | /* Pool is empty */ | - | ||||||||||||
| 120 | if ((pool->max_size != 0) && (pool->curr_size >= pool->max_size))
| 0-7 | ||||||||||||
| 121 | return NULL; executed 1 time by 1 test: return ((void *)0) ;Executed by:
| 1 | ||||||||||||
| 122 | - | |||||||||||||
| 123 | job = async_job_new(); | - | ||||||||||||
| 124 | if (job != NULL) {
| 0-6 | ||||||||||||
| 125 | if (! async_fibre_makecontext(&job->fibrectx)) {
| 0-6 | ||||||||||||
| 126 | async_job_free(job); | - | ||||||||||||
| 127 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||
| 128 | } | - | ||||||||||||
| 129 | pool->curr_size++; | - | ||||||||||||
| 130 | } executed 6 times by 1 test: end of blockExecuted by:
| 6 | ||||||||||||
| 131 | } executed 6 times by 1 test: end of blockExecuted by:
| 6 | ||||||||||||
| 132 | return job; executed 7 times by 1 test: return job;Executed by:
| 7 | ||||||||||||
| 133 | } | - | ||||||||||||
| 134 | - | |||||||||||||
| 135 | static void async_release_job(ASYNC_JOB *job) { | - | ||||||||||||
| 136 | async_pool *pool; | - | ||||||||||||
| 137 | - | |||||||||||||
| 138 | pool = (async_pool *)CRYPTO_THREAD_get_local(&poolkey); | - | ||||||||||||
| 139 | OPENSSL_free(job->funcargs); | - | ||||||||||||
| 140 | job->funcargs = NULL; | - | ||||||||||||
| 141 | sk_ASYNC_JOB_push(pool->jobs, job); | - | ||||||||||||
| 142 | } executed 7 times by 1 test: end of blockExecuted by:
| 7 | ||||||||||||
| 143 | - | |||||||||||||
| 144 | void async_start_func(void) | - | ||||||||||||
| 145 | { | - | ||||||||||||
| 146 | ASYNC_JOB *job; | - | ||||||||||||
| 147 | async_ctx *ctx = async_get_ctx(); | - | ||||||||||||
| 148 | - | |||||||||||||
| 149 | while (1) { | - | ||||||||||||
| 150 | /* Run the job */ | - | ||||||||||||
| 151 | job = ctx->currjob; | - | ||||||||||||
| 152 | job->ret = job->func(job->funcargs); | - | ||||||||||||
| 153 | - | |||||||||||||
| 154 | /* Stop the job */ | - | ||||||||||||
| 155 | job->status = ASYNC_JOB_STOPPING; | - | ||||||||||||
| 156 | if (!async_fibre_swapcontext(&job->fibrectx,
| 0-1 | ||||||||||||
| 157 | &ctx->dispatcher, 1)) {
| 0-1 | ||||||||||||
| 158 | /* | - | ||||||||||||
| 159 | * Should not happen. Getting here will close the thread...can't do | - | ||||||||||||
| 160 | * much about it | - | ||||||||||||
| 161 | */ | - | ||||||||||||
| 162 | ASYNCerr(ASYNC_F_ASYNC_START_FUNC, ASYNC_R_FAILED_TO_SWAP_CONTEXT); | - | ||||||||||||
| 163 | } never executed: end of block | 0 | ||||||||||||
| 164 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||
| 165 | } never executed: end of block | 0 | ||||||||||||
| 166 | - | |||||||||||||
| 167 | int ASYNC_start_job(ASYNC_JOB **job, ASYNC_WAIT_CTX *wctx, int *ret, | - | ||||||||||||
| 168 | int (*func)(void *), void *args, size_t size) | - | ||||||||||||
| 169 | { | - | ||||||||||||
| 170 | async_ctx *ctx; | - | ||||||||||||
| 171 | - | |||||||||||||
| 172 | if (!OPENSSL_init_crypto(OPENSSL_INIT_ASYNC, NULL))
| 0-17 | ||||||||||||
| 173 | return ASYNC_ERR; never executed: return 0; | 0 | ||||||||||||
| 174 | - | |||||||||||||
| 175 | ctx = async_get_ctx(); | - | ||||||||||||
| 176 | if (ctx == NULL)
| 5-12 | ||||||||||||
| 177 | ctx = async_ctx_new(); executed 5 times by 1 test: ctx = async_ctx_new();Executed by:
| 5 | ||||||||||||
| 178 | if (ctx == NULL)
| 0-17 | ||||||||||||
| 179 | return ASYNC_ERR; never executed: return 0; | 0 | ||||||||||||
| 180 | - | |||||||||||||
| 181 | if (*job)
| 8-9 | ||||||||||||
| 182 | ctx->currjob = *job; executed 9 times by 1 test: ctx->currjob = *job;Executed by:
| 9 | ||||||||||||
| 183 | - | |||||||||||||
| 184 | for (;;) { | - | ||||||||||||
| 185 | if (ctx->currjob != NULL) {
| 8-25 | ||||||||||||
| 186 | if (ctx->currjob->status == ASYNC_JOB_STOPPING) {
| 7-18 | ||||||||||||
| 187 | *ret = ctx->currjob->ret; | - | ||||||||||||
| 188 | ctx->currjob->waitctx = NULL; | - | ||||||||||||
| 189 | async_release_job(ctx->currjob); | - | ||||||||||||
| 190 | ctx->currjob = NULL; | - | ||||||||||||
| 191 | *job = NULL; | - | ||||||||||||
| 192 | return ASYNC_FINISH; executed 7 times by 1 test: return 3;Executed by:
| 7 | ||||||||||||
| 193 | } | - | ||||||||||||
| 194 | - | |||||||||||||
| 195 | if (ctx->currjob->status == ASYNC_JOB_PAUSING) {
| 9 | ||||||||||||
| 196 | *job = ctx->currjob; | - | ||||||||||||
| 197 | ctx->currjob->status = ASYNC_JOB_PAUSED; | - | ||||||||||||
| 198 | ctx->currjob = NULL; | - | ||||||||||||
| 199 | return ASYNC_PAUSE; executed 9 times by 1 test: return 2;Executed by:
| 9 | ||||||||||||
| 200 | } | - | ||||||||||||
| 201 | - | |||||||||||||
| 202 | if (ctx->currjob->status == ASYNC_JOB_PAUSED) {
| 0-9 | ||||||||||||
| 203 | ctx->currjob = *job; | - | ||||||||||||
| 204 | /* Resume previous job */ | - | ||||||||||||
| 205 | if (!async_fibre_swapcontext(&ctx->dispatcher,
| 0-9 | ||||||||||||
| 206 | &ctx->currjob->fibrectx, 1)) {
| 0-9 | ||||||||||||
| 207 | ASYNCerr(ASYNC_F_ASYNC_START_JOB, | - | ||||||||||||
| 208 | ASYNC_R_FAILED_TO_SWAP_CONTEXT); | - | ||||||||||||
| 209 | goto err; never executed: goto err; | 0 | ||||||||||||
| 210 | } | - | ||||||||||||
| 211 | continue; executed 9 times by 1 test: continue;Executed by:
| 9 | ||||||||||||
| 212 | } | - | ||||||||||||
| 213 | - | |||||||||||||
| 214 | /* Should not happen */ | - | ||||||||||||
| 215 | ASYNCerr(ASYNC_F_ASYNC_START_JOB, ERR_R_INTERNAL_ERROR); | - | ||||||||||||
| 216 | async_release_job(ctx->currjob); | - | ||||||||||||
| 217 | ctx->currjob = NULL; | - | ||||||||||||
| 218 | *job = NULL; | - | ||||||||||||
| 219 | return ASYNC_ERR; never executed: return 0; | 0 | ||||||||||||
| 220 | } | - | ||||||||||||
| 221 | - | |||||||||||||
| 222 | /* Start a new job */ | - | ||||||||||||
| 223 | if ((ctx->currjob = async_get_pool_job()) == NULL)
| 1-7 | ||||||||||||
| 224 | return ASYNC_NO_JOBS; executed 1 time by 1 test: return 1;Executed by:
| 1 | ||||||||||||
| 225 | - | |||||||||||||
| 226 | if (args != NULL) {
| 0-7 | ||||||||||||
| 227 | ctx->currjob->funcargs = OPENSSL_malloc(size); | - | ||||||||||||
| 228 | if (ctx->currjob->funcargs == NULL) {
| 0 | ||||||||||||
| 229 | ASYNCerr(ASYNC_F_ASYNC_START_JOB, ERR_R_MALLOC_FAILURE); | - | ||||||||||||
| 230 | async_release_job(ctx->currjob); | - | ||||||||||||
| 231 | ctx->currjob = NULL; | - | ||||||||||||
| 232 | return ASYNC_ERR; never executed: return 0; | 0 | ||||||||||||
| 233 | } | - | ||||||||||||
| 234 | memcpy(ctx->currjob->funcargs, args, size); | - | ||||||||||||
| 235 | } else { never executed: end of block | 0 | ||||||||||||
| 236 | ctx->currjob->funcargs = NULL; | - | ||||||||||||
| 237 | } executed 7 times by 1 test: end of blockExecuted by:
| 7 | ||||||||||||
| 238 | - | |||||||||||||
| 239 | ctx->currjob->func = func; | - | ||||||||||||
| 240 | ctx->currjob->waitctx = wctx; | - | ||||||||||||
| 241 | if (!async_fibre_swapcontext(&ctx->dispatcher,
| 0-7 | ||||||||||||
| 242 | &ctx->currjob->fibrectx, 1)) {
| 0-7 | ||||||||||||
| 243 | ASYNCerr(ASYNC_F_ASYNC_START_JOB, ASYNC_R_FAILED_TO_SWAP_CONTEXT); | - | ||||||||||||
| 244 | goto err; never executed: goto err; | 0 | ||||||||||||
| 245 | } | - | ||||||||||||
| 246 | } executed 7 times by 1 test: end of blockExecuted by:
| 7 | ||||||||||||
| 247 | - | |||||||||||||
| 248 | err: code before this statement never executed: err: | 0 | ||||||||||||
| 249 | async_release_job(ctx->currjob); | - | ||||||||||||
| 250 | ctx->currjob = NULL; | - | ||||||||||||
| 251 | *job = NULL; | - | ||||||||||||
| 252 | return ASYNC_ERR; never executed: return 0; | 0 | ||||||||||||
| 253 | } | - | ||||||||||||
| 254 | - | |||||||||||||
| 255 | int ASYNC_pause_job(void) | - | ||||||||||||
| 256 | { | - | ||||||||||||
| 257 | ASYNC_JOB *job; | - | ||||||||||||
| 258 | async_ctx *ctx = async_get_ctx(); | - | ||||||||||||
| 259 | - | |||||||||||||
| 260 | if (ctx == NULL
| 9-10 | ||||||||||||
| 261 | || ctx->currjob == NULL
| 0-10 | ||||||||||||
| 262 | || ctx->blocked) {
| 1-9 | ||||||||||||
| 263 | /* | - | ||||||||||||
| 264 | * Could be we've deliberately not been started within a job so this is | - | ||||||||||||
| 265 | * counted as success. | - | ||||||||||||
| 266 | */ | - | ||||||||||||
| 267 | return 1; executed 10 times by 1 test: return 1;Executed by:
| 10 | ||||||||||||
| 268 | } | - | ||||||||||||
| 269 | - | |||||||||||||
| 270 | job = ctx->currjob; | - | ||||||||||||
| 271 | job->status = ASYNC_JOB_PAUSING; | - | ||||||||||||
| 272 | - | |||||||||||||
| 273 | if (!async_fibre_swapcontext(&job->fibrectx,
| 0-9 | ||||||||||||
| 274 | &ctx->dispatcher, 1)) {
| 0-9 | ||||||||||||
| 275 | ASYNCerr(ASYNC_F_ASYNC_PAUSE_JOB, ASYNC_R_FAILED_TO_SWAP_CONTEXT); | - | ||||||||||||
| 276 | return 0; never executed: return 0; | 0 | ||||||||||||
| 277 | } | - | ||||||||||||
| 278 | /* Reset counts of added and deleted fds */ | - | ||||||||||||
| 279 | async_wait_ctx_reset_counts(job->waitctx); | - | ||||||||||||
| 280 | - | |||||||||||||
| 281 | return 1; executed 9 times by 1 test: return 1;Executed by:
| 9 | ||||||||||||
| 282 | } | - | ||||||||||||
| 283 | - | |||||||||||||
| 284 | static void async_empty_pool(async_pool *pool) | - | ||||||||||||
| 285 | { | - | ||||||||||||
| 286 | ASYNC_JOB *job; | - | ||||||||||||
| 287 | - | |||||||||||||
| 288 | if (!pool || !pool->jobs)
| 0-5 | ||||||||||||
| 289 | return; never executed: return; | 0 | ||||||||||||
| 290 | - | |||||||||||||
| 291 | do { | - | ||||||||||||
| 292 | job = sk_ASYNC_JOB_pop(pool->jobs); | - | ||||||||||||
| 293 | async_job_free(job); | - | ||||||||||||
| 294 | } while (job); executed 11 times by 1 test: end of blockExecuted by:
| 5-11 | ||||||||||||
| 295 | } executed 5 times by 1 test: end of blockExecuted by:
| 5 | ||||||||||||
| 296 | - | |||||||||||||
| 297 | int async_init(void) | - | ||||||||||||
| 298 | { | - | ||||||||||||
| 299 | if (!CRYPTO_THREAD_init_local(&ctxkey, NULL))
| 0-4 | ||||||||||||
| 300 | return 0; never executed: return 0; | 0 | ||||||||||||
| 301 | - | |||||||||||||
| 302 | if (!CRYPTO_THREAD_init_local(&poolkey, NULL)) {
| 0-4 | ||||||||||||
| 303 | CRYPTO_THREAD_cleanup_local(&ctxkey); | - | ||||||||||||
| 304 | return 0; never executed: return 0; | 0 | ||||||||||||
| 305 | } | - | ||||||||||||
| 306 | - | |||||||||||||
| 307 | return 1; executed 4 times by 1 test: return 1;Executed by:
| 4 | ||||||||||||
| 308 | } | - | ||||||||||||
| 309 | - | |||||||||||||
| 310 | void async_deinit(void) | - | ||||||||||||
| 311 | { | - | ||||||||||||
| 312 | CRYPTO_THREAD_cleanup_local(&ctxkey); | - | ||||||||||||
| 313 | CRYPTO_THREAD_cleanup_local(&poolkey); | - | ||||||||||||
| 314 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||
| 315 | - | |||||||||||||
| 316 | int ASYNC_init_thread(size_t max_size, size_t init_size) | - | ||||||||||||
| 317 | { | - | ||||||||||||
| 318 | async_pool *pool; | - | ||||||||||||
| 319 | size_t curr_size = 0; | - | ||||||||||||
| 320 | - | |||||||||||||
| 321 | if (init_size > max_size) {
| 0-5 | ||||||||||||
| 322 | ASYNCerr(ASYNC_F_ASYNC_INIT_THREAD, ASYNC_R_INVALID_POOL_SIZE); | - | ||||||||||||
| 323 | return 0; never executed: return 0; | 0 | ||||||||||||
| 324 | } | - | ||||||||||||
| 325 | - | |||||||||||||
| 326 | if (!OPENSSL_init_crypto(OPENSSL_INIT_ASYNC, NULL))
| 0-5 | ||||||||||||
| 327 | return 0; never executed: return 0; | 0 | ||||||||||||
| 328 | - | |||||||||||||
| 329 | if (!ossl_init_thread_start(OPENSSL_INIT_THREAD_ASYNC))
| 0-5 | ||||||||||||
| 330 | return 0; never executed: return 0; | 0 | ||||||||||||
| 331 | - | |||||||||||||
| 332 | pool = OPENSSL_zalloc(sizeof(*pool)); | - | ||||||||||||
| 333 | if (pool == NULL) {
| 0-5 | ||||||||||||
| 334 | ASYNCerr(ASYNC_F_ASYNC_INIT_THREAD, ERR_R_MALLOC_FAILURE); | - | ||||||||||||
| 335 | return 0; never executed: return 0; | 0 | ||||||||||||
| 336 | } | - | ||||||||||||
| 337 | - | |||||||||||||
| 338 | pool->jobs = sk_ASYNC_JOB_new_reserve(NULL, init_size); | - | ||||||||||||
| 339 | if (pool->jobs == NULL) {
| 0-5 | ||||||||||||
| 340 | ASYNCerr(ASYNC_F_ASYNC_INIT_THREAD, ERR_R_MALLOC_FAILURE); | - | ||||||||||||
| 341 | OPENSSL_free(pool); | - | ||||||||||||
| 342 | return 0; never executed: return 0; | 0 | ||||||||||||
| 343 | } | - | ||||||||||||
| 344 | - | |||||||||||||
| 345 | pool->max_size = max_size; | - | ||||||||||||
| 346 | - | |||||||||||||
| 347 | /* Pre-create jobs as required */ | - | ||||||||||||
| 348 | while (init_size--) {
| 0-5 | ||||||||||||
| 349 | ASYNC_JOB *job; | - | ||||||||||||
| 350 | job = async_job_new(); | - | ||||||||||||
| 351 | if (job == NULL || !async_fibre_makecontext(&job->fibrectx)) {
| 0 | ||||||||||||
| 352 | /* | - | ||||||||||||
| 353 | * Not actually fatal because we already created the pool, just | - | ||||||||||||
| 354 | * skip creation of any more jobs | - | ||||||||||||
| 355 | */ | - | ||||||||||||
| 356 | async_job_free(job); | - | ||||||||||||
| 357 | break; never executed: break; | 0 | ||||||||||||
| 358 | } | - | ||||||||||||
| 359 | job->funcargs = NULL; | - | ||||||||||||
| 360 | sk_ASYNC_JOB_push(pool->jobs, job); /* Cannot fail due to reserve */ | - | ||||||||||||
| 361 | curr_size++; | - | ||||||||||||
| 362 | } never executed: end of block | 0 | ||||||||||||
| 363 | pool->curr_size = curr_size; | - | ||||||||||||
| 364 | if (!CRYPTO_THREAD_set_local(&poolkey, pool)) {
| 0-5 | ||||||||||||
| 365 | ASYNCerr(ASYNC_F_ASYNC_INIT_THREAD, ASYNC_R_FAILED_TO_SET_POOL); | - | ||||||||||||
| 366 | goto err; never executed: goto err; | 0 | ||||||||||||
| 367 | } | - | ||||||||||||
| 368 | - | |||||||||||||
| 369 | return 1; executed 5 times by 1 test: return 1;Executed by:
| 5 | ||||||||||||
| 370 | err: | - | ||||||||||||
| 371 | async_empty_pool(pool); | - | ||||||||||||
| 372 | sk_ASYNC_JOB_free(pool->jobs); | - | ||||||||||||
| 373 | OPENSSL_free(pool); | - | ||||||||||||
| 374 | return 0; never executed: return 0; | 0 | ||||||||||||
| 375 | } | - | ||||||||||||
| 376 | - | |||||||||||||
| 377 | void async_delete_thread_state(void) | - | ||||||||||||
| 378 | { | - | ||||||||||||
| 379 | async_pool *pool = (async_pool *)CRYPTO_THREAD_get_local(&poolkey); | - | ||||||||||||
| 380 | - | |||||||||||||
| 381 | if (pool != NULL) {
| 1-5 | ||||||||||||
| 382 | async_empty_pool(pool); | - | ||||||||||||
| 383 | sk_ASYNC_JOB_free(pool->jobs); | - | ||||||||||||
| 384 | OPENSSL_free(pool); | - | ||||||||||||
| 385 | CRYPTO_THREAD_set_local(&poolkey, NULL); | - | ||||||||||||
| 386 | } executed 5 times by 1 test: end of blockExecuted by:
| 5 | ||||||||||||
| 387 | async_local_cleanup(); | - | ||||||||||||
| 388 | async_ctx_free(); | - | ||||||||||||
| 389 | } executed 6 times by 1 test: end of blockExecuted by:
| 6 | ||||||||||||
| 390 | - | |||||||||||||
| 391 | void ASYNC_cleanup_thread(void) | - | ||||||||||||
| 392 | { | - | ||||||||||||
| 393 | if (!OPENSSL_init_crypto(OPENSSL_INIT_ASYNC, NULL))
| 0-5 | ||||||||||||
| 394 | return; never executed: return; | 0 | ||||||||||||
| 395 | - | |||||||||||||
| 396 | async_delete_thread_state(); | - | ||||||||||||
| 397 | } executed 5 times by 1 test: end of blockExecuted by:
| 5 | ||||||||||||
| 398 | - | |||||||||||||
| 399 | ASYNC_JOB *ASYNC_get_current_job(void) | - | ||||||||||||
| 400 | { | - | ||||||||||||
| 401 | async_ctx *ctx; | - | ||||||||||||
| 402 | - | |||||||||||||
| 403 | if (!OPENSSL_init_crypto(OPENSSL_INIT_ASYNC, NULL))
| 0-8 | ||||||||||||
| 404 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||
| 405 | - | |||||||||||||
| 406 | ctx = async_get_ctx(); | - | ||||||||||||
| 407 | if (ctx == NULL)
| 2-6 | ||||||||||||
| 408 | return NULL; executed 6 times by 1 test: return ((void *)0) ;Executed by:
| 6 | ||||||||||||
| 409 | - | |||||||||||||
| 410 | return ctx->currjob; executed 2 times by 1 test: return ctx->currjob;Executed by:
| 2 | ||||||||||||
| 411 | } | - | ||||||||||||
| 412 | - | |||||||||||||
| 413 | ASYNC_WAIT_CTX *ASYNC_get_wait_ctx(ASYNC_JOB *job) | - | ||||||||||||
| 414 | { | - | ||||||||||||
| 415 | return job->waitctx; executed 1 time by 1 test: return job->waitctx;Executed by:
| 1 | ||||||||||||
| 416 | } | - | ||||||||||||
| 417 | - | |||||||||||||
| 418 | void ASYNC_block_pause(void) | - | ||||||||||||
| 419 | { | - | ||||||||||||
| 420 | async_ctx *ctx; | - | ||||||||||||
| 421 | - | |||||||||||||
| 422 | if (!OPENSSL_init_crypto(OPENSSL_INIT_ASYNC, NULL))
| 0-1 | ||||||||||||
| 423 | return; never executed: return; | 0 | ||||||||||||
| 424 | - | |||||||||||||
| 425 | ctx = async_get_ctx(); | - | ||||||||||||
| 426 | if (ctx == NULL || ctx->currjob == NULL) {
| 0-1 | ||||||||||||
| 427 | /* | - | ||||||||||||
| 428 | * We're not in a job anyway so ignore this | - | ||||||||||||
| 429 | */ | - | ||||||||||||
| 430 | return; never executed: return; | 0 | ||||||||||||
| 431 | } | - | ||||||||||||
| 432 | ctx->blocked++; | - | ||||||||||||
| 433 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||
| 434 | - | |||||||||||||
| 435 | void ASYNC_unblock_pause(void) | - | ||||||||||||
| 436 | { | - | ||||||||||||
| 437 | async_ctx *ctx; | - | ||||||||||||
| 438 | - | |||||||||||||
| 439 | if (!OPENSSL_init_crypto(OPENSSL_INIT_ASYNC, NULL))
| 0-1 | ||||||||||||
| 440 | return; never executed: return; | 0 | ||||||||||||
| 441 | - | |||||||||||||
| 442 | ctx = async_get_ctx(); | - | ||||||||||||
| 443 | if (ctx == NULL || ctx->currjob == NULL) {
| 0-1 | ||||||||||||
| 444 | /* | - | ||||||||||||
| 445 | * We're not in a job anyway so ignore this | - | ||||||||||||
| 446 | */ | - | ||||||||||||
| 447 | return; never executed: return; | 0 | ||||||||||||
| 448 | } | - | ||||||||||||
| 449 | if (ctx->blocked > 0)
| 0-1 | ||||||||||||
| 450 | ctx->blocked--; executed 1 time by 1 test: ctx->blocked--;Executed by:
| 1 | ||||||||||||
| 451 | } executed 1 time by 1 test: end of blockExecuted by:
| 1 | ||||||||||||
| Source code | Switch to Preprocessed file |