|
From: <sv...@va...> - 2005-09-14 20:36:41
|
Author: sewardj
Date: 2005-09-14 21:36:39 +0100 (Wed, 14 Sep 2005)
New Revision: 4660
Log:
* Change the return conventions for VG_(am_get_advisory) to be
more convenient.
* Add a new convenience function VG_(am_get_advisory_client_simple).
* Fix more syscalls/thread stack stuff
Modified:
branches/ASPACEM/coregrind/m_aspacemgr/aspacemgr.c
branches/ASPACEM/coregrind/m_syswrap/syswrap-generic.c
branches/ASPACEM/coregrind/m_syswrap/syswrap-x86-linux.c
branches/ASPACEM/coregrind/m_ume.c
branches/ASPACEM/coregrind/pub_core_aspacemgr.h
Modified: branches/ASPACEM/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
--- branches/ASPACEM/coregrind/m_aspacemgr/aspacemgr.c 2005-09-14 20:07:2=
7 UTC (rev 4659)
+++ branches/ASPACEM/coregrind/m_aspacemgr/aspacemgr.c 2005-09-14 20:36:3=
9 UTC (rev 4660)
@@ -2275,9 +2275,9 @@
=20
/* Query aspacem to ask where a mapping should go. */
=20
-Bool VG_(am_get_advisory) ( MapRequest* req,=20
+Addr VG_(am_get_advisory) ( MapRequest* req,=20
Bool forClient,=20
- /*OUT*/Addr* result )
+ /*OUT*/Bool* ok )
{
/* This function implements allocation policy.
=20
@@ -2287,11 +2287,11 @@
and by forClient, which says whether this is for the client or
for V.=20
=20
- Return values: the request can be vetoed (return False), in
- which case the caller should not attempt to proceed with making
- the mapping. Otherwise, the caller may proceed, and the
- preferred address at which the mapping should happen is written
- in *result.
+ Return values: the request can be vetoed (*ok is set to False),
+ in which case the caller should not attempt to proceed with
+ making the mapping. Otherwise, *ok is set to True, the caller
+ may proceed, and the preferred address at which the mapping
+ should happen is returned.
=20
Note that this is an advisory system only: the kernel can in
fact do whatever it likes as far as placement goes, and we have
@@ -2315,8 +2315,7 @@
grant it providing all areas inside the request are either
free or are file mappings belonging to the client. In other
words we are prepared to let the client trash its own mappings
- if it wants to. =20
- */
+ if it wants to. */
Int i, j;
Addr holeStart, holeEnd, holeLen;
Bool fixed_not_required;
@@ -2341,13 +2340,17 @@
}
=20
/* Reject zero-length requests */
- if (req->len =3D=3D 0)
- return False;
+ if (req->len =3D=3D 0) {
+ *ok =3D False;
+ return 0;
+ }
=20
/* Reject wraparounds */
if ((req->rkind=3D=3DMFixed || req->rkind=3D=3DMHint)
- && req->start + req->len < req->start)
- return False;
+ && req->start + req->len < req->start) {
+ *ok =3D False;
+ return 0;
+ }
=20
/* ------ Implement Policy Exception #1 ------ */
=20
@@ -2365,10 +2368,11 @@
}
}
if (allow) {
- *result =3D reqStart;
- return True;
- }
- return False;
+ *ok =3D True;
+ return reqStart;
+ }
+ *ok =3D False;
+ return 0;
}
=20
/* ------ Implement the Default Policy ------ */
@@ -2426,38 +2430,57 @@
switch (req->rkind) {
case MFixed:
if (fixedIdx >=3D 0) {
- *result =3D req->start;
- return True;
+ *ok =3D True;
+ return req->start;
} else {
- return False;
+ *ok =3D False;
+ return 0;
}
break;
case MHint:
if (fixedIdx >=3D 0) {
- *result =3D req->start;
- return True;
+ *ok =3D True;
+ return req->start;
}
if (floatIdx >=3D 0) {
- *result =3D nsegments[floatIdx].start;
- return True;
+ *ok =3D True;
+ return nsegments[floatIdx].start;
}
- return False;
+ *ok =3D False;
+ return 0;
case MAny:
if (floatIdx >=3D 0) {
- *result =3D nsegments[floatIdx].start;
- return True;
+ *ok =3D True;
+ return nsegments[floatIdx].start;
}
- return False;
+ *ok =3D False;
+ return 0;
default:=20
break;
}
=20
/*NOTREACHED*/
aspacem_barf("getAdvisory: unknown request kind");
- return False;
+ *ok =3D False;
+ return 0;
}
=20
+/* Convenience wrapper for VG_(am_get_advisory) for client floating or
+ fixed requests. If start is zero, a floating request is issued; if
+ nonzero, a fixed request at that address is issued. Same comments
+ about return values apply. */
=20
+Addr VG_(am_get_advisory_client_simple) ( Addr start, SizeT len,=20
+ /*OUT*/Bool* ok )
+{
+ MapRequest mreq;
+ mreq.rkind =3D start=3D=3D0 ? MAny : MFixed;
+ mreq.start =3D start;
+ mreq.len =3D len;
+ return VG_(am_get_advisory)( &mreq, True/*client*/, ok );
+}
+
+
/* Notifies aspacem that the client completed an mmap successfully.
The segment array is updated accordingly. */
=20
@@ -2595,7 +2618,7 @@
req.rkind =3D MFixed;
req.start =3D start;
req.len =3D length;
- ok =3D VG_(am_get_advisory)( &req, True/*client*/, &advised );
+ advised =3D VG_(am_get_advisory)( &req, True/*client*/, &ok );
if (!ok || advised !=3D start)
return VG_(mk_SysRes_Error)( VKI_EINVAL );
=20
@@ -2659,7 +2682,7 @@
req.rkind =3D MFixed;
req.start =3D start;
req.len =3D length;
- ok =3D VG_(am_get_advisory)( &req, True/*client*/, &advised );
+ advised =3D VG_(am_get_advisory)( &req, True/*client*/, &ok );
if (!ok || advised !=3D start)
return VG_(mk_SysRes_Error)( VKI_EINVAL );
=20
@@ -2715,7 +2738,7 @@
req.rkind =3D MAny;
req.start =3D 0;
req.len =3D length;
- ok =3D VG_(am_get_advisory)( &req, True/*client*/, &advised );
+ advised =3D VG_(am_get_advisory)( &req, True/*client*/, &ok );
if (!ok)
return VG_(mk_SysRes_Error)( VKI_EINVAL );
=20
@@ -2772,7 +2795,7 @@
req.rkind =3D MAny;
req.start =3D 0;
req.len =3D length;
- ok =3D VG_(am_get_advisory)( &req, False/*valgrind*/, &advised );
+ advised =3D VG_(am_get_advisory)( &req, False/*valgrind*/, &ok );
if (!ok)
return VG_(mk_SysRes_Error)( VKI_EINVAL );
=20
Modified: branches/ASPACEM/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
--- branches/ASPACEM/coregrind/m_syswrap/syswrap-generic.c 2005-09-14 20:=
07:27 UTC (rev 4659)
+++ branches/ASPACEM/coregrind/m_syswrap/syswrap-generic.c 2005-09-14 20:=
36:39 UTC (rev 4660)
@@ -1508,9 +1508,14 @@
UWord arg0, UWord arg1, UWord arg2 )
{
/* void *shmat(int shmid, const void *shmaddr, int shmflg); */
- UInt segmentSize =3D get_shm_size ( arg0 );
- if (arg1 =3D=3D 0)
- arg1 =3D VG_(find_map_space)(0, segmentSize, True);
+ UInt segmentSize =3D get_shm_size ( arg0 );
+ UWord tmp;
+ Bool ok;
+ if (arg1 =3D=3D 0) {
+ tmp =3D VG_(am_get_advisory_client_simple)(0, segmentSize, &ok);
+ if (ok)
+ arg1 =3D ok;
+ }
else if (!ML_(valid_client_addr)(arg1, segmentSize, tid, "shmat"))
arg1 =3D 0;
return arg1;
@@ -4573,7 +4578,7 @@
}
=20
/* Enquire ... */
- mreq_ok =3D VG_(am_get_advisory)( &mreq, True/*client*/, &advised );
+ advised =3D VG_(am_get_advisory)( &mreq, True/*client*/, &mreq_ok );
if (!mreq_ok) {
/* Our request was bounced, so we'd better fail. */
SET_STATUS_Failure( VKI_EINVAL );
Modified: branches/ASPACEM/coregrind/m_syswrap/syswrap-x86-linux.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_syswrap/syswrap-x86-linux.c 2005-09-14 2=
0:07:27 UTC (rev 4659)
+++ branches/ASPACEM/coregrind/m_syswrap/syswrap-x86-linux.c 2005-09-14 2=
0:36:39 UTC (rev 4660)
@@ -376,7 +376,7 @@
ThreadState* ptst =3D VG_(get_ThreadState)(ptid);
ThreadState* ctst =3D VG_(get_ThreadState)(ctid);
UWord* stack;
- Segment* seg;
+ NSegment* seg;
SysRes res;
Int eax;
vki_sigset_t blockall, savedmask;
@@ -428,14 +428,14 @@
memory mappings and try to derive some useful information. We
assume that esp starts near its highest possible value, and can
only go down to the start of the mmaped segment. */
- seg =3D VG_(find_segment)((Addr)esp);
- if (seg) {
+ seg =3D VG_(am_find_nsegment)((Addr)esp);
+ if (seg && seg->kind !=3D SkResvn) {
ctst->client_stack_highest_word =3D (Addr)VG_PGROUNDUP(esp);
- ctst->client_stack_szB =3D ctst->client_stack_highest_word - seg-=
>addr;
+ ctst->client_stack_szB =3D ctst->client_stack_highest_word - seg->=
start;
=20
if (debug)
VG_(printf)("tid %d: guessed client stack range %p-%p\n",
- ctid, seg->addr, VG_PGROUNDUP(esp));
+ ctid, seg->start, VG_PGROUNDUP(esp));
} else {
VG_(message)(Vg_UserMsg, "!? New thread %d starts with ESP(%p) unm=
apped\n",
ctid, esp);
@@ -1514,7 +1514,7 @@
}
=20
/* Enquire ... */
- mreq_ok =3D VG_(am_get_advisory)( &mreq, True/*client*/, &advised );
+ advised =3D VG_(am_get_advisory)( &mreq, True/*client*/, &mreq_ok );
if (!mreq_ok) {
/* Our request was bounced, so we'd better fail. */
SET_STATUS_Failure( VKI_EINVAL );
Modified: branches/ASPACEM/coregrind/m_ume.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_ume.c 2005-09-14 20:07:27 UTC (rev 4659)
+++ branches/ASPACEM/coregrind/m_ume.c 2005-09-14 20:36:39 UTC (rev 4660)
@@ -605,7 +605,6 @@
Char* base =3D (Char *)info->exe_base;
Char* baseoff;
Addr advised;
- MapRequest mreq;
Bool ok;
=20
if (info->map_base !=3D 0)
@@ -617,10 +616,9 @@
the specified address. This is a bit of hack, but it should
work because there should be no intervening transactions with
aspacem which could cause those fixed maps to fail. */
- mreq.rkind =3D base ? MFixed : MAny;
- mreq.start =3D (Addr)base;
- mreq.len =3D interp_size;
- ok =3D VG_(am_get_advisory)( &mreq, True/*client*/, &advised );
+ advised =3D VG_(am_get_advisory_client_simple)(=20
+ (Addr)base, interp_size, &ok=20
+ );
if (!ok) {
/* bomb out */
SysRes res =3D VG_(mk_SysRes_Error)(VKI_EINVAL);
Modified: branches/ASPACEM/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
--- branches/ASPACEM/coregrind/pub_core_aspacemgr.h 2005-09-14 20:07:27 U=
TC (rev 4659)
+++ branches/ASPACEM/coregrind/pub_core_aspacemgr.h 2005-09-14 20:36:39 U=
TC (rev 4660)
@@ -289,13 +289,22 @@
}
MapRequest;
=20
-/* Query aspacem to ask where a mapping should go. On success,
- returns True and the advised placement is in *result. If False is
- returned, it means aspacem has vetoed the mapping, and so the
+/* Query aspacem to ask where a mapping should go. On success, the
+ advised placement is returned, and *ok is set to True. On failure,
+ zero is returned and *ok is set to False. Note that *ok must be
+ consulted by the caller to establish success or failure; that
+ cannot be established reliably from the returned value. If *ok is
+ set to False, it means aspacem has vetoed the mapping, and so the
caller should not proceed with it. */
-extern Bool VG_(am_get_advisory)
- ( MapRequest* req, Bool forClient, /*OUT*/Addr* result );
+extern Addr VG_(am_get_advisory)
+ ( MapRequest* req, Bool forClient, /*OUT*/Bool* ok );
=20
+/* Convenience wrapper for VG_(am_get_advisory) for client floating or
+ fixed requests. If start is zero, a floating request is issued; if
+ nonzero, a fixed request at that address is issued. Same comments
+ about return values apply. */
+extern Addr VG_(am_get_advisory_client_simple)=20
+ ( Addr start, SizeT len, /*OUT*/Bool* ok );
=20
/* Notifies aspacem that the client completed an mmap successfully.
The segment array is updated accordingly. */
|