aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/gpg-error.h.in3
-rw-r--r--src/posix-lock.c16
-rw-r--r--src/w32-lock.c20
3 files changed, 33 insertions, 6 deletions
diff --git a/src/gpg-error.h.in b/src/gpg-error.h.in
index adb796b..4bd28bf 100644
--- a/src/gpg-error.h.in
+++ b/src/gpg-error.h.in
@@ -291,7 +291,8 @@ gpg_error_from_syserror (void)
#define GPGRT_LOCK_DEFINE(name) \
static gpgrt_lock_t name = GPGRT_LOCK_INITIALIZER
-
+/* NB: If GPGRT_LOCK_DEFINE is not used, zero out the lock variable
+ before passing it to gpgrt_lock_init. */
gpg_err_code_t gpgrt_lock_init (gpgrt_lock_t *lockhd);
gpg_err_code_t gpgrt_lock_lock (gpgrt_lock_t *lockhd);
gpg_err_code_t gpgrt_lock_unlock (gpgrt_lock_t *lockhd);
diff --git a/src/posix-lock.c b/src/posix-lock.c
index 363cc09..5b0cab5 100644
--- a/src/posix-lock.c
+++ b/src/posix-lock.c
@@ -116,9 +116,21 @@ get_lock_object (gpgrt_lock_t *lockhd)
gpg_err_code_t
gpgrt_lock_init (gpgrt_lock_t *lockhd)
{
- _gpgrt_lock_t *lock = get_lock_object (lockhd);
+ _gpgrt_lock_t *lock = (_gpgrt_lock_t*)lockhd;
int rc;
+ /* If VERS is zero we assume that no static initialization has been
+ done, so we setup our ABI version right here. The caller might
+ have called us to test whether lock support is at all available. */
+ if (!lock->vers)
+ {
+ if (sizeof (gpgrt_lock_t) < sizeof (_gpgrt_lock_t))
+ abort ();
+ lock->vers = LOCK_ABI_VERSION;
+ }
+ else /* Run the usual check. */
+ lock = get_lock_object (lockhd);
+
#if USE_POSIX_THREADS
if (use_pthread_p())
{
@@ -198,7 +210,7 @@ gpgrt_lock_destroy (gpgrt_lock_t *lockhd)
rc = gpg_err_code_from_errno (rc);
else
{
- /* Re-init the the mutex so that it can be re-used. */
+ /* Re-init the mutex so that it can be re-used. */
gpgrt_lock_t tmp = GPGRT_LOCK_INITIALIZER;
memcpy (lockhd, &tmp, sizeof tmp);
}
diff --git a/src/w32-lock.c b/src/w32-lock.c
index 0ad9409..56a0ed5 100644
--- a/src/w32-lock.c
+++ b/src/w32-lock.c
@@ -52,10 +52,24 @@ get_lock_object (gpgrt_lock_t *lockhd)
gpg_err_code_t
gpgrt_lock_init (gpgrt_lock_t *lockhd)
{
- _gpgrt_lock_t *lock = get_lock_object (lockhd);
+ _gpgrt_lock_t *lock = (_gpgrt_lock_t*)lockhd;
+
+ /* If VERS is zero we assume that no static initialization has been
+ done, so we setup our ABI version right here. The caller might
+ have called us to test whether lock support is at all available. */
+ if (!lock->vers)
+ {
+ if (sizeof (gpgrt_lock_t) < sizeof (_gpgrt_lock_t))
+ abort ();
+ lock->vers = LOCK_ABI_VERSION;
+ }
+ else /* Run the usual check. */
+ {
+ lock = get_lock_object (lockhd);
+ if (sizeof (gpgrt_lock_t) < sizeof (_gpgrt_lock_t))
+ abort ();
+ }
- if (sizeof (gpgrt_lock_t) < sizeof (_gpgrt_lock_t))
- abort ();
InitializeCriticalSection (&lock->csec);
lock->initdone = 1;
}