VirtualBox

source: vbox/trunk/src/libs/openssl-3.3.2/crypto/threads_none.c@ 109193

Last change on this file since 109193 was 108206, checked in by vboxsync, 3 months ago

openssl-3.3.2: Exported all files to OSE and removed .scm-settings ​bugref:10757

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.6 KB
Line 
1/*
2 * Copyright 2016-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#include <openssl/crypto.h>
11#include "internal/cryptlib.h"
12#include "internal/rcu.h"
13#include "rcu_internal.h"
14
15#if !defined(OPENSSL_THREADS) || defined(CRYPTO_TDEBUG)
16
17# if defined(OPENSSL_SYS_UNIX)
18# include <sys/types.h>
19# include <unistd.h>
20# endif
21
22struct rcu_lock_st {
23 struct rcu_cb_item *cb_items;
24};
25
26CRYPTO_RCU_LOCK *ossl_rcu_lock_new(int num_writers,
27 ossl_unused OSSL_LIB_CTX *ctx)
28{
29 struct rcu_lock_st *lock;
30
31 lock = OPENSSL_zalloc(sizeof(*lock));
32 return lock;
33}
34
35void ossl_rcu_lock_free(CRYPTO_RCU_LOCK *lock)
36{
37 OPENSSL_free(lock);
38}
39
40void ossl_rcu_read_lock(CRYPTO_RCU_LOCK *lock)
41{
42 return;
43}
44
45void ossl_rcu_write_lock(CRYPTO_RCU_LOCK *lock)
46{
47 return;
48}
49
50void ossl_rcu_write_unlock(CRYPTO_RCU_LOCK *lock)
51{
52 return;
53}
54
55void ossl_rcu_read_unlock(CRYPTO_RCU_LOCK *lock)
56{
57 return;
58}
59
60void ossl_synchronize_rcu(CRYPTO_RCU_LOCK *lock)
61{
62 struct rcu_cb_item *items = lock->cb_items;
63 struct rcu_cb_item *tmp;
64
65 lock->cb_items = NULL;
66
67 while (items != NULL) {
68 tmp = items->next;
69 items->fn(items->data);
70 OPENSSL_free(items);
71 items = tmp;
72 }
73}
74
75int ossl_rcu_call(CRYPTO_RCU_LOCK *lock, rcu_cb_fn cb, void *data)
76{
77 struct rcu_cb_item *new = OPENSSL_zalloc(sizeof(*new));
78
79 if (new == NULL)
80 return 0;
81
82 new->fn = cb;
83 new->data = data;
84 new->next = lock->cb_items;
85 lock->cb_items = new;
86 return 1;
87}
88
89void *ossl_rcu_uptr_deref(void **p)
90{
91 return (void *)*p;
92}
93
94void ossl_rcu_assign_uptr(void **p, void **v)
95{
96 *(void **)p = *(void **)v;
97}
98
99CRYPTO_RWLOCK *CRYPTO_THREAD_lock_new(void)
100{
101 CRYPTO_RWLOCK *lock;
102
103 if ((lock = CRYPTO_zalloc(sizeof(unsigned int), NULL, 0)) == NULL)
104 /* Don't set error, to avoid recursion blowup. */
105 return NULL;
106
107 *(unsigned int *)lock = 1;
108
109 return lock;
110}
111
112__owur int CRYPTO_THREAD_read_lock(CRYPTO_RWLOCK *lock)
113{
114 if (!ossl_assert(*(unsigned int *)lock == 1))
115 return 0;
116 return 1;
117}
118
119__owur int CRYPTO_THREAD_write_lock(CRYPTO_RWLOCK *lock)
120{
121 if (!ossl_assert(*(unsigned int *)lock == 1))
122 return 0;
123 return 1;
124}
125
126int CRYPTO_THREAD_unlock(CRYPTO_RWLOCK *lock)
127{
128 if (!ossl_assert(*(unsigned int *)lock == 1))
129 return 0;
130 return 1;
131}
132
133void CRYPTO_THREAD_lock_free(CRYPTO_RWLOCK *lock) {
134 if (lock == NULL)
135 return;
136
137 *(unsigned int *)lock = 0;
138 OPENSSL_free(lock);
139
140 return;
141}
142
143int CRYPTO_THREAD_run_once(CRYPTO_ONCE *once, void (*init)(void))
144{
145 if (*once != 0)
146 return 1;
147
148 init();
149 *once = 1;
150
151 return 1;
152}
153
154#define OPENSSL_CRYPTO_THREAD_LOCAL_KEY_MAX 256
155
156static void *thread_local_storage[OPENSSL_CRYPTO_THREAD_LOCAL_KEY_MAX];
157
158int CRYPTO_THREAD_init_local(CRYPTO_THREAD_LOCAL *key, void (*cleanup)(void *))
159{
160 static unsigned int thread_local_key = 0;
161
162 if (thread_local_key >= OPENSSL_CRYPTO_THREAD_LOCAL_KEY_MAX)
163 return 0;
164
165 *key = thread_local_key++;
166
167 thread_local_storage[*key] = NULL;
168
169 return 1;
170}
171
172void *CRYPTO_THREAD_get_local(CRYPTO_THREAD_LOCAL *key)
173{
174 if (*key >= OPENSSL_CRYPTO_THREAD_LOCAL_KEY_MAX)
175 return NULL;
176
177 return thread_local_storage[*key];
178}
179
180int CRYPTO_THREAD_set_local(CRYPTO_THREAD_LOCAL *key, void *val)
181{
182 if (*key >= OPENSSL_CRYPTO_THREAD_LOCAL_KEY_MAX)
183 return 0;
184
185 thread_local_storage[*key] = val;
186
187 return 1;
188}
189
190int CRYPTO_THREAD_cleanup_local(CRYPTO_THREAD_LOCAL *key)
191{
192 *key = OPENSSL_CRYPTO_THREAD_LOCAL_KEY_MAX + 1;
193 return 1;
194}
195
196CRYPTO_THREAD_ID CRYPTO_THREAD_get_current_id(void)
197{
198 return 0;
199}
200
201int CRYPTO_THREAD_compare_id(CRYPTO_THREAD_ID a, CRYPTO_THREAD_ID b)
202{
203 return (a == b);
204}
205
206int CRYPTO_atomic_add(int *val, int amount, int *ret, CRYPTO_RWLOCK *lock)
207{
208 *val += amount;
209 *ret = *val;
210
211 return 1;
212}
213
214int CRYPTO_atomic_or(uint64_t *val, uint64_t op, uint64_t *ret,
215 CRYPTO_RWLOCK *lock)
216{
217 *val |= op;
218 *ret = *val;
219
220 return 1;
221}
222
223int CRYPTO_atomic_load(uint64_t *val, uint64_t *ret, CRYPTO_RWLOCK *lock)
224{
225 *ret = *val;
226
227 return 1;
228}
229
230int CRYPTO_atomic_load_int(int *val, int *ret, CRYPTO_RWLOCK *lock)
231{
232 *ret = *val;
233
234 return 1;
235}
236
237int openssl_init_fork_handlers(void)
238{
239 return 0;
240}
241
242int openssl_get_fork_id(void)
243{
244# if defined(OPENSSL_SYS_UNIX)
245 return getpid();
246# else
247 return 0;
248# endif
249}
250#endif
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette