Various cleanups to revised low-level memory manager.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@3253 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/coregrind/core.h b/coregrind/core.h
index 6f500f1..f145a3a 100644
--- a/coregrind/core.h
+++ b/coregrind/core.h
@@ -1313,11 +1313,8 @@
next segment along. */
extern Segment *VG_(find_segment_above_mapped)(Addr a);
-extern Segment *VG_(first_segment)(void);
-extern Segment *VG_(next_segment)(Segment *);
-
-extern Bool VG_(seg_contains)(const Segment *s, Addr ptr, SizeT size);
-extern Bool VG_(seg_overlaps)(const Segment *s, Addr ptr, SizeT size);
+extern Bool VG_(seg_contains)(const Segment *s, Addr ptr, SizeT size);
+extern Bool VG_(seg_overlaps)(const Segment *s, Addr ptr, SizeT size);
extern void VG_(pad_address_space) (void);
extern void VG_(unpad_address_space)(void);
diff --git a/coregrind/vg_memory.c b/coregrind/vg_memory.c
index 77fb28c..e10a839 100644
--- a/coregrind/vg_memory.c
+++ b/coregrind/vg_memory.c
@@ -527,6 +527,8 @@
return (p < se && pe > s->addr);
}
+#if 0
+/* 20050228: apparently unused */
/* Prepare a Segment structure for recycling by freeing everything
hanging off it. */
static void recycleseg(Segment *s)
@@ -552,47 +554,23 @@
VG_(SkipNode_Free)(&sk_segments, s);
}
+#endif
-/* Split a segment at address a, returning the new segment */
-Segment *VG_(split_segment)(Addr a)
+
+/* Get rid of any translations arising from s. */
+/* Note, this is not really the job of the low level memory manager.
+ When it comes time to rewrite this subsystem, clean this up. */
+static void dump_translations_from ( Segment* s )
{
- Segment *s = VG_(SkipList_Find)(&sk_segments, &a);
- Segment *ns;
- Int delta;
-vg_assert(0);
- vg_assert((a & (VKI_PAGE_SIZE-1)) == 0);
-
- /* missed */
- if (s == NULL)
- return NULL;
-
- /* a at or beyond endpoint */
- if (s->addr == a || a >= (s->addr+s->len))
- return NULL;
-
- vg_assert(a > s->addr && a < (s->addr+s->len));
-
- ns = VG_(SkipNode_Alloc)(&sk_segments);
-
- *ns = *s;
-
- delta = a - s->addr;
- ns->addr += delta;
- ns->offset += delta;
- ns->len -= delta;
- s->len = delta;
-
- if (s->filename != NULL)
- ns->filename = VG_(arena_strdup)(VG_AR_CORE, s->filename);
-
- if (ns->symtab != NULL)
- VG_(symtab_incref)(ns->symtab);
-
- VG_(SkipList_Insert)(&sk_segments, ns);
-
- return ns;
+ if (s->flags & SF_CODE) {
+ VG_(discard_translations)(s->addr, s->len);
+ if (0)
+ VG_(printf)("dumping translations in %p .. %p\n",
+ s->addr, s->addr+s->len);
+ }
}
+
/* This unmaps all the segments in the range [addr, addr+len); any
partial mappings at the ends are truncated. */
void VG_(unmap_range)(Addr addr, SizeT len)
@@ -637,6 +615,7 @@
/* this segment's tail is truncated by [addr, addr+len)
-> truncate tail
*/
+ dump_translations_from(s);
s->len = addr - s->addr;
if (debug)
@@ -651,6 +630,7 @@
VG_(printf)(" case 2: s->addr=%p s->len=%d delta=%d\n",
s->addr, s->len, delta);
+ dump_translations_from(s);
s->addr += delta;
s->offset += delta;
s->len -= delta;
@@ -660,6 +640,7 @@
/* this segment is completely contained within [addr, addr+len)
-> delete segment
*/
+ dump_translations_from(s);
delete_segment_at(i);
if (debug)
@@ -668,10 +649,11 @@
/* [addr, addr+len) is contained within a single segment
-> split segment into 3, delete middle portion
*/
- Int i_middle = split_segment(addr);
+ Int i_middle;
+ dump_translations_from(s);
+ i_middle = split_segment(addr);
vg_assert(i_middle != -1);
(void)split_segment(addr+len);
-
vg_assert(segments[i_middle].addr == addr);
delete_segment_at(i_middle);
@@ -684,41 +666,6 @@
if (0) show_segments("unmap_range(AFTER)");
}
-/* If possible, merge segment with its neighbours - some segments,
- including s, may be destroyed in the process */
-static void merge_segments(Addr a, SizeT len)
-{
- Segment *s;
- Segment *next;
-
- vg_assert((a & (VKI_PAGE_SIZE-1)) == 0);
- vg_assert((len & (VKI_PAGE_SIZE-1)) == 0);
-
- a -= VKI_PAGE_SIZE;
- len += VKI_PAGE_SIZE;
-
- for(s = VG_(SkipList_Find)(&sk_segments, &a);
- s != NULL && s->addr < (a+len);) {
- next = VG_(SkipNode_Next)(&sk_segments, s);
-
- if (next && segments_are_mergeable(s, next)) {
- Segment *rs;
-
- if (0)
- VG_(printf)("merge %p-%p with %p-%p\n",
- s->addr, s->addr+s->len,
- next->addr, next->addr+next->len);
- s->len += next->len;
- s = VG_(SkipNode_Next)(&sk_segments, next);
-
- rs = VG_(SkipList_Remove)(&sk_segments, &next->addr);
- vg_assert(next == rs);
- freeseg(next);
- } else
- s = next;
- }
-}
-
/* Add a binding of [addr,addr+len) to
(prot,flags,dev,ino,off,filename) in the segment array.
@@ -1092,19 +1039,6 @@
}
-
-Segment *VG_(first_segment)(void)
-{
-vg_assert(0);
- return VG_(SkipNode_First)(&sk_segments);
-}
-
-Segment *VG_(next_segment)(Segment *s)
-{
-vg_assert(0);
- return VG_(SkipNode_Next)(&sk_segments, s);
-}
-
/*------------------------------------------------------------*/
/*--- Tracking permissions around %esp changes. ---*/
/*------------------------------------------------------------*/
diff --git a/coregrind/vg_symtab2.c b/coregrind/vg_symtab2.c
index 7e2497f..67e65cb 100644
--- a/coregrind/vg_symtab2.c
+++ b/coregrind/vg_symtab2.c
@@ -1342,6 +1342,10 @@
mapped = mapped & ~(VKI_PAGE_SIZE-1);
mapped_end = (mapped_end + VKI_PAGE_SIZE - 1) & ~(VKI_PAGE_SIZE-1);
+#if 0
+ /* 20050228: disabled this until VG_(next_segment) can be
+ reinstated in some clean incarnation of the low level
+ memory manager. */
if (VG_(needs).data_syms &&
(mapped >= si->start && mapped <= (si->start+si->size)) &&
(mapped_end > (si->start+si->size))) {
@@ -1375,6 +1379,8 @@
si->size = newsz;
}
}
+#endif
+
}
}
diff --git a/coregrind/vg_syscalls.c b/coregrind/vg_syscalls.c
index cd7e63e..b18e402 100644
--- a/coregrind/vg_syscalls.c
+++ b/coregrind/vg_syscalls.c
@@ -240,7 +240,7 @@
if (seg == NULL || !VG_(seg_contains)(seg, old_addr, old_size))
return -VKI_EINVAL;
- next = VG_(next_segment)(seg);
+ next = VG_(find_segment_above_mapped)(old_addr);
if (0)
VG_(printf)("mremap: old_addr+new_size=%p next->addr=%p flags=%d\n",