]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Handle a couple kinds of executable mutation: a read-only bss, and a
authorNicholas Nethercote <njn@valgrind.org>
Sat, 26 Mar 2005 16:22:43 +0000 (16:22 +0000)
committerNicholas Nethercote <njn@valgrind.org>
Sat, 26 Mar 2005 16:22:43 +0000 (16:22 +0000)
zero-length segment.

MERGED FROM CVS HEAD

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@3446

coregrind/ume.c

index cf526c3c4534a01687f70cc7206d00da9741445a..7fd3aa8d65d1e62b9266f028086c48edfe5bffb0 100644 (file)
@@ -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);
         }