Revision 992f48a0 linux-user/flatload.c
b/linux-user/flatload.c | ||
---|---|---|
63 | 63 |
#define UNLOADED_LIB 0x7ff000ff /* Placeholder for unused library */ |
64 | 64 |
|
65 | 65 |
struct lib_info { |
66 |
target_ulong start_code; /* Start of text segment */
|
|
67 |
target_ulong start_data; /* Start of data segment */
|
|
68 |
target_ulong end_data; /* Start of bss section */
|
|
69 |
target_ulong start_brk; /* End of data segment */
|
|
70 |
target_ulong text_len; /* Length of text segment */
|
|
71 |
target_ulong entry; /* Start address for this module */
|
|
72 |
target_ulong build_date; /* When this one was compiled */
|
|
66 |
abi_ulong start_code; /* Start of text segment */
|
|
67 |
abi_ulong start_data; /* Start of data segment */
|
|
68 |
abi_ulong end_data; /* Start of bss section */
|
|
69 |
abi_ulong start_brk; /* End of data segment */
|
|
70 |
abi_ulong text_len; /* Length of text segment */
|
|
71 |
abi_ulong entry; /* Start address for this module */
|
|
72 |
abi_ulong build_date; /* When this one was compiled */
|
|
73 | 73 |
short loaded; /* Has this library been loaded? */ |
74 | 74 |
}; |
75 | 75 |
|
... | ... | |
89 | 89 |
*/ |
90 | 90 |
|
91 | 91 |
/* Push a block of strings onto the guest stack. */ |
92 |
static target_ulong copy_strings(target_ulong p, int n, char **s)
|
|
92 |
static abi_ulong copy_strings(abi_ulong p, int n, char **s)
|
|
93 | 93 |
{ |
94 | 94 |
int len; |
95 | 95 |
|
... | ... | |
102 | 102 |
return p; |
103 | 103 |
} |
104 | 104 |
|
105 |
int target_pread(int fd, target_ulong ptr, target_ulong len,
|
|
106 |
target_ulong offset)
|
|
105 |
int target_pread(int fd, abi_ulong ptr, abi_ulong len,
|
|
106 |
abi_ulong offset)
|
|
107 | 107 |
{ |
108 | 108 |
void *buf; |
109 | 109 |
int ret; |
... | ... | |
262 | 262 |
|
263 | 263 |
/****************************************************************************/ |
264 | 264 |
|
265 |
static target_ulong
|
|
266 |
calc_reloc(target_ulong r, struct lib_info *p, int curid, int internalp)
|
|
265 |
static abi_ulong
|
|
266 |
calc_reloc(abi_ulong r, struct lib_info *p, int curid, int internalp)
|
|
267 | 267 |
{ |
268 |
target_ulong addr;
|
|
268 |
abi_ulong addr;
|
|
269 | 269 |
int id; |
270 |
target_ulong start_brk;
|
|
271 |
target_ulong start_data;
|
|
272 |
target_ulong text_len;
|
|
273 |
target_ulong start_code;
|
|
270 |
abi_ulong start_brk;
|
|
271 |
abi_ulong start_data;
|
|
272 |
abi_ulong text_len;
|
|
273 |
abi_ulong start_code;
|
|
274 | 274 |
|
275 | 275 |
#ifdef CONFIG_BINFMT_SHARED_FLAT |
276 | 276 |
#error needs checking |
... | ... | |
381 | 381 |
/****************************************************************************/ |
382 | 382 |
|
383 | 383 |
static int load_flat_file(struct linux_binprm * bprm, |
384 |
struct lib_info *libinfo, int id, target_ulong *extra_stack)
|
|
384 |
struct lib_info *libinfo, int id, abi_ulong *extra_stack)
|
|
385 | 385 |
{ |
386 | 386 |
struct flat_hdr * hdr; |
387 |
target_ulong textpos = 0, datapos = 0, result;
|
|
388 |
target_ulong realdatastart = 0;
|
|
389 |
target_ulong text_len, data_len, bss_len, stack_len, flags;
|
|
390 |
target_ulong memp = 0; /* for finding the brk area */
|
|
391 |
target_ulong extra;
|
|
392 |
target_ulong reloc = 0, rp;
|
|
387 |
abi_ulong textpos = 0, datapos = 0, result;
|
|
388 |
abi_ulong realdatastart = 0;
|
|
389 |
abi_ulong text_len, data_len, bss_len, stack_len, flags;
|
|
390 |
abi_ulong memp = 0; /* for finding the brk area */
|
|
391 |
abi_ulong extra;
|
|
392 |
abi_ulong reloc = 0, rp;
|
|
393 | 393 |
int i, rev, relocs = 0; |
394 |
target_ulong fpos;
|
|
395 |
target_ulong start_code, end_code;
|
|
396 |
target_ulong indx_len;
|
|
394 |
abi_ulong fpos;
|
|
395 |
abi_ulong start_code, end_code;
|
|
396 |
abi_ulong indx_len;
|
|
397 | 397 |
|
398 | 398 |
hdr = ((struct flat_hdr *) bprm->buf); /* exec-header */ |
399 | 399 |
|
... | ... | |
440 | 440 |
/* |
441 | 441 |
* calculate the extra space we need to map in |
442 | 442 |
*/ |
443 |
extra = relocs * sizeof(target_ulong);
|
|
443 |
extra = relocs * sizeof(abi_ulong);
|
|
444 | 444 |
if (extra < bss_len + stack_len) |
445 | 445 |
extra = bss_len + stack_len; |
446 | 446 |
|
447 | 447 |
/* Add space for library base pointers. Make sure this does not |
448 | 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;
|
|
449 |
indx_len = MAX_SHARED_LIBS * sizeof(abi_ulong);
|
|
450 |
indx_len = (indx_len + 15) & ~(abi_ulong)15;
|
|
451 | 451 |
|
452 | 452 |
/* |
453 | 453 |
* there are a couple of cases here, the separate code/data |
... | ... | |
485 | 485 |
#ifdef CONFIG_BINFMT_ZFLAT |
486 | 486 |
if (flags & FLAT_FLAG_GZDATA) { |
487 | 487 |
result = decompress_exec(bprm, fpos, (char *) datapos, |
488 |
data_len + (relocs * sizeof(target_ulong)))
|
|
488 |
data_len + (relocs * sizeof(abi_ulong)))
|
|
489 | 489 |
} else |
490 | 490 |
#endif |
491 | 491 |
{ |
492 | 492 |
result = target_pread(bprm->fd, datapos, |
493 |
data_len + (relocs * sizeof(target_ulong)),
|
|
493 |
data_len + (relocs * sizeof(abi_ulong)),
|
|
494 | 494 |
fpos); |
495 | 495 |
} |
496 | 496 |
if (result < 0) { |
... | ... | |
544 | 544 |
text_len, 0); |
545 | 545 |
if (result >= 0) { |
546 | 546 |
result = target_pread(bprm->fd, datapos, |
547 |
data_len + (relocs * sizeof(target_ulong)),
|
|
547 |
data_len + (relocs * sizeof(abi_ulong)),
|
|
548 | 548 |
ntohl(hdr->data_start)); |
549 | 549 |
} |
550 | 550 |
} |
... | ... | |
597 | 597 |
if (flags & FLAT_FLAG_GOTPIC) { |
598 | 598 |
rp = datapos; |
599 | 599 |
while (1) { |
600 |
target_ulong addr;
|
|
600 |
abi_ulong addr;
|
|
601 | 601 |
addr = tgetl(rp); |
602 | 602 |
if (addr == -1) |
603 | 603 |
break; |
... | ... | |
607 | 607 |
return -ENOEXEC; |
608 | 608 |
tputl(rp, addr); |
609 | 609 |
} |
610 |
rp += sizeof(target_ulong);
|
|
610 |
rp += sizeof(abi_ulong);
|
|
611 | 611 |
} |
612 | 612 |
} |
613 | 613 |
|
... | ... | |
624 | 624 |
*/ |
625 | 625 |
if (rev > OLD_FLAT_VERSION) { |
626 | 626 |
for (i = 0; i < relocs; i++) { |
627 |
target_ulong addr, relval;
|
|
627 |
abi_ulong addr, relval;
|
|
628 | 628 |
|
629 | 629 |
/* Get the address of the pointer to be |
630 | 630 |
relocated (of course, the address has to be |
631 | 631 |
relocated first). */ |
632 |
relval = tgetl(reloc + i * sizeof (target_ulong));
|
|
632 |
relval = tgetl(reloc + i * sizeof (abi_ulong));
|
|
633 | 633 |
addr = flat_get_relocate_addr(relval); |
634 | 634 |
rp = calc_reloc(addr, libinfo, id, 1); |
635 | 635 |
if (rp == RELOC_FAILED) |
... | ... | |
657 | 657 |
} |
658 | 658 |
} else { |
659 | 659 |
for (i = 0; i < relocs; i++) { |
660 |
target_ulong relval;
|
|
661 |
relval = tgetl(reloc + i * sizeof (target_ulong));
|
|
660 |
abi_ulong relval;
|
|
661 |
relval = tgetl(reloc + i * sizeof (abi_ulong));
|
|
662 | 662 |
old_reloc(&libinfo[0], relval); |
663 | 663 |
} |
664 | 664 |
} |
... | ... | |
712 | 712 |
struct image_info * info) |
713 | 713 |
{ |
714 | 714 |
struct lib_info libinfo[MAX_SHARED_LIBS]; |
715 |
target_ulong p = bprm->p;
|
|
716 |
target_ulong stack_len;
|
|
717 |
target_ulong start_addr;
|
|
718 |
target_ulong sp;
|
|
715 |
abi_ulong p = bprm->p;
|
|
716 |
abi_ulong stack_len;
|
|
717 |
abi_ulong start_addr;
|
|
718 |
abi_ulong sp;
|
|
719 | 719 |
int res; |
720 | 720 |
int i, j; |
721 | 721 |
|
... | ... | |
740 | 740 |
/* Update data segment pointers for all libraries */ |
741 | 741 |
for (i=0; i<MAX_SHARED_LIBS; i++) { |
742 | 742 |
if (libinfo[i].loaded) { |
743 |
target_ulong p;
|
|
743 |
abi_ulong p;
|
|
744 | 744 |
p = libinfo[i].start_data; |
745 | 745 |
for (j=0; j<MAX_SHARED_LIBS; j++) { |
746 | 746 |
p -= 4; |
... | ... | |
758 | 758 |
p = copy_strings(p, bprm->envc, bprm->envp); |
759 | 759 |
p = copy_strings(p, bprm->argc, bprm->argv); |
760 | 760 |
/* Align stack. */ |
761 |
sp = p & ~(target_ulong)(sizeof(target_ulong) - 1);
|
|
761 |
sp = p & ~(abi_ulong)(sizeof(abi_ulong) - 1);
|
|
762 | 762 |
/* Enforce final stack alignment of 16 bytes. This is sufficient |
763 | 763 |
for all current targets, and excess alignment is harmless. */ |
764 | 764 |
stack_len = bprm->envc + bprm->argc + 2; |
765 | 765 |
stack_len += 3; /* argc, arvg, argp */ |
766 |
stack_len *= sizeof(target_ulong);
|
|
766 |
stack_len *= sizeof(abi_ulong);
|
|
767 | 767 |
if ((sp + stack_len) & 15) |
768 | 768 |
sp -= 16 - ((sp + stack_len) & 15); |
769 | 769 |
sp = loader_build_argptr(bprm->envc, bprm->argc, sp, p, 1); |
Also available in: Unified diff