Commit 2a1094cd88afa69c0e7ecd1e81c712cc8f635153
1 parent
080a0ba4
bFLT loader alignment fix.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2669 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
1 changed file
with
11 additions
and
8 deletions
linux-user/flatload.c
| @@ -393,6 +393,7 @@ static int load_flat_file(struct linux_binprm * bprm, | @@ -393,6 +393,7 @@ static int load_flat_file(struct linux_binprm * bprm, | ||
| 393 | int i, rev, relocs = 0; | 393 | int i, rev, relocs = 0; |
| 394 | target_ulong fpos; | 394 | target_ulong fpos; |
| 395 | target_ulong start_code, end_code; | 395 | target_ulong start_code, end_code; |
| 396 | + target_ulong indx_len; | ||
| 396 | 397 | ||
| 397 | hdr = ((struct flat_hdr *) bprm->buf); /* exec-header */ | 398 | hdr = ((struct flat_hdr *) bprm->buf); /* exec-header */ |
| 398 | 399 | ||
| @@ -443,6 +444,11 @@ static int load_flat_file(struct linux_binprm * bprm, | @@ -443,6 +444,11 @@ static int load_flat_file(struct linux_binprm * bprm, | ||
| 443 | if (extra < bss_len + stack_len) | 444 | if (extra < bss_len + stack_len) |
| 444 | extra = bss_len + stack_len; | 445 | extra = bss_len + stack_len; |
| 445 | 446 | ||
| 447 | + /* Add space for library base pointers. Make sure this does not | ||
| 448 | + misalign the doesn't misalign the data segment. */ | ||
| 449 | + indx_len = MAX_SHARED_LIBS * sizeof(target_ulong); | ||
| 450 | + indx_len = (indx_len + 15) & ~(target_ulong)15; | ||
| 451 | + | ||
| 446 | /* | 452 | /* |
| 447 | * there are a couple of cases here, the separate code/data | 453 | * there are a couple of cases here, the separate code/data |
| 448 | * case, and then the fully copied to RAM case which lumps | 454 | * case, and then the fully copied to RAM case which lumps |
| @@ -462,8 +468,7 @@ static int load_flat_file(struct linux_binprm * bprm, | @@ -462,8 +468,7 @@ static int load_flat_file(struct linux_binprm * bprm, | ||
| 462 | return -1; | 468 | return -1; |
| 463 | } | 469 | } |
| 464 | 470 | ||
| 465 | - realdatastart = target_mmap(0, data_len + extra + | ||
| 466 | - MAX_SHARED_LIBS * sizeof(target_ulong), | 471 | + realdatastart = target_mmap(0, data_len + extra + indx_len, |
| 467 | PROT_READ|PROT_WRITE|PROT_EXEC, | 472 | PROT_READ|PROT_WRITE|PROT_EXEC, |
| 468 | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); | 473 | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); |
| 469 | 474 | ||
| @@ -471,7 +476,7 @@ static int load_flat_file(struct linux_binprm * bprm, | @@ -471,7 +476,7 @@ static int load_flat_file(struct linux_binprm * bprm, | ||
| 471 | fprintf(stderr, "Unable to allocate RAM for process data\n"); | 476 | fprintf(stderr, "Unable to allocate RAM for process data\n"); |
| 472 | return realdatastart; | 477 | return realdatastart; |
| 473 | } | 478 | } |
| 474 | - datapos = realdatastart + MAX_SHARED_LIBS * sizeof(target_ulong); | 479 | + datapos = realdatastart + indx_len; |
| 475 | 480 | ||
| 476 | DBG_FLT("BINFMT_FLAT: Allocated data+bss+stack (%d bytes): %x\n", | 481 | DBG_FLT("BINFMT_FLAT: Allocated data+bss+stack (%d bytes): %x\n", |
| 477 | (int)(data_len + bss_len + stack_len), (int)datapos); | 482 | (int)(data_len + bss_len + stack_len), (int)datapos); |
| @@ -498,8 +503,7 @@ static int load_flat_file(struct linux_binprm * bprm, | @@ -498,8 +503,7 @@ static int load_flat_file(struct linux_binprm * bprm, | ||
| 498 | 503 | ||
| 499 | } else { | 504 | } else { |
| 500 | 505 | ||
| 501 | - textpos = target_mmap(0, text_len + data_len + extra + | ||
| 502 | - MAX_SHARED_LIBS * sizeof(target_ulong), | 506 | + textpos = target_mmap(0, text_len + data_len + extra + indx_len, |
| 503 | PROT_READ | PROT_EXEC | PROT_WRITE, | 507 | PROT_READ | PROT_EXEC | PROT_WRITE, |
| 504 | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); | 508 | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); |
| 505 | if (textpos == -1 ) { | 509 | if (textpos == -1 ) { |
| @@ -508,9 +512,8 @@ static int load_flat_file(struct linux_binprm * bprm, | @@ -508,9 +512,8 @@ static int load_flat_file(struct linux_binprm * bprm, | ||
| 508 | } | 512 | } |
| 509 | 513 | ||
| 510 | realdatastart = textpos + ntohl(hdr->data_start); | 514 | realdatastart = textpos + ntohl(hdr->data_start); |
| 511 | - datapos = realdatastart + MAX_SHARED_LIBS * sizeof(target_ulong); | ||
| 512 | - reloc = (textpos + ntohl(hdr->reloc_start) + | ||
| 513 | - MAX_SHARED_LIBS * sizeof(target_ulong)); | 515 | + datapos = realdatastart + indx_len; |
| 516 | + reloc = (textpos + ntohl(hdr->reloc_start) + indx_len); | ||
| 514 | memp = textpos; | 517 | memp = textpos; |
| 515 | 518 | ||
| 516 | #ifdef CONFIG_BINFMT_ZFLAT | 519 | #ifdef CONFIG_BINFMT_ZFLAT |