Commit 768a4a36a444ef5aef1f103adf42553eadfe4614
1 parent
0d3267a7
Fix userland ELF loader for zero sized BSS.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2244 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
1 changed file
with
6 additions
and
3 deletions
linux-user/elfload.c
| ... | ... | @@ -553,10 +553,13 @@ static void set_brk(unsigned long start, unsigned long end) |
| 553 | 553 | /* We need to explicitly zero any fractional pages after the data |
| 554 | 554 | section (i.e. bss). This would contain the junk from the file that |
| 555 | 555 | should not be in memory. */ |
| 556 | -static void padzero(unsigned long elf_bss) | |
| 556 | +static void padzero(unsigned long elf_bss, unsigned long last_bss) | |
| 557 | 557 | { |
| 558 | 558 | unsigned long nbyte; |
| 559 | 559 | |
| 560 | + if (elf_bss >= last_bss) | |
| 561 | + return; | |
| 562 | + | |
| 560 | 563 | /* XXX: this is really a hack : if the real host page size is |
| 561 | 564 | smaller than the target page size, some pages after the end |
| 562 | 565 | of the file may not be mapped. A better fix would be to |
| ... | ... | @@ -798,7 +801,7 @@ static unsigned long load_elf_interp(struct elfhdr * interp_elf_ex, |
| 798 | 801 | * that there are zeromapped pages up to and including the last |
| 799 | 802 | * bss page. |
| 800 | 803 | */ |
| 801 | - padzero(elf_bss); | |
| 804 | + padzero(elf_bss, last_bss); | |
| 802 | 805 | elf_bss = TARGET_ELF_PAGESTART(elf_bss + qemu_host_page_size - 1); /* What we have mapped so far */ |
| 803 | 806 | |
| 804 | 807 | /* Map the last of the bss segment */ |
| ... | ... | @@ -1227,7 +1230,7 @@ int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs, |
| 1227 | 1230 | sections */ |
| 1228 | 1231 | set_brk(elf_bss, elf_brk); |
| 1229 | 1232 | |
| 1230 | - padzero(elf_bss); | |
| 1233 | + padzero(elf_bss, elf_brk); | |
| 1231 | 1234 | |
| 1232 | 1235 | #if 0 |
| 1233 | 1236 | printf("(start_brk) %x\n" , info->start_brk); | ... | ... |