15
/* from personality.h */
18
* Flags for bug emulation.
20
* These occupy the top three bytes.
23
ADDR_NO_RANDOMIZE = 0x0040000, /* disable randomization of VA space */
24
FDPIC_FUNCPTRS = 0x0080000, /* userspace function ptrs point to descriptors
27
MMAP_PAGE_ZERO = 0x0100000,
28
ADDR_COMPAT_LAYOUT = 0x0200000,
29
READ_IMPLIES_EXEC = 0x0400000,
30
ADDR_LIMIT_32BIT = 0x0800000,
31
SHORT_INODE = 0x1000000,
32
WHOLE_SECONDS = 0x2000000,
33
STICKY_TIMEOUTS = 0x4000000,
34
ADDR_LIMIT_3GB = 0x8000000,
40
* These go in the low byte. Avoid using the top bit, it will
41
* conflict with error returns.
45
PER_LINUX_32BIT = 0x0000 | ADDR_LIMIT_32BIT,
46
PER_LINUX_FDPIC = 0x0000 | FDPIC_FUNCPTRS,
47
PER_SVR4 = 0x0001 | STICKY_TIMEOUTS | MMAP_PAGE_ZERO,
48
PER_SVR3 = 0x0002 | STICKY_TIMEOUTS | SHORT_INODE,
49
PER_SCOSVR3 = 0x0003 | STICKY_TIMEOUTS |
50
WHOLE_SECONDS | SHORT_INODE,
51
PER_OSR5 = 0x0003 | STICKY_TIMEOUTS | WHOLE_SECONDS,
52
PER_WYSEV386 = 0x0004 | STICKY_TIMEOUTS | SHORT_INODE,
53
PER_ISCR4 = 0x0005 | STICKY_TIMEOUTS,
55
PER_SUNOS = 0x0006 | STICKY_TIMEOUTS,
56
PER_XENIX = 0x0007 | STICKY_TIMEOUTS | SHORT_INODE,
58
PER_LINUX32_3GB = 0x0008 | ADDR_LIMIT_3GB,
59
PER_IRIX32 = 0x0009 | STICKY_TIMEOUTS,/* IRIX5 32-bit */
60
PER_IRIXN32 = 0x000a | STICKY_TIMEOUTS,/* IRIX6 new 32-bit */
61
PER_IRIX64 = 0x000b | STICKY_TIMEOUTS,/* IRIX6 64-bit */
63
PER_SOLARIS = 0x000d | STICKY_TIMEOUTS,
64
PER_UW7 = 0x000e | STICKY_TIMEOUTS | MMAP_PAGE_ZERO,
65
PER_OSF4 = 0x000f, /* OSF/1 v4 */
71
* Return the base personality without flags.
73
#define personality(pers) (pers & PER_MASK)
75
/* this flag is uneffective under linux too, should be deleted */
77
#define MAP_DENYWRITE 0
80
/* should probably go in elf.h */
87
#define ELF_PLATFORM get_elf_platform()
89
static const char *get_elf_platform(void)
91
static char elf_platform[] = "i386";
92
int family = (global_env->cpuid_version >> 8) & 0xff;
96
elf_platform[1] = '0' + family;
100
#define ELF_HWCAP get_elf_hwcap()
102
static uint32_t get_elf_hwcap(void)
104
return global_env->cpuid_features;
108
#define ELF_START_MMAP 0x2aaaaab000ULL
109
#define elf_check_arch(x) ( ((x) == ELF_ARCH) )
111
#define ELF_CLASS ELFCLASS64
112
#define ELF_DATA ELFDATA2LSB
113
#define ELF_ARCH EM_X86_64
115
static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop)
118
regs->rsp = infop->start_stack;
119
regs->rip = infop->entry;
18
124
#define ELF_START_MMAP 0x80000000
29
135
#define ELF_DATA ELFDATA2LSB
30
136
#define ELF_ARCH EM_386
32
/* SVR4/i386 ABI (pages 3-31, 3-32) says that when the program
33
starts %edx contains a pointer to a function which might be
34
registered using `atexit'. This provides a mean for the
35
dynamic linker to call DT_FINI functions for shared libraries
36
that have been loaded before the code runs.
38
A value of 0 tells we have no such handler. */
39
#define ELF_PLAT_INIT(_r) _r->edx = 0
41
138
static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop)
43
140
regs->esp = infop->start_stack;
44
141
regs->eip = infop->entry;
143
/* SVR4/i386 ABI (pages 3-31, 3-32) says that when the program
144
starts %edx contains a pointer to a function which might be
145
registered using `atexit'. This provides a mean for the
146
dynamic linker to call DT_FINI functions for shared libraries
147
that have been loaded before the code runs.
149
A value of 0 tells we have no such handler. */
47
154
#define USE_ELF_CORE_DUMP
48
155
#define ELF_EXEC_PAGESIZE 4096
64
171
#define ELF_ARCH EM_ARM
66
#define ELF_PLAT_INIT(_r) _r->ARM_r0 = 0
68
173
static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop)
70
target_long *stack = (void *)infop->start_stack;
175
abi_long stack = infop->start_stack;
71
176
memset(regs, 0, sizeof(*regs));
72
177
regs->ARM_cpsr = 0x10;
73
regs->ARM_pc = infop->entry;
178
if (infop->entry & 1)
179
regs->ARM_cpsr |= CPSR_T;
180
regs->ARM_pc = infop->entry & 0xfffffffe;
74
181
regs->ARM_sp = infop->start_stack;
75
regs->ARM_r2 = tswapl(stack[2]); /* envp */
76
regs->ARM_r1 = tswapl(stack[1]); /* argv */
182
/* FIXME - what to for failure of get_user()? */
183
get_user_ual(regs->ARM_r2, stack + 8); /* envp */
184
get_user_ual(regs->ARM_r1, stack + 4); /* envp */
77
185
/* XXX: it seems that r0 is zeroed after ! */
78
// regs->ARM_r0 = tswapl(stack[0]); /* argc */
187
/* For uClinux PIC binaries. */
188
/* XXX: Linux does this only on ARM with no MMU (do we care ?) */
189
regs->ARM_r10 = infop->start_data;
81
192
#define USE_ELF_CORE_DUMP
82
193
#define ELF_EXEC_PAGESIZE 4096
197
ARM_HWCAP_ARM_SWP = 1 << 0,
198
ARM_HWCAP_ARM_HALF = 1 << 1,
199
ARM_HWCAP_ARM_THUMB = 1 << 2,
200
ARM_HWCAP_ARM_26BIT = 1 << 3,
201
ARM_HWCAP_ARM_FAST_MULT = 1 << 4,
202
ARM_HWCAP_ARM_FPA = 1 << 5,
203
ARM_HWCAP_ARM_VFP = 1 << 6,
204
ARM_HWCAP_ARM_EDSP = 1 << 7,
207
#define ELF_HWCAP (ARM_HWCAP_ARM_SWP | ARM_HWCAP_ARM_HALF \
208
| ARM_HWCAP_ARM_THUMB | ARM_HWCAP_ARM_FAST_MULT \
209
| ARM_HWCAP_ARM_FPA | ARM_HWCAP_ARM_VFP)
86
213
#ifdef TARGET_SPARC
214
#ifdef TARGET_SPARC64
216
#define ELF_START_MMAP 0x80000000
219
#define elf_check_arch(x) ( (x) == EM_SPARCV9 || (x) == EM_SPARC32PLUS )
221
#define elf_check_arch(x) ( (x) == EM_SPARC32PLUS || (x) == EM_SPARC )
224
#define ELF_CLASS ELFCLASS64
225
#define ELF_DATA ELFDATA2MSB
226
#define ELF_ARCH EM_SPARCV9
228
#define STACK_BIAS 2047
230
static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop)
235
regs->pc = infop->entry;
236
regs->npc = regs->pc + 4;
239
regs->u_regs[14] = infop->start_stack - 16 * 4;
241
if (personality(infop->personality) == PER_LINUX32)
242
regs->u_regs[14] = infop->start_stack - 16 * 4;
244
regs->u_regs[14] = infop->start_stack - 16 * 8 - STACK_BIAS;
88
249
#define ELF_START_MMAP 0x80000000
90
251
#define elf_check_arch(x) ( (x) == EM_SPARC )
153
309
* - for compatibility with glibc ARCH_DLINFO must always be defined on PPC,
154
310
* even if DLINFO_ARCH_ITEMS goes to zero or is undefined.
156
#define DLINFO_ARCH_ITEMS 3
312
#define DLINFO_ARCH_ITEMS 5
157
313
#define ARCH_DLINFO \
159
sp -= DLINFO_ARCH_ITEMS * 2; \
160
NEW_AUX_ENT(0, AT_DCACHEBSIZE, 0x20); \
161
NEW_AUX_ENT(1, AT_ICACHEBSIZE, 0x20); \
162
NEW_AUX_ENT(2, AT_UCACHEBSIZE, 0); \
315
NEW_AUX_ENT(AT_DCACHEBSIZE, 0x20); \
316
NEW_AUX_ENT(AT_ICACHEBSIZE, 0x20); \
317
NEW_AUX_ENT(AT_UCACHEBSIZE, 0); \
164
319
* Now handle glibc compatibility. \
167
NEW_AUX_ENT(0, AT_IGNOREPPC, AT_IGNOREPPC); \
168
NEW_AUX_ENT(1, AT_IGNOREPPC, AT_IGNOREPPC); \
321
NEW_AUX_ENT(AT_IGNOREPPC, AT_IGNOREPPC); \
322
NEW_AUX_ENT(AT_IGNOREPPC, AT_IGNOREPPC); \
171
325
static inline void init_thread(struct target_pt_regs *_regs, struct image_info *infop)
173
_regs->msr = 1 << MSR_PR; /* Set user mode */
327
abi_ulong pos = infop->start_stack;
329
#if defined(TARGET_PPC64) && !defined(TARGET_ABI32)
330
abi_ulong entry, toc;
174
333
_regs->gpr[1] = infop->start_stack;
334
#if defined(TARGET_PPC64) && !defined(TARGET_ABI32)
335
entry = ldq_raw(infop->entry) + infop->load_addr;
336
toc = ldq_raw(infop->entry + 8) + infop->load_addr;
338
infop->entry = entry;
175
340
_regs->nip = infop->entry;
341
/* Note that isn't exactly what regular kernel does
342
* but this is what the ABI wants and is needed to allow
343
* execution of PPC BSD programs.
345
/* FIXME - what to for failure of get_user()? */
346
get_user_ual(_regs->gpr[3], pos);
347
pos += sizeof(abi_ulong);
349
for (tmp = 1; tmp != 0; pos += sizeof(abi_ulong))
178
354
#define USE_ELF_CORE_DUMP
361
#define ELF_START_MMAP 0x80000000
363
#define elf_check_arch(x) ( (x) == EM_MIPS )
366
#define ELF_CLASS ELFCLASS64
368
#define ELF_CLASS ELFCLASS32
370
#ifdef TARGET_WORDS_BIGENDIAN
371
#define ELF_DATA ELFDATA2MSB
373
#define ELF_DATA ELFDATA2LSB
375
#define ELF_ARCH EM_MIPS
377
static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop)
379
regs->cp0_status = 2 << CP0St_KSU;
380
regs->cp0_epc = infop->entry;
381
regs->regs[29] = infop->start_stack;
384
#define USE_ELF_CORE_DUMP
385
#define ELF_EXEC_PAGESIZE 4096
387
#endif /* TARGET_MIPS */
391
#define ELF_START_MMAP 0x80000000
393
#define elf_check_arch(x) ( (x) == EM_SH )
395
#define ELF_CLASS ELFCLASS32
396
#define ELF_DATA ELFDATA2LSB
397
#define ELF_ARCH EM_SH
399
static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop)
401
/* Check other registers XXXXX */
402
regs->pc = infop->entry;
403
regs->regs[15] = infop->start_stack;
406
#define USE_ELF_CORE_DUMP
407
#define ELF_EXEC_PAGESIZE 4096
413
#define ELF_START_MMAP 0x80000000
415
#define elf_check_arch(x) ( (x) == EM_CRIS )
417
#define ELF_CLASS ELFCLASS32
418
#define ELF_DATA ELFDATA2LSB
419
#define ELF_ARCH EM_CRIS
421
static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop)
423
regs->erp = infop->entry;
426
#define USE_ELF_CORE_DUMP
427
#define ELF_EXEC_PAGESIZE 8192
433
#define ELF_START_MMAP 0x80000000
435
#define elf_check_arch(x) ( (x) == EM_68K )
437
#define ELF_CLASS ELFCLASS32
438
#define ELF_DATA ELFDATA2MSB
439
#define ELF_ARCH EM_68K
441
/* ??? Does this need to do anything?
442
#define ELF_PLAT_INIT(_r) */
444
static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop)
446
regs->usp = infop->start_stack;
448
regs->pc = infop->entry;
451
#define USE_ELF_CORE_DUMP
452
#define ELF_EXEC_PAGESIZE 8192
458
#define ELF_START_MMAP (0x30000000000ULL)
460
#define elf_check_arch(x) ( (x) == ELF_ARCH )
462
#define ELF_CLASS ELFCLASS64
463
#define ELF_DATA ELFDATA2MSB
464
#define ELF_ARCH EM_ALPHA
466
static inline void init_thread(struct target_pt_regs *regs, struct image_info *infop)
468
regs->pc = infop->entry;
470
regs->usp = infop->start_stack;
471
regs->unique = infop->start_data; /* ? */
472
printf("Set unique value to " TARGET_FMT_lx " (" TARGET_FMT_lx ")\n",
473
regs->unique, infop->start_data);
476
#define USE_ELF_CORE_DUMP
477
#define ELF_EXEC_PAGESIZE 8192
479
#endif /* TARGET_ALPHA */
482
#define ELF_PLATFORM (NULL)
491
#define ELF_CLASS ELFCLASS32
493
#define bswaptls(ptr) bswap32s(ptr)
186
* MAX_ARG_PAGES defines the number of pages allocated for arguments
187
* and envelope for the new program. 32 should suffice, this gives
188
* a maximum env+arg of 128kB w/4KB pages!
190
#define MAX_ARG_PAGES 32
193
* This structure is used to hold the arguments that are
194
* used when loading binaries.
196
struct linux_binprm {
198
unsigned long page[MAX_ARG_PAGES];
204
char * filename; /* Name of binary */
205
unsigned long loader, exec;
206
int dont_iput; /* binfmt handler has put inode */
211
500
unsigned int a_info; /* Use macros N_MAGIC, etc for access */
290
558
bswap16s(&ehdr->e_shstrndx); /* Section header string table index */
293
static void bswap_phdr(Elf32_Phdr *phdr)
561
static void bswap_phdr(struct elf_phdr *phdr)
295
563
bswap32s(&phdr->p_type); /* Segment type */
296
bswap32s(&phdr->p_offset); /* Segment file offset */
297
bswap32s(&phdr->p_vaddr); /* Segment virtual address */
298
bswap32s(&phdr->p_paddr); /* Segment physical address */
299
bswap32s(&phdr->p_filesz); /* Segment size in file */
300
bswap32s(&phdr->p_memsz); /* Segment size in memory */
564
bswaptls(&phdr->p_offset); /* Segment file offset */
565
bswaptls(&phdr->p_vaddr); /* Segment virtual address */
566
bswaptls(&phdr->p_paddr); /* Segment physical address */
567
bswaptls(&phdr->p_filesz); /* Segment size in file */
568
bswaptls(&phdr->p_memsz); /* Segment size in memory */
301
569
bswap32s(&phdr->p_flags); /* Segment flags */
302
bswap32s(&phdr->p_align); /* Segment alignment */
570
bswaptls(&phdr->p_align); /* Segment alignment */
305
static void bswap_shdr(Elf32_Shdr *shdr)
573
static void bswap_shdr(struct elf_shdr *shdr)
307
575
bswap32s(&shdr->sh_name);
308
576
bswap32s(&shdr->sh_type);
309
bswap32s(&shdr->sh_flags);
310
bswap32s(&shdr->sh_addr);
311
bswap32s(&shdr->sh_offset);
312
bswap32s(&shdr->sh_size);
577
bswaptls(&shdr->sh_flags);
578
bswaptls(&shdr->sh_addr);
579
bswaptls(&shdr->sh_offset);
580
bswaptls(&shdr->sh_size);
313
581
bswap32s(&shdr->sh_link);
314
582
bswap32s(&shdr->sh_info);
315
bswap32s(&shdr->sh_addralign);
316
bswap32s(&shdr->sh_entsize);
583
bswaptls(&shdr->sh_addralign);
584
bswaptls(&shdr->sh_entsize);
319
static void bswap_sym(Elf32_Sym *sym)
587
static void bswap_sym(struct elf_sym *sym)
321
589
bswap32s(&sym->st_name);
322
bswap32s(&sym->st_value);
323
bswap32s(&sym->st_size);
590
bswaptls(&sym->st_value);
591
bswaptls(&sym->st_size);
324
592
bswap16s(&sym->st_shndx);
328
static void * get_free_page(void)
332
/* User-space version of kernel get_free_page. Returns a page-aligned
333
* page-sized chunk of memory.
335
retval = (void *)target_mmap(0, host_page_size, PROT_READ|PROT_WRITE,
336
MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
338
if((long)retval == -1) {
339
perror("get_free_page");
347
static void free_page(void * pageaddr)
349
target_munmap((unsigned long)pageaddr, host_page_size);
353
* 'copy_string()' copies argument/envelope strings from user
597
* 'copy_elf_strings()' copies argument/envelope strings from user
354
598
* memory to free pages in kernel mem. These are in a format ready
355
599
* to be put directly into the top of new user memory.
358
static unsigned long copy_strings(int argc,char ** argv,unsigned long *page,
602
static abi_ulong copy_elf_strings(int argc,char ** argv, void **page,
361
605
char *tmp, *tmp1, *pag = NULL;
362
606
int len, offset = 0;
407
static int in_group_p(gid_t g)
409
/* return TRUE if we're in the specified group, FALSE otherwise */
412
gid_t grouplist[NGROUPS];
414
ngroup = getgroups(NGROUPS, grouplist);
415
for(i = 0; i < ngroup; i++) {
416
if(grouplist[i] == g) {
423
static int count(char ** vec)
427
for(i = 0; *vec; i++) {
434
static int prepare_binprm(struct linux_binprm *bprm)
438
int retval, id_change;
440
if(fstat(bprm->fd, &st) < 0) {
445
if(!S_ISREG(mode)) { /* Must be regular file */
448
if(!(mode & 0111)) { /* Must have at least one execute bit set */
452
bprm->e_uid = geteuid();
453
bprm->e_gid = getegid();
458
bprm->e_uid = st.st_uid;
459
if(bprm->e_uid != geteuid()) {
466
* If setgid is set but no group execute bit then this
467
* is a candidate for mandatory locking, not a setgid
470
if ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) {
471
bprm->e_gid = st.st_gid;
472
if (!in_group_p(bprm->e_gid)) {
477
memset(bprm->buf, 0, sizeof(bprm->buf));
478
retval = lseek(bprm->fd, 0L, SEEK_SET);
480
retval = read(bprm->fd, bprm->buf, 128);
483
perror("prepare_binprm");
485
/* return(-errno); */
492
unsigned long setup_arg_pages(unsigned long p, struct linux_binprm * bprm,
493
struct image_info * info)
495
unsigned long stack_base, size, error;
652
static abi_ulong setup_arg_pages(abi_ulong p, struct linux_binprm *bprm,
653
struct image_info *info)
655
abi_ulong stack_base, size, error;
498
658
/* Create enough stack to hold everything. If we don't use
513
673
/* we reserve one extra page at the top of the stack as guard */
514
target_mprotect(error + size, host_page_size, PROT_NONE);
674
target_mprotect(error + size, qemu_host_page_size, PROT_NONE);
516
676
stack_base = error + size - MAX_ARG_PAGES*TARGET_PAGE_SIZE;
520
bprm->loader += stack_base;
522
bprm->exec += stack_base;
524
679
for (i = 0 ; i < MAX_ARG_PAGES ; i++) {
525
680
if (bprm->page[i]) {
528
memcpy((void *)stack_base, (void *)bprm->page[i], TARGET_PAGE_SIZE);
529
free_page((void *)bprm->page[i]);
682
/* FIXME - check return value of memcpy_to_target() for failure */
683
memcpy_to_target(stack_base, bprm->page[i], TARGET_PAGE_SIZE);
531
stack_base += TARGET_PAGE_SIZE;
686
stack_base += TARGET_PAGE_SIZE;
536
static void set_brk(unsigned long start, unsigned long end)
691
static void set_brk(abi_ulong start, abi_ulong end)
538
693
/* page-align the start and end addresses... */
539
694
start = HOST_PAGE_ALIGN(start);
552
707
/* We need to explicitly zero any fractional pages after the data
553
708
section (i.e. bss). This would contain the junk from the file that
554
709
should not be in memory. */
555
static void padzero(unsigned long elf_bss)
710
static void padzero(abi_ulong elf_bss, abi_ulong last_bss)
714
if (elf_bss >= last_bss)
560
717
/* XXX: this is really a hack : if the real host page size is
561
718
smaller than the target page size, some pages after the end
562
719
of the file may not be mapped. A better fix would be to
563
720
patch target_mmap(), but it is more complicated as the file
564
721
size must be known */
565
if (real_host_page_size < host_page_size) {
566
unsigned long end_addr, end_addr1;
567
end_addr1 = (elf_bss + real_host_page_size - 1) &
568
~(real_host_page_size - 1);
722
if (qemu_real_host_page_size < qemu_host_page_size) {
723
abi_ulong end_addr, end_addr1;
724
end_addr1 = (elf_bss + qemu_real_host_page_size - 1) &
725
~(qemu_real_host_page_size - 1);
569
726
end_addr = HOST_PAGE_ALIGN(elf_bss);
570
727
if (end_addr1 < end_addr) {
571
mmap((void *)end_addr1, end_addr - end_addr1,
728
mmap((void *)g2h(end_addr1), end_addr - end_addr1,
572
729
PROT_READ|PROT_WRITE|PROT_EXEC,
573
730
MAP_FIXED|MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
577
nbyte = elf_bss & (host_page_size-1);
734
nbyte = elf_bss & (qemu_host_page_size-1);
579
nbyte = host_page_size - nbyte;
580
fpnt = (char *) elf_bss;
736
nbyte = qemu_host_page_size - nbyte;
738
/* FIXME - what to do if put_user() fails? */
739
put_user_u8(0, elf_bss);
583
741
} while (--nbyte);
587
static unsigned int * create_elf_tables(char *p, int argc, int envc,
588
struct elfhdr * exec,
589
unsigned long load_addr,
590
unsigned long load_bias,
591
unsigned long interp_load_addr, int ibcs,
592
struct image_info *info)
746
static abi_ulong create_elf_tables(abi_ulong p, int argc, int envc,
747
struct elfhdr * exec,
750
abi_ulong interp_load_addr, int ibcs,
751
struct image_info *info)
594
target_ulong *argv, *envp;
595
target_ulong *sp, *csp;
755
abi_ulong u_platform;
756
const char *k_platform;
757
const int n = sizeof(elf_addr_t);
761
k_platform = ELF_PLATFORM;
763
size_t len = strlen(k_platform) + 1;
764
sp -= (len + n - 1) & ~(n - 1);
766
/* FIXME - check return value of memcpy_to_target() for failure */
767
memcpy_to_target(sp, k_platform, len);
599
770
* Force 16 byte _final_ alignment here for generality.
601
sp = (unsigned int *) (~15UL & (unsigned long) p);
603
csp -= (DLINFO_ITEMS + 1) * 2;
772
sp = sp &~ (abi_ulong)15;
773
size = (DLINFO_ITEMS + 1) * 2;
604
776
#ifdef DLINFO_ARCH_ITEMS
605
csp -= DLINFO_ARCH_ITEMS*2;
777
size += DLINFO_ARCH_ITEMS * 2;
609
csp -= (!ibcs ? 3 : 1); /* argc itself */
610
if ((unsigned long)csp & 15UL)
611
sp -= ((unsigned long)csp & 15UL) / sizeof(*sp);
613
#define NEW_AUX_ENT(nr, id, val) \
614
put_user (id, sp + (nr * 2)); \
615
put_user (val, sp + (nr * 2 + 1))
617
NEW_AUX_ENT (0, AT_NULL, 0);
619
sp -= DLINFO_ITEMS*2;
620
NEW_AUX_ENT( 0, AT_PHDR, (target_ulong)(load_addr + exec->e_phoff));
621
NEW_AUX_ENT( 1, AT_PHENT, (target_ulong)(sizeof (struct elf_phdr)));
622
NEW_AUX_ENT( 2, AT_PHNUM, (target_ulong)(exec->e_phnum));
623
NEW_AUX_ENT( 3, AT_PAGESZ, (target_ulong)(TARGET_PAGE_SIZE));
624
NEW_AUX_ENT( 4, AT_BASE, (target_ulong)(interp_load_addr));
625
NEW_AUX_ENT( 5, AT_FLAGS, (target_ulong)0);
626
NEW_AUX_ENT( 6, AT_ENTRY, load_bias + exec->e_entry);
627
NEW_AUX_ENT( 7, AT_UID, (target_ulong) getuid());
628
NEW_AUX_ENT( 8, AT_EUID, (target_ulong) geteuid());
629
NEW_AUX_ENT( 9, AT_GID, (target_ulong) getgid());
630
NEW_AUX_ENT(11, AT_EGID, (target_ulong) getegid());
779
size += envc + argc + 2;
780
size += (!ibcs ? 3 : 1); /* argc itself */
783
sp -= 16 - (size & 15);
785
/* This is correct because Linux defines
786
* elf_addr_t as Elf32_Off / Elf64_Off
788
#define NEW_AUX_ENT(id, val) do { \
789
sp -= n; put_user_ual(val, sp); \
790
sp -= n; put_user_ual(id, sp); \
793
NEW_AUX_ENT (AT_NULL, 0);
795
/* There must be exactly DLINFO_ITEMS entries here. */
796
NEW_AUX_ENT(AT_PHDR, (abi_ulong)(load_addr + exec->e_phoff));
797
NEW_AUX_ENT(AT_PHENT, (abi_ulong)(sizeof (struct elf_phdr)));
798
NEW_AUX_ENT(AT_PHNUM, (abi_ulong)(exec->e_phnum));
799
NEW_AUX_ENT(AT_PAGESZ, (abi_ulong)(TARGET_PAGE_SIZE));
800
NEW_AUX_ENT(AT_BASE, (abi_ulong)(interp_load_addr));
801
NEW_AUX_ENT(AT_FLAGS, (abi_ulong)0);
802
NEW_AUX_ENT(AT_ENTRY, load_bias + exec->e_entry);
803
NEW_AUX_ENT(AT_UID, (abi_ulong) getuid());
804
NEW_AUX_ENT(AT_EUID, (abi_ulong) geteuid());
805
NEW_AUX_ENT(AT_GID, (abi_ulong) getgid());
806
NEW_AUX_ENT(AT_EGID, (abi_ulong) getegid());
807
NEW_AUX_ENT(AT_HWCAP, (abi_ulong) ELF_HWCAP);
809
NEW_AUX_ENT(AT_PLATFORM, u_platform);
631
810
#ifdef ARCH_DLINFO
633
812
* ARCH_DLINFO must come last so platform specific code can enforce
634
813
* special alignment requirements on the AUXV if necessary (eg. PPC).
638
817
#undef NEW_AUX_ENT
645
put_user((target_ulong)envp,--sp);
646
put_user((target_ulong)argv,--sp);
649
info->arg_start = (unsigned int)((unsigned long)p & 0xffffffff);
651
put_user((target_ulong)p,argv++);
658
info->arg_end = info->env_start = (unsigned int)((unsigned long)p & 0xffffffff);
660
put_user((target_ulong)p,envp++);
667
info->env_end = (unsigned int)((unsigned long)p & 0xffffffff);
819
sp = loader_build_argptr(envc, argc, sp, p, !ibcs);
673
static unsigned long load_elf_interp(struct elfhdr * interp_elf_ex,
675
unsigned long *interp_load_addr)
824
static abi_ulong load_elf_interp(struct elfhdr * interp_elf_ex,
826
abi_ulong *interp_load_addr)
677
828
struct elf_phdr *elf_phdata = NULL;
678
829
struct elf_phdr *eppnt;
679
unsigned long load_addr = 0;
830
abi_ulong load_addr = 0;
680
831
int load_addr_set = 0;
682
unsigned long last_bss, elf_bss;
833
abi_ulong last_bss, elf_bss;
691
842
bswap_ehdr(interp_elf_ex);
693
844
/* First of all, some simple consistency checks */
694
if ((interp_elf_ex->e_type != ET_EXEC &&
695
interp_elf_ex->e_type != ET_DYN) ||
845
if ((interp_elf_ex->e_type != ET_EXEC &&
846
interp_elf_ex->e_type != ET_DYN) ||
696
847
!elf_check_arch(interp_elf_ex->e_machine)) {
848
return ~((abi_ulong)0UL);
701
852
/* Now read in all of the header information */
703
854
if (sizeof(struct elf_phdr) * interp_elf_ex->e_phnum > TARGET_PAGE_SIZE)
706
elf_phdata = (struct elf_phdr *)
855
return ~(abi_ulong)0UL;
857
elf_phdata = (struct elf_phdr *)
707
858
malloc(sizeof(struct elf_phdr) * interp_elf_ex->e_phnum);
861
return ~((abi_ulong)0UL);
713
864
* If the size of this structure has changed, then punt, since
714
865
* we will be doing the wrong thing.
716
867
if (interp_elf_ex->e_phentsize != sizeof(struct elf_phdr)) {
717
868
free(elf_phdata);
869
return ~((abi_ulong)0UL);
721
872
retval = lseek(interpreter_fd, interp_elf_ex->e_phoff, SEEK_SET);
858
1015
/* Now know where the strtab and symtab are. Snarf them. */
859
disas_symtab = malloc(symtab.sh_size);
860
disas_strtab = strings = malloc(strtab.sh_size);
861
if (!disas_symtab || !disas_strtab)
1016
s = malloc(sizeof(*s));
1017
s->disas_symtab = malloc(symtab.sh_size);
1018
#if (ELF_CLASS == ELFCLASS64)
1019
syms32 = malloc(symtab.sh_size / sizeof(struct elf_sym)
1020
* sizeof(struct elf32_sym));
1022
s->disas_strtab = strings = malloc(strtab.sh_size);
1023
if (!s->disas_symtab || !s->disas_strtab)
864
1026
lseek(fd, symtab.sh_offset, SEEK_SET);
865
if (read(fd, disas_symtab, symtab.sh_size) != symtab.sh_size)
1027
if (read(fd, s->disas_symtab, symtab.sh_size) != symtab.sh_size)
1030
for (i = 0; i < symtab.sh_size / sizeof(struct elf_sym); i++) {
868
1031
#ifdef BSWAP_NEEDED
869
for (i = 0; i < symtab.sh_size / sizeof(struct elf_sym); i++)
870
bswap_sym(disas_symtab + sizeof(struct elf_sym)*i);
1032
bswap_sym(s->disas_symtab + sizeof(struct elf_sym)*i);
1034
#if (ELF_CLASS == ELFCLASS64)
1035
sym = s->disas_symtab + sizeof(struct elf_sym)*i;
1036
syms32[i].st_name = sym->st_name;
1037
syms32[i].st_info = sym->st_info;
1038
syms32[i].st_other = sym->st_other;
1039
syms32[i].st_shndx = sym->st_shndx;
1040
syms32[i].st_value = sym->st_value & 0xffffffff;
1041
syms32[i].st_size = sym->st_size & 0xffffffff;
1045
#if (ELF_CLASS == ELFCLASS64)
1046
free(s->disas_symtab);
1047
s->disas_symtab = syms32;
873
1049
lseek(fd, strtab.sh_offset, SEEK_SET);
874
1050
if (read(fd, strings, strtab.sh_size) != strtab.sh_size)
876
disas_num_syms = symtab.sh_size / sizeof(struct elf_sym);
1052
s->disas_num_syms = symtab.sh_size / sizeof(struct elf_sym);
879
static int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs,
880
struct image_info * info)
1057
int load_elf_binary(struct linux_binprm * bprm, struct target_pt_regs * regs,
1058
struct image_info * info)
882
1060
struct elfhdr elf_ex;
883
1061
struct elfhdr interp_elf_ex;
884
1062
struct exec interp_ex;
885
1063
int interpreter_fd = -1; /* avoid warning */
886
unsigned long load_addr, load_bias;
1064
abi_ulong load_addr, load_bias;
887
1065
int load_addr_set = 0;
888
1066
unsigned int interpreter_type = INTERPRETER_NONE;
889
1067
unsigned char ibcs2_interpreter;
891
unsigned long mapped_addr;
1069
abi_ulong mapped_addr;
892
1070
struct elf_phdr * elf_ppnt;
893
1071
struct elf_phdr *elf_phdata;
894
unsigned long elf_bss, k, elf_brk;
1072
abi_ulong elf_bss, k, elf_brk;
896
1074
char * elf_interpreter;
897
unsigned long elf_entry, interp_load_addr = 0;
1075
abi_ulong elf_entry, interp_load_addr = 0;
899
unsigned long start_code, end_code, end_data;
900
unsigned long elf_stack;
1077
abi_ulong start_code, end_code, start_data, end_data;
1078
abi_ulong reloc_func_desc = 0;
1079
abi_ulong elf_stack;
901
1080
char passed_fileno[6];
903
1082
ibcs2_interpreter = 0;
1252
1437
and some applications "depend" upon this behavior.
1253
1438
Since we do not have the power to recompile these, we
1254
1439
emulate the SVr4 behavior. Sigh. */
1255
mapped_addr = target_mmap(0, host_page_size, PROT_READ | PROT_EXEC,
1440
mapped_addr = target_mmap(0, qemu_host_page_size, PROT_READ | PROT_EXEC,
1256
1441
MAP_FIXED | MAP_PRIVATE, -1, 0);
1259
#ifdef ELF_PLAT_INIT
1261
* The ABI may specify that certain registers be set up in special
1262
* ways (on i386 %edx is the address of a DT_FINI function, for
1263
* example. This macro performs whatever initialization to
1264
* the regs structure is required.
1266
ELF_PLAT_INIT(regs);
1270
1444
info->entry = elf_entry;
1277
int elf_exec(const char * filename, char ** argv, char ** envp,
1278
struct target_pt_regs * regs, struct image_info *infop)
1280
struct linux_binprm bprm;
1284
bprm.p = TARGET_PAGE_SIZE*MAX_ARG_PAGES-sizeof(unsigned int);
1285
for (i=0 ; i<MAX_ARG_PAGES ; i++) /* clear page-table */
1287
retval = open(filename, O_RDONLY);
1291
bprm.filename = (char *)filename;
1296
bprm.argc = count(argv);
1297
bprm.envc = count(envp);
1299
retval = prepare_binprm(&bprm);
1302
bprm.p = copy_strings(1, &bprm.filename, bprm.page, bprm.p);
1304
bprm.p = copy_strings(bprm.envc,envp,bprm.page,bprm.p);
1305
bprm.p = copy_strings(bprm.argc,argv,bprm.page,bprm.p);
1312
retval = load_elf_binary(&bprm,regs,infop);
1315
/* success. Initialize important registers */
1316
init_thread(regs, infop);
1320
/* Something went wrong, return the inode and free the argument pages*/
1321
for (i=0 ; i<MAX_ARG_PAGES ; i++) {
1322
free_page((void *)bprm.page[i]);
1328
1449
static int load_aout_interp(void * exptr, int interp_fd)
1330
1451
printf("a.out interpreter not yet supported\n");
1455
void do_init_thread(struct target_pt_regs *regs, struct image_info *infop)
1457
init_thread(regs, infop);