Modularised signal libc stuff into m_libcsignal.



git-svn-id: svn://svn.valgrind.org/valgrind/trunk@3870 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/coregrind/Makefile.am b/coregrind/Makefile.am
index 7e11f44..3769b92 100644
--- a/coregrind/Makefile.am
+++ b/coregrind/Makefile.am
@@ -50,6 +50,7 @@
 	pub_core_libcassert.h	\
 	pub_core_libcfile.h	\
 	pub_core_libcprint.h	\
+	pub_core_libcsignal.h	\
 	pub_core_main.h		\
 	pub_core_mallocfree.h	\
 	pub_core_options.h	\
@@ -95,6 +96,7 @@
 	m_libcassert.c \
 	m_libcfile.c \
 	m_libcprint.c \
+	m_libcsignal.c \
 	m_main.c \
 	m_mallocfree.c \
 	m_options.c \
diff --git a/coregrind/linux/core_os.c b/coregrind/linux/core_os.c
index 18bf8c2..517f51e 100644
--- a/coregrind/linux/core_os.c
+++ b/coregrind/linux/core_os.c
@@ -33,6 +33,7 @@
 #include "pub_core_debuglog.h"
 #include "pub_core_libcassert.h"
 #include "pub_core_libcprint.h"
+#include "pub_core_libcsignal.h"
 #include "pub_core_options.h"
 #include "pub_core_signals.h"
 #include "pub_core_tooliface.h"
diff --git a/coregrind/m_debuginfo/symtypes.c b/coregrind/m_debuginfo/symtypes.c
index ad6d193..c22cb4c 100644
--- a/coregrind/m_debuginfo/symtypes.c
+++ b/coregrind/m_debuginfo/symtypes.c
@@ -34,6 +34,7 @@
 #include "pub_core_libcbase.h"
 #include "pub_core_libcassert.h"
 #include "pub_core_libcprint.h"
+#include "pub_core_libcsignal.h"
 #include "pub_core_tooliface.h"
 #include "priv_symtypes.h"
 
diff --git a/coregrind/m_libcsignal.c b/coregrind/m_libcsignal.c
new file mode 100644
index 0000000..2320635
--- /dev/null
+++ b/coregrind/m_libcsignal.c
@@ -0,0 +1,236 @@
+
+/*--------------------------------------------------------------------*/
+/*--- Signal-related libc stuff.                    m_libcsignal.c ---*/
+/*--------------------------------------------------------------------*/
+ 
+/*
+   This file is part of Valgrind, a dynamic binary instrumentation
+   framework.
+
+   Copyright (C) 2000-2005 Julian Seward 
+      jseward@acm.org
+
+   This program is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   This program 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
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307, USA.
+
+   The GNU General Public License is contained in the file COPYING.
+*/
+
+#include "core.h"
+#include "pub_core_libcbase.h"
+#include "pub_core_libcassert.h"
+#include "pub_core_libcsignal.h"
+#include "vki_unistd.h"
+
+/* sigemptyset, sigfullset, sigaddset and sigdelset return 0 on
+   success and -1 on error.  */
+
+Int VG_(sigfillset)( vki_sigset_t* set )
+{
+   Int i;
+   if (set == NULL)
+      return -1;
+   for (i = 0; i < _VKI_NSIG_WORDS; i++)
+      set->sig[i] = ~(UWord)0x0;
+   return 0;
+}
+
+Int VG_(sigemptyset)( vki_sigset_t* set )
+{
+   Int i;
+   if (set == NULL)
+      return -1;
+   for (i = 0; i < _VKI_NSIG_WORDS; i++)
+      set->sig[i] = 0x0;
+   return 0;
+}
+
+Bool VG_(isemptysigset)( const vki_sigset_t* set )
+{
+   Int i;
+   vg_assert(set != NULL);
+   for (i = 0; i < _VKI_NSIG_WORDS; i++)
+      if (set->sig[i] != 0x0) return False;
+   return True;
+}
+
+Bool VG_(isfullsigset)( const vki_sigset_t* set )
+{
+   Int i;
+   vg_assert(set != NULL);
+   for (i = 0; i < _VKI_NSIG_WORDS; i++)
+      if (set->sig[i] != ~(UWord)0x0) return False;
+   return True;
+}
+
+Bool VG_(iseqsigset)( const vki_sigset_t* set1, const vki_sigset_t* set2 )
+{
+   Int i;
+   vg_assert(set1 != NULL && set2 != NULL);
+   for (i = 0; i < _VKI_NSIG_WORDS; i++)
+      if (set1->sig[i] != set2->sig[i]) return False;
+   return True;
+}
+
+
+Int VG_(sigaddset)( vki_sigset_t* set, Int signum )
+{
+   if (set == NULL)
+      return -1;
+   if (signum < 1 || signum > _VKI_NSIG)
+      return -1;
+   signum--;
+   set->sig[signum / _VKI_NSIG_BPW] |= (1UL << (signum % _VKI_NSIG_BPW));
+   return 0;
+}
+
+Int VG_(sigdelset)( vki_sigset_t* set, Int signum )
+{
+   if (set == NULL)
+      return -1;
+   if (signum < 1 || signum > _VKI_NSIG)
+      return -1;
+   signum--;
+   set->sig[signum / _VKI_NSIG_BPW] &= ~(1UL << (signum % _VKI_NSIG_BPW));
+   return 0;
+}
+
+Int VG_(sigismember) ( const vki_sigset_t* set, Int signum )
+{
+   if (set == NULL)
+      return 0;
+   if (signum < 1 || signum > _VKI_NSIG)
+      return 0;
+   signum--;
+   if (1 & ((set->sig[signum / _VKI_NSIG_BPW]) >> (signum % _VKI_NSIG_BPW)))
+      return 1;
+   else
+      return 0;
+}
+
+
+/* Add all signals in src to dst. */
+void VG_(sigaddset_from_set)( vki_sigset_t* dst, vki_sigset_t* src )
+{
+   Int i;
+   vg_assert(dst != NULL && src != NULL);
+   for (i = 0; i < _VKI_NSIG_WORDS; i++)
+      dst->sig[i] |= src->sig[i];
+}
+
+/* Remove all signals in src from dst. */
+void VG_(sigdelset_from_set)( vki_sigset_t* dst, vki_sigset_t* src )
+{
+   Int i;
+   vg_assert(dst != NULL && src != NULL);
+   for (i = 0; i < _VKI_NSIG_WORDS; i++)
+      dst->sig[i] &= ~(src->sig[i]);
+}
+
+
+/* The functions sigaction, sigprocmask, sigpending and sigsuspend
+   return 0 on success and -1 on error.  
+*/
+Int VG_(sigprocmask)( Int how, const vki_sigset_t* set, vki_sigset_t* oldset)
+{
+   SysRes res = VG_(do_syscall4)(__NR_rt_sigprocmask, 
+                                 how, (UWord)set, (UWord)oldset, 
+                                 _VKI_NSIG_WORDS * sizeof(UWord));
+   return res.isError ? -1 : 0;
+}
+
+
+Int VG_(sigaction) ( Int signum, const struct vki_sigaction* act,  
+                     struct vki_sigaction* oldact)
+{
+   SysRes res = VG_(do_syscall4)(__NR_rt_sigaction,
+                                 signum, (UWord)act, (UWord)oldact, 
+                                 _VKI_NSIG_WORDS * sizeof(UWord));
+   return res.isError ? -1 : 0;
+}
+
+
+Int VG_(sigaltstack)( const vki_stack_t* ss, vki_stack_t* oss )
+{
+   SysRes res = VG_(do_syscall2)(__NR_sigaltstack, (UWord)ss, (UWord)oss);
+   return res.isError ? -1 : 0;
+}
+
+Int VG_(sigtimedwait)( const vki_sigset_t *set, vki_siginfo_t *info, 
+                       const struct vki_timespec *timeout )
+{
+   SysRes res = VG_(do_syscall4)(__NR_rt_sigtimedwait, (UWord)set, (UWord)info, 
+                                 (UWord)timeout, sizeof(*set));
+   return res.isError ? -1 : res.val;
+}
+ 
+Int VG_(signal)(Int signum, void (*sighandler)(Int))
+{
+   SysRes res;
+   Int    n;
+   struct vki_sigaction sa;
+   sa.ksa_handler = sighandler;
+   sa.sa_flags = VKI_SA_ONSTACK | VKI_SA_RESTART;
+   sa.sa_restorer = NULL;
+   n = VG_(sigemptyset)( &sa.sa_mask );
+   vg_assert(n == 0);
+   res = VG_(do_syscall4)(__NR_rt_sigaction, signum, (UWord)&sa, (UWord)NULL,
+                           _VKI_NSIG_WORDS * sizeof(UWord));
+   return res.isError ? -1 : 0;
+}
+
+
+Int VG_(kill)( Int pid, Int signo )
+{
+   SysRes res = VG_(do_syscall2)(__NR_kill, pid, signo);
+   return res.isError ? -1 : 0;
+}
+
+
+Int VG_(tkill)( ThreadId tid, Int signo )
+{
+   SysRes res = VG_(mk_SysRes_Error)(VKI_ENOSYS);
+
+#if 0
+   /* This isn't right because the client may create a process
+      structure with multiple thread groups */
+   res = VG_(do_syscall)(__NR_tgkill, VG_(getpid)(), tid, signo);
+#endif
+
+   res = VG_(do_syscall2)(__NR_tkill, tid, signo);
+
+   if (res.isError && res.val == VKI_ENOSYS)
+      res = VG_(do_syscall2)(__NR_kill, tid, signo);
+
+   return res.isError ? -1 : 0;
+}
+
+Int VG_(sigpending) ( vki_sigset_t* set )
+{
+// Nb: AMD64/Linux doesn't have __NR_sigpending;  it only provides
+// __NR_rt_sigpending.  This function will have to be abstracted in some
+// way to account for this.  In the meantime, the easy option is to forget
+// about it for AMD64 until it's needed.
+#ifdef __amd64__
+   I_die_here;
+#else
+   SysRes res = VG_(do_syscall1)(__NR_sigpending, (UWord)set);
+   return res.isError ? -1 : 0;
+#endif
+}
+
+/*--------------------------------------------------------------------*/
+/*--- end                                                          ---*/
+/*--------------------------------------------------------------------*/
diff --git a/coregrind/m_main.c b/coregrind/m_main.c
index 86d250f..eef6149 100644
--- a/coregrind/m_main.c
+++ b/coregrind/m_main.c
@@ -40,6 +40,7 @@
 #include "pub_core_libcassert.h"
 #include "pub_core_libcfile.h"
 #include "pub_core_libcprint.h"
+#include "pub_core_libcsignal.h"
 #include "pub_core_main.h"
 #include "pub_core_options.h"
 #include "pub_core_profile.h"
diff --git a/coregrind/m_scheduler/scheduler.c b/coregrind/m_scheduler/scheduler.c
index 64e297c..43a4af2 100644
--- a/coregrind/m_scheduler/scheduler.c
+++ b/coregrind/m_scheduler/scheduler.c
@@ -66,6 +66,7 @@
 #include "pub_core_libcbase.h"
 #include "pub_core_libcassert.h"
 #include "pub_core_libcprint.h"
+#include "pub_core_libcsignal.h"
 #include "pub_core_main.h"
 #include "pub_core_options.h"
 #include "pub_core_profile.h"
diff --git a/coregrind/m_signals.c b/coregrind/m_signals.c
index 45abd45..89f658b 100644
--- a/coregrind/m_signals.c
+++ b/coregrind/m_signals.c
@@ -86,6 +86,7 @@
 #include "pub_core_libcbase.h"
 #include "pub_core_libcassert.h"
 #include "pub_core_libcprint.h"
+#include "pub_core_libcsignal.h"
 #include "pub_core_main.h"
 #include "pub_core_options.h"
 #include "pub_core_signals.h"
diff --git a/coregrind/m_syscalls/syscalls-amd64-linux.c b/coregrind/m_syscalls/syscalls-amd64-linux.c
index 4ac9f31..98600fd 100644
--- a/coregrind/m_syscalls/syscalls-amd64-linux.c
+++ b/coregrind/m_syscalls/syscalls-amd64-linux.c
@@ -36,10 +36,11 @@
 #include "pub_core_libcbase.h"
 #include "pub_core_libcassert.h"
 #include "pub_core_libcprint.h"
+#include "pub_core_libcsignal.h"
 #include "pub_core_sigframe.h"
+#include "pub_core_signals.h"
 #include "pub_core_syscalls.h"
 #include "pub_core_tooliface.h"
-#include "pub_core_signals.h"
 
 #include "priv_types_n_macros.h"
 #include "priv_syscalls-generic.h"   /* for decls of generic wrappers */
diff --git a/coregrind/m_syscalls/syscalls-generic.c b/coregrind/m_syscalls/syscalls-generic.c
index 2451816..291bd3c 100644
--- a/coregrind/m_syscalls/syscalls-generic.c
+++ b/coregrind/m_syscalls/syscalls-generic.c
@@ -32,9 +32,10 @@
 #include "pub_core_debuglog.h"
 #include "pub_core_aspacemgr.h"
 #include "pub_core_libcbase.h"
-#include "pub_core_libcprint.h"
-#include "pub_core_libcfile.h"
 #include "pub_core_libcassert.h"
+#include "pub_core_libcfile.h"
+#include "pub_core_libcprint.h"
+#include "pub_core_libcsignal.h"
 #include "pub_core_main.h"
 #include "pub_core_stacktrace.h"
 #include "pub_core_tooliface.h"
diff --git a/coregrind/m_syscalls/syscalls-main.c b/coregrind/m_syscalls/syscalls-main.c
index 4b925d3..bae018d 100644
--- a/coregrind/m_syscalls/syscalls-main.c
+++ b/coregrind/m_syscalls/syscalls-main.c
@@ -33,6 +33,7 @@
 #include "pub_core_libcbase.h"
 #include "pub_core_libcassert.h"
 #include "pub_core_libcprint.h"
+#include "pub_core_libcsignal.h"
 #include "pub_core_stacktrace.h"
 #include "pub_core_tooliface.h"
 #include "pub_core_options.h"
diff --git a/coregrind/m_syscalls/syscalls-x86-linux.c b/coregrind/m_syscalls/syscalls-x86-linux.c
index e851a9e..86c97f4 100644
--- a/coregrind/m_syscalls/syscalls-x86-linux.c
+++ b/coregrind/m_syscalls/syscalls-x86-linux.c
@@ -41,10 +41,11 @@
 #include "pub_core_libcbase.h"
 #include "pub_core_libcassert.h"
 #include "pub_core_libcprint.h"
+#include "pub_core_libcsignal.h"
 #include "pub_core_sigframe.h"
+#include "pub_core_signals.h"
 #include "pub_core_syscalls.h"
 #include "pub_core_tooliface.h"
-#include "pub_core_signals.h"
 
 #include "priv_types_n_macros.h"
 #include "priv_syscalls-generic.h"   /* for decls of generic wrappers */
diff --git a/coregrind/pub_core_libcsignal.h b/coregrind/pub_core_libcsignal.h
new file mode 100644
index 0000000..5b6ef0e
--- /dev/null
+++ b/coregrind/pub_core_libcsignal.h
@@ -0,0 +1,44 @@
+
+/*--------------------------------------------------------------------*/
+/*--- Signal-related libc stuff.             pub_core_libcsignal.h ---*/
+/*--------------------------------------------------------------------*/
+
+/*
+   This file is part of Valgrind, a dynamic binary instrumentation
+   framework.
+
+   Copyright (C) 2000-2005 Julian Seward
+      jseward@acm.org
+
+   This program is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   This program 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
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307, USA.
+
+   The GNU General Public License is contained in the file COPYING.
+*/
+
+#ifndef __PUB_CORE_LIBCSIGNAL_H
+#define __PUB_CORE_LIBCSIGNAL_H
+
+//--------------------------------------------------------------------
+// PURPOSE: This module contains all the libc code related to signals.
+//--------------------------------------------------------------------
+
+#include "pub_tool_libcsignal.h"
+
+#endif   // __PUB_CORE_LIBCSIGNAL_H
+
+/*--------------------------------------------------------------------*/
+/*--- end                                                          ---*/
+/*--------------------------------------------------------------------*/
diff --git a/coregrind/vg_mylibc.c b/coregrind/vg_mylibc.c
index 6c0fe19..147ecd5 100644
--- a/coregrind/vg_mylibc.c
+++ b/coregrind/vg_mylibc.c
@@ -45,207 +45,6 @@
 #include "vki_unistd.h"
 
 
-/* ---------------------------------------------------------------------
-   Wrappers around system calls, and other stuff, to do with signals.
-   ------------------------------------------------------------------ */
-
-/* sigemptyset, sigfullset, sigaddset and sigdelset return 0 on
-   success and -1 on error.  
-*/
-Int VG_(sigfillset)( vki_sigset_t* set )
-{
-   Int i;
-   if (set == NULL)
-      return -1;
-   for (i = 0; i < _VKI_NSIG_WORDS; i++)
-      set->sig[i] = ~(UWord)0x0;
-   return 0;
-}
-
-Int VG_(sigemptyset)( vki_sigset_t* set )
-{
-   Int i;
-   if (set == NULL)
-      return -1;
-   for (i = 0; i < _VKI_NSIG_WORDS; i++)
-      set->sig[i] = 0x0;
-   return 0;
-}
-
-Bool VG_(isemptysigset)( const vki_sigset_t* set )
-{
-   Int i;
-   vg_assert(set != NULL);
-   for (i = 0; i < _VKI_NSIG_WORDS; i++)
-      if (set->sig[i] != 0x0) return False;
-   return True;
-}
-
-Bool VG_(isfullsigset)( const vki_sigset_t* set )
-{
-   Int i;
-   vg_assert(set != NULL);
-   for (i = 0; i < _VKI_NSIG_WORDS; i++)
-      if (set->sig[i] != ~(UWord)0x0) return False;
-   return True;
-}
-
-Bool VG_(iseqsigset)( const vki_sigset_t* set1, const vki_sigset_t* set2 )
-{
-   Int i;
-   vg_assert(set1 != NULL && set2 != NULL);
-   for (i = 0; i < _VKI_NSIG_WORDS; i++)
-      if (set1->sig[i] != set2->sig[i]) return False;
-   return True;
-}
-
-
-Int VG_(sigaddset)( vki_sigset_t* set, Int signum )
-{
-   if (set == NULL)
-      return -1;
-   if (signum < 1 || signum > _VKI_NSIG)
-      return -1;
-   signum--;
-   set->sig[signum / _VKI_NSIG_BPW] |= (1UL << (signum % _VKI_NSIG_BPW));
-   return 0;
-}
-
-Int VG_(sigdelset)( vki_sigset_t* set, Int signum )
-{
-   if (set == NULL)
-      return -1;
-   if (signum < 1 || signum > _VKI_NSIG)
-      return -1;
-   signum--;
-   set->sig[signum / _VKI_NSIG_BPW] &= ~(1UL << (signum % _VKI_NSIG_BPW));
-   return 0;
-}
-
-Int VG_(sigismember) ( const vki_sigset_t* set, Int signum )
-{
-   if (set == NULL)
-      return 0;
-   if (signum < 1 || signum > _VKI_NSIG)
-      return 0;
-   signum--;
-   if (1 & ((set->sig[signum / _VKI_NSIG_BPW]) >> (signum % _VKI_NSIG_BPW)))
-      return 1;
-   else
-      return 0;
-}
-
-
-/* Add all signals in src to dst. */
-void VG_(sigaddset_from_set)( vki_sigset_t* dst, vki_sigset_t* src )
-{
-   Int i;
-   vg_assert(dst != NULL && src != NULL);
-   for (i = 0; i < _VKI_NSIG_WORDS; i++)
-      dst->sig[i] |= src->sig[i];
-}
-
-/* Remove all signals in src from dst. */
-void VG_(sigdelset_from_set)( vki_sigset_t* dst, vki_sigset_t* src )
-{
-   Int i;
-   vg_assert(dst != NULL && src != NULL);
-   for (i = 0; i < _VKI_NSIG_WORDS; i++)
-      dst->sig[i] &= ~(src->sig[i]);
-}
-
-
-/* The functions sigaction, sigprocmask, sigpending and sigsuspend
-   return 0 on success and -1 on error.  
-*/
-Int VG_(sigprocmask)( Int how, const vki_sigset_t* set, vki_sigset_t* oldset)
-{
-   SysRes res = VG_(do_syscall4)(__NR_rt_sigprocmask, 
-                                 how, (UWord)set, (UWord)oldset, 
-                                 _VKI_NSIG_WORDS * sizeof(UWord));
-   return res.isError ? -1 : 0;
-}
-
-
-Int VG_(sigaction) ( Int signum, const struct vki_sigaction* act,  
-                     struct vki_sigaction* oldact)
-{
-   SysRes res = VG_(do_syscall4)(__NR_rt_sigaction,
-                                 signum, (UWord)act, (UWord)oldact, 
-                                 _VKI_NSIG_WORDS * sizeof(UWord));
-   return res.isError ? -1 : 0;
-}
-
-
-Int VG_(sigaltstack)( const vki_stack_t* ss, vki_stack_t* oss )
-{
-   SysRes res = VG_(do_syscall2)(__NR_sigaltstack, (UWord)ss, (UWord)oss);
-   return res.isError ? -1 : 0;
-}
-
-Int VG_(sigtimedwait)( const vki_sigset_t *set, vki_siginfo_t *info, 
-                       const struct vki_timespec *timeout )
-{
-   SysRes res = VG_(do_syscall4)(__NR_rt_sigtimedwait, (UWord)set, (UWord)info, 
-                                 (UWord)timeout, sizeof(*set));
-   return res.isError ? -1 : res.val;
-}
- 
-Int VG_(signal)(Int signum, void (*sighandler)(Int))
-{
-   SysRes res;
-   Int    n;
-   struct vki_sigaction sa;
-   sa.ksa_handler = sighandler;
-   sa.sa_flags = VKI_SA_ONSTACK | VKI_SA_RESTART;
-   sa.sa_restorer = NULL;
-   n = VG_(sigemptyset)( &sa.sa_mask );
-   vg_assert(n == 0);
-   res = VG_(do_syscall4)(__NR_rt_sigaction, signum, (UWord)&sa, (UWord)NULL,
-                           _VKI_NSIG_WORDS * sizeof(UWord));
-   return res.isError ? -1 : 0;
-}
-
-
-Int VG_(kill)( Int pid, Int signo )
-{
-   SysRes res = VG_(do_syscall2)(__NR_kill, pid, signo);
-   return res.isError ? -1 : 0;
-}
-
-
-Int VG_(tkill)( ThreadId tid, Int signo )
-{
-   SysRes res = VG_(mk_SysRes_Error)(VKI_ENOSYS);
-
-#if 0
-   /* This isn't right because the client may create a process
-      structure with multiple thread groups */
-   res = VG_(do_syscall)(__NR_tgkill, VG_(getpid)(), tid, signo);
-#endif
-
-   res = VG_(do_syscall2)(__NR_tkill, tid, signo);
-
-   if (res.isError && res.val == VKI_ENOSYS)
-      res = VG_(do_syscall2)(__NR_kill, tid, signo);
-
-   return res.isError ? -1 : 0;
-}
-
-Int VG_(sigpending) ( vki_sigset_t* set )
-{
-// Nb: AMD64/Linux doesn't have __NR_sigpending;  it only provides
-// __NR_rt_sigpending.  This function will have to be abstracted in some
-// way to account for this.  In the meantime, the easy option is to forget
-// about it for AMD64 until it's needed.
-#ifdef __amd64__
-   I_die_here;
-#else
-   SysRes res = VG_(do_syscall1)(__NR_sigpending, (UWord)set);
-   return res.isError ? -1 : 0;
-#endif
-}
-
 Int VG_(waitpid)(Int pid, Int *status, Int options)
 {
    SysRes res = VG_(do_syscall4)(__NR_wait4, pid, (UWord)status, options, 0);
@@ -857,3 +656,4 @@
 /*--------------------------------------------------------------------*/
 /*--- end                                                          ---*/
 /*--------------------------------------------------------------------*/
+
diff --git a/include/Makefile.am b/include/Makefile.am
index a38b33d..6445b3d 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -12,6 +12,7 @@
 	pub_tool_libcassert.h 		\
 	pub_tool_libcfile.h 		\
 	pub_tool_libcprint.h 		\
+	pub_tool_libcsignal.h 		\
 	pub_tool_mallocfree.h 		\
 	pub_tool_options.h 		\
 	pub_tool_profile.h		\
diff --git a/include/pub_tool_libcsignal.h b/include/pub_tool_libcsignal.h
new file mode 100644
index 0000000..8463bb3
--- /dev/null
+++ b/include/pub_tool_libcsignal.h
@@ -0,0 +1,76 @@
+
+/*--------------------------------------------------------------------*/
+/*--- Signal-related libc stuff.             pub_tool_libcsignal.h ---*/
+/*--------------------------------------------------------------------*/
+
+/*
+   This file is part of Valgrind, a dynamic binary instrumentation
+   framework.
+
+   Copyright (C) 2000-2005 Julian Seward
+      jseward@acm.org
+
+   This program is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   This program 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
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307, USA.
+
+   The GNU General Public License is contained in the file COPYING.
+*/
+
+#ifndef __PUB_TOOL_LIBCBSIGNAL_H
+#define __PUB_TOOL_LIBCBSIGNAL_H
+
+/* Note that these use the vki_ (kernel) structure
+   definitions, which are different in places from those that glibc
+   defines.  Since we're operating right at the kernel interface, glibc's view
+   of the world is entirely irrelevant. */
+
+/* --- Signal set ops --- */
+extern Int  VG_(sigfillset)  ( vki_sigset_t* set );
+extern Int  VG_(sigemptyset) ( vki_sigset_t* set );
+
+extern Bool VG_(isfullsigset)  ( const vki_sigset_t* set );
+extern Bool VG_(isemptysigset) ( const vki_sigset_t* set );
+extern Bool VG_(iseqsigset)    ( const vki_sigset_t* set1,
+                                 const vki_sigset_t* set2 );
+
+extern Int  VG_(sigaddset)   ( vki_sigset_t* set, Int signum );
+extern Int  VG_(sigdelset)   ( vki_sigset_t* set, Int signum );
+extern Int  VG_(sigismember) ( const vki_sigset_t* set, Int signum );
+
+extern void VG_(sigaddset_from_set) ( vki_sigset_t* dst, vki_sigset_t* src );
+extern void VG_(sigdelset_from_set) ( vki_sigset_t* dst, vki_sigset_t* src );
+
+/* --- Mess with the kernel's sig state --- */
+extern Int VG_(sigprocmask) ( Int how, const vki_sigset_t* set,
+                              vki_sigset_t* oldset );
+extern Int VG_(sigaction)   ( Int signum,
+                              const struct vki_sigaction* act,
+                              struct vki_sigaction* oldact );
+
+extern Int VG_(sigtimedwait)( const vki_sigset_t *, vki_siginfo_t *, 
+			      const struct vki_timespec * );
+
+extern Int VG_(signal)      ( Int signum, void (*sighandler)(Int) );
+extern Int VG_(sigaltstack) ( const vki_stack_t* ss, vki_stack_t* oss );
+
+extern Int VG_(kill)        ( Int pid, Int signo );
+extern Int VG_(tkill)       ( ThreadId tid, Int signo );
+extern Int VG_(sigpending)  ( vki_sigset_t* set );
+
+#endif   // __PUB_TOOL_LIBCBSIGNAL_H
+
+/*--------------------------------------------------------------------*/
+/*--- end                                                          ---*/
+/*--------------------------------------------------------------------*/
diff --git a/include/tool.h b/include/tool.h
index ecaf3ba..cd44a61 100644
--- a/include/tool.h
+++ b/include/tool.h
@@ -176,47 +176,6 @@
 /* Calls "mark_addr" with register values (which may or may not be pointers) */
 extern void VG_(mark_from_registers)(void (*mark_addr)(Addr addr));
 
-/* ------------------------------------------------------------------ */
-/* signal.h.
-
-   Note that these use the vk_ (kernel) structure
-   definitions, which are different in places from those that glibc
-   defines.  Since we're operating right at the kernel interface, glibc's view
-   of the world is entirely irrelevant. */
-
-/* --- Signal set ops --- */
-extern Int  VG_(sigfillset)  ( vki_sigset_t* set );
-extern Int  VG_(sigemptyset) ( vki_sigset_t* set );
-
-extern Bool VG_(isfullsigset)  ( const vki_sigset_t* set );
-extern Bool VG_(isemptysigset) ( const vki_sigset_t* set );
-extern Bool VG_(iseqsigset)    ( const vki_sigset_t* set1,
-                                 const vki_sigset_t* set2 );
-
-extern Int  VG_(sigaddset)   ( vki_sigset_t* set, Int signum );
-extern Int  VG_(sigdelset)   ( vki_sigset_t* set, Int signum );
-extern Int  VG_(sigismember) ( const vki_sigset_t* set, Int signum );
-
-extern void VG_(sigaddset_from_set) ( vki_sigset_t* dst, vki_sigset_t* src );
-extern void VG_(sigdelset_from_set) ( vki_sigset_t* dst, vki_sigset_t* src );
-
-/* --- Mess with the kernel's sig state --- */
-extern Int VG_(sigprocmask) ( Int how, const vki_sigset_t* set,
-                              vki_sigset_t* oldset );
-extern Int VG_(sigaction)   ( Int signum,
-                              const struct vki_sigaction* act,
-                              struct vki_sigaction* oldact );
-
-extern Int VG_(sigtimedwait)( const vki_sigset_t *, vki_siginfo_t *, 
-			      const struct vki_timespec * );
-
-extern Int VG_(signal)      ( Int signum, void (*sighandler)(Int) );
-extern Int VG_(sigaltstack) ( const vki_stack_t* ss, vki_stack_t* oss );
-
-extern Int VG_(kill)        ( Int pid, Int signo );
-extern Int VG_(tkill)       ( ThreadId tid, Int signo );
-extern Int VG_(sigpending)  ( vki_sigset_t* set );
-
 extern Int VG_(waitpid)	    ( Int pid, Int *status, Int options );
 
 /* ------------------------------------------------------------------ */
diff --git a/memcheck/mac_leakcheck.c b/memcheck/mac_leakcheck.c
index 82c1804..ad626da 100644
--- a/memcheck/mac_leakcheck.c
+++ b/memcheck/mac_leakcheck.c
@@ -35,6 +35,7 @@
 #include "pub_tool_libcbase.h"
 #include "pub_tool_libcassert.h"
 #include "pub_tool_libcprint.h"
+#include "pub_tool_libcsignal.h"
 
 /* Define to debug the memory-leak-detector. */
 #define VG_DEBUG_LEAKCHECK 0