From 55ecc47ee63e1b0c2df8e361a3e850a293cc79ef Mon Sep 17 00:00:00 2001 From: Julian Seward Date: Thu, 7 Jul 2005 13:52:53 +0000 Subject: [PATCH] Don't allow vex to chase into any block for which we might want to create a self-checking translation. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@4126 --- coregrind/m_aspacemgr/aspacemgr.c | 2 +- coregrind/m_translate.c | 45 +++++++++++++++++++++++++------ 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/coregrind/m_aspacemgr/aspacemgr.c b/coregrind/m_aspacemgr/aspacemgr.c index 4c66ec1a5..e5fea3375 100644 --- a/coregrind/m_aspacemgr/aspacemgr.c +++ b/coregrind/m_aspacemgr/aspacemgr.c @@ -222,7 +222,7 @@ static Int allocate_segname ( const HChar* name ) an address after it, and 0 if it denotes an address covered by seg. */ -static Int compare_addr_with_seg ( Addr a, Segment* seg ) +static inline Int compare_addr_with_seg ( Addr a, Segment* seg ) { if (a < seg->addr) return -1; diff --git a/coregrind/m_translate.c b/coregrind/m_translate.c index 9d28c173e..b49c30ec1 100644 --- a/coregrind/m_translate.c +++ b/coregrind/m_translate.c @@ -380,18 +380,46 @@ void log_bytes ( HChar* bytes, Int nbytes ) /* This stops Vex from chasing into function entry points that we wish to redirect. Chasing across them obviously defeats the redirect mechanism, with bad effects for Memcheck, Addrcheck, and possibly - others. */ + others. + + Also, we must stop Vex chasing into blocks for which we might want + to self checking. +*/ static Bool chase_into_ok ( Addr64 addr64 ) { - Addr addr = (Addr)addr64; - if (addr != VG_(code_redirect)(addr)) { - if (0) VG_(printf)("not chasing into 0x%x\n", addr); - return False; - } else { - return True; /* ok to chase into 'addr' */ - } + /* Work through a list of possibilities why we might not want to + allow a chase. */ + Addr addr = (Addr)addr64; + + /* All chasing disallowed if all bbs require self-checks. */ + if (VG_(clo_smc_support) == Vg_SmcAll) + goto dontchase; + + /* AAABBBCCC: if default self-checks are in force, reject if we + would choose to have a self-check for the dest. Note, this must + match the logic at XXXYYYZZZ below. */ + if (VG_(clo_smc_support) == Vg_SmcStack) { + Segment* seg = VG_(find_segment)(addr); + if (seg && (seg->flags & SF_GROWDOWN)) + goto dontchase; + } + + /* Destination is redirected? */ + if (addr != VG_(code_redirect)(addr)) + goto dontchase; + + /* well, ok then. go on and chase. */ + return True; + + vg_assert(0); + /*NOTREACHED*/ + + dontchase: + if (0) VG_(printf)("not chasing into 0x%x\n", addr); + return False; } + Bool VG_(translate) ( ThreadId tid, Addr64 orig_addr, Bool debugging_translation, @@ -509,6 +537,7 @@ Bool VG_(translate) ( ThreadId tid, case Vg_SmcNone: do_self_check = False; break; case Vg_SmcAll: do_self_check = True; break; case Vg_SmcStack: + /* XXXYYYZZZ: must match the logic at AAABBBCCC above */ do_self_check = seg ? toBool(seg->flags & SF_GROWDOWN) : False; break; default: vg_assert2(0, "unknown VG_(clo_smc_support) value");