| 6 | // |
| 7 | // https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 |
| 15 | #ifndef OPENSSL_HEADER_THREAD_H |
| 16 | #define OPENSSL_HEADER_THREAD_H |
| 17 |
| 18 | #include <sys/types.h> |
| 19 |
| 20 | #include <openssl/base.h> // IWYU pragma: export |
| 21 |
| 22 | #if defined(__cplusplus) |
| 23 | extern "C" { |
| 24 | #endif |
| 25 |
| 26 |
| 27 | // CRYPTO_refcount_t is the type of a reference count. |
| 28 | // |
| 29 | // Since some platforms use C11 atomics to access this, it should have the |
| 30 | // _Atomic qualifier. However, this header is included by C++ programs as well |
| 31 | // as C code that might not set -std=c11. So, in practice, it's not possible to |
| 32 | // do that. Instead we statically assert that the size and native alignment of |
| 33 | // a plain uint32_t and an _Atomic uint32_t are equal in refcount.c. |
| 34 | typedef uint32_t CRYPTO_refcount_t; |
| 35 |
| 36 |
| 37 | // Deprecated functions. |
| 38 | // |
| 39 | // Historically, OpenSSL required callers to provide locking callbacks. |
| 40 | // BoringSSL does not use external callbacks for locking, but some old code |
| 41 | // calls these functions and so no-op implementations are provided. |
| 42 |
| 43 | // These defines do nothing but are provided to make old code easier to |
| 44 | // compile. |
| 45 | #define CRYPTO_LOCK 1 |
| 46 | #define CRYPTO_UNLOCK 2 |
| 47 | #define CRYPTO_READ 4 |
| 48 | #define CRYPTO_WRITE 8 |
| 49 |
| 50 | // CRYPTO_num_locks returns one. (This is non-zero that callers who allocate |
| 51 | // sizeof(lock) times this value don't get zero and then fail because malloc(0) |
| 52 | // returned NULL.) |
| 53 | OPENSSL_EXPORT int CRYPTO_num_locks(void); |
| 54 |
| 55 | // CRYPTO_set_locking_callback does nothing. |
| 56 | OPENSSL_EXPORT void CRYPTO_set_locking_callback( |
| 57 | void (*func)(int mode, int lock_num, const char *file, int line)); |
| 58 |
| 59 | // CRYPTO_set_add_lock_callback does nothing. |
| 60 | OPENSSL_EXPORT void CRYPTO_set_add_lock_callback(int (*func)( |
| 61 | int *num, int amount, int lock_num, const char *file, int line)); |
| 62 |
| 63 | // CRYPTO_get_locking_callback returns NULL. |
| 64 | OPENSSL_EXPORT void (*CRYPTO_get_locking_callback(void))(int mode, int lock_num, |
| 65 | const char *file, |
| 66 | int line); |
| 67 |
| 68 | // CRYPTO_get_lock_name returns a fixed, dummy string. |
| 69 | OPENSSL_EXPORT const char *CRYPTO_get_lock_name(int lock_num); |
| 70 |
| 71 | // CRYPTO_THREADID_set_callback returns one. |
| 72 | OPENSSL_EXPORT int CRYPTO_THREADID_set_callback( |
| 73 | void (*threadid_func)(CRYPTO_THREADID *threadid)); |
| 74 |
| 75 | // CRYPTO_THREADID_set_numeric does nothing. |
| 76 | OPENSSL_EXPORT void CRYPTO_THREADID_set_numeric(CRYPTO_THREADID *id, |
| 77 | unsigned long val); |
| 78 |
| 79 | // CRYPTO_THREADID_set_pointer does nothing. |
| 80 | OPENSSL_EXPORT void CRYPTO_THREADID_set_pointer(CRYPTO_THREADID *id, void *ptr); |
| 81 |
| 82 | // CRYPTO_THREADID_current does nothing. |
| 83 | OPENSSL_EXPORT void CRYPTO_THREADID_current(CRYPTO_THREADID *id); |
| 84 |
| 85 | // CRYPTO_set_id_callback does nothing. |
| 86 | OPENSSL_EXPORT void CRYPTO_set_id_callback(unsigned long (*func)(void)); |
| 87 |
| 88 | typedef struct { |
| 89 | int references; |
| 90 | struct CRYPTO_dynlock_value *data; |
| 91 | } CRYPTO_dynlock; |
| 92 |
| 93 | // CRYPTO_set_dynlock_create_callback does nothing. |
| 94 | OPENSSL_EXPORT void CRYPTO_set_dynlock_create_callback( |
| 95 | struct CRYPTO_dynlock_value *(*dyn_create_function)(const char *file, |
| 96 | int line)); |
| 97 |
| 98 | // CRYPTO_set_dynlock_lock_callback does nothing. |
| 99 | OPENSSL_EXPORT void CRYPTO_set_dynlock_lock_callback(void (*dyn_lock_function)( |
| 100 | int mode, struct CRYPTO_dynlock_value *l, const char *file, int line)); |
| 101 |
| 102 | // CRYPTO_set_dynlock_destroy_callback does nothing. |
| 103 | OPENSSL_EXPORT void CRYPTO_set_dynlock_destroy_callback( |
| 104 | void (*dyn_destroy_function)(struct CRYPTO_dynlock_value *l, |
| 105 | const char *file, int line)); |
| 106 |
| 107 | // CRYPTO_get_dynlock_create_callback returns NULL. |
| 108 | OPENSSL_EXPORT struct CRYPTO_dynlock_value *( |
| 109 | *CRYPTO_get_dynlock_create_callback(void))(const char *file, int line); |
| 110 |
| 111 | // CRYPTO_get_dynlock_lock_callback returns NULL. |
| 112 | OPENSSL_EXPORT void (*CRYPTO_get_dynlock_lock_callback(void))( |
| 113 | int mode, struct CRYPTO_dynlock_value *l, const char *file, int line); |
| 114 |
| 115 | // CRYPTO_get_dynlock_destroy_callback returns NULL. |
| 116 | OPENSSL_EXPORT void (*CRYPTO_get_dynlock_destroy_callback(void))( |
| 117 | struct CRYPTO_dynlock_value *l, const char *file, int line); |
| 118 |
| 119 |
| 120 | #if defined(__cplusplus) |
| 121 | } // extern C |
| 122 | #endif |
| 123 |
| 124 | #endif // OPENSSL_HEADER_THREAD_H |
| 125 |