140 |
#ifdef BFD |
#ifdef BFD |
141 |
asection *const sec = section; |
asection *const sec = section; |
142 |
#endif |
#endif |
143 |
const Elf32_Phdr *const ph = section; |
const ElfW(Phdr) *const ph = section; |
144 |
|
|
145 |
if (u->error) |
if (u->error) |
146 |
return; |
return; |
843 |
static void |
static void |
844 |
check_elf (struct execdata *e) |
check_elf (struct execdata *e) |
845 |
{ |
{ |
846 |
Elf32_Ehdr *ehdr = map (e, 0, sizeof (Elf32_Ehdr)); |
ElfW(Ehdr) *ehdr = map (e, 0, sizeof (ElfW(Ehdr))); |
847 |
Elf32_Phdr *phdr; |
ElfW(Phdr) *phdr; |
848 |
|
|
849 |
if (! ehdr) |
if (! ehdr) |
850 |
{ |
{ |
853 |
return; |
return; |
854 |
} |
} |
855 |
|
|
856 |
if (*(Elf32_Word *) ehdr != ((union { Elf32_Word word; |
if (*(ElfW(Word) *) ehdr != ((union { ElfW(Word) word; |
857 |
unsigned char string[SELFMAG]; }) |
unsigned char string[SELFMAG]; }) |
858 |
{ string: ELFMAG }).word) |
{ string: ELFMAG }).word) |
859 |
{ |
{ |
866 |
ehdr->e_ident[EI_VERSION] != EV_CURRENT || |
ehdr->e_ident[EI_VERSION] != EV_CURRENT || |
867 |
ehdr->e_version != EV_CURRENT || |
ehdr->e_version != EV_CURRENT || |
868 |
ehdr->e_ehsize < sizeof *ehdr || |
ehdr->e_ehsize < sizeof *ehdr || |
869 |
ehdr->e_phentsize != sizeof (Elf32_Phdr)) |
ehdr->e_phentsize != sizeof (ElfW(Phdr))) |
870 |
{ |
{ |
871 |
e->error = ENOEXEC; |
e->error = ENOEXEC; |
872 |
return; |
return; |
883 |
e->info.elf.loadbase = 0; |
e->info.elf.loadbase = 0; |
884 |
e->info.elf.phnum = ehdr->e_phnum; |
e->info.elf.phnum = ehdr->e_phnum; |
885 |
|
|
886 |
phdr = map (e, ehdr->e_phoff, ehdr->e_phnum * sizeof (Elf32_Phdr)); |
phdr = map (e, ehdr->e_phoff, ehdr->e_phnum * sizeof (ElfW(Phdr))); |
887 |
if (! phdr) |
if (! phdr) |
888 |
{ |
{ |
889 |
if (!e->error) |
if (!e->error) |
896 |
/* Copy MAPPED_PHDR into E->info.elf.phdr, filling in |
/* Copy MAPPED_PHDR into E->info.elf.phdr, filling in |
897 |
E->interp.phdr, *PHDR_ADDR, and *PHDR_SIZE in the process. */ |
E->interp.phdr, *PHDR_ADDR, and *PHDR_SIZE in the process. */ |
898 |
static void |
static void |
899 |
check_elf_phdr (struct execdata *e, const Elf32_Phdr *mapped_phdr, |
check_elf_phdr (struct execdata *e, const ElfW(Phdr) *mapped_phdr, |
900 |
vm_address_t *phdr_addr, vm_size_t *phdr_size) |
vm_address_t *phdr_addr, vm_size_t *phdr_size) |
901 |
{ |
{ |
902 |
const Elf32_Phdr *phdr; |
const ElfW(Phdr) *phdr; |
903 |
|
|
904 |
memcpy (e->info.elf.phdr, mapped_phdr, |
memcpy (e->info.elf.phdr, mapped_phdr, |
905 |
e->info.elf.phnum * sizeof (Elf32_Phdr)); |
e->info.elf.phnum * sizeof (ElfW(Phdr))); |
906 |
|
|
907 |
for (phdr = e->info.elf.phdr; |
for (phdr = e->info.elf.phdr; |
908 |
phdr < &e->info.elf.phdr[e->info.elf.phnum]; |
phdr < &e->info.elf.phdr[e->info.elf.phnum]; |
1025 |
else |
else |
1026 |
#endif |
#endif |
1027 |
{ |
{ |
1028 |
Elf32_Word i; |
ElfW(Word) i; |
1029 |
for (i = 0; i < e->info.elf.phnum; ++i) |
for (i = 0; i < e->info.elf.phnum; ++i) |
1030 |
if (e->info.elf.phdr[i].p_type == PT_LOAD) |
if (e->info.elf.phdr[i].p_type == PT_LOAD) |
1031 |
load_section (&e->info.elf.phdr[i], e); |
load_section (&e->info.elf.phdr[i], e); |
1439 |
else |
else |
1440 |
#endif |
#endif |
1441 |
{ |
{ |
1442 |
const Elf32_Phdr *phdr = e.info.elf.phdr; |
const ElfW(Phdr) *phdr = e.info.elf.phdr; |
1443 |
e.info.elf.phdr = alloca (e.info.elf.phnum * sizeof (Elf32_Phdr)); |
e.info.elf.phdr = alloca (e.info.elf.phnum * sizeof (ElfW(Phdr))); |
1444 |
check_elf_phdr (&e, phdr, &phdr_addr, &phdr_size); |
check_elf_phdr (&e, phdr, &phdr_addr, &phdr_size); |
1445 |
} |
} |
1446 |
|
|
1722 |
else |
else |
1723 |
#endif |
#endif |
1724 |
{ |
{ |
1725 |
const Elf32_Phdr *phdr = interp.info.elf.phdr; |
const ElfW(Phdr) *phdr = interp.info.elf.phdr; |
1726 |
interp.info.elf.phdr = alloca (interp.info.elf.phnum * |
interp.info.elf.phdr = alloca (interp.info.elf.phnum * |
1727 |
sizeof (Elf32_Phdr)); |
sizeof (ElfW(Phdr))); |
1728 |
check_elf_phdr (&interp, phdr, NULL, NULL); |
check_elf_phdr (&interp, phdr, NULL, NULL); |
1729 |
} |
} |
1730 |
} |
} |