diff options
author | Werner Koch <wk@gnupg.org> | 2014-01-09 19:14:09 +0100 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2014-01-16 17:23:21 +0100 |
commit | cfc151ba637200e4fc05d9481a8df2071b2f9a47 (patch) | |
tree | f1a1c3e1fc81663d622dd5189462a249bd01eac3 /random | |
parent | 49edeebb43174865cf4fa2c170a42a8e4274c4f0 (diff) | |
download | libgcrypt-cfc151ba637200e4fc05d9481a8df2071b2f9a47.tar.gz |
Replace ath based mutexes by gpgrt based locks.
* configure.ac (NEED_GPG_ERROR_VERSION): Require 1.13.
(gl_LOCK): Remove.
* src/ath.c, src/ath.h: Remove. Remove from all files. Replace all
mutexes by gpgrt based statically initialized locks.
* src/global.c (global_init): Remove ath_init.
(_gcry_vcontrol): Make ath install a dummy function.
(print_config): Remove threads info line.
* doc/gcrypt.texi: Simplify the multi-thread related documentation.
--
The current code does only work on ELF systems with weak symbol
support. In particular no locks were used under Windows. With the
new gpgrt_lock functions from the soon to be released libgpg-error
1.13 we have a better portable scheme which also allows for static
initialized mutexes.
Signed-off-by: Werner Koch <wk@gnupg.org>
Diffstat (limited to 'random')
-rw-r--r-- | random/random-csprng.c | 15 | ||||
-rw-r--r-- | random/random-daemon.c | 24 | ||||
-rw-r--r-- | random/random-fips.c | 23 | ||||
-rw-r--r-- | random/random-system.c | 24 | ||||
-rw-r--r-- | random/random.c | 23 |
5 files changed, 34 insertions, 75 deletions
diff --git a/random/random-csprng.c b/random/random-csprng.c index 87235d82..429c84f8 100644 --- a/random/random-csprng.c +++ b/random/random-csprng.c @@ -60,7 +60,6 @@ #include "random.h" #include "rand-internal.h" #include "cipher.h" /* Required for the rmd160_hash_buffer() prototype. */ -#include "ath.h" #ifndef RAND_MAX /* For SunOS. */ #define RAND_MAX 32767 @@ -181,7 +180,7 @@ static int quick_test; static int faked_rng; /* This is the lock we use to protect all pool operations. */ -static ath_mutex_t pool_lock; +GPGRT_LOCK_DEFINE (pool_lock); /* This is a helper for assert calls. These calls are used to assert that functions are called in a locked state. It is not meant to be @@ -259,14 +258,10 @@ static void initialize_basics(void) { static int initialized; - int err; if (!initialized) { initialized = 1; - err = ath_mutex_init (&pool_lock); - if (err) - log_fatal ("failed to create the pool lock: %s\n", strerror (err) ); #ifdef USE_RANDOM_DAEMON _gcry_daemon_initialize_basics (); @@ -286,9 +281,9 @@ lock_pool (void) { int err; - err = ath_mutex_lock (&pool_lock); + err = gpgrt_lock_lock (&pool_lock); if (err) - log_fatal ("failed to acquire the pool lock: %s\n", strerror (err)); + log_fatal ("failed to acquire the pool lock: %s\n", gpg_strerror (err)); pool_is_locked = 1; } @@ -299,9 +294,9 @@ unlock_pool (void) int err; pool_is_locked = 0; - err = ath_mutex_unlock (&pool_lock); + err = gpgrt_lock_unlock (&pool_lock); if (err) - log_fatal ("failed to release the pool lock: %s\n", strerror (err)); + log_fatal ("failed to release the pool lock: %s\n", gpg_strerror (err)); } diff --git a/random/random-daemon.c b/random/random-daemon.c index 98a01536..8ea4df28 100644 --- a/random/random-daemon.c +++ b/random/random-daemon.c @@ -28,8 +28,6 @@ sensitive data. */ -#error This dameon needs to be fixed due to the ath changes - #include <config.h> #include <stdio.h> #include <stdlib.h> @@ -42,7 +40,6 @@ #include "g10lib.h" #include "random.h" -#include "ath.h" @@ -51,7 +48,7 @@ #define RANDOM_DAEMON_SOCKET "/var/run/libgcrypt/S.gcryptrnd" /* The lock serializing access to the daemon. */ -static ath_mutex_t daemon_lock = ATH_MUTEX_INITIALIZER; +GPGRT_LOCK_DEFINE (daemon_lock); /* The socket connected to the daemon. */ static int daemon_socket = -1; @@ -129,16 +126,7 @@ connect_to_socket (const char *socketname, int *sock) void _gcry_daemon_initialize_basics (void) { - static int initialized; - int err; - - if (!initialized) - { - initialized = 1; - err = ath_mutex_init (&daemon_lock); - if (err) - log_fatal ("failed to create the daemon lock: %s\n", strerror (err) ); - } + /* Not anymore required. */ } @@ -213,7 +201,7 @@ call_daemon (const char *socketname, if (!req_nbytes) return 0; - ath_mutex_lock (&daemon_lock); + gpgrt_lock_lock (&daemon_lock); /* Open the socket if that has not been done. */ if (!initialized) @@ -225,7 +213,7 @@ call_daemon (const char *socketname, { daemon_socket = -1; log_info ("not using random daemon\n"); - ath_mutex_unlock (&daemon_lock); + gpgrt_lock_unlock (&daemon_lock); return err; } } @@ -233,7 +221,7 @@ call_daemon (const char *socketname, /* Check that we have a valid socket descriptor. */ if ( daemon_socket == -1 ) { - ath_mutex_unlock (&daemon_lock); + gpgrt_lock_unlock (&daemon_lock); return gcry_error (GPG_ERR_INTERNAL); } @@ -325,7 +313,7 @@ call_daemon (const char *socketname, } while (req_nbytes); - ath_mutex_unlock (&daemon_lock); + gpgrt_lock_unlock (&daemon_lock); return err; } diff --git a/random/random-fips.c b/random/random-fips.c index d00825e2..0a763628 100644 --- a/random/random-fips.c +++ b/random/random-fips.c @@ -66,13 +66,12 @@ #include "g10lib.h" #include "random.h" #include "rand-internal.h" -#include "ath.h" /* This is the lock we use to serialize access to this RNG. The extra integer variable is only used to check the locking state; that is, it is not meant to be thread-safe but merely as a failsafe feature to assert proper locking. */ -static ath_mutex_t fips_rng_lock; +GPGRT_LOCK_DEFINE (fips_rng_lock); static int fips_rng_is_locked; @@ -190,15 +189,11 @@ static void basic_initialization (void) { static int initialized; - int my_errno; if (initialized) return; initialized = 1; - my_errno = ath_mutex_init (&fips_rng_lock); - if (my_errno) - log_fatal ("failed to create the RNG lock: %s\n", strerror (my_errno)); fips_rng_is_locked = 0; /* Make sure that we are still using the values we have @@ -214,11 +209,11 @@ basic_initialization (void) static void lock_rng (void) { - int my_errno; + gpg_err_code_t rc; - my_errno = ath_mutex_lock (&fips_rng_lock); - if (my_errno) - log_fatal ("failed to acquire the RNG lock: %s\n", strerror (my_errno)); + rc = gpgrt_lock_lock (&fips_rng_lock); + if (rc) + log_fatal ("failed to acquire the RNG lock: %s\n", gpg_strerror (rc)); fips_rng_is_locked = 1; } @@ -227,12 +222,12 @@ lock_rng (void) static void unlock_rng (void) { - int my_errno; + gpg_err_code_t rc; fips_rng_is_locked = 0; - my_errno = ath_mutex_unlock (&fips_rng_lock); - if (my_errno) - log_fatal ("failed to release the RNG lock: %s\n", strerror (my_errno)); + rc = gpgrt_lock_unlock (&fips_rng_lock); + if (rc) + log_fatal ("failed to release the RNG lock: %s\n", gpg_strerror (rc)); } static void diff --git a/random/random-system.c b/random/random-system.c index 3962ab88..8b79511c 100644 --- a/random/random-system.c +++ b/random/random-system.c @@ -35,13 +35,12 @@ #include "g10lib.h" #include "random.h" #include "rand-internal.h" -#include "ath.h" /* This is the lock we use to serialize access to this RNG. The extra integer variable is only used to check the locking state; that is, it is not meant to be thread-safe but merely as a failsafe feature to assert proper locking. */ -static ath_mutex_t system_rng_lock; +GPGRT_LOCK_DEFINE (system_rng_lock); static int system_rng_is_locked; @@ -58,16 +57,11 @@ static void basic_initialization (void) { static int initialized; - int my_errno; if (initialized) return; initialized = 1; - my_errno = ath_mutex_init (&system_rng_lock); - if (my_errno) - log_fatal ("failed to create the System RNG lock: %s\n", - strerror (my_errno)); system_rng_is_locked = 0; /* Make sure that we are still using the values we traditionally @@ -83,12 +77,12 @@ basic_initialization (void) static void lock_rng (void) { - int my_errno; + gpg_err_code_t rc; - my_errno = ath_mutex_lock (&system_rng_lock); - if (my_errno) + rc = gpgrt_lock_lock (&system_rng_lock); + if (rc) log_fatal ("failed to acquire the System RNG lock: %s\n", - strerror (my_errno)); + gpg_strerror (rc)); system_rng_is_locked = 1; } @@ -97,13 +91,13 @@ lock_rng (void) static void unlock_rng (void) { - int my_errno; + gpg_err_code_t rc; system_rng_is_locked = 0; - my_errno = ath_mutex_unlock (&system_rng_lock); - if (my_errno) + rc = gpgrt_lock_unlock (&system_rng_lock); + if (rc) log_fatal ("failed to release the System RNG lock: %s\n", - strerror (my_errno)); + gpg_strerror (rc)); } diff --git a/random/random.c b/random/random.c index ff9d6d25..41d4cb36 100644 --- a/random/random.c +++ b/random/random.c @@ -34,7 +34,6 @@ #include "random.h" #include "rand-internal.h" #include "cipher.h" /* For _gcry_sha1_hash_buffer(). */ -#include "ath.h" /* If not NULL a progress function called from certain places and the @@ -54,7 +53,7 @@ static struct /* This is the lock we use to protect the buffer used by the nonce generation. */ -static ath_mutex_t nonce_buffer_lock; +GPGRT_LOCK_DEFINE (nonce_buffer_lock); @@ -140,18 +139,6 @@ _gcry_set_preferred_rng_type (int type) void _gcry_random_initialize (int full) { - static int nonce_initialized; - int err; - - if (!nonce_initialized) - { - nonce_initialized = 1; - err = ath_mutex_init (&nonce_buffer_lock); - if (err) - log_fatal ("failed to create the nonce buffer lock: %s\n", - strerror (err) ); - } - if (fips_mode ()) _gcry_rngfips_initialize (full); else if (rng_types.standard) @@ -450,10 +437,10 @@ _gcry_create_nonce (void *buffer, size_t length) _gcry_random_initialize (1); /* Acquire the nonce buffer lock. */ - err = ath_mutex_lock (&nonce_buffer_lock); + err = gpgrt_lock_lock (&nonce_buffer_lock); if (err) log_fatal ("failed to acquire the nonce buffer lock: %s\n", - strerror (err)); + gpg_strerror (err)); apid = getpid (); /* The first time initialize our buffer. */ @@ -501,10 +488,10 @@ _gcry_create_nonce (void *buffer, size_t length) } /* Release the nonce buffer lock. */ - err = ath_mutex_unlock (&nonce_buffer_lock); + err = gpgrt_lock_unlock (&nonce_buffer_lock); if (err) log_fatal ("failed to release the nonce buffer lock: %s\n", - strerror (err)); + gpg_strerror (err)); } |