From: Julian Seward Date: Thu, 29 Sep 2005 21:20:41 +0000 (+0000) Subject: Fix a very stupid bug in the new aspacemgr, in which mmap "hint-style" X-Git-Tag: svn/VALGRIND_3_1_0~408 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a8627dede81113da15334f750f6e0728a7489a65;p=thirdparty%2Fvalgrind.git Fix a very stupid bug in the new aspacemgr, in which mmap "hint-style" requests were being granted at the requested address when they should not have been. This was causing ppc32-linux to crash at startup (since the wrongly-granted mapping annihilated 5 others). This shows the value of a multiplatform approach -- the bug applies to all targets, yet x86 and amd64 appeared to work perfectly. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@4820 --- diff --git a/coregrind/m_aspacemgr/aspacemgr.c b/coregrind/m_aspacemgr/aspacemgr.c index e617d6dd4d..9ec0b17a20 100644 --- a/coregrind/m_aspacemgr/aspacemgr.c +++ b/coregrind/m_aspacemgr/aspacemgr.c @@ -1586,9 +1586,14 @@ Addr VG_(am_get_advisory) ( MapRequest* req, other words we are prepared to let the client trash its own mappings if it wants to. - Similarly, a hinted client map will be granted at the - requested address providing the same conditions hold. + The Default Policy is overriden by Policy Exception #2: + If the request is for a hinted client map, we are prepared to + grant it providing all areas inside the request are either + free or reservations. In other words we are prepared to let + the client have a hinted mapping anywhere it likes provided + it does not trash either any of its own mappings or any of + valgrind's mappings. */ Int i, j; Addr holeStart, holeEnd, holeLen; @@ -1628,7 +1633,7 @@ Addr VG_(am_get_advisory) ( MapRequest* req, /* ------ Implement Policy Exception #1 ------ */ - if (forClient && (req->rkind == MFixed || req->rkind == MHint)) { + if (forClient && req->rkind == MFixed) { Int iLo = find_nsegment_idx(reqStart); Int iHi = find_nsegment_idx(reqEnd); Bool allow = True; @@ -1648,12 +1653,32 @@ Addr VG_(am_get_advisory) ( MapRequest* req, *ok = True; return reqStart; } - /* Not acceptable. Fixed fails, Hint is now attempted by the - default policy. */ - if (req->rkind == MFixed) { - *ok = False; - return 0; + /* Not acceptable. Fail. */ + *ok = False; + return 0; + } + + /* ------ Implement Policy Exception #2 ------ */ + + if (forClient && req->rkind == MHint) { + Int iLo = find_nsegment_idx(reqStart); + Int iHi = find_nsegment_idx(reqEnd); + Bool allow = True; + for (i = iLo; i <= iHi; i++) { + if (nsegments[i].kind == SkFree + || nsegments[i].kind == SkResvn) { + /* ok */ + } else { + allow = False; + break; + } + } + if (allow) { + /* Acceptable. Granted. */ + *ok = True; + return reqStart; } + /* Not acceptable. Fall through to the default policy. */ } /* ------ Implement the Default Policy ------ */