return 1;
}
+int CRYPTO_atomic_load_int(int *val, int *ret, CRYPTO_RWLOCK *lock)
+{
+ *ret = *val;
+
+ return 1;
+}
+
int openssl_init_fork_handlers(void)
{
return 0;
return 1;
}
+
+int CRYPTO_atomic_load_int(int *val, int *ret, CRYPTO_RWLOCK *lock)
+{
+# if defined(__GNUC__) && defined(__ATOMIC_ACQUIRE) && !defined(BROKEN_CLANG_ATOMICS)
+ if (__atomic_is_lock_free(sizeof(*val), val)) {
+ __atomic_load(val, ret, __ATOMIC_ACQUIRE);
+ return 1;
+ }
+# elif defined(__sun) && (defined(__SunOS_5_10) || defined(__SunOS_5_11))
+ /* This will work for all future Solaris versions. */
+ if (ret != NULL) {
+ *ret = (int *)atomic_or_uint_nv((unsigned int *)val, 0);
+ return 1;
+ }
+# endif
+ if (lock == NULL || !CRYPTO_THREAD_read_lock(lock))
+ return 0;
+ *ret = *val;
+ if (!CRYPTO_THREAD_unlock(lock))
+ return 0;
+
+ return 1;
+}
+
# ifndef FIPS_MODULE
int openssl_init_fork_handlers(void)
{
#endif
}
+int CRYPTO_atomic_load_int(int *val, int *ret, CRYPTO_RWLOCK *lock)
+{
+#if (defined(NO_INTERLOCKEDOR64))
+ if (lock == NULL || !CRYPTO_THREAD_read_lock(lock))
+ return 0;
+ *ret = *val;
+ if (!CRYPTO_THREAD_unlock(lock))
+ return 0;
+
+ return 1;
+#else
+ *ret = (int)InterlockedOr((LONG volatile *)val, 0);
+ return 1;
+#endif
+}
+
int openssl_init_fork_handlers(void)
{
return 0;
CRYPTO_THREAD_lock_new, CRYPTO_THREAD_read_lock, CRYPTO_THREAD_write_lock,
CRYPTO_THREAD_unlock, CRYPTO_THREAD_lock_free,
CRYPTO_atomic_add, CRYPTO_atomic_or, CRYPTO_atomic_load,
+CRYPTO_atomic_load_int,
OSSL_set_max_threads, OSSL_get_max_threads,
OSSL_get_thread_support_flags - OpenSSL thread support
int CRYPTO_atomic_or(uint64_t *val, uint64_t op, uint64_t *ret,
CRYPTO_RWLOCK *lock);
int CRYPTO_atomic_load(uint64_t *val, uint64_t *ret, CRYPTO_RWLOCK *lock);
+ int CRYPTO_atomic_load_int(int *val, int *ret, CRYPTO_RWLOCK *lock);
int OSSL_set_max_threads(OSSL_LIB_CTX *ctx, uint64_t max_threads);
uint64_t OSSL_get_max_threads(OSSL_LIB_CTX *ctx);
=item *
+CRYPTO_atomic_load_int() works identically to CRYPTO_atomic_load() but operates
+on an I<int> value instead of a I<uint64_t> value.
+
+=item *
+
OSSL_set_max_threads() sets the maximum number of threads to be used by the
thread pool. If the argument is 0, thread pooling is disabled. OpenSSL will
not create any threads and existing threads in the thread pool will be torn
char *ossl_buf2hexstr_sep(const unsigned char *buf, long buflen, char sep);
unsigned char *ossl_hexstr2buf_sep(const char *str, long *buflen,
const char sep);
+
#endif
# define CRYPTO_UP_REF(val, ret, lock) CRYPTO_atomic_add(val, 1, ret, lock)
# define CRYPTO_DOWN_REF(val, ret, lock) CRYPTO_atomic_add(val, -1, ret, lock)
-# define CRYPTO_GET_REF(val, ret, lock) CRYPTO_atomic_load(val, ret, lock)
+# define CRYPTO_GET_REF(val, ret, lock) CRYPTO_atomic_load_int(val, ret, lock)
# endif
int CRYPTO_atomic_or(uint64_t *val, uint64_t op, uint64_t *ret,
CRYPTO_RWLOCK *lock);
int CRYPTO_atomic_load(uint64_t *val, uint64_t *ret, CRYPTO_RWLOCK *lock);
+int CRYPTO_atomic_load_int(int *val, int *ret, CRYPTO_RWLOCK *lock);
/* No longer needed, so this is a no-op */
#define OPENSSL_malloc_init() while(0) continue
*/
static void quic_lock(QUIC_CONNECTION *qc)
{
+#if defined(OPENSSL_THREADS)
ossl_crypto_mutex_lock(qc->mutex);
+#endif
}
/* Precondition: Channel mutex is held (unchecked) */
QUIC_NEEDS_LOCK
static void quic_unlock(QUIC_CONNECTION *qc)
{
+#if defined(OPENSSL_THREADS)
ossl_crypto_mutex_unlock(qc->mutex);
+#endif
}
if (qc->tls == NULL || (sc = SSL_CONNECTION_FROM_SSL(qc->tls)) == NULL)
goto err;
+#if defined(OPENSSL_THREADS)
if ((qc->mutex = ossl_crypto_mutex_new()) == NULL)
goto err;
+#endif
+#if !defined(OPENSSL_NO_QUIC_THREAD_ASSIST)
qc->is_thread_assisted
= (ssl_base->method == OSSL_QUIC_client_thread_method());
+#endif
qc->as_server = 0; /* TODO(QUIC): server support */
qc->as_server_state = qc->as_server;
err:
if (qc != NULL) {
+#if defined(OPENSSL_THREADS)
+ ossl_crypto_mutex_free(qc->mutex);
+#endif
ossl_quic_channel_free(qc->ch);
SSL_free(qc->tls);
}
/* Ensure we have no remaining XSOs. */
assert(ctx.qc->num_xso == 0);
+#if !defined(OPENSSL_NO_QUIC_THREAD_ASSIST)
if (ctx.qc->is_thread_assisted && ctx.qc->started) {
ossl_quic_thread_assist_wait_stopped(&ctx.qc->thread_assist);
ossl_quic_thread_assist_cleanup(&ctx.qc->thread_assist);
}
+#endif
ossl_quic_channel_free(ctx.qc->ch);
/* Note: SSL_free calls OPENSSL_free(qc) for us */
SSL_free(ctx.qc->tls);
+#if defined(OPENSSL_THREADS)
ossl_crypto_mutex_free(&ctx.qc->mutex); /* freed while still locked */
+#endif
}
/* SSL method init */
if (!expect_quic(s, &ctx))
return;
+#if !defined(OPENSSL_NO_QUIC_THREAD_ASSIST)
if (ctx.qc->is_thread_assisted && ctx.qc->started)
ossl_quic_thread_assist_notify_deadline_changed(&ctx.qc->thread_assist);
+#endif
}
QUIC_NEEDS_LOCK
|| !ossl_quic_channel_start(qc->ch))
goto err;
+#if !defined(OPENSSL_NO_QUIC_THREAD_ASSIST)
if (qc->is_thread_assisted)
if (!ossl_quic_thread_assist_init_start(&qc->thread_assist, qc->ch))
goto err;
+#endif
}
qc->started = 1;
/* Do not block forever; should not happen. */
return 0;
+# if defined(OPENSSL_THREADS)
if (mutex != NULL)
ossl_crypto_mutex_unlock(mutex);
+# endif
do {
/*
pres = select(maxfd + 1, &rfd_set, &wfd_set, &efd_set, ptv);
} while (pres == -1 && get_last_socket_error_is_eintr());
+# if defined(OPENSSL_THREADS)
if (mutex != NULL)
ossl_crypto_mutex_lock(mutex);
+# endif
return pres < 0 ? 0 : 1;
#else
/* Do not block forever; should not happen. */
return 0;
+# if defined(OPENSSL_THREADS)
if (mutex != NULL)
ossl_crypto_mutex_unlock(mutex);
+# endif
do {
if (ossl_time_is_infinite(deadline)) {
pres = poll(pfds, npfd, timeout_ms);
} while (pres == -1 && get_last_socket_error_is_eintr());
+# if defined(OPENSSL_THREADS)
if (mutex != NULL)
ossl_crypto_mutex_lock(mutex);
+# endif
return pres < 0 ? 0 : 1;
#endif
srv->args = *args;
+#if defined(OPENSSL_THREADS)
if ((srv->mutex = ossl_crypto_mutex_new()) == NULL)
goto err;
+#endif
srv->ctx = SSL_CTX_new_ex(srv->args.libctx, srv->args.propq, TLS_method());
if (srv->ctx == NULL)
err:
if (srv != NULL) {
ossl_quic_channel_free(srv->ch);
+#if defined(OPENSSL_THREADS)
ossl_crypto_mutex_free(&srv->mutex);
+#endif
}
OPENSSL_free(srv);
BIO_free(srv->args.net_wbio);
SSL_free(srv->tls);
SSL_CTX_free(srv->ctx);
+#if defined(OPENSSL_THREADS)
ossl_crypto_mutex_free(&srv->mutex);
+#endif
OPENSSL_free(srv);
}
size_t offset = 0;
size_t op_idx = 0;
const struct script_op *op = NULL;
- int no_advance = 0, first = 1, end_wait_warning = 0;
+ int no_advance = 0, first = 1;
+#if defined(OPENSSL_THREADS)
+ int end_wait_warning = 0;
+#endif
OSSL_TIME op_start_time = ossl_time_zero(), op_deadline = ossl_time_zero();
struct helper_local hl;
#define REPEAT_SLOTS 8
if (!TEST_size_t_eq(repeat_stack_len, 0))
goto out;
+#if defined(OPENSSL_THREADS)
if (thread_idx < 0) {
int done;
size_t i;
}
}
}
+#endif
TEST_info("script finished on thread %d", thread_idx);
testresult = 1;
case OPK_NEW_THREAD:
{
#if !defined(OPENSSL_THREADS)
- TEST_error("threading not supported");
+ /*
+ * If this test script requires threading and we do not have
+ * support for it, skip the rest of it.
+ */
+ TEST_skip("threading not supported, skipping");
+ testresult = 1;
goto out;
#else
size_t i;
if (!TEST_true(run_script_worker(&h, script, -1)))
goto out;
+#if defined(OPENSSL_THREADS)
if (!TEST_true(join_threads(h.threads, h.num_threads)))
goto out;
+#endif
testresult = 1;
out:
#include "internal/common.h"
#include "internal/sockets.h"
#include "internal/quic_tserver.h"
+#include "internal/quic_thread_assist.h"
#include "internal/quic_ssl.h"
#include "internal/time.h"
#include "testutil.h"
OSSL_TIME (*now_cb)(void *arg) = use_fake_time ? fake_now : real_now;
size_t limit_ms = 1000;
+#if defined(OPENSSL_NO_QUIC_THREAD_ASSIST)
+ if (use_thread_assist) {
+ TEST_skip("thread assisted mode not enabled");
+ return 1;
+ }
+#endif
+
ina.s_addr = htonl(0x7f000001UL);
/* Setup test server. */
X509_STORE_CTX_init_rpk ? 3_2_0 EXIST::FUNCTION:
X509_STORE_CTX_get0_rpk ? 3_2_0 EXIST::FUNCTION:
X509_STORE_CTX_set0_rpk ? 3_2_0 EXIST::FUNCTION:
+CRYPTO_atomic_load_int ? 3_2_0 EXIST::FUNCTION: