| 1 |
// Copyright (C) 1995-1998 Eric Young ([email protected]) All rights reserved. |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
#ifndef OPENSSL_HEADER_THREAD_H |
| 5 |
#define OPENSSL_HEADER_THREAD_H |
| 6 |
|
| 7 |
#include <sys/types.h> |
| 8 |
|
| 9 |
#include <openssl/base.h> |
| 10 |
|
| 11 |
#if defined(__cplusplus) |
| 12 |
extern "C" { |
| 13 |
#endif |
| 14 |
|
| 15 |
|
| 16 |
#if !defined(OPENSSL_THREADS) |
| 17 |
typedef struct crypto_mutex_st { |
| 18 |
char padding; // Empty structs have different sizes in C and C++. |
| 19 |
} CRYPTO_MUTEX; |
| 20 |
#elif defined(OPENSSL_WINDOWS) |
| 21 |
// CRYPTO_MUTEX can appear in public header files so we really don't want to |
| 22 |
// pull in windows.h. It's statically asserted that this structure is large |
| 23 |
// enough to contain a Windows SRWLOCK by thread_win.c. |
| 24 |
typedef union crypto_mutex_st { |
| 25 |
void *handle; |
| 26 |
} CRYPTO_MUTEX; |
| 27 |
#elif !defined(__GLIBC__) |
| 28 |
#if defined(OPENSSL_OPENBSD) |
| 29 |
#include <pthread.h> |
| 30 |
#endif |
| 31 |
typedef pthread_rwlock_t CRYPTO_MUTEX; |
| 32 |
#else |
| 33 |
// On glibc, |pthread_rwlock_t| is hidden under feature flags, and we can't |
| 34 |
// ensure that we'll be able to get it from a public header. It's statically |
| 35 |
// asserted that this structure is large enough to contain a |pthread_rwlock_t| |
| 36 |
// by thread_pthread.c. |
| 37 |
typedef union crypto_mutex_st { |
| 38 |
double alignment; |
| 39 |
uint8_t padding[3 * sizeof(int) + 5 * sizeof(unsigned) + 16 + 8]; |
| 40 |
} CRYPTO_MUTEX; |
| 41 |
#endif |
| 42 |
|
| 43 |
// CRYPTO_refcount_t is the type of a reference count. |
| 44 |
// |
| 45 |
// Since some platforms use C11 atomics to access this, it should have the |
| 46 |
// _Atomic qualifier. However, this header is included by C++ programs as well |
| 47 |
// as C code that might not set -std=c11. So, in practice, it's not possible to |
| 48 |
// do that. Instead we statically assert that the size and native alignment of |
| 49 |
// a plain uint32_t and an _Atomic uint32_t are equal in refcount_c11.c. |
| 50 |
typedef uint32_t CRYPTO_refcount_t; |
| 51 |
|
| 52 |
// AWSLC_thread_local_clear destructs AWS-LC-related thread-local data. |
| 53 |
// If no other AWS-LC function is subsequently called on this thread prior to |
| 54 |
// its termination, our internal thread-local destructor function will not be |
| 55 |
// invoked. If performed on all active threads, this may allow a shared |
| 56 |
// AWS-LC library to be unloaded safely via |dlclose|. |
| 57 |
OPENSSL_EXPORT int AWSLC_thread_local_clear(void); |
| 58 |
|
| 59 |
// AWSLC_thread_local_shutdown deletes the key used to track thread-local data. |
| 60 |
// This function is not thread-safe. It is needed to avoid leaking resources in |
| 61 |
// consumers that use |dlopen|/|dlclose| to access the AWS-LC shared library. |
| 62 |
// It should be called prior to |dlclose| after all other threads have completed |
| 63 |
// calls to |AWSLC_thread_local_clear|. |
| 64 |
OPENSSL_EXPORT int AWSLC_thread_local_shutdown(void); |
| 65 |
|
| 66 |
// General No-op Functions [Deprecated]. |
| 67 |
// |
| 68 |
// Historically, OpenSSL required callers to provide locking callbacks. |
| 69 |
// BoringSSL is thread-safe by default, but some old code calls these functions |
| 70 |
// and so no-op implementations are provided. |
| 71 |
|
| 72 |
// These defines do nothing but are provided to make old code easier to |
| 73 |
// compile. |
| 74 |
#define CRYPTO_LOCK 1 |
| 75 |
#define CRYPTO_UNLOCK 2 |
| 76 |
#define CRYPTO_READ 4 |
| 77 |
#define CRYPTO_WRITE 8 |
| 78 |
|
| 79 |
// CRYPTO_num_locks returns one. (This is non-zero that callers who allocate |
| 80 |
// sizeof(lock) times this value don't get zero and then fail because malloc(0) |
| 81 |
// returned NULL.) |
| 82 |
OPENSSL_EXPORT OPENSSL_DEPRECATED int CRYPTO_num_locks(void); |
| 83 |
|
| 84 |
// CRYPTO_set_locking_callback does nothing. |
| 85 |
OPENSSL_EXPORT OPENSSL_DEPRECATED void CRYPTO_set_locking_callback( |
| 86 |
void (*func)(int mode, int lock_num, const char *file, int line)); |
| 87 |
|
| 88 |
// CRYPTO_set_add_lock_callback does nothing. |
| 89 |
OPENSSL_EXPORT OPENSSL_DEPRECATED void CRYPTO_set_add_lock_callback(int (*func)( |
| 90 |
int *num, int amount, int lock_num, const char *file, int line)); |
| 91 |
|
| 92 |
// CRYPTO_get_locking_callback returns NULL. |
| 93 |
OPENSSL_EXPORT OPENSSL_DEPRECATED void (*CRYPTO_get_locking_callback(void))( |
| 94 |
int mode, int lock_num, const char *file, int line); |
| 95 |
|
| 96 |
// CRYPTO_get_lock_name returns a fixed, dummy string. |
| 97 |
OPENSSL_EXPORT OPENSSL_DEPRECATED const char *CRYPTO_get_lock_name( |
| 98 |
int lock_num); |
| 99 |
|
| 100 |
// CRYPTO_THREADID_set_callback returns one. |
| 101 |
OPENSSL_EXPORT OPENSSL_DEPRECATED int CRYPTO_THREADID_set_callback( |
| 102 |
void (*threadid_func)(CRYPTO_THREADID *threadid)); |
| 103 |
|
| 104 |
// CRYPTO_THREADID_set_numeric does nothing. |
| 105 |
OPENSSL_EXPORT OPENSSL_DEPRECATED void CRYPTO_THREADID_set_numeric( |
| 106 |
CRYPTO_THREADID *id, unsigned long val); |
| 107 |
|
| 108 |
// CRYPTO_THREADID_set_pointer does nothing. |
| 109 |
OPENSSL_EXPORT OPENSSL_DEPRECATED void CRYPTO_THREADID_set_pointer( |
| 110 |
CRYPTO_THREADID *id, void *ptr); |
| 111 |
|
| 112 |
// CRYPTO_THREADID_current does nothing. |
| 113 |
OPENSSL_EXPORT OPENSSL_DEPRECATED void CRYPTO_THREADID_current( |
| 114 |
CRYPTO_THREADID *id); |
| 115 |
|
| 116 |
// CRYPTO_set_id_callback does nothing. |
| 117 |
OPENSSL_EXPORT OPENSSL_DEPRECATED void CRYPTO_set_id_callback( |
| 118 |
unsigned long (*func)(void)); |
| 119 |
|
| 120 |
typedef struct { |
| 121 |
int references; |
| 122 |
struct CRYPTO_dynlock_value *data; |
| 123 |
} CRYPTO_dynlock; |
| 124 |
|
| 125 |
// CRYPTO_set_dynlock_create_callback does nothing. |
| 126 |
OPENSSL_EXPORT OPENSSL_DEPRECATED void CRYPTO_set_dynlock_create_callback( |
| 127 |
struct CRYPTO_dynlock_value *(*dyn_create_function)(const char *file, |
| 128 |
int line)); |
| 129 |
|
| 130 |
// CRYPTO_set_dynlock_lock_callback does nothing. |
| 131 |
OPENSSL_EXPORT OPENSSL_DEPRECATED void CRYPTO_set_dynlock_lock_callback( |
| 132 |
void (*dyn_lock_function)(int mode, struct CRYPTO_dynlock_value *l, |
| 133 |
const char *file, int line)); |
| 134 |
|
| 135 |
// CRYPTO_set_dynlock_destroy_callback does nothing. |
| 136 |
OPENSSL_EXPORT OPENSSL_DEPRECATED void CRYPTO_set_dynlock_destroy_callback( |
| 137 |
void (*dyn_destroy_function)(struct CRYPTO_dynlock_value *l, |
| 138 |
const char *file, int line)); |
| 139 |
|
| 140 |
// CRYPTO_get_dynlock_create_callback returns NULL. |
| 141 |
OPENSSL_EXPORT OPENSSL_DEPRECATED struct CRYPTO_dynlock_value *( |
| 142 |
*CRYPTO_get_dynlock_create_callback(void))(const char *file, int line); |
| 143 |
|
| 144 |
// CRYPTO_get_dynlock_lock_callback returns NULL. |
| 145 |
OPENSSL_EXPORT OPENSSL_DEPRECATED void (*CRYPTO_get_dynlock_lock_callback( |
| 146 |
void))(int mode, struct CRYPTO_dynlock_value *l, const char *file, |
| 147 |
int line); |
| 148 |
|
| 149 |
// CRYPTO_get_dynlock_destroy_callback returns NULL. |
| 150 |
OPENSSL_EXPORT OPENSSL_DEPRECATED void (*CRYPTO_get_dynlock_destroy_callback( |
| 151 |
void))(struct CRYPTO_dynlock_value *l, const char *file, int line); |
| 152 |
|
| 153 |
|
| 154 |
#if defined(__cplusplus) |
| 155 |
} // extern C |
| 156 |
#endif |
| 157 |
|
| 158 |
#endif // OPENSSL_HEADER_THREAD_H |