Coverage Report

Created: 2025-10-28 06:56

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl/crypto/async/arch/async_posix.h
Line
Count
Source
1
/*
2
 * Copyright 2015-2024 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
#ifndef OSSL_CRYPTO_ASYNC_POSIX_H
11
#define OSSL_CRYPTO_ASYNC_POSIX_H
12
#include <openssl/e_os2.h>
13
14
#if defined(OPENSSL_SYS_UNIX) \
15
    && defined(OPENSSL_THREADS) && !defined(OPENSSL_NO_ASYNC) \
16
    && !defined(__ANDROID__) && !defined(__OpenBSD__) \
17
    && !defined(OPENSSL_SYS_TANDEM)
18
19
# include <unistd.h>
20
21
# if _POSIX_VERSION >= 200112L \
22
    && (_POSIX_VERSION < 200809L || defined(__GLIBC__) || defined(__FreeBSD__))
23
24
# include <pthread.h>
25
26
#  define ASYNC_POSIX
27
#  define ASYNC_ARCH
28
29
#  if defined(__CET__) || defined(__ia64__)
30
/*
31
 * When Intel CET is enabled, makecontext will create a different
32
 * shadow stack for each context.  async_fibre_swapcontext cannot
33
 * use _longjmp.  It must call swapcontext to swap shadow stack as
34
 * well as normal stack.
35
 * On IA64 the register stack engine is not saved across setjmp/longjmp. Here
36
 * swapcontext() performs correctly.
37
 */
38
#   define USE_SWAPCONTEXT
39
#  endif
40
#  if defined(__aarch64__) && defined(__clang__) \
41
    && defined(__ARM_FEATURE_BTI_DEFAULT) && __ARM_FEATURE_BTI_DEFAULT == 1
42
/*
43
 * setjmp/longjmp don't currently work with BTI on all libc implementations
44
 * when compiled by clang. This is because clang doesn't put a BTI after the
45
 * call to setjmp where it returns the second time. This then fails on libc
46
 * implementations - notably glibc - which use an indirect jump to there.
47
 * So use the swapcontext implementation, which does work.
48
 * See https://github.com/llvm/llvm-project/issues/48888.
49
 */
50
#   define USE_SWAPCONTEXT
51
#  endif
52
#   if defined(OPENSSL_SYS_TANDEM)
53
#    include <tdmsig.h>
54
#   else
55
#    include <ucontext.h>
56
#   endif
57
#   ifndef USE_SWAPCONTEXT
58
#    include <setjmp.h>
59
#   endif
60
61
typedef struct async_fibre_st {
62
    ucontext_t fibre;
63
#  ifndef USE_SWAPCONTEXT
64
    jmp_buf env;
65
    int env_init;
66
#  endif
67
} async_fibre;
68
69
int async_local_init(void);
70
void async_local_deinit(void);
71
72
static ossl_inline int async_fibre_swapcontext(async_fibre *o, async_fibre *n, int r)
73
0
{
74
#  ifdef USE_SWAPCONTEXT
75
    swapcontext(&o->fibre, &n->fibre);
76
#  else
77
0
    o->env_init = 1;
78
79
0
    if (!r || !_setjmp(o->env)) {
80
0
        if (n->env_init)
81
0
            _longjmp(n->env, 1);
82
0
        else
83
0
            setcontext(&n->fibre);
84
0
    }
85
0
#  endif
86
87
0
    return 1;
88
0
}
Unexecuted instantiation: async.c:async_fibre_swapcontext
Unexecuted instantiation: async_wait.c:async_fibre_swapcontext
Unexecuted instantiation: async_posix.c:async_fibre_swapcontext
89
90
#  define async_fibre_init_dispatcher(d)
91
92
int async_fibre_makecontext(async_fibre *fibre);
93
void async_fibre_free(async_fibre *fibre);
94
95
# endif
96
#endif
97
#endif /* OSSL_CRYPTO_ASYNC_POSIX_H */