]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Factor out the 'extend' function. We only need one version for Linux and
authorFlorian Krohm <florian@eich-krohm.de>
Sat, 18 Apr 2015 10:33:54 +0000 (10:33 +0000)
committerFlorian Krohm <florian@eich-krohm.de>
Sat, 18 Apr 2015 10:33:54 +0000 (10:33 +0000)
one for Darwin. Down from 11.
Carve out a new function 'track_frame_memory' that communicates to the
tool the allocation of a new stack frame. This was slightly different on
Linux and Darwin but should be the same on both platforms.
New files: priv_sigframe.h and sigframe-common.c

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15109

15 files changed:
coregrind/Makefile.am
coregrind/m_sigframe/priv_sigframe.h [new file with mode: 0644]
coregrind/m_sigframe/sigframe-amd64-darwin.c
coregrind/m_sigframe/sigframe-amd64-linux.c
coregrind/m_sigframe/sigframe-arm-linux.c
coregrind/m_sigframe/sigframe-arm64-linux.c
coregrind/m_sigframe/sigframe-common.c [new file with mode: 0644]
coregrind/m_sigframe/sigframe-mips32-linux.c
coregrind/m_sigframe/sigframe-mips64-linux.c
coregrind/m_sigframe/sigframe-ppc32-linux.c
coregrind/m_sigframe/sigframe-ppc64-linux.c
coregrind/m_sigframe/sigframe-s390x-linux.c
coregrind/m_sigframe/sigframe-tilegx-linux.c
coregrind/m_sigframe/sigframe-x86-darwin.c
coregrind/m_sigframe/sigframe-x86-linux.c

index e62d774a1c1187b558a72759790a5a177d7e78c6..f43d4c900cc649338ca75947946e4f3801048d8a 100644 (file)
@@ -243,6 +243,7 @@ noinst_HEADERS = \
        m_scheduler/priv_sema.h \
        m_scheduler/priv_sched-lock.h \
        m_scheduler/priv_sched-lock-impl.h \
+       m_sigframe/priv_sigframe.h \
        m_syswrap/priv_types_n_macros.h \
        m_syswrap/priv_syswrap-generic.h \
        m_syswrap/priv_syswrap-linux.h \
@@ -377,6 +378,7 @@ COREGRIND_SOURCES_COMMON = \
        m_scheduler/sema.c \
        m_scheduler/sched-lock.c \
        m_scheduler/sched-lock-generic.c \
+       m_sigframe/sigframe-common.c \
        m_sigframe/sigframe-x86-linux.c \
        m_sigframe/sigframe-amd64-linux.c \
        m_sigframe/sigframe-ppc32-linux.c \
diff --git a/coregrind/m_sigframe/priv_sigframe.h b/coregrind/m_sigframe/priv_sigframe.h
new file mode 100644 (file)
index 0000000..a81f4d0
--- /dev/null
@@ -0,0 +1,46 @@
+/* -*- mode: C; c-basic-offset: 3; -*- */
+
+/*--------------------------------------------------------------------*/
+/*--- Module-local header file for m_sigframe.                     ---*/
+/*---                                              priv_sigframe.h ---*/
+/*--------------------------------------------------------------------*/
+
+/*
+   This file is part of Valgrind, a dynamic binary instrumentation
+   framework.
+
+   Copyright (C) 2015-2015   Florian Krohm
+
+   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 __PRIV_SIGFRAME_H
+#define __PRIV_SIGFRAME_H
+
+#include "pub_core_basics.h"        // types
+#include "pub_core_threadstate.h"   // ThreadState
+
+/* --------------- Implemented in sigframe-common.c ---------------*/
+
+Bool ML_(sf_extend_stack)( const ThreadState *tst, Addr addr, SizeT size );
+
+#endif   // __PRIV_SIGFRAME_H
+
+/*--------------------------------------------------------------------*/
+/*--- end                                                          ---*/
+/*--------------------------------------------------------------------*/
index 3aa52a3b74333c15c640b57d37b7c1b24d305a92..77752beda9838c1dc2dc5e7d434d13c5f9da5bd9 100644 (file)
@@ -82,19 +82,6 @@ struct hacky_sigframe {
 };
 
 
-/* Extend the stack segment downwards if needed so as to ensure the
-   new signal frames are mapped to something.  Return a Bool
-   indicating whether or not the operation was successful.
-*/
-static Bool extend ( ThreadState *tst, Addr addr, SizeT size )
-{
-   ThreadId tid = tst->tid;
-   VG_TRACK( new_mem_stack_signal, addr - VG_STACK_REDZONE_SZB,
-             size + VG_STACK_REDZONE_SZB, tid );
-   return True;
-}
-
-
 /* Create a signal frame for thread 'tid'.  Make a 3-arg frame
    regardless of whether the client originally requested a 1-arg
    version (no SA_SIGINFO) or a 3-arg one (SA_SIGINFO) since in the
@@ -122,7 +109,7 @@ void VG_(sigframe_create) ( ThreadId tid,
                 entry to a function. */
 
    tst = VG_(get_ThreadState)(tid);
-   if (!extend(tst, rsp, sp_top_of_frame - rsp))
+   if (! ML_(sf_extend_stack)(tst, rsp, sp_top_of_frame - rsp))
       return;
 
    vg_assert(VG_IS_16_ALIGNED(rsp+8));
index 62698aab93f6a0a7e8d44891a1f1793025e220f3..a2b79e5adba49382256ffd8638482ace18880ff4 100644 (file)
@@ -45,6 +45,7 @@
 #include "pub_core_tooliface.h"
 #include "pub_core_trampoline.h"
 #include "pub_core_sigframe.h"   /* self */
+#include "priv_sigframe.h"
 
 /* This module creates and removes signal frames for signal deliveries
    on amd64-linux.
@@ -372,50 +373,6 @@ void synth_ucontext(ThreadId tid, const vki_siginfo_t *si,
 }
 
 
-/* Extend the stack segment downwards if needed so as to ensure the
-   new signal frames are mapped to something.  Return a Bool
-   indicating whether or not the operation was successful.
-*/
-static Bool extend ( ThreadState *tst, Addr addr, SizeT size )
-{
-   ThreadId        tid = tst->tid;
-   NSegment const* stackseg = NULL;
-
-   if (VG_(extend_stack)(tid, addr)) {
-      stackseg = VG_(am_find_nsegment)(addr);
-      if (0 && stackseg)
-        VG_(printf)("frame=%#lx seg=%#lx-%#lx\n",
-                    addr, stackseg->start, stackseg->end);
-   }
-
-   if (stackseg == NULL || !stackseg->hasR || !stackseg->hasW) {
-      VG_(message)(
-         Vg_UserMsg,
-         "Can't extend stack to %#lx during signal delivery for thread %d:\n",
-         addr, tid);
-      if (stackseg == NULL)
-         VG_(message)(Vg_UserMsg, "  no stack segment\n");
-      else
-         VG_(message)(Vg_UserMsg, "  too small or bad protection modes\n");
-
-      /* set SIGSEGV to default handler */
-      VG_(set_default_handler)(VKI_SIGSEGV);
-      VG_(synth_fault_mapping)(tid, addr);
-
-      /* The whole process should be about to die, since the default
-        action of SIGSEGV to kill the whole process. */
-      return False;
-   }
-
-   /* For tracking memory events, indicate the entire frame has been
-      allocated. */
-   VG_TRACK( new_mem_stack_signal, addr - VG_STACK_REDZONE_SZB,
-             size + VG_STACK_REDZONE_SZB, tid );
-
-   return True;
-}
-
-
 /* Build the Valgrind-specific part of a signal frame. */
 
 static void build_vg_sigframe(struct vg_sigframe *frame,
@@ -455,7 +412,7 @@ static Addr build_rt_sigframe(ThreadState *tst,
    rsp = VG_ROUNDDN(rsp, 16) - 8;
    frame = (struct rt_sigframe *)rsp;
 
-   if (!extend(tst, rsp, sizeof(*frame)))
+   if (! ML_(sf_extend_stack)(tst, rsp, sizeof(*frame)))
       return rsp_top_of_frame;
 
    /* retaddr, siginfo, uContext fields are to be written */
index fe8cb1274f2b47df035cc40d0a3cb977a62d6e54..dbbebc34da366bf1b517b4d07ed0a00b1a6da627 100644 (file)
@@ -50,7 +50,7 @@
 #include "pub_core_signals.h"
 #include "pub_core_tooliface.h"
 #include "pub_core_trampoline.h"
-#include "pub_core_transtab.h"      // VG_(discard_translations)
+#include "priv_sigframe.h"
 
 
 /* This uses the hack of dumping the vex guest state along with both
@@ -81,44 +81,6 @@ struct rt_sigframe {
    struct sigframe sig;
 };
 
-static Bool extend ( ThreadState *tst, Addr addr, SizeT size )
-{
-   ThreadId        tid = tst->tid;
-   NSegment const* stackseg = NULL;
-
-   if (VG_(extend_stack)(tid, addr)) {
-      stackseg = VG_(am_find_nsegment)(addr);
-      if (0 && stackseg)
-    VG_(printf)("frame=%#lx seg=%#lx-%#lx\n",
-           addr, stackseg->start, stackseg->end);
-   }
-
-   if (stackseg == NULL || !stackseg->hasR || !stackseg->hasW) {
-      VG_(message)(
-         Vg_UserMsg,
-         "Can't extend stack to %#lx during signal delivery for thread %d:",
-         addr, tid);
-      if (stackseg == NULL)
-         VG_(message)(Vg_UserMsg, "  no stack segment");
-      else
-         VG_(message)(Vg_UserMsg, "  too small or bad protection modes");
-
-      /* set SIGSEGV to default handler */
-      VG_(set_default_handler)(VKI_SIGSEGV);
-      VG_(synth_fault_mapping)(tid, addr);
-
-      /* The whole process should be about to die, since the default
-    action of SIGSEGV to kill the whole process. */
-      return False;
-   }
-
-   /* For tracking memory events, indicate the entire frame has been
-      allocated. */
-   VG_TRACK( new_mem_stack_signal, addr - VG_STACK_REDZONE_SZB,
-             size + VG_STACK_REDZONE_SZB, tid );
-
-   return True;
-}
 
 static void synth_ucontext( ThreadId tid, const vki_siginfo_t *si,
                     UWord trapno, UWord err, const vki_sigset_t *set, 
@@ -223,7 +185,7 @@ void VG_(sigframe_create)( ThreadId tid,
    sp -= size;
    sp = VG_ROUNDDN(sp, 16);
 
-   if(!extend(tst, sp, size))
+   if(! ML_(sf_extend_stack)(tst, sp, size))
       I_die_here; // XXX Incorrect behavior
 
 
index 0bea57d0bb5fca7b47560c0fd7ce4e61f127431f..1b09696d0fa7e7a90910b06f8b2e372ee553696d 100644 (file)
@@ -33,7 +33,6 @@
 
 #include "pub_core_basics.h"
 #include "pub_core_vki.h"
-//ZZ #include "pub_core_vkiscnums.h"
 #include "pub_core_libcsetjmp.h"    // to keep _threadstate.h happy
 #include "pub_core_threadstate.h"
 #include "pub_core_aspacemgr.h"
@@ -46,7 +45,7 @@
 #include "pub_core_signals.h"
 #include "pub_core_tooliface.h"
 #include "pub_core_trampoline.h"
-//ZZ #include "pub_core_transtab.h"      // VG_(discard_translations)
+#include "priv_sigframe.h"
 
 
 /* This uses the hack of dumping the vex guest state along with both
@@ -79,44 +78,6 @@ struct rt_sigframe {
    struct sigframe sig;
 };
 
-static Bool extend ( ThreadState *tst, Addr addr, SizeT size )
-{
-   ThreadId        tid = tst->tid;
-   NSegment const* stackseg = NULL;
-
-   if (VG_(extend_stack)(tid, addr)) {
-      stackseg = VG_(am_find_nsegment)(addr);
-      if (0 && stackseg)
-         VG_(printf)("frame=%#lx seg=%#lx-%#lx\n",
-                     addr, stackseg->start, stackseg->end);
-   }
-
-   if (stackseg == NULL || !stackseg->hasR || !stackseg->hasW) {
-      VG_(message)(
-         Vg_UserMsg,
-         "Can't extend stack to %#lx during signal delivery for thread %d:",
-         addr, tid);
-      if (stackseg == NULL)
-         VG_(message)(Vg_UserMsg, "  no stack segment");
-      else
-         VG_(message)(Vg_UserMsg, "  too small or bad protection modes");
-
-      /* set SIGSEGV to default handler */
-      VG_(set_default_handler)(VKI_SIGSEGV);
-      VG_(synth_fault_mapping)(tid, addr);
-
-      /* The whole process should be about to die, since the default
-         action of SIGSEGV to kill the whole process. */
-      return False;
-   }
-
-   /* For tracking memory events, indicate the entire frame has been
-      allocated. */
-   VG_TRACK( new_mem_stack_signal, addr - VG_STACK_REDZONE_SZB,
-             size + VG_STACK_REDZONE_SZB, tid );
-
-   return True;
-}
 
 static void synth_ucontext( ThreadId tid, const vki_siginfo_t *si,
                             UWord trapno, UWord err, const vki_sigset_t *set, 
@@ -212,7 +173,7 @@ void VG_(sigframe_create)( ThreadId tid,
    sp -= size;
    sp = VG_ROUNDDN(sp, 16);
 
-   if (!extend(tst, sp, size))
+   if (! ML_(sf_extend_stack)(tst, sp, size))
       return; // Give up.  No idea if this is correct
 
    struct rt_sigframe *rsf = (struct rt_sigframe *)sp;
diff --git a/coregrind/m_sigframe/sigframe-common.c b/coregrind/m_sigframe/sigframe-common.c
new file mode 100644 (file)
index 0000000..59b34ee
--- /dev/null
@@ -0,0 +1,110 @@
+/* -*- mode: C; c-basic-offset: 3; -*- */
+
+/*--------------------------------------------------------------------*/
+/*--- Signal frames handling: stuff common to most/all platforms   ---*/
+/*---                                                              ---*/
+/*---                                            sigframe-common.c ---*/
+/*--------------------------------------------------------------------*/
+
+/*
+   This file is part of Valgrind, a dynamic binary instrumentation
+   framework.
+
+   Copyright (C) 2000-2013 Nicholas Nethercote
+      njn@valgrind.org
+   Copyright (C) 2006-2013 OpenWorks Ltd
+      info@open-works.co.uk
+
+   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 "pub_core_aspacemgr.h"      // VG_(am_find_nsegment)
+#include "pub_core_signals.h"        // VG_(extend_stack)
+#include "pub_core_libcprint.h"      // VG_(umsg)
+#include "pub_core_tooliface.h"      // VG_TRACK
+#include "pub_core_machine.h"        // VG_STACK_REDZONE_SZB
+#include "priv_sigframe.h"           // self
+
+
+/* For tracking memory events, indicate the entire frame has been
+   allocated.  Except, don't mess with the area which
+   overlaps the previous frame's redzone. */
+static void track_frame_memory ( Addr addr, SizeT size, ThreadId tid )
+{
+   VG_TRACK( new_mem_stack_signal, addr - VG_STACK_REDZONE_SZB, size, tid );
+}
+
+#if defined(VGO_linux)
+
+/* Extend the stack segment downwards if needed so as to ensure the
+   new signal frames are mapped to something.  Return a Bool
+   indicating whether or not the operation was successful. */
+Bool ML_(sf_extend_stack) ( const ThreadState *tst, Addr addr, SizeT size )
+{
+   ThreadId        tid = tst->tid;
+   const NSegment *stackseg = NULL;
+
+   if (VG_(extend_stack)(tid, addr)) {
+      stackseg = VG_(am_find_nsegment)(addr);
+      if (0 && stackseg)
+        VG_(printf)("frame=%#lx seg=%#lx-%#lx\n",
+                    addr, stackseg->start, stackseg->end);
+   }
+
+   if (stackseg == NULL || !stackseg->hasR || !stackseg->hasW) {
+      VG_(umsg)("Can't extend stack to %#lx during signal delivery for "
+                "thread %d:\n", addr, tid);
+      if (stackseg == NULL)
+         VG_(umsg)("  no stack segment\n");
+      else
+         VG_(umsg)("  too small or bad protection modes\n");
+
+      /* set SIGSEGV to default handler */
+      VG_(set_default_handler)(VKI_SIGSEGV);
+      VG_(synth_fault_mapping)(tid, addr);
+
+      /* The whole process should be about to die, since the default
+        action of SIGSEGV to kill the whole process. */
+      return False;
+   }
+
+   /* Tell the tool about the new memory */
+   track_frame_memory(addr, size, tid);
+
+   return True;
+}
+
+#elif defined(VGO_darwin)
+
+/* Extend the stack segment downwards if needed so as to ensure the
+   new signal frames are mapped to something.  Return a Bool
+   indicating whether or not the operation was successful. */
+Bool ML_(sf_extend_stack) ( const ThreadState *tst, Addr addr, SizeT size )
+{
+   /* Tell the tool about the new memory */
+   track_frame_memory(addr, size, tst->tid);
+   return True;
+}
+
+#else
+#error unknown OS
+#endif
+
+/*--------------------------------------------------------------------*/
+/*--- end                                                          ---*/
+/*--------------------------------------------------------------------*/
index 4c8c8aa5198ee4c0d0ab26721ab4edd162e1e43e..6f09e4d2fc9027f2fd8086504caae32cface7289 100644 (file)
@@ -46,7 +46,7 @@
 #include "pub_core_signals.h"
 #include "pub_core_tooliface.h"
 #include "pub_core_trampoline.h"
-#include "pub_core_transtab.h"      // VG_(discard_translations)
+#include "priv_sigframe.h"
 
 struct vg_sig_private
 {
@@ -74,45 +74,6 @@ struct rt_sigframe
   struct vg_sig_private priv;
 };
 
-/* Extend the stack segment downwards if needed so as to ensure the
-   new signal frames are mapped to something.  Return a Bool
-   indicating whether or not the operation was successful.
-*/
-static Bool extend ( ThreadState *tst, Addr addr, SizeT size )
-{
-  ThreadId        tid = tst->tid;
-  NSegment const* stackseg = NULL;
-
-  if (VG_(extend_stack)(tid, addr)) {
-     stackseg = VG_(am_find_nsegment)(addr);
-  }
-
-   if (stackseg == NULL || !stackseg->hasR || !stackseg->hasW)
-     {
-       VG_(message)(Vg_UserMsg,
-         "Can't extend stack to %#lx during signal delivery for thread %d:\n",
-         addr, tid );
-       if (stackseg == NULL)
-         VG_(message)( Vg_UserMsg, "  no stack segment\n" );
-       else
-         VG_(message)( Vg_UserMsg, "  too small or bad protection modes\n" );
-
-       /* set SIGSEGV to default handler */
-       VG_(set_default_handler)( VKI_SIGSEGV );
-       VG_(synth_fault_mapping)( tid, addr );
-
-       /* The whole process should be about to die, since the default
-          action of SIGSEGV to kill the whole process. */
-      return False;
-    }
-
-    /* For tracking memory events, indicate the entire frame has been
-       allocated. */
-    VG_TRACK( new_mem_stack_signal, addr - VG_STACK_REDZONE_SZB,
-              size + VG_STACK_REDZONE_SZB, tid );
-
-    return True;
-}
 
 static 
 void setup_sigcontext2 ( ThreadState* tst, struct vki_sigcontext **sc1,
@@ -187,7 +148,7 @@ void VG_(sigframe_create)( ThreadId tid,
     }
 
   tst = VG_(get_ThreadState)(tid);
-  if (!extend(tst, sp, sp_top_of_frame - sp))
+  if (! ML_(sf_extend_stack)(tst, sp, sp_top_of_frame - sp))
     return;
 
   vg_assert(VG_IS_8_ALIGNED(sp));
index bb178ecf9476110311bef6c3a605415c3f086d08..fa6615b248e8dc79eb37d8a853eec02d4f5c413f 100644 (file)
@@ -46,7 +46,7 @@
 #include "pub_core_signals.h"
 #include "pub_core_tooliface.h"
 #include "pub_core_trampoline.h"
-#include "pub_core_transtab.h"  /* VG_(discard_translations) */
+#include "priv_sigframe.h"
 
 struct vg_sig_private {
    UInt magicPI;
@@ -71,44 +71,6 @@ struct rt_sigframe {
    struct vg_sig_private priv;
 };
 
-/* Extend the stack segment downwards if needed so as to ensure the new signal
-   frames are mapped to something. Return a Bool indicating whether or not the
-   operation was successful.
-*/
-static Bool extend ( ThreadState *tst, Addr addr, SizeT size )
-{
-   ThreadId tid = tst->tid;
-   NSegment const* stackseg = NULL;
-
-   if (VG_(extend_stack)(tid, addr)) {
-      stackseg = VG_(am_find_nsegment)(addr);
-   }
-
-   if (stackseg == NULL || !stackseg->hasR || !stackseg->hasW) {
-      VG_(message)(Vg_UserMsg,
-         "Can't extend stack to %#lx during signal delivery for thread %d:\n",
-         addr, tid);
-      if (stackseg == NULL)
-         VG_(message)(Vg_UserMsg, " no stack segment\n");
-      else
-         VG_(message)(Vg_UserMsg, " too small or bad protection modes\n");
-
-      /* set SIGSEGV to default handler */
-      VG_(set_default_handler)(VKI_SIGSEGV);
-      VG_(synth_fault_mapping)(tid, addr);
-
-      /* The whole process should be about to die, since the default
-         action of SIGSEGV to kill the whole process. */
-      return False;
-   }
-
-   /* For tracking memory events, indicate the entire frame has been
-      allocated. */
-   VG_TRACK(new_mem_stack_signal, addr - VG_STACK_REDZONE_SZB,
-            size + VG_STACK_REDZONE_SZB, tid);
-
-   return True;
-}
 
 static void setup_sigcontext ( ThreadState* tst, struct vki_sigcontext **sc1,
                                const vki_siginfo_t *si)
@@ -173,7 +135,7 @@ void VG_(sigframe_create) ( ThreadId tid,
    sp = sp_top_of_frame - sizeof(struct rt_sigframe);
 
    tst = VG_(get_ThreadState)(tid);
-   if (!extend(tst, sp, sp_top_of_frame - sp))
+   if (! ML_(sf_extend_stack)(tst, sp, sp_top_of_frame - sp))
       return;
 
    sp = VG_ROUNDDN(sp, 16);
index e48846c6489246a493a5d151264cca3b731ee2c2..346abb229c06afec8375b17233da7671b7f8e01c 100644 (file)
@@ -49,7 +49,7 @@
 #include "pub_core_tooliface.h"
 #include "pub_core_trampoline.h"
 #include "pub_core_transtab.h"      // VG_(discard_translations)
-
+#include "priv_sigframe.h"
 
 /* This module creates and removes signal frames for signal deliveries
    on ppc32-linux.
@@ -502,48 +502,6 @@ void stack_mcontext ( struct vki_mcontext *mc,
 //..                   Vg_CoreSignal, zztid, VG_O_STACK_PTR, sizeof(Addr))
 */
 
-/* Extend the stack segment downwards if needed so as to ensure the
-   new signal frames are mapped to something.  Return a Bool
-   indicating whether or not the operation was successful.
-*/
-static Bool extend ( ThreadState *tst, Addr addr, SizeT size )
-{
-   ThreadId        tid = tst->tid;
-   NSegment const* stackseg = NULL;
-
-   if (VG_(extend_stack)(tid, addr)) {
-      stackseg = VG_(am_find_nsegment)(addr);
-      if (0 && stackseg)
-        VG_(printf)("frame=%#lx seg=%#lx-%#lx\n",
-                    addr, stackseg->start, stackseg->end);
-   }
-
-   if (stackseg == NULL || !stackseg->hasR || !stackseg->hasW) {
-      VG_(message)(
-         Vg_UserMsg,
-         "Can't extend stack to %#lx during signal delivery for thread %d:\n",
-         addr, tid);
-      if (stackseg == NULL)
-         VG_(message)(Vg_UserMsg, "  no stack segment\n");
-      else
-         VG_(message)(Vg_UserMsg, "  too small or bad protection modes\n");
-
-      /* set SIGSEGV to default handler */
-      VG_(set_default_handler)(VKI_SIGSEGV);
-      VG_(synth_fault_mapping)(tid, addr);
-
-      /* The whole process should be about to die, since the default
-        action of SIGSEGV to kill the whole process. */
-      return False;
-   }
-
-   /* For tracking memory events, indicate the entire frame has been
-      allocated. */
-   VG_TRACK( new_mem_stack_signal, addr - VG_STACK_REDZONE_SZB,
-             size + VG_STACK_REDZONE_SZB, tid );
-
-   return True;
-}
 
 //.. /* Build the Valgrind-specific part of a signal frame. */
 //.. 
@@ -692,7 +650,7 @@ void VG_(sigframe_create)( ThreadId tid,
 
    tst = VG_(get_ThreadState)(tid);
 
-   if (!extend(tst, sp, sp_top_of_frame - sp))
+   if (! ML_(sf_extend_stack)(tst, sp, sp_top_of_frame - sp))
       return;
 
    vg_assert(VG_IS_16_ALIGNED(sp));
index 1bf3f4812754ae17b303c6f4f335dabbfb81ffc8..8a6bcb3ebbc80626fad175d1bd8115c905c41084 100644 (file)
@@ -49,7 +49,7 @@
 #include "pub_core_tooliface.h"
 #include "pub_core_trampoline.h"
 #include "pub_core_transtab.h"      // VG_(discard_translations)
-
+#include "priv_sigframe.h"
 
 /* This module creates and removes signal frames for signal deliveries
    on ppc64-linux.
@@ -132,49 +132,6 @@ struct rt_sigframe {
    } while (0)
 
 
-/* Extend the stack segment downwards if needed so as to ensure the
-   new signal frames are mapped to something.  Return a Bool
-   indicating whether or not the operation was successful.
-*/
-static Bool extend ( ThreadState *tst, Addr addr, SizeT size )
-{
-   ThreadId        tid = tst->tid;
-   NSegment const* stackseg = NULL;
-
-   if (VG_(extend_stack)(tid, addr)) {
-      stackseg = VG_(am_find_nsegment)(addr);
-      if (0 && stackseg)
-        VG_(printf)("frame=%#lx seg=%#lx-%#lx\n",
-                    addr, stackseg->start, stackseg->end);
-   }
-
-   if (stackseg == NULL || !stackseg->hasR || !stackseg->hasW) {
-      VG_(message)(
-         Vg_UserMsg,
-         "Can't extend stack to %#lx during signal delivery for thread %d:\n",
-         addr, tid);
-      if (stackseg == NULL)
-         VG_(message)(Vg_UserMsg, "  no stack segment\n");
-      else
-         VG_(message)(Vg_UserMsg, "  too small or bad protection modes\n");
-
-      /* set SIGSEGV to default handler */
-      VG_(set_default_handler)(VKI_SIGSEGV);
-      VG_(synth_fault_mapping)(tid, addr);
-
-      /* The whole process should be about to die, since the default
-        action of SIGSEGV to kill the whole process. */
-      return False;
-   }
-
-   /* For tracking memory events, indicate the entire frame has been
-      allocated. */
-   VG_TRACK( new_mem_stack_signal, addr - VG_STACK_REDZONE_SZB,
-             size + VG_STACK_REDZONE_SZB, tid );
-
-   return True;
-}
-
 
 /* EXPORTED */
 void VG_(sigframe_create)( ThreadId tid, 
@@ -201,7 +158,7 @@ void VG_(sigframe_create)( ThreadId tid,
    sp = sp_top_of_frame - sizeof(struct rt_sigframe);
 
    tst = VG_(get_ThreadState)(tid);
-   if (!extend(tst, sp, sp_top_of_frame - sp))
+   if (! ML_(sf_extend_stack)(tst, sp, sp_top_of_frame - sp))
       return;
 
    vg_assert(VG_IS_16_ALIGNED(sp));
index b8a58949f636487677facade982531dc12cc1f86..b3ca4aebf0b4380b738f73d3640be7aa0037b97f 100644 (file)
@@ -45,6 +45,7 @@
 #include "pub_core_signals.h"
 #include "pub_core_tooliface.h"
 #include "pub_core_trampoline.h"
+#include "priv_sigframe.h"
 
 #if defined(VGA_s390x)
 
@@ -258,49 +259,6 @@ static void restore_sigregs(ThreadState *tst, _vki_sigregs *sigregs)
    tst->arch.vex.guest_IA = sigregs->regs.psw.addr;
 }
 
-/* Extend the stack segment downwards if needed so as to ensure the
-   new signal frames are mapped to something.  Return a Bool
-   indicating whether or not the operation was successful.
-*/
-static Bool extend ( ThreadState *tst, Addr addr, SizeT size )
-{
-   ThreadId        tid = tst->tid;
-   NSegment const* stackseg = NULL;
-
-   if (VG_(extend_stack)(tid, addr)) {
-      stackseg = VG_(am_find_nsegment)(addr);
-      if (0 && stackseg)
-        VG_(printf)("frame=%#lx seg=%#lx-%#lx\n",
-                    addr, stackseg->start, stackseg->end);
-   }
-
-   if (stackseg == NULL || !stackseg->hasR || !stackseg->hasW) {
-      VG_(message)(
-         Vg_UserMsg,
-         "Can't extend stack to %#lx during signal delivery for thread %d:\n",
-         addr, tid);
-      if (stackseg == NULL)
-         VG_(message)(Vg_UserMsg, "  no stack segment\n");
-      else
-         VG_(message)(Vg_UserMsg, "  too small or bad protection modes\n");
-
-      /* set SIGSEGV to default handler */
-      VG_(set_default_handler)(VKI_SIGSEGV);
-      VG_(synth_fault_mapping)(tid, addr);
-
-      /* The whole process should be about to die, since the default
-        action of SIGSEGV to kill the whole process. */
-      return False;
-   }
-
-   /* For tracking memory events, indicate the entire frame has been
-      allocated. */
-   VG_TRACK( new_mem_stack_signal, addr - VG_STACK_REDZONE_SZB,
-             size + VG_STACK_REDZONE_SZB, tid );
-
-   return True;
-}
-
 
 /* Build the Valgrind-specific part of a signal frame. */
 
@@ -340,7 +298,7 @@ static Addr build_sigframe(ThreadState *tst,
    sp -= sizeof(*frame);
    frame = (struct sigframe *)sp;
 
-   if (!extend(tst, sp, sizeof(*frame)))
+   if (! ML_(sf_extend_stack)(tst, sp, sizeof(*frame)))
       return sp_top_of_frame;
 
    /* retcode, sigNo, sc, sregs fields are to be written */
@@ -400,7 +358,7 @@ static Addr build_rt_sigframe(ThreadState *tst,
    sp -= sizeof(*frame);
    frame = (struct rt_sigframe *)sp;
 
-   if (!extend(tst, sp, sizeof(*frame)))
+   if (! ML_(sf_extend_stack)(tst, sp, sizeof(*frame)))
       return sp_top_of_frame;
 
    /* retcode, sigNo, sc, sregs fields are to be written */
index 9514afee06eaab34ea36732a29b2faac8d6a3207..48d0859693818c521e49d679211e8da97ebb8d84 100644 (file)
@@ -47,7 +47,7 @@
 #include "pub_core_signals.h"
 #include "pub_core_tooliface.h"
 #include "pub_core_trampoline.h"
-#include "pub_core_transtab.h"      // VG_(discard_translations)
+#include "priv_sigframe.h"
 
 struct vg_sig_private
 {
@@ -67,44 +67,6 @@ struct rt_sigframe {
   struct vg_sig_private priv;
 };
 
-/* Extend the stack segment downwards if needed so as to ensure the
-   new signal frames are mapped to something.  Return a Bool
-   indicating whether or not the operation was successful.
-*/
-static Bool extend ( ThreadState *tst, Addr addr, SizeT size )
-{
-  ThreadId        tid = tst->tid;
-  NSegment const* stackseg = NULL;
-
-  if (VG_(extend_stack)(tid, addr))
-    stackseg = VG_(am_find_nsegment)(addr);
-
-  if (stackseg == NULL || !stackseg->hasR || !stackseg->hasW)
-  {
-    VG_(message)(Vg_UserMsg,
-                 "Can't extend stack to %#lx during signal delivery for thread %d:\n",
-                 addr, tid );
-    if (stackseg == NULL)
-      VG_(message)( Vg_UserMsg, "  no stack segment\n" );
-    else
-      VG_(message)( Vg_UserMsg, "  too small or bad protection modes\n" );
-
-    /* set SIGSEGV to default handler */
-    VG_(set_default_handler)( VKI_SIGSEGV );
-    VG_(synth_fault_mapping)( tid, addr );
-
-    /* The whole process should be about to die, since the default
-       action of SIGSEGV to kill the whole process. */
-    return False;
-  }
-
-  /* For tracking memory events, indicate the entire frame has been
-     allocated. */
-  VG_TRACK( new_mem_stack_signal, addr - VG_STACK_REDZONE_SZB,
-            size + VG_STACK_REDZONE_SZB, tid );
-
-  return True;
-}
 
 static
 void setup_sigcontext2 ( ThreadState* tst, struct vki_sigcontext **sc1,
@@ -196,7 +158,7 @@ void VG_(sigframe_create)( ThreadId tid,
   sp = sp_top_of_frame - sizeof(struct rt_sigframe);
 
   tst = VG_(get_ThreadState)(tid);
-  if (!extend(tst, sp, sizeof(struct rt_sigframe)))
+  if (! ML_(sf_extend_stack)(tst, sp, sizeof(struct rt_sigframe)))
     return;
 
   vg_assert(VG_IS_8_ALIGNED(sp));
index ea92ebfbee2d4f5a3336c54f954b89b3cfc1a2dd..6c2c1efc2ed9bf2cd8ce36ae9c8d724e7e80cd7c 100644 (file)
@@ -85,25 +85,6 @@ struct hacky_sigframe {
 };
 
 
-/* Extend the stack segment downwards if needed so as to ensure the
-   new signal frames are mapped to something.  Return a Bool
-   indicating whether or not the operation was successful.
-*/
-static Bool extend ( ThreadState *tst, Addr addr, SizeT size )
-{
-   ThreadId tid = tst->tid;
-   /* For tracking memory events, indicate the entire frame has been
-      allocated.  Except, don't mess with the area which
-      overlaps the previous frame's redzone. */
-   /* XXX is the following call really right?  compared with the
-      amd64-linux version, this doesn't appear to handle the redzone
-      in the same way. */
-   VG_TRACK( new_mem_stack_signal,
-             addr - VG_STACK_REDZONE_SZB, size, tid );
-   return True;
-}
-
-
 /* Create a signal frame for thread 'tid'.  Make a 3-arg frame
    regardless of whether the client originally requested a 1-arg
    version (no SA_SIGINFO) or a 3-arg one (SA_SIGINFO) since in the
@@ -131,7 +112,7 @@ void VG_(sigframe_create) ( ThreadId tid,
                 entry to a function. */
 
    tst = VG_(get_ThreadState)(tid);
-   if (!extend(tst, esp, sp_top_of_frame - esp))
+   if (! ML_(sf_extend_stack)(tst, esp, sp_top_of_frame - esp))
       return;
 
    vg_assert(VG_IS_16_ALIGNED(esp+4));
index 2c7c8d001cb77251f0cbf43c96c791db7adedff9..d6597b6c967466cbf810fe5e8cda9f7ff5f30227 100644 (file)
@@ -45,7 +45,7 @@
 #include "pub_core_tooliface.h"
 #include "pub_core_trampoline.h"
 #include "pub_core_sigframe.h"   /* self */
-
+#include "priv_sigframe.h"
 
 /* This module creates and removes signal frames for signal deliveries
    on x86-linux.
@@ -393,50 +393,6 @@ void synth_ucontext(ThreadId tid, const vki_siginfo_t *si,
 }
 
 
-/* Extend the stack segment downwards if needed so as to ensure the
-   new signal frames are mapped to something.  Return a Bool
-   indicating whether or not the operation was successful.
-*/
-static Bool extend ( ThreadState *tst, Addr addr, SizeT size )
-{
-   ThreadId        tid = tst->tid;
-   NSegment const* stackseg = NULL;
-
-   if (VG_(extend_stack)(tid, addr)) {
-      stackseg = VG_(am_find_nsegment)(addr);
-      if (0 && stackseg)
-        VG_(printf)("frame=%#lx seg=%#lx-%#lx\n",
-                    addr, stackseg->start, stackseg->end);
-   }
-
-   if (stackseg == NULL || !stackseg->hasR || !stackseg->hasW) {
-      VG_(message)(
-         Vg_UserMsg,
-         "Can't extend stack to %#lx during signal delivery for thread %d:\n",
-         addr, tid);
-      if (stackseg == NULL)
-         VG_(message)(Vg_UserMsg, "  no stack segment\n");
-      else
-         VG_(message)(Vg_UserMsg, "  too small or bad protection modes\n");
-
-      /* set SIGSEGV to default handler */
-      VG_(set_default_handler)(VKI_SIGSEGV);
-      VG_(synth_fault_mapping)(tid, addr);
-
-      /* The whole process should be about to die, since the default
-        action of SIGSEGV to kill the whole process. */
-      return False;
-   }
-
-   /* For tracking memory events, indicate the entire frame has been
-      allocated. */
-   VG_TRACK( new_mem_stack_signal, addr - VG_STACK_REDZONE_SZB,
-             size + VG_STACK_REDZONE_SZB, tid );
-
-   return True;
-}
-
-
 /* Build the Valgrind-specific part of a signal frame. */
 
 static void build_vg_sigframe(struct vg_sigframe *frame,
@@ -478,7 +434,7 @@ static Addr build_sigframe(ThreadState *tst,
    esp = VG_ROUNDDN(esp, 16);
    frame = (struct sigframe *)esp;
 
-   if (!extend(tst, esp, sizeof(*frame)))
+   if (! ML_(sf_extend_stack)(tst, esp, sizeof(*frame)))
       return esp_top_of_frame;
 
    /* retaddr, sigNo, siguContext fields are to be written */
@@ -535,7 +491,7 @@ static Addr build_rt_sigframe(ThreadState *tst,
    esp = VG_ROUNDDN(esp, 16);
    frame = (struct rt_sigframe *)esp;
 
-   if (!extend(tst, esp, sizeof(*frame)))
+   if (! ML_(sf_extend_stack)(tst, esp, sizeof(*frame)))
       return esp_top_of_frame;
 
    /* retaddr, sigNo, pSiginfo, puContext fields are to be written */