This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 07/10] Add __pthread_set_abort_hook export


From: Andi Kleen <ak@linux.intel.com>

For some debugging scenarios it is useful to catch aborts. Looking
at the abort code can be the only way to get information out of a
memory transaction.

This exports an __pthread_set_abort_hook function that can set
this abort hook.

Requires adding a GLIBC_2.18 namespace.

Separate patch because it changes the external ABI and tags
everything with GLIBC_2.18.  Backports that do not want to change
that can leave this patch out. tst-elision2 -- which tests this
hook -- will the automatically disable itself.

2013-01-10  Andi Kleen  <ak@linux.intel.com>

	* Versions.def (GLIBC_2.18): Add for pthread.
	* Versions: Add __pthread_set_abort_hook.
	* sysdeps/pthread/pthread.h (__pthread_set_abort_hook,
         __pthread_abort_hook_t): Add.
	* sysdeps/unix/sysv/linux/i386/nptl/libpthread.abilist: Add 2.18.
	* sysdeps/unix/sysv/linux/x86_64/64/nptl/libpthread.abilist: dito.
	* sysdeps/unix/sysv/linux/x86/abort-hook.c: New file.
	* sysdeps/unix/sysv/linux/x86/Makefile: Add abort-hook.
	* sysdeps/unix/sysv/linux/x86/elision-conf.c (__tsx_abort_hook):
	Remove.
	* sysdeps/unix/sysv/linux/x86/elision-conf.h (SUPPORTS_ABORT_HOOK):
	Add.
---
 Versions.def                                       |    1 +
 nptl/Versions                                      |    4 ++
 nptl/sysdeps/pthread/pthread.h                     |   10 ++++++
 nptl/sysdeps/unix/sysv/linux/x86/Makefile          |    2 +-
 nptl/sysdeps/unix/sysv/linux/x86/abort-hook.c      |   32 ++++++++++++++++++++
 nptl/sysdeps/unix/sysv/linux/x86/elision-conf.c    |    1 -
 nptl/sysdeps/unix/sysv/linux/x86/elision-conf.h    |    1 +
 .../unix/sysv/linux/i386/nptl/libpthread.abilist   |    3 ++
 .../sysv/linux/x86_64/64/nptl/libpthread.abilist   |    3 ++
 9 files changed, 55 insertions(+), 2 deletions(-)
 create mode 100644 nptl/sysdeps/unix/sysv/linux/x86/abort-hook.c

diff --git a/Versions.def b/Versions.def
index 3c9e0ae..899d6ee 100644
--- a/Versions.def
+++ b/Versions.def
@@ -99,6 +99,7 @@ libpthread {
   GLIBC_2.6
   GLIBC_2.11
   GLIBC_2.12
+  GLIBC_2.18
   GLIBC_PRIVATE
 }
 libresolv {
diff --git a/nptl/Versions b/nptl/Versions
index 6a10375..0c3a572 100644
--- a/nptl/Versions
+++ b/nptl/Versions
@@ -252,6 +252,10 @@ libpthread {
     pthread_setname_np; pthread_getname_np;
   };
 
+  GLIBC_2.18 {
+    __pthread_set_abort_hook;
+  };
+
   GLIBC_PRIVATE {
     __pthread_initialize_minimal;
     __pthread_clock_gettime; __pthread_clock_settime;
diff --git a/nptl/sysdeps/pthread/pthread.h b/nptl/sysdeps/pthread/pthread.h
index f1b86b9..754ca86 100644
--- a/nptl/sysdeps/pthread/pthread.h
+++ b/nptl/sysdeps/pthread/pthread.h
@@ -1176,6 +1176,16 @@ extern int pthread_atfork (void (*__prepare) (void),
 			   void (*__child) (void)) __THROW;
 
 
+#ifdef __USE_GNU
+typedef void (*__pthread_abort_hook_t) (unsigned);
+
+/* Set an abort hook HOOK that is called when a lock transaction aborts.
+   The HOOK is called with the system specific transaction abort status.
+   Returns the old hook. */
+
+extern __pthread_abort_hook_t __pthread_set_abort_hook (__pthread_abort_hook_t hook);
+#endif
+
 #ifdef __USE_EXTERN_INLINES
 /* Optimizations.  */
 __extern_inline int
diff --git a/nptl/sysdeps/unix/sysv/linux/x86/Makefile b/nptl/sysdeps/unix/sysv/linux/x86/Makefile
index 61b7552..e7b9612 100644
--- a/nptl/sysdeps/unix/sysv/linux/x86/Makefile
+++ b/nptl/sysdeps/unix/sysv/linux/x86/Makefile
@@ -1,3 +1,3 @@
 libpthread-sysdep_routines += init-arch
 libpthread-sysdep_routines += elision-lock elision-unlock elision-timed \
-			      elision-trylock
+			      elision-trylock abort-hook
diff --git a/nptl/sysdeps/unix/sysv/linux/x86/abort-hook.c b/nptl/sysdeps/unix/sysv/linux/x86/abort-hook.c
new file mode 100644
index 0000000..8ac8afd
--- /dev/null
+++ b/nptl/sysdeps/unix/sysv/linux/x86/abort-hook.c
@@ -0,0 +1,32 @@
+/* abort-hook.c: Lock elision tunable parameters.
+   Copyright (C) 2012 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>. */
+#include <pthreadP.h>
+#include "elision-conf.h"
+
+__pthread_abort_hook_t __tsx_abort_hook attribute_hidden;
+
+/* Allow user programs to hook into the abort handler.
+   This is useful for debugging situations where you need to get
+   information out of a transaction. */
+
+__pthread_abort_hook_t __pthread_set_abort_hook(__pthread_abort_hook_t hook)
+{
+  __pthread_abort_hook_t old = __tsx_abort_hook;
+  __tsx_abort_hook = hook;
+  return old;
+}
diff --git a/nptl/sysdeps/unix/sysv/linux/x86/elision-conf.c b/nptl/sysdeps/unix/sysv/linux/x86/elision-conf.c
index 479ace4..4cfaea1 100644
--- a/nptl/sysdeps/unix/sysv/linux/x86/elision-conf.c
+++ b/nptl/sysdeps/unix/sysv/linux/x86/elision-conf.c
@@ -240,4 +240,3 @@ void (*const init_array []) (int, char **, char **)
   &elision_init
 };
 
-__pthread_abort_hook_t __tsx_abort_hook attribute_hidden;
diff --git a/nptl/sysdeps/unix/sysv/linux/x86/elision-conf.h b/nptl/sysdeps/unix/sysv/linux/x86/elision-conf.h
index f6d07ff..559f7aa 100644
--- a/nptl/sysdeps/unix/sysv/linux/x86/elision-conf.h
+++ b/nptl/sysdeps/unix/sysv/linux/x86/elision-conf.h
@@ -50,5 +50,6 @@ extern int __pthread_mutex_trylock_rtm (pthread_mutex_t *);
 extern int __pthread_mutex_trylock (pthread_mutex_t *);
 
 #define SUPPORTS_ELISION 1
+#define SUPPORTS_ABORT_HOOK 1
 
 #endif
diff --git a/sysdeps/unix/sysv/linux/i386/nptl/libpthread.abilist b/sysdeps/unix/sysv/linux/i386/nptl/libpthread.abilist
index 827114f..95722ad 100644
--- a/sysdeps/unix/sysv/linux/i386/nptl/libpthread.abilist
+++ b/sysdeps/unix/sysv/linux/i386/nptl/libpthread.abilist
@@ -174,6 +174,9 @@ GLIBC_2.12
  pthread_mutexattr_getrobust F
  pthread_mutexattr_setrobust F
  pthread_setname_np F
+GLIBC_2.18
+ GLIBC_2.18 A
+ __pthread_set_abort_hook F
 GLIBC_2.2
  GLIBC_2.2 A
  __open64 F
diff --git a/sysdeps/unix/sysv/linux/x86_64/64/nptl/libpthread.abilist b/sysdeps/unix/sysv/linux/x86_64/64/nptl/libpthread.abilist
index 7c33f35..6894adf 100644
--- a/sysdeps/unix/sysv/linux/x86_64/64/nptl/libpthread.abilist
+++ b/sysdeps/unix/sysv/linux/x86_64/64/nptl/libpthread.abilist
@@ -8,6 +8,9 @@ GLIBC_2.12
  pthread_mutexattr_getrobust F
  pthread_mutexattr_setrobust F
  pthread_setname_np F
+GLIBC_2.18
+ GLIBC_2.18 A
+ __pthread_set_abort_hook F
 GLIBC_2.2.5
  GLIBC_2.2.5 A
  _IO_flockfile F
-- 
1.7.7.6


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]