diff options
author | njn <njn@a5019735-40e9-0310-863c-91ae7b9d1cf9> | 2005-03-26 16:22:43 +0000 |
---|---|---|
committer | njn <njn@a5019735-40e9-0310-863c-91ae7b9d1cf9> | 2005-03-26 16:22:43 +0000 |
commit | 098da0626cf6f9815d0bde28b9ea28aff4adbff8 (patch) | |
tree | 398c2285d7eac7699faa63369fd3872d85168833 | |
parent | da388f4773e4152acfb9c42c67e4c95e61a8cf26 (diff) |
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 a5019735-40e9-0310-863c-91ae7b9d1cf9
-rw-r--r-- | coregrind/ume.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/coregrind/ume.c b/coregrind/ume.c index cf526c3c..7fd3aa8d 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); } |