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