Factor out the 'extend' function. We only need one version for Linux and

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
This commit is contained in:
Florian Krohm 2015-04-18 10:33:54 +00:00
parent 40315d9702
commit d1a1c32462
15 changed files with 182 additions and 462 deletions

View 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 \

View File

@ -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 ---*/
/*--------------------------------------------------------------------*/

View 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));

View 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 */

View 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

View 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;

View File

@ -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 ---*/
/*--------------------------------------------------------------------*/

View 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));

View 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);

View 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));

View 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));

View 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 */

View 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));

View 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));

View 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 */