|
From: <sv...@va...> - 2005-12-06 16:09:55
|
Author: sewardj
Date: 2005-12-06 16:09:52 +0000 (Tue, 06 Dec 2005)
New Revision: 5295
Log:
Handle code deletions in the unredirected-cache, and add sanity
checks.
Modified:
branches/FNWRAP/coregrind/m_transtab.c
Modified: branches/FNWRAP/coregrind/m_transtab.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/FNWRAP/coregrind/m_transtab.c 2005-12-06 16:09:28 UTC (rev 5=
294)
+++ branches/FNWRAP/coregrind/m_transtab.c 2005-12-06 16:09:52 UTC (rev 5=
295)
@@ -557,6 +557,9 @@
=20
/* Sanity check absolutely everything. True =3D=3D check passed. */
=20
+/* forward */
+static Bool sanity_check_redir_tt_tc ( void );
+
static Bool sanity_check_all_sectors ( void )
{
Int sno;
@@ -570,6 +573,8 @@
if (!sane)
return False;
}
+ if (!sanity_check_redir_tt_tc() )
+ return False;
return True;
}
=20
@@ -958,6 +963,9 @@
/*--- Delete translations. ---*/
/*-------------------------------------------------------------*/
=20
+/* forward */
+static void unredir_discard_translations( Addr64, ULong );
+
/* Stuff for deleting translations which intersect with a given
address range. Unfortunately, to make this run at a reasonable
speed, it is complex. */
@@ -1179,6 +1187,9 @@
if (anyDeleted)
invalidateFastCache();
=20
+ /* don't forget the no-redir cache */
+ unredir_discard_translations( guest_start, range );
+
/* Post-deletion sanity check */
if (VG_(clo_sanity_level >=3D 4)) {
Int i;
@@ -1229,9 +1240,17 @@
}
UTCEntry;
=20
+/* We just allocate forwards in _tc, never deleting. */
static ULong unredir_tc[N_UNREDIR_TCQ] __attribute__((aligned(8)));
static Int unredir_tc_used;
+
+/* Slots in _tt can come into use and out again (.inUse).
+ Nevertheless _tt_highwater is maintained so that invalidations
+ don't have to scan all the slots when only a few are in use.
+ _tt_highwater holds the index of the highest ever allocated
+ slot. */
static UTCEntry unredir_tt[N_UNREDIR_TT];
+static Int unredir_tt_highwater;
=20
=20
static void init_unredir_tt_tc ( void )
@@ -1240,8 +1259,27 @@
unredir_tc_used =3D 0;
for (i =3D 0; i < N_UNREDIR_TT; i++)
unredir_tt[i].inUse =3D False;
+ unredir_tt_highwater =3D -1;
}
=20
+/* Do a sanity check; return False on failure. */
+static Bool sanity_check_redir_tt_tc ( void )
+{
+ Int i;
+ if (unredir_tt_highwater < -1) return False;
+ if (unredir_tt_highwater >=3D N_UNREDIR_TT) return False;
+
+ for (i =3D unredir_tt_highwater+1; i < N_UNREDIR_TT; i++)
+ if (unredir_tt[i].inUse)
+ return False;
+
+ if (unredir_tc_used < 0) return False;
+ if (unredir_tc_used > N_UNREDIR_TCQ) return False;
+
+ return True;
+}
+
+
/* Add an UNREDIRECTED translation of vge to TT/TC. The translation
is temporarily in code[0 .. code_len-1].
*/
@@ -1254,6 +1292,8 @@
Int i, j, code_szQ;
HChar *srcP, *dstP;
=20
+ vg_assert(sanity_check_redir_tt_tc());
+
/* This is the whole point: it's not redirected! */
vg_assert(entry =3D=3D vge->base[0]);
=20
@@ -1278,6 +1318,9 @@
vg_assert(i >=3D 0 && i < N_UNREDIR_TT);
vg_assert(unredir_tt[i].inUse =3D=3D False);
=20
+ if (i > unredir_tt_highwater)
+ unredir_tt_highwater =3D i;
+
dstP =3D (HChar*)&unredir_tc[unredir_tc_used];
srcP =3D (HChar*)code;
for (j =3D 0; j < code_len; j++)
@@ -1309,7 +1352,20 @@
return False;
}
=20
+static void unredir_discard_translations( Addr64 guest_start, ULong rang=
e )
+{
+ Int i;
=20
+ vg_assert(sanity_check_redir_tt_tc());
+
+ for (i =3D 0; i <=3D unredir_tt_highwater; i++) {
+ if (unredir_tt[i].inUse
+ && overlaps( guest_start, range, &unredir_tt[i].vge))
+ unredir_tt[i].inUse =3D False;
+ }
+}
+
+
/*------------------------------------------------------------*/
/*--- Initialisation. ---*/
/*------------------------------------------------------------*/
|