From: Nicholas Nethercote Date: Sat, 26 Mar 2005 16:22:43 +0000 (+0000) Subject: Handle a couple kinds of executable mutation: a read-only bss, and a X-Git-Tag: svn/VALGRIND_3_0_0~872 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=32dd4093dcb37dbe6f67b0e8a3d1cfdce22a02bb;p=thirdparty%2Fvalgrind.git Handle a couple kinds of executable mutation: a read-only bss, and a zero-length segment. MERGED FROM CVS HEAD git-svn-id: svn://svn.valgrind.org/valgrind/trunk@3446 --- diff --git a/coregrind/ume.c b/coregrind/ume.c index cf526c3c45..7fd3aa8d65 100644 --- a/coregrind/ume.c +++ b/coregrind/ume.c @@ -247,11 +247,14 @@ ESZ(Addr) mapelf(struct elfinfo *e, ESZ(Addr) base) // map the pages that are required instead of rounding everything to // the specified alignment (ph->p_align). (AMD64 doesn't work if you // use ph->p_align -- part of stage2's memory gets trashed somehow.) - - res = mmap((char *)PGROUNDDN(addr), PGROUNDUP(bss)-PGROUNDDN(addr), - prot, MAP_FIXED|MAP_PRIVATE, e->fd, PGROUNDDN(off)); - check_mmap(res, (char*)PGROUNDDN(addr), - PGROUNDUP(bss)-PGROUNDDN(addr)); + // + // The condition handles the case of a zero-length segment. + if (PGROUNDUP(bss)-PGROUNDDN(addr) > 0) { + res = mmap((char *)PGROUNDDN(addr), PGROUNDUP(bss)-PGROUNDDN(addr), + prot, MAP_FIXED|MAP_PRIVATE, e->fd, PGROUNDDN(off)); + check_mmap(res, (char*)PGROUNDDN(addr), + PGROUNDUP(bss)-PGROUNDDN(addr)); + } // if memsz > filesz, fill the remainder with zeroed pages if (memsz > filesz) { @@ -265,7 +268,9 @@ ESZ(Addr) mapelf(struct elfinfo *e, ESZ(Addr) base) } bytes = bss & (VKI_PAGE_SIZE - 1); - if (bytes > 0) { + + // The 'prot' condition allows for a read-only bss + if ((prot & PROT_WRITE) && (bytes > 0)) { bytes = VKI_PAGE_SIZE - bytes; memset((char *)bss, 0, bytes); }