[openssl-commits] [openssl] master update
paul.dale at oracle.com
paul.dale at oracle.com
Tue Oct 10 02:54:31 UTC 2017
The branch master has been updated
via 30ff41beab5d8a53cbcbdab4109b32b9ef5c0f6e (commit)
via 94683b7acb62a5d99b8b4d66283e6d6dd0007f7a (commit)
from 338ead0ff9b22aecbc3b28e37ea05d142e13ee13 (commit)
- Log -----------------------------------------------------------------
commit 30ff41beab5d8a53cbcbdab4109b32b9ef5c0f6e
Author: Pauli <paul.dale at oracle.com>
Date: Mon Oct 9 14:39:43 2017 +1000
Add atomic write call
Reviewed-by: Rich Salz <rsalz at openssl.org>
(Merged from https://github.com/openssl/openssl/pull/4414)
commit 94683b7acb62a5d99b8b4d66283e6d6dd0007f7a
Author: Pauli <paul.dale at oracle.com>
Date: Mon Sep 25 12:04:42 2017 +1000
Add a CRYPTO_atomic_read call which allows an int variable to be read
in an atomic fashion.
Reviewed-by: Rich Salz <rsalz at openssl.org>
(Merged from https://github.com/openssl/openssl/pull/4414)
-----------------------------------------------------------------------
Summary of changes:
crypto/threads_none.c | 12 ++++++++++++
crypto/threads_pthread.c | 38 +++++++++++++++++++++++++++++++++++++
crypto/threads_win.c | 12 ++++++++++++
doc/man3/CRYPTO_THREAD_run_once.pod | 16 +++++++++++++++-
include/openssl/crypto.h | 2 ++
util/libcrypto.num | 2 ++
6 files changed, 81 insertions(+), 1 deletion(-)
diff --git a/crypto/threads_none.c b/crypto/threads_none.c
index ffad757..30ed4e6 100644
--- a/crypto/threads_none.c
+++ b/crypto/threads_none.c
@@ -125,6 +125,18 @@ int CRYPTO_atomic_add(int *val, int amount, int *ret, CRYPTO_RWLOCK *lock)
return 1;
}
+int CRYPTO_atomic_read(int *val, int *ret, CRYPTO_RWLOCK *lock)
+{
+ *ret = *val;
+ return 1;
+}
+
+int CRYPTO_atomic_write(int *val, int n, CRYPTO_RWLOCK *lock)
+{
+ *val = n;
+ return 1;
+}
+
int openssl_init_fork_handlers(void)
{
return 0;
diff --git a/crypto/threads_pthread.c b/crypto/threads_pthread.c
index 9644c25..34be314 100644
--- a/crypto/threads_pthread.c
+++ b/crypto/threads_pthread.c
@@ -169,6 +169,44 @@ int CRYPTO_atomic_add(int *val, int amount, int *ret, CRYPTO_RWLOCK *lock)
return 1;
}
+int CRYPTO_atomic_read(int *val, int *ret, CRYPTO_RWLOCK *lock)
+{
+# if defined(__GNUC__) && defined(__ATOMIC_ACQUIRE)
+ if (__atomic_is_lock_free(sizeof(*val), val)) {
+ __atomic_load(val, ret, __ATOMIC_ACQUIRE);
+ return 1;
+ }
+# endif
+ if (!CRYPTO_THREAD_write_lock(lock))
+ return 0;
+
+ *ret = *val;
+
+ if (!CRYPTO_THREAD_unlock(lock))
+ return 0;
+
+ return 1;
+}
+
+int CRYPTO_atomic_write(int *val, int n, CRYPTO_RWLOCK *lock)
+{
+# if defined(__GNUC__) && defined(__ATOMIC_RELEASE)
+ if (__atomic_is_lock_free(sizeof(*val), val)) {
+ __atomic_store(val, &n, __ATOMIC_RELEASE);
+ return 1;
+ }
+# endif
+ if (!CRYPTO_THREAD_write_lock(lock))
+ return 0;
+
+ *val = n;
+
+ if (!CRYPTO_THREAD_unlock(lock))
+ return 0;
+
+ return 1;
+}
+
# ifdef OPENSSL_SYS_UNIX
static pthread_once_t fork_once_control = PTHREAD_ONCE_INIT;
diff --git a/crypto/threads_win.c b/crypto/threads_win.c
index 512e19f..ab2eb25 100644
--- a/crypto/threads_win.c
+++ b/crypto/threads_win.c
@@ -133,6 +133,18 @@ int CRYPTO_atomic_add(int *val, int amount, int *ret, CRYPTO_RWLOCK *lock)
return 1;
}
+int CRYPTO_atomic_read(int *val, int *ret, CRYPTO_RWLOCK *lock)
+{
+ InterlockedCompareExchange(val, 0, 0);
+ return 1;
+}
+
+int CRYPTO_atomic_write(int *val, int n, CRYPTO_RWLOCK *lock)
+{
+ InterlockedExchange(val, n);
+ return 1;
+}
+
int openssl_init_fork_handlers(void)
{
return 0;
diff --git a/doc/man3/CRYPTO_THREAD_run_once.pod b/doc/man3/CRYPTO_THREAD_run_once.pod
index 9a4df19..734d2d8 100644
--- a/doc/man3/CRYPTO_THREAD_run_once.pod
+++ b/doc/man3/CRYPTO_THREAD_run_once.pod
@@ -4,7 +4,8 @@
CRYPTO_THREAD_run_once,
CRYPTO_THREAD_lock_new, CRYPTO_THREAD_read_lock, CRYPTO_THREAD_write_lock,
-CRYPTO_THREAD_unlock, CRYPTO_THREAD_lock_free, CRYPTO_atomic_add - OpenSSL thread support
+CRYPTO_THREAD_unlock, CRYPTO_THREAD_lock_free, CRYPTO_atomic_add,
+CRYPTO_atomic_read, CRYPTO_atomic_write - OpenSSL thread support
=head1 SYNOPSIS
@@ -20,6 +21,8 @@ CRYPTO_THREAD_unlock, CRYPTO_THREAD_lock_free, CRYPTO_atomic_add - OpenSSL threa
void CRYPTO_THREAD_lock_free(CRYPTO_RWLOCK *lock);
int CRYPTO_atomic_add(int *val, int amount, int *ret, CRYPTO_RWLOCK *lock);
+ int CRYPTO_atomic_read(int *val, int *ret, CRYPTO_RWLOCK *lock);
+ int CRYPTO_atomic_write(int *val, int n, CRYPTO_RWLOCK *lock);
=head1 DESCRIPTION
@@ -74,6 +77,17 @@ operations are supported on the specific platform. Because of this, if a
variable is modified by CRYPTO_atomic_add() then CRYPTO_atomic_add() must
be the only way that the variable is modified.
+=item *
+
+CRYPTO_atomic_read() atomically reads B<val> and returns the result of
+the operation in B<ret>. B<lock> will be locked, unless atomic operations
+are supported on the specific platform.
+
+=item *
+
+CRYPTO_atomic_write() atomically writes B<n> to B<val>. B<lock> will be
+locked, unless atomic operations are supported on the specific platform.
+
=back
=head1 RETURN VALUES
diff --git a/include/openssl/crypto.h b/include/openssl/crypto.h
index 9fc0663..c2aa07c 100644
--- a/include/openssl/crypto.h
+++ b/include/openssl/crypto.h
@@ -74,6 +74,8 @@ int CRYPTO_THREAD_unlock(CRYPTO_RWLOCK *lock);
void CRYPTO_THREAD_lock_free(CRYPTO_RWLOCK *lock);
int CRYPTO_atomic_add(int *val, int amount, int *ret, CRYPTO_RWLOCK *lock);
+int CRYPTO_atomic_read(int *val, int *ret, CRYPTO_RWLOCK *lock);
+int CRYPTO_atomic_write(int *val, int n, CRYPTO_RWLOCK *lock);
/*
* The following can be used to detect memory leaks in the library. If
diff --git a/util/libcrypto.num b/util/libcrypto.num
index 48e97ff..5343aed 100644
--- a/util/libcrypto.num
+++ b/util/libcrypto.num
@@ -4398,3 +4398,5 @@ EVP_PKEY_meth_set_check 4341 1_1_1 EXIST::FUNCTION:
EVP_PKEY_meth_get_check 4342 1_1_1 EXIST::FUNCTION:
EVP_PKEY_meth_remove 4343 1_1_1 EXIST::FUNCTION:
OPENSSL_sk_reserve 4344 1_1_1 EXIST::FUNCTION:
+CRYPTO_atomic_read 4345 1_1_1 EXIST::FUNCTION:
+CRYPTO_atomic_write 4346 1_1_1 EXIST::FUNCTION:
More information about the openssl-commits
mailing list