[git] GPG-ERROR - branch, master, updated. libgpg-error-1.24-12-g25d463c

by Werner Koch cvs at cvs.gnupg.org
Fri Nov 11 20:31:43 CET 2016


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Error codes used by GnuPG et al.".

The branch, master has been updated
       via  25d463c67821901c8fd6736c815f11e85bbae66f (commit)
      from  b1ccab5bf8e1206aae1307ad5d23890be4251c8f (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 25d463c67821901c8fd6736c815f11e85bbae66f
Author: Werner Koch <wk at gnupg.org>
Date:   Fri Nov 11 20:26:49 2016 +0100

    Use the syscall clamp functions also for lock functions
    
    * src/posix-lock.c (pre_lock_func, post_lock_func): New.
    (_gpgrt_lock_set_lock_clamp): New.
    (_gpgrt_lock_lock): Use clamp functions.
    * src/w32-lock.c (pre_lock_func, post_lock_func): New.
    (_gpgrt_lock_set_lock_clamp): New.
    (_gpgrt_lock_lock): Use clamp functions.
    * src/posix-lock.c (pre_syscall_func, post_syscall_func): New.
    (_gpgrt_thread_set_syscall_clamp): New.
    (_gpgrt_yield): Use clamp functions.
    * src/w32-lock.c (pre_syscall_func, post_syscall_func): New.
    (_gpgrt_thread_set_syscall_clamp): New.
    (_gpgrt_yield): Use clamp functions.
    * src/estream.c: Include lock.h and thread.h.
    (do_deinit): Call _gpgrt_lock_set_lock_clamp.
    (_gpgrt_set_syscall_clamp): Ditto.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/src/estream.c b/src/estream.c
index 95d7211..d0f0ba9 100644
--- a/src/estream.c
+++ b/src/estream.c
@@ -95,7 +95,8 @@
 
 #include "gpgrt-int.h"
 #include "estream-printf.h"
-
+#include "thread.h"
+#include "lock.h"
 
 #ifndef O_BINARY
 # define O_BINARY 0
@@ -564,6 +565,8 @@ do_deinit (void)
   /* Reset the syscall clamp.  */
   pre_syscall_func = NULL;
   post_syscall_func = NULL;
+  _gpgrt_thread_set_syscall_clamp (NULL, NULL);
+  _gpgrt_lock_set_lock_clamp (NULL, NULL);
 }
 
 
@@ -598,6 +601,8 @@ _gpgrt_set_syscall_clamp (void (*pre)(void), void (*post)(void))
 {
   pre_syscall_func = pre;
   post_syscall_func = post;
+  _gpgrt_thread_set_syscall_clamp (pre, post);
+  _gpgrt_lock_set_lock_clamp (pre, post);
 }
 
 
diff --git a/src/lock.h b/src/lock.h
index a830b36..b7395db 100644
--- a/src/lock.h
+++ b/src/lock.h
@@ -20,5 +20,7 @@
 #ifndef LOCK_H
 #define LOCK_H
 
+void _gpgrt_lock_set_lock_clamp (void (*pre)(void), void (*post)(void));
+
 
 #endif /*LOCK_H*/
diff --git a/src/posix-lock.c b/src/posix-lock.c
index 2e0ae92..d251d2f 100644
--- a/src/posix-lock.c
+++ b/src/posix-lock.c
@@ -44,6 +44,14 @@
 #include "posix-lock-obj.h"
 
 
+/*
+ * Functions called before and after blocking syscalls.
+ * gpgrt_set_syscall_clamp is used to set them.
+ */
+static void (*pre_lock_func)(void);
+static void (*post_lock_func)(void);
+
+
 #if USE_POSIX_THREADS
 # if USE_POSIX_THREADS_WEAK
    /* On ELF systems it is easy to use pthreads using weak
@@ -103,6 +111,16 @@ use_pthread_p (void)
 #endif /*USE_POSIX_THREADS*/
 
 
+/* Helper to set the clamp functions.  This is called as a helper from
+ * _gpgrt_set_syscall_clamp to keep the function pointers local. */
+void
+_gpgrt_lock_set_lock_clamp (void (*pre)(void), void (*post)(void))
+{
+  pre_lock_func = pre;
+  post_lock_func = post;
+}
+
+
 
 static _gpgrt_lock_t *
 get_lock_object (gpgrt_lock_t *lockhd)
@@ -171,9 +189,13 @@ _gpgrt_lock_lock (gpgrt_lock_t *lockhd)
 #if USE_POSIX_THREADS
   if (use_pthread_p())
     {
+      if (pre_lock_func)
+        pre_lock_func ();
       rc = pthread_mutex_lock (&lock->u.mtx);
       if (rc)
         rc = gpg_err_code_from_errno (rc);
+      if (post_lock_func)
+        post_lock_func ();
     }
   else
     rc = 0; /* Threads are not used.  */
diff --git a/src/posix-thread.c b/src/posix-thread.c
index 270dc91..00a43e2 100644
--- a/src/posix-thread.c
+++ b/src/posix-thread.c
@@ -43,18 +43,44 @@
 
 #include "thread.h"
 
+/*
+ * Functions called before and after blocking syscalls.
+ * gpgrt_set_syscall_clamp is used to set them.
+ */
+static void (*pre_syscall_func)(void);
+static void (*post_syscall_func)(void);
+
+
+/* Helper to set the clamp functions.  This is called as a helper from
+ * _gpgrt_set_syscall_clamp to keep the function pointers local. */
+void
+_gpgrt_thread_set_syscall_clamp (void (*pre)(void), void (*post)(void))
+{
+  pre_syscall_func = pre;
+  post_syscall_func = post;
+}
+
+
 
 gpg_err_code_t
 _gpgrt_yield (void)
 {
 #if USE_POSIX_THREADS
 # ifdef _POSIX_PRIORITY_SCHEDULING
+   if (pre_syscall_func)
+     pre_syscall_func ();
    sched_yield ();
+   if (post_syscall_func)
+     post_syscall_func ();
 # else
    return GPG_ERR_NOT_SUPPORTED;
 # endif
 #elif USE_SOLARIS_THREADS
+  if (pre_syscall_func)
+    pre_syscall_func ();
   thr_yield ();
+  if (post_syscall_func)
+    post_syscall_func ();
 #else
   return GPG_ERR_NOT_SUPPORTED;
 #endif
diff --git a/src/thread.h b/src/thread.h
index c650a99..f064cce 100644
--- a/src/thread.h
+++ b/src/thread.h
@@ -20,5 +20,7 @@
 #ifndef THREAD_H
 #define THREAD_H
 
+void _gpgrt_thread_set_syscall_clamp (void (*pre)(void), void (*post)(void));
+
 
 #endif /*THREAD_H*/
diff --git a/src/w32-lock.c b/src/w32-lock.c
index d1decc9..51b13a1 100644
--- a/src/w32-lock.c
+++ b/src/w32-lock.c
@@ -37,6 +37,26 @@
 #include "w32-lock-obj.h"
 
 
+
+/*
+ * Functions called before and after blocking syscalls.
+ * gpgrt_set_syscall_clamp is used to set them.
+ */
+static void (*pre_lock_func)(void);
+static void (*post_lock_func)(void);
+
+
+/* Helper to set the clamp functions.  This is called as a helper from
+ * _gpgrt_set_syscall_clamp to keep the function pointers local. */
+void
+_gpgrt_lock_set_lock_clamp (void (*pre)(void), void (*post)(void))
+{
+  pre_lock_func = pre;
+  post_lock_func = post;
+}
+
+
+
 static _gpgrt_lock_t *
 get_lock_object (gpgrt_lock_t *lockhd)
 {
@@ -101,7 +121,11 @@ _gpgrt_lock_lock (gpgrt_lock_t *lockhd)
         }
     }
 
+  if (pre_lock_func)
+    pre_lock_func ();
   EnterCriticalSection (&lock->csec);
+  if (post_lock_func)
+    post_lock_func ();
   return 0;
 }
 
diff --git a/src/w32-thread.c b/src/w32-thread.c
index 6860075..aef421f 100644
--- a/src/w32-thread.c
+++ b/src/w32-thread.c
@@ -35,10 +35,32 @@
 
 #include "thread.h"
 
+/*
+ * Functions called before and after blocking syscalls.
+ * gpgrt_set_syscall_clamp is used to set them.
+ */
+static void (*pre_syscall_func)(void);
+static void (*post_syscall_func)(void);
+
+
+/* Helper to set the clamp functions.  This is called as a helper from
+ * _gpgrt_set_syscall_clamp to keep the function pointers local. */
+void
+_gpgrt_thread_set_syscall_clamp (void (*pre)(void), void (*post)(void))
+{
+  pre_syscall_func = pre;
+  post_syscall_func = post;
+}
+
+
 
 gpg_err_code_t
 _gpgrt_yield (void)
 {
+  if (pre_syscall_func)
+    pre_syscall_func ();
   Sleep (0);
+  if (post_syscall_func)
+    post_syscall_func ();
   return 0;
 }

-----------------------------------------------------------------------

Summary of changes:
 src/estream.c      |  7 ++++++-
 src/lock.h         |  2 ++
 src/posix-lock.c   | 22 ++++++++++++++++++++++
 src/posix-thread.c | 26 ++++++++++++++++++++++++++
 src/thread.h       |  2 ++
 src/w32-lock.c     | 24 ++++++++++++++++++++++++
 src/w32-thread.c   | 22 ++++++++++++++++++++++
 7 files changed, 104 insertions(+), 1 deletion(-)


hooks/post-receive
-- 
Error codes used by GnuPG et al.
http://git.gnupg.org




More information about the Gnupg-commits mailing list