]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Fix BZ #342683. Based on patch by Ivo Raisr.
authorFlorian Krohm <florian@eich-krohm.de>
Sat, 25 Apr 2015 18:23:21 +0000 (18:23 +0000)
committerFlorian Krohm <florian@eich-krohm.de>
Sat, 25 Apr 2015 18:23:21 +0000 (18:23 +0000)
What this does is to make sure that the initial client data segment
is marked as unaddressable. This is consistent with the behaviour of
brk when the data segment is shrunk. The "freed" memory is marked
as unaddressable.
Special tweaks were needed for s390 which was returning early from
the funtion to avoid sloppy register definedness initialisation.

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

NEWS
coregrind/m_initimg/initimg-linux.c
memcheck/tests/dw4.stderr.exp

diff --git a/NEWS b/NEWS
index 2a61168449ee81a0ec883df7f15cb4f21fadcf6a..71e0755f69117d34efbc9997d367be42ad32c78f 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -108,6 +108,7 @@ where XXXXXX is the bug number as listed below.
 342353  Allow dumping full massif output while valgrind is still running
 342603  Add I2C_SMBUS ioctl support
 342635  OS X 10.10 (Yosemite) - missing system calls and fcntl code
+342683  Mark memory past the initial brk limit as unaddressable
 342795  Internal glibc __GI_mempcpy call should be intercepted
 343012  Unhandled syscall 319 (memfd_create)
 343069  Patch updating v4l2 API support
index 868325bd2dcfa20ccbec70e9308fc8e21f720595..64b404fe7dabe3fbf57eaed9bd75b02bbc6a30f8 100644 (file)
@@ -1143,7 +1143,12 @@ void VG_(ii_finalise_image)( IIFinaliseImageInfo iifii )
    VG_TRACK(post_reg_write, Vg_CoreStartup, /*tid*/1, VG_O_STACK_PTR, 8);
    VG_TRACK(post_reg_write, Vg_CoreStartup, /*tid*/1, VG_O_FPC_REG,   4);
    VG_TRACK(post_reg_write, Vg_CoreStartup, /*tid*/1, VG_O_INSTR_PTR, 8);
-   return;
+
+   /* At the end of this function there is code to mark all guest state
+      registers as defined. For s390 that would be wrong, because the ABI
+      says that all registers except SP, IA, and FPC are undefined upon
+      process startup. */
+#define PRECISE_GUEST_REG_DEFINEDNESS_AT_STARTUP 1
 
 #  elif defined(VGP_mips32_linux)
    vg_assert(0 == sizeof(VexGuestMIPS32State) % 16);
@@ -1192,9 +1197,20 @@ void VG_(ii_finalise_image)( IIFinaliseImageInfo iifii )
 #    error Unknown platform
 #  endif
 
+#  if !defined(PRECISE_GUEST_REG_DEFINEDNESS_AT_STARTUP)
    /* Tell the tool that we just wrote to the registers. */
    VG_TRACK( post_reg_write, Vg_CoreStartup, /*tid*/1, /*offset*/0,
              sizeof(VexGuestArchState));
+#  endif
+
+   /* Tell the tool about the client data segment and then kill it which will
+      make it inaccessible/unaddressable. */
+   const NSegment *seg = VG_(am_find_nsegment)(VG_(brk_base));
+   vg_assert(seg);
+   vg_assert(seg->kind == SkAnonC);
+   VG_TRACK(new_mem_brk, VG_(brk_base), seg->end + 1 - VG_(brk_base),
+            1/*tid*/);
+   VG_TRACK(die_mem_brk, VG_(brk_base), seg->end + 1 - VG_(brk_base));
 }
 
 #endif // defined(VGO_linux)
index e396a43b8ab3a240a8cf9e5f6ea0fcf6fe419d8c..917dcb57e3182e85dcd1e10cfd197037b0a47adf 100644 (file)
@@ -27,8 +27,8 @@ Uninitialised byte(s) found during client check request
    by 0x........: main (dw4.c:82)
  Address 0x........ is in a rw- mapped file valgrind-dw4-test.PID segment
 
-Uninitialised byte(s) found during client check request
-   at 0x........: croak (dw4.c:32)
+Unaddressable byte(s) found during client check request
+   at 0x........: croak (dw4.c:25)
    by 0x........: main (dw4.c:87)
  Address 0x........ is 0 bytes after the brk data segment limit 0x........