|
From: <sv...@va...> - 2005-09-24 12:44:11
|
Author: sewardj
Date: 2005-09-24 13:43:57 +0100 (Sat, 24 Sep 2005)
New Revision: 4744
Log:
Minor refinements to segment permission checking.
Modified:
branches/ASPACEM/coregrind/m_translate.c
Modified: branches/ASPACEM/coregrind/m_translate.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- branches/ASPACEM/coregrind/m_translate.c 2005-09-24 11:57:15 UTC (rev=
4743)
+++ branches/ASPACEM/coregrind/m_translate.c 2005-09-24 12:43:57 UTC (rev=
4744)
@@ -381,6 +381,24 @@
'tid' is the identity of the thread needing this block.
*/
=20
+/* Look for reasons to disallow making translations from the given
+ segment. */
+
+static Bool translations_allowable_from_seg ( NSegment* seg )
+{
+# if defined(VGA_x86)
+ Bool allowR =3D True;
+# else
+ Bool allowR =3D False;
+# endif
+
+ return seg !=3D NULL
+ && (seg->kind =3D=3D SkAnonC || seg->kind =3D=3D SkFileC)
+ && (seg->hasX || (seg->hasR && allowR));
+}
+
+
+
/* 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
@@ -397,6 +415,8 @@
static ThreadId chase_into_ok__CLOSURE_tid;
static Bool chase_into_ok ( Addr64 addr64 )
{
+ NSegment* seg;
+
/* Work through a list of possibilities why we might not want to
allow a chase. */
Addr addr =3D (Addr)addr64;
@@ -405,12 +425,16 @@
if (VG_(clo_smc_check) =3D=3D Vg_SmcAll)
goto dontchase;
=20
+ /* Check the segment permissions. */
+ seg =3D VG_(am_find_nsegment)(addr);
+ if (!translations_allowable_from_seg(seg))
+ 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_check) =3D=3D Vg_SmcStack) {
ThreadId tid =3D chase_into_ok__CLOSURE_tid;
- NSegment* seg =3D VG_(am_find_nsegment)(addr);
if (seg
&& (seg->kind =3D=3D SkAnonC || seg->kind =3D=3D SkFileC)
&& seg->start <=3D VG_(get_SP)(tid)
@@ -442,7 +466,7 @@
{
Addr64 redir, orig_addr0 =3D orig_addr;
Int tmpbuf_used, verbosity, i;
- Bool notrace_until_done, do_self_check, allowR, seg_ok;
+ Bool notrace_until_done, do_self_check;
UInt notrace_until_limit =3D 0;
NSegment* seg;
VexGuestExtents vge;
@@ -529,22 +553,11 @@
bbs_done);
}
=20
- /* Figure out what segment the requested address is in, and=20
- look for possible reasons to disallow it. */
+ /* Are we allowed to translate here? */
=20
seg =3D VG_(am_find_nsegment)(orig_addr);
=20
-# if defined(VGA_x86)
- allowR =3D True;
-# else
- allowR =3D False;
-# endif
-
- seg_ok =3D seg !=3D NULL
- && (seg->kind =3D=3D SkAnonC || seg->kind =3D=3D SkFileC)
- && (seg->hasX || (seg->hasR && allowR));
-
- if (!seg_ok) {
+ if (!translations_allowable_from_seg(seg)) {
/* U R busted, sonny. Place your hands on your head and step
away from the orig_addr. */
/* Code address is bad - deliver a signal instead */
@@ -623,8 +636,14 @@
VGP_POPCC(VgpVexTime);
=20
/* Tell aspacem of all segments that have had translations taken
- from them. */
- for (i =3D 0; i < vge.n_used; i++) {
+ from them. Optimisation: don't re-look up vge.base[0] since seg
+ should already point to it. */
+
+ vg_assert( vge.base[0] =3D=3D (Addr64)orig_addr );
+ if (seg->kind =3D=3D SkFileC || seg->kind =3D=3D SkAnonC)
+ seg->hasT =3D True; /* has cached code */
+
+ for (i =3D 1; i < vge.n_used; i++) {
seg =3D VG_(am_find_nsegment)( vge.base[i] );
if (seg->kind =3D=3D SkFileC || seg->kind =3D=3D SkAnonC)
seg->hasT =3D True; /* has cached code */
|