Skip to content

Commit

Permalink
linux-user: Fix initialization of the heap contents when allocating n…
Browse files Browse the repository at this point in the history
…ew pages

Technically the new mmapped pages are already initialized to zero
since they are anonymous, however we have to take care with the
contents that come from the remaining part of the previous page: it
may contains garbage data due to a previous heap usage (grown then
shrunken).

This patch completes commit 55f08c8.  The problem could be reproduced
when emulating the build process of Perl 5.12.3 on ARMedSlack 13.37:

    make[1]: Entering directory `/tmp/perl-5.12.3/cpan/Compress-Raw-Bzip2'
    cc -c  -I. -fno-strict-aliasing -pipe -fstack-protector                 \
           -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64  \
           -O2   -DVERSION=\"2.024\" -DXS_VERSION=\"2.024\" -fPIC "-I../.." \
           -DBZ_NO_STDIO  decompress.c
    decompress.c: In function 'BZ2_decompress':
    decompress.c:621:1: internal compiler error: Segmentation fault

Signed-off-by: Riku Voipio <[email protected]>
Signed-off-by: Laurent ALFONSI <[email protected]>
Signed-off-by: Cédric VINCENT <[email protected]>
  • Loading branch information
cedric-vincent authored and Riku Voipio committed Sep 9, 2011
1 parent 07ff2c4 commit 70afc34
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions linux-user/syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,15 @@ abi_long do_brk(abi_ulong new_brk)
MAP_ANON|MAP_PRIVATE, 0, 0));

if (mapped_addr == brk_page) {
/* Heap contents are initialized to zero, as for anonymous
* mapped pages. Technically the new pages are already
* initialized to zero since they *are* anonymous mapped
* pages, however we have to take care with the contents that
* come from the remaining part of the previous page: it may
* contains garbage data due to a previous heap usage (grown
* then shrunken). */
memset(g2h(target_brk), 0, brk_page - target_brk);

target_brk = new_brk;
brk_page = HOST_PAGE_ALIGN(target_brk);
DEBUGF_BRK("%#010x (mapped_addr == brk_page)\n", target_brk);
Expand Down

0 comments on commit 70afc34

Please sign in to comment.