|
From: <sv...@va...> - 2005-10-04 16:00:04
|
Author: tom
Date: 2005-10-04 16:59:54 +0100 (Tue, 04 Oct 2005)
New Revision: 4854
Log:
Create a new SkShmC segment type for shared memory segments so that we
can ensure they are never merged with adjacent segments. This makes
sure that we can find the right piece of memory to release when the
shmdt system call occurs.
Modified:
trunk/coregrind/m_aspacemgr/aspacemgr.c
trunk/coregrind/m_syswrap/syswrap-generic.c
trunk/coregrind/pub_core_aspacemgr.h
trunk/include/pub_tool_aspacemgr.h
Modified: trunk/coregrind/m_aspacemgr/aspacemgr.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
--- trunk/coregrind/m_aspacemgr/aspacemgr.c 2005-10-04 13:02:31 UTC (rev =
4853)
+++ trunk/coregrind/m_aspacemgr/aspacemgr.c 2005-10-04 15:59:54 UTC (rev =
4854)
@@ -441,6 +441,7 @@
case SkAnonV: return "ANON";
case SkFileC: return "file";
case SkFileV: return "FILE";
+ case SkShmC: return "shm ";
case SkResvn: return "RSVN";
default: return "????";
}
@@ -523,7 +524,7 @@
);
break;
=20
- case SkAnonC: case SkAnonV:
+ case SkAnonC: case SkAnonV: case SkShmC:
VG_(debugLog)(
logLevel, "aspacem",
"%3d: %s %010llx-%010llx %s %c%c%c%c%c\n",
@@ -688,7 +689,7 @@
&& !s->hasR && !s->hasW && !s->hasX && !s->hasT
&& !s->isCH;
=20
- case SkAnonC: case SkAnonV:
+ case SkAnonC: case SkAnonV: case SkShmC:
return=20
s->smode =3D=3D SmFixed=20
&& s->dev =3D=3D 0 && s->ino =3D=3D 0 && s->offset =3D=3D 0 =
&& s->fnIdx =3D=3D -1
@@ -754,6 +755,9 @@
}
break;
=20
+ case SkShmC:
+ return False;
+
default:
break;
=20
@@ -890,7 +894,8 @@
same =3D nsegments[i].kind =3D=3D SkAnonC
|| nsegments[i].kind =3D=3D SkAnonV
|| nsegments[i].kind =3D=3D SkFileC
- || nsegments[i].kind =3D=3D SkFileV;
+ || nsegments[i].kind =3D=3D SkFileV
+ || nsegments[i].kind =3D=3D SkShmC;
=20
seg_prot =3D 0;
if (nsegments[i].hasR) seg_prot |=3D VKI_PROT_READ;
@@ -1106,7 +1111,7 @@
return NULL;
}
switch (nsegments[i].kind) {
- case SkFileC: case SkFileV:=20
+ case SkFileC: case SkFileV: case SkShmC:
case SkAnonC: case SkAnonV: case SkResvn:
return &nsegments[i];
default:
@@ -1169,6 +1174,7 @@
for (i =3D iLo; i <=3D iHi; i++) {
if ( (nsegments[i].kind =3D=3D SkFileC=20
|| nsegments[i].kind =3D=3D SkAnonC
+ || nsegments[i].kind =3D=3D SkShmC
|| (nsegments[i].kind =3D=3D SkFree && freeOk)
|| (nsegments[i].kind =3D=3D SkResvn && freeOk))
&& (needR ? nsegments[i].hasR : True)
@@ -1638,6 +1644,7 @@
if (nsegments[i].kind =3D=3D SkFree
|| nsegments[i].kind =3D=3D SkFileC
|| nsegments[i].kind =3D=3D SkAnonC
+ || nsegments[i].kind =3D=3D SkShmC
|| nsegments[i].kind =3D=3D SkResvn) {
/* ok */
} else {
@@ -1830,6 +1837,37 @@
return needDiscard;
}
=20
+/* Notifies aspacem that the client completed a shmat successfully.
+ The segment array is updated accordingly. If the returned Bool is
+ True, the caller should immediately discard translations from the
+ specified address range. */
+
+Bool
+VG_(am_notify_client_shmat)( Addr a, SizeT len, UInt prot )
+{
+ NSegment seg;
+ Bool needDiscard;
+
+ aspacem_assert(len > 0);
+ aspacem_assert(VG_IS_PAGE_ALIGNED(a));
+ aspacem_assert(VG_IS_PAGE_ALIGNED(len));
+
+ /* Discard is needed if any of the just-trashed range had T. */
+ needDiscard =3D any_Ts_in_range( a, len );
+
+ init_nsegment( &seg );
+ seg.kind =3D SkShmC;
+ seg.start =3D a;
+ seg.end =3D a + len - 1;
+ seg.offset =3D 0;
+ seg.hasR =3D toBool(prot & VKI_PROT_READ);
+ seg.hasW =3D toBool(prot & VKI_PROT_WRITE);
+ seg.hasX =3D toBool(prot & VKI_PROT_EXEC);
+ add_segment( &seg );
+ AM_SANITY_CHECK;
+ return needDiscard;
+}
+
/* Notifies aspacem that an mprotect was completed successfully. The
segment array is updated accordingly. Note, as with
VG_(am_notify_munmap), it is not the job of this function to reject
@@ -1866,7 +1904,7 @@
for (i =3D iLo; i <=3D iHi; i++) {
/* Apply the permissions to all relevant segments. */
switch (nsegments[i].kind) {
- case SkAnonC: case SkAnonV: case SkFileC: case SkFileV:
+ case SkAnonC: case SkAnonV: case SkFileC: case SkFileV: case Sk=
ShmC:
nsegments[i].hasR =3D newR;
nsegments[i].hasW =3D newW;
nsegments[i].hasX =3D newX;
Modified: trunk/coregrind/m_syswrap/syswrap-generic.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
--- trunk/coregrind/m_syswrap/syswrap-generic.c 2005-10-04 13:02:31 UTC (=
rev 4853)
+++ trunk/coregrind/m_syswrap/syswrap-generic.c 2005-10-04 15:59:54 UTC (=
rev 4854)
@@ -1600,8 +1600,7 @@
cope with the discrepancy, aspacem's sync checker omits the
dev/ino correspondence check in cases where V does not know
the dev/ino. */
- d =3D VG_(am_notify_client_mmap)( res, VG_PGROUNDUP(segmentSize),=20
- prot, VKI_MAP_ANONYMOUS, 0,0);
+ d =3D VG_(am_notify_client_shmat)( res, VG_PGROUNDUP(segmentSize),=
prot );
=20
/* we don't distinguish whether it's read-only or
* read-write -- it doesn't matter really. */
@@ -1630,7 +1629,11 @@
if (s !=3D NULL) {
Addr s_start =3D s->start;
SizeT s_len =3D s->end+1 - s->start;
- Bool d =3D VG_(am_notify_munmap)(s_start, s_len);
+ Bool d;
+
+ vg_assert(s->kind =3D=3D SkShmC && s->start =3D=3D arg0);
+
+ d =3D VG_(am_notify_munmap)(s_start, s_len);
s =3D NULL; /* s is now invalid */
VG_TRACK( die_mem_munmap, s_start, s_len );
if (d)
Modified: trunk/coregrind/pub_core_aspacemgr.h
=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
--- trunk/coregrind/pub_core_aspacemgr.h 2005-10-04 13:02:31 UTC (rev 485=
3)
+++ trunk/coregrind/pub_core_aspacemgr.h 2005-10-04 15:59:54 UTC (rev 485=
4)
@@ -155,6 +155,12 @@
extern Bool VG_(am_notify_client_mmap)
( Addr a, SizeT len, UInt prot, UInt flags, Int fd, Off64T offset );
=20
+/* Notifies aspacem that the client completed a shmat successfully.
+ The segment array is updated accordingly. If the returned Bool is
+ True, the caller should immediately discard translations from the
+ specified address range. */
+extern Bool VG_(am_notify_client_shmat)( Addr a, SizeT len, UInt prot );
+
/* Notifies aspacem that an mprotect was completed successfully. The
segment array is updated accordingly. Note, as with
VG_(am_notify_munmap), it is not the job of this function to reject
Modified: trunk/include/pub_tool_aspacemgr.h
=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
--- trunk/include/pub_tool_aspacemgr.h 2005-10-04 13:02:31 UTC (rev 4853)
+++ trunk/include/pub_tool_aspacemgr.h 2005-10-04 15:59:54 UTC (rev 4854)
@@ -43,6 +43,7 @@
SkAnonV, // anonymous mapping belonging to valgrind
SkFileC, // file mapping belonging to the client
SkFileV, // file mapping belonging to valgrind
+ SkShmC, // shared memory segment belonging to the client
SkResvn // reservation
}
SegKind;
@@ -73,6 +74,12 @@
// there is an associated file
// segment may have permissions
=20
+ kind =3D=3D SkShmC:
+ // smode=3D=3DSmFixed
+ // there's no associated file:
+ dev=3D=3Dino=3D=3Dfoff =3D 0, fnidx =3D=3D -1
+ // segment may have permissions
+
kind =3D=3D SkResvn
// the segment may be resized if required
// there's no associated file:
|