]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Add a note about our suspect handling of brk(). And disable the brk() part
authorNicholas Nethercote <njn@valgrind.org>
Fri, 24 Jul 2009 19:09:52 +0000 (19:09 +0000)
committerNicholas Nethercote <njn@valgrind.org>
Fri, 24 Jul 2009 19:09:52 +0000 (19:09 +0000)
of origin1-yes.c, because it's a pain, giving different results on different
systems.  This allowed origin1-yes.stderr.exp-darwin to be removed.

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

memcheck/mc_main.c
memcheck/tests/Makefile.am
memcheck/tests/origin1-yes.c
memcheck/tests/origin1-yes.stderr.exp
memcheck/tests/origin1-yes.stderr.exp-darwin [deleted file]

index d14b80b14f4307bbcbd0e732ba67efc81aefcd2b..4882f3b43fd28cfc80d83ddef21d5cc2279f1181 100644 (file)
@@ -5735,6 +5735,50 @@ static void mc_pre_clo_init(void)
 
    VG_(track_new_mem_startup)     ( mc_new_mem_startup );
    VG_(track_new_mem_stack_signal)( make_mem_undefined_w_tid );
+   // We assume that brk()/sbrk() does not initialise new memory.  Is this
+   // accurate?  John Reiser says:
+   //
+   //   0) sbrk() can *decrease* process address space.  No zero fill is done
+   //   for a decrease, not even the fragment on the high end of the last page
+   //   that is beyond the new highest address.  For maximum safety and
+   //   portability, then the bytes in the last page that reside above [the
+   //   new] sbrk(0) should be considered to be uninitialized, but in practice
+   //   it is exceedingly likely that they will retain their previous
+   //   contents.
+   //
+   //   1) If an increase is large enough to require new whole pages, then
+   //   those new whole pages (like all new pages) are zero-filled by the
+   //   operating system.  So if sbrk(0) already is page aligned, then
+   //   sbrk(PAGE_SIZE) *does* zero-fill the new memory.
+   //
+   //   2) Any increase that lies within an existing allocated page is not
+   //   changed.  So if (x = sbrk(0)) is not page aligned, then
+   //   sbrk(PAGE_SIZE) yields ((PAGE_SIZE -1) & -x) bytes which keep their
+   //   existing contents, and an additional PAGE_SIZE bytes which are zeroed.
+   //   ((PAGE_SIZE -1) & x) of them are "covered" by the sbrk(), and the rest
+   //   of them come along for the ride because the operating system deals
+   //   only in whole pages.  Again, for maximum safety and portability, then
+   //   anything that lives above [the new] sbrk(0) should be considered
+   //   uninitialized, but in practice will retain previous contents [zero in
+   //   this case.]"
+   //
+   // In short: 
+   //
+   //   A key property of sbrk/brk is that new whole pages that are supplied
+   //   by the operating system *do* get initialized to zero.
+   //
+   // As for the portability of all this:
+   //
+   //   sbrk and brk are not POSIX.  However, any system that is a derivative
+   //   of *nix has sbrk and brk because there are too many softwares (such as
+   //   the Bourne shell) which rely on the traditional memory map (.text,
+   //   .data+.bss, stack) and the existence of sbrk/brk.
+   //
+   // So we should arguably observe all this.  However:
+   // - The current inaccuracy has caused maybe one complaint in seven years(?)
+   // - Telying on the zeroed-ness of whole brk'd pages is pretty grotty... I
+   //   doubt most programmers know the above information.
+   // So I'm not terribly unhappy with marking it as undefined. --njn.
    VG_(track_new_mem_brk)         ( make_mem_undefined_w_tid );
    VG_(track_new_mem_mmap)        ( mc_new_mem_mmap );
    
index 3d16a9573dafb91b2bb5b6e260dffef9ff6f1fb8..d12e483303d3d0f539c7844cb5025bbb766c152d 100644 (file)
@@ -111,8 +111,7 @@ EXTRA_DIST = \
        new_override.stderr.exp new_override.stdout.exp new_override.vgtest \
        noisy_child.vgtest noisy_child.stderr.exp noisy_child.stdout.exp \
        null_socket.stderr.exp null_socket.vgtest \
-       origin1-yes.vgtest origin1-yes.stdout.exp \
-           origin1-yes.stderr.exp origin1-yes.stderr.exp-darwin \
+       origin1-yes.vgtest origin1-yes.stdout.exp origin1-yes.stderr.exp \
        origin2-not-quite.vgtest origin2-not-quite.stdout.exp \
        origin2-not-quite.stderr.exp \
        origin3-no.vgtest origin3-no.stdout.exp \
index 3ebe6f0f4112425a422096b1deb8081ebbbe3cf4..79e351eca3ecd991bf53d0e73d092fa35a4317cd 100644 (file)
@@ -86,21 +86,28 @@ int main(void)
    }
 
    // Heap segment (brk), uninitialised
-   // Nb: on Darwin, sbrk() is implemented via vm_allocate() which always
-   // zeroes its allocated memory.  So we use a separate .exp file for Darwin,
-   // but we add an extra printf on Darwin only so that it cannot be
-   // successfully matched on non-Darwin platforms.
-#if defined(VGO_darwin)
+   // CURRENTLY DISABLED.  Why?
+   // - On Darwin, sbrk() is implemented via vm_allocate() which always zeroes
+   //   its allocated memory.  For a while we used use a separate .exp file
+   //   for Darwin, but we add an extra printf on Darwin only so that it
+   //   cannot be successfully matched on non-Darwin platforms.
+   // - On Ubuntu 9.04 configured with --enable-only32bit, the brk symbol
+   //   shows up as "???"
+   // - Our current treatment of brk is suspect;  whole new pages allocated
+   //   with brk should arguably be marked defined -- see the big comment
+   //   above track_new_mem_brk() in memcheck/mc_main.c.
+//#if defined(VGO_darwin)
       fprintf(stderr, "\nUndef 7 of 8 (brk)\n");
-      fprintf(stderr, "\n(no complaint; sbrk initialises memory on Darwin)\n");
-#else
-   {
-      int* ptr_to_new_brk_limit = sbrk(4096);
-      int  undef_brk_int = *ptr_to_new_brk_limit;
-      fprintf(stderr, "\nUndef 7 of 8 (brk)\n");
-      x += (undef_brk_int == 0x12345678 ? 15 : 26);
-   }
-#endif
+//      fprintf(stderr, "\n(no complaint; sbrk initialises memory on Darwin)\n");
+      fprintf(stderr, "\n(currently disabled)\n");
+//#else
+//   {
+//      int* ptr_to_new_brk_limit = sbrk(4096);
+//      int  undef_brk_int = *ptr_to_new_brk_limit;
+//      fprintf(stderr, "\nUndef 7 of 8 (brk)\n");
+//      x += (undef_brk_int == 0x12345678 ? 15 : 26);
+//   }
+//#endif
 
    // User block, marked as undefined
    {
index e2af1abdca7ba3fd4a0da95ea56ff686bf7c743e..2015d5361ec6f0f872a8c7a589983bbad80ecf4e 100644 (file)
@@ -44,19 +44,14 @@ Conditional jump or move depends on uninitialised value(s)
 
 Undef 7 of 8 (brk)
 
-Conditional jump or move depends on uninitialised value(s)
-   at 0x........: main (origin1-yes.c:101)
- Uninitialised value was created
-   at 0x........: brk (in /...libc...)
-   by 0x........: sbrk (in /...libc...)
-   by 0x........: main (origin1-yes.c:98)
+(currently disabled)
 
 Undef 8 of 8 (MAKE_MEM_UNDEFINED)
 
 Conditional jump or move depends on uninitialised value(s)
-   at 0x........: main (origin1-yes.c:110)
+   at 0x........: main (origin1-yes.c:117)
  Uninitialised value was created by a client request
-   at 0x........: main (origin1-yes.c:108)
+   at 0x........: main (origin1-yes.c:115)
 
 Def 1 of 3
 
diff --git a/memcheck/tests/origin1-yes.stderr.exp-darwin b/memcheck/tests/origin1-yes.stderr.exp-darwin
deleted file mode 100644 (file)
index add1a37..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-
-Undef 1 of 8 (stack, 32 bit)
-Conditional jump or move depends on uninitialised value(s)
-   at 0x........: main (origin1-yes.c:37)
- Uninitialised value was created by a stack allocation
-   at 0x........: main (origin1-yes.c:23)
-
-Undef 2 of 8 (stack, 32 bit)
-
-Conditional jump or move depends on uninitialised value(s)
-   at 0x........: main (origin1-yes.c:49)
- Uninitialised value was created by a stack allocation
-   at 0x........: main (origin1-yes.c:23)
-
-Undef 3 of 8 (stack, 64 bit)
-
-Conditional jump or move depends on uninitialised value(s)
-   at 0x........: main (origin1-yes.c:56)
- Uninitialised value was created by a stack allocation
-   at 0x........: main (origin1-yes.c:23)
-
-Undef 4 of 8 (mallocd, 32-bit)
-
-Conditional jump or move depends on uninitialised value(s)
-   at 0x........: main (origin1-yes.c:64)
- Uninitialised value was created by a heap allocation
-   at 0x........: malloc (vg_replace_malloc.c:...)
-   by 0x........: main (origin1-yes.c:61)
-
-Undef 5 of 8 (realloc)
-
-Conditional jump or move depends on uninitialised value(s)
-   at 0x........: main (origin1-yes.c:76)
- Uninitialised value was created by a heap allocation
-   at 0x........: realloc (vg_replace_malloc.c:...)
-   by 0x........: main (origin1-yes.c:71)
-
-Undef 6 of 8 (MALLOCLIKE_BLOCK)
-
-Conditional jump or move depends on uninitialised value(s)
-   at 0x........: main (origin1-yes.c:85)
- Uninitialised value was created by a heap allocation
-   at 0x........: main (origin1-yes.c:82)
-
-Undef 7 of 8 (brk)
-
-(no complaint; sbrk initialises memory on Darwin)
-
-Undef 8 of 8 (MAKE_MEM_UNDEFINED)
-
-Conditional jump or move depends on uninitialised value(s)
-   at 0x........: main (origin1-yes.c:110)
- Uninitialised value was created by a client request
-   at 0x........: main (origin1-yes.c:108)
-
-Def 1 of 3
-
-Def 2 of 3
-
-Def 3 of 3