4 * Copyright (c) 2013 Stacey D. Son
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
20 #include "qemu/osdep.h"
23 #include "disas/disas.h"
24 #include "qemu/path.h"
35 /* from personality.h */
38 * Flags for bug emulation.
40 * These occupy the top three bytes.
43 ADDR_NO_RANDOMIZE
= 0x0040000, /* disable randomization of VA space */
44 FDPIC_FUNCPTRS
= 0x0080000, /* userspace function ptrs point to descriptors
47 MMAP_PAGE_ZERO
= 0x0100000,
48 ADDR_COMPAT_LAYOUT
= 0x0200000,
49 READ_IMPLIES_EXEC
= 0x0400000,
50 ADDR_LIMIT_32BIT
= 0x0800000,
51 SHORT_INODE
= 0x1000000,
52 WHOLE_SECONDS
= 0x2000000,
53 STICKY_TIMEOUTS
= 0x4000000,
54 ADDR_LIMIT_3GB
= 0x8000000,
60 * These go in the low byte. Avoid using the top bit, it will
61 * conflict with error returns.
65 PER_LINUX_32BIT
= 0x0000 | ADDR_LIMIT_32BIT
,
66 PER_LINUX_FDPIC
= 0x0000 | FDPIC_FUNCPTRS
,
67 PER_SVR4
= 0x0001 | STICKY_TIMEOUTS
| MMAP_PAGE_ZERO
,
68 PER_SVR3
= 0x0002 | STICKY_TIMEOUTS
| SHORT_INODE
,
69 PER_SCOSVR3
= 0x0003 | STICKY_TIMEOUTS
|
70 WHOLE_SECONDS
| SHORT_INODE
,
71 PER_OSR5
= 0x0003 | STICKY_TIMEOUTS
| WHOLE_SECONDS
,
72 PER_WYSEV386
= 0x0004 | STICKY_TIMEOUTS
| SHORT_INODE
,
73 PER_ISCR4
= 0x0005 | STICKY_TIMEOUTS
,
75 PER_SUNOS
= 0x0006 | STICKY_TIMEOUTS
,
76 PER_XENIX
= 0x0007 | STICKY_TIMEOUTS
| SHORT_INODE
,
78 PER_LINUX32_3GB
= 0x0008 | ADDR_LIMIT_3GB
,
79 PER_IRIX32
= 0x0009 | STICKY_TIMEOUTS
,/* IRIX5 32-bit */
80 PER_IRIXN32
= 0x000a | STICKY_TIMEOUTS
,/* IRIX6 new 32-bit */
81 PER_IRIX64
= 0x000b | STICKY_TIMEOUTS
,/* IRIX6 64-bit */
83 PER_SOLARIS
= 0x000d | STICKY_TIMEOUTS
,
84 PER_UW7
= 0x000e | STICKY_TIMEOUTS
| MMAP_PAGE_ZERO
,
85 PER_OSF4
= 0x000f, /* OSF/1 v4 */
91 * Return the base personality without flags.
93 #define personality(pers) (pers & PER_MASK)
95 /* this flag is uneffective under linux too, should be deleted */
97 #define MAP_DENYWRITE 0
100 /* should probably go in elf.h */
107 #define ELF_PLATFORM get_elf_platform()
109 static const char *get_elf_platform(void)
111 static char elf_platform
[] = "i386";
112 int family
= object_property_get_int(OBJECT(thread_cpu
), "family", NULL
);
116 elf_platform
[1] = '0' + family
;
120 #define ELF_HWCAP get_elf_hwcap()
122 static uint32_t get_elf_hwcap(void)
124 X86CPU
*cpu
= X86_CPU(thread_cpu
);
126 return cpu
->env
.features
[FEAT_1_EDX
];
130 #define ELF_START_MMAP 0x2aaaaab000ULL
131 #define elf_check_arch(x) (((x) == ELF_ARCH))
133 #define ELF_CLASS ELFCLASS64
134 #define ELF_DATA ELFDATA2LSB
135 #define ELF_ARCH EM_X86_64
137 static inline void init_thread(struct target_pt_regs
*regs
, struct image_info
*infop
)
140 regs
->rsp
= infop
->start_stack
;
141 regs
->rip
= infop
->entry
;
142 if (bsd_type
== target_freebsd
) {
143 regs
->rdi
= infop
->start_stack
;
149 #define ELF_START_MMAP 0x80000000
152 * This is used to ensure we don't load something for the wrong architecture.
154 #define elf_check_arch(x) (((x) == EM_386) || ((x) == EM_486))
157 * These are used to set parameters in the core dumps.
159 #define ELF_CLASS ELFCLASS32
160 #define ELF_DATA ELFDATA2LSB
161 #define ELF_ARCH EM_386
163 static inline void init_thread(struct target_pt_regs
*regs
, struct image_info
*infop
)
165 regs
->esp
= infop
->start_stack
;
166 regs
->eip
= infop
->entry
;
168 /* SVR4/i386 ABI (pages 3-31, 3-32) says that when the program
169 starts %edx contains a pointer to a function which might be
170 registered using `atexit'. This provides a mean for the
171 dynamic linker to call DT_FINI functions for shared libraries
172 that have been loaded before the code runs.
174 A value of 0 tells we have no such handler. */
179 #define USE_ELF_CORE_DUMP
180 #define ELF_EXEC_PAGESIZE 4096
186 #define ELF_START_MMAP 0x80000000
188 #define elf_check_arch(x) ((x) == EM_ARM)
190 #define ELF_CLASS ELFCLASS32
191 #ifdef TARGET_WORDS_BIGENDIAN
192 #define ELF_DATA ELFDATA2MSB
194 #define ELF_DATA ELFDATA2LSB
196 #define ELF_ARCH EM_ARM
198 static inline void init_thread(struct target_pt_regs
*regs
, struct image_info
*infop
)
200 abi_long stack
= infop
->start_stack
;
201 memset(regs
, 0, sizeof(*regs
));
202 regs
->ARM_cpsr
= 0x10;
203 if (infop
->entry
& 1)
204 regs
->ARM_cpsr
|= CPSR_T
;
205 regs
->ARM_pc
= infop
->entry
& 0xfffffffe;
206 regs
->ARM_sp
= infop
->start_stack
;
207 /* FIXME - what to for failure of get_user()? */
208 get_user_ual(regs
->ARM_r2
, stack
+ 8); /* envp */
209 get_user_ual(regs
->ARM_r1
, stack
+ 4); /* envp */
210 /* XXX: it seems that r0 is zeroed after ! */
212 /* For uClinux PIC binaries. */
213 /* XXX: Linux does this only on ARM with no MMU (do we care ?) */
214 regs
->ARM_r10
= infop
->start_data
;
217 #define USE_ELF_CORE_DUMP
218 #define ELF_EXEC_PAGESIZE 4096
222 ARM_HWCAP_ARM_SWP
= 1 << 0,
223 ARM_HWCAP_ARM_HALF
= 1 << 1,
224 ARM_HWCAP_ARM_THUMB
= 1 << 2,
225 ARM_HWCAP_ARM_26BIT
= 1 << 3,
226 ARM_HWCAP_ARM_FAST_MULT
= 1 << 4,
227 ARM_HWCAP_ARM_FPA
= 1 << 5,
228 ARM_HWCAP_ARM_VFP
= 1 << 6,
229 ARM_HWCAP_ARM_EDSP
= 1 << 7,
232 #define ELF_HWCAP (ARM_HWCAP_ARM_SWP | ARM_HWCAP_ARM_HALF \
233 | ARM_HWCAP_ARM_THUMB | ARM_HWCAP_ARM_FAST_MULT \
234 | ARM_HWCAP_ARM_FPA | ARM_HWCAP_ARM_VFP)
239 #ifdef TARGET_SPARC64
241 #define ELF_START_MMAP 0x80000000
244 #define elf_check_arch(x) ((x) == EM_SPARCV9 || (x) == EM_SPARC32PLUS)
246 #define elf_check_arch(x) ((x) == EM_SPARC32PLUS || (x) == EM_SPARC)
249 #define ELF_CLASS ELFCLASS64
250 #define ELF_DATA ELFDATA2MSB
251 #define ELF_ARCH EM_SPARCV9
253 #define STACK_BIAS 2047
255 static inline void init_thread(struct target_pt_regs
*regs
, struct image_info
*infop
)
260 regs
->pc
= infop
->entry
;
261 regs
->npc
= regs
->pc
+ 4;
264 regs
->u_regs
[14] = infop
->start_stack
- 16 * 4;
266 if (personality(infop
->personality
) == PER_LINUX32
)
267 regs
->u_regs
[14] = infop
->start_stack
- 16 * 4;
269 regs
->u_regs
[14] = infop
->start_stack
- 16 * 8 - STACK_BIAS
;
270 if (bsd_type
== target_freebsd
) {
271 regs
->u_regs
[8] = infop
->start_stack
;
272 regs
->u_regs
[11] = infop
->start_stack
;
279 #define ELF_START_MMAP 0x80000000
281 #define elf_check_arch(x) ((x) == EM_SPARC)
283 #define ELF_CLASS ELFCLASS32
284 #define ELF_DATA ELFDATA2MSB
285 #define ELF_ARCH EM_SPARC
287 static inline void init_thread(struct target_pt_regs
*regs
, struct image_info
*infop
)
290 regs
->pc
= infop
->entry
;
291 regs
->npc
= regs
->pc
+ 4;
293 regs
->u_regs
[14] = infop
->start_stack
- 16 * 4;
301 #define ELF_START_MMAP 0x80000000
303 #if defined(TARGET_PPC64) && !defined(TARGET_ABI32)
305 #define elf_check_arch(x) ((x) == EM_PPC64)
307 #define ELF_CLASS ELFCLASS64
311 #define elf_check_arch(x) ((x) == EM_PPC)
313 #define ELF_CLASS ELFCLASS32
317 #ifdef TARGET_WORDS_BIGENDIAN
318 #define ELF_DATA ELFDATA2MSB
320 #define ELF_DATA ELFDATA2LSB
322 #define ELF_ARCH EM_PPC
325 * We need to put in some extra aux table entries to tell glibc what
326 * the cache block size is, so it can use the dcbz instruction safely.
328 #define AT_DCACHEBSIZE 19
329 #define AT_ICACHEBSIZE 20
330 #define AT_UCACHEBSIZE 21
331 /* A special ignored type value for PPC, for glibc compatibility. */
332 #define AT_IGNOREPPC 22
334 * The requirements here are:
335 * - keep the final alignment of sp (sp & 0xf)
336 * - make sure the 32-bit value at the first 16 byte aligned position of
337 * AUXV is greater than 16 for glibc compatibility.
338 * AT_IGNOREPPC is used for that.
339 * - for compatibility with glibc ARCH_DLINFO must always be defined on PPC,
340 * even if DLINFO_ARCH_ITEMS goes to zero or is undefined.
342 #define DLINFO_ARCH_ITEMS 5
343 #define ARCH_DLINFO \
345 NEW_AUX_ENT(AT_DCACHEBSIZE, 0x20); \
346 NEW_AUX_ENT(AT_ICACHEBSIZE, 0x20); \
347 NEW_AUX_ENT(AT_UCACHEBSIZE, 0); \
349 * Now handle glibc compatibility. \
351 NEW_AUX_ENT(AT_IGNOREPPC, AT_IGNOREPPC); \
352 NEW_AUX_ENT(AT_IGNOREPPC, AT_IGNOREPPC); \
355 static inline void init_thread(struct target_pt_regs
*_regs
, struct image_info
*infop
)
357 abi_ulong pos
= infop
->start_stack
;
359 #if defined(TARGET_PPC64) && !defined(TARGET_ABI32)
360 abi_ulong entry
, toc
;
363 _regs
->gpr
[1] = infop
->start_stack
;
364 #if defined(TARGET_PPC64) && !defined(TARGET_ABI32)
365 get_user_u64(entry
, infop
->entry
);
366 entry
+= infop
->load_addr
;
367 get_user_u64(toc
, infop
->entry
+ 8);
368 toc
+= infop
->load_addr
;
370 infop
->entry
= entry
;
372 _regs
->nip
= infop
->entry
;
373 /* Note that isn't exactly what regular kernel does
374 * but this is what the ABI wants and is needed to allow
375 * execution of PPC BSD programs.
377 /* FIXME - what to for failure of get_user()? */
378 get_user_ual(_regs
->gpr
[3], pos
);
379 pos
+= sizeof(abi_ulong
);
381 for (tmp
= 1; tmp
!= 0; pos
+= sizeof(abi_ulong
)) {
382 get_user_ual(tmp
, pos
);
387 #define USE_ELF_CORE_DUMP
388 #define ELF_EXEC_PAGESIZE 4096
394 #define ELF_START_MMAP 0x80000000
396 #define elf_check_arch(x) ((x) == EM_MIPS)
399 #define ELF_CLASS ELFCLASS64
401 #define ELF_CLASS ELFCLASS32
403 #ifdef TARGET_WORDS_BIGENDIAN
404 #define ELF_DATA ELFDATA2MSB
406 #define ELF_DATA ELFDATA2LSB
408 #define ELF_ARCH EM_MIPS
410 static inline void init_thread(struct target_pt_regs
*regs
, struct image_info
*infop
)
412 regs
->cp0_status
= 2 << CP0St_KSU
;
413 regs
->cp0_epc
= infop
->entry
;
414 regs
->regs
[29] = infop
->start_stack
;
417 #define USE_ELF_CORE_DUMP
418 #define ELF_EXEC_PAGESIZE 4096
420 #endif /* TARGET_MIPS */
424 #define ELF_START_MMAP 0x80000000
426 #define elf_check_arch(x) ((x) == EM_SH)
428 #define ELF_CLASS ELFCLASS32
429 #define ELF_DATA ELFDATA2LSB
430 #define ELF_ARCH EM_SH
432 static inline void init_thread(struct target_pt_regs
*regs
, struct image_info
*infop
)
434 /* Check other registers XXXXX */
435 regs
->pc
= infop
->entry
;
436 regs
->regs
[15] = infop
->start_stack
;
439 #define USE_ELF_CORE_DUMP
440 #define ELF_EXEC_PAGESIZE 4096
446 #define ELF_START_MMAP 0x80000000
448 #define elf_check_arch(x) ((x) == EM_CRIS)
450 #define ELF_CLASS ELFCLASS32
451 #define ELF_DATA ELFDATA2LSB
452 #define ELF_ARCH EM_CRIS
454 static inline void init_thread(struct target_pt_regs
*regs
, struct image_info
*infop
)
456 regs
->erp
= infop
->entry
;
459 #define USE_ELF_CORE_DUMP
460 #define ELF_EXEC_PAGESIZE 8192
466 #define ELF_START_MMAP 0x80000000
468 #define elf_check_arch(x) ((x) == EM_68K)
470 #define ELF_CLASS ELFCLASS32
471 #define ELF_DATA ELFDATA2MSB
472 #define ELF_ARCH EM_68K
474 /* ??? Does this need to do anything?
475 #define ELF_PLAT_INIT(_r) */
477 static inline void init_thread(struct target_pt_regs
*regs
, struct image_info
*infop
)
479 regs
->usp
= infop
->start_stack
;
481 regs
->pc
= infop
->entry
;
484 #define USE_ELF_CORE_DUMP
485 #define ELF_EXEC_PAGESIZE 8192
491 #define ELF_START_MMAP (0x30000000000ULL)
493 #define elf_check_arch(x) ((x) == ELF_ARCH)
495 #define ELF_CLASS ELFCLASS64
496 #define ELF_DATA ELFDATA2MSB
497 #define ELF_ARCH EM_ALPHA
499 static inline void init_thread(struct target_pt_regs
*regs
, struct image_info
*infop
)
501 regs
->pc
= infop
->entry
;
503 regs
->usp
= infop
->start_stack
;
504 regs
->unique
= infop
->start_data
; /* ? */
505 printf("Set unique value to " TARGET_FMT_lx
" (" TARGET_FMT_lx
")\n",
506 regs
->unique
, infop
->start_data
);
509 #define USE_ELF_CORE_DUMP
510 #define ELF_EXEC_PAGESIZE 8192
512 #endif /* TARGET_ALPHA */
515 #define ELF_PLATFORM (NULL)
524 #define ELF_CLASS ELFCLASS32
526 #define bswaptls(ptr) bswap32s(ptr)
533 unsigned int a_info
; /* Use macros N_MAGIC, etc for access */
534 unsigned int a_text
; /* length of text, in bytes */
535 unsigned int a_data
; /* length of data, in bytes */
536 unsigned int a_bss
; /* length of uninitialized data area, in bytes */
537 unsigned int a_syms
; /* length of symbol table data in file, in bytes */
538 unsigned int a_entry
; /* start address */
539 unsigned int a_trsize
; /* length of relocation info for text, in bytes */
540 unsigned int a_drsize
; /* length of relocation info for data, in bytes */
544 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
550 /* max code+data+bss space allocated to elf interpreter */
551 #define INTERP_MAP_SIZE (32 * 1024 * 1024)
553 /* max code+data+bss+brk space allocated to ET_DYN executables */
554 #define ET_DYN_MAP_SIZE (128 * 1024 * 1024)
556 /* Necessary parameters */
557 #define TARGET_ELF_EXEC_PAGESIZE TARGET_PAGE_SIZE
558 #define TARGET_ELF_PAGESTART(_v) ((_v) & ~(unsigned long)(TARGET_ELF_EXEC_PAGESIZE - 1))
559 #define TARGET_ELF_PAGEOFFSET(_v) ((_v) & (TARGET_ELF_EXEC_PAGESIZE - 1))
561 #define INTERPRETER_NONE 0
562 #define INTERPRETER_AOUT 1
563 #define INTERPRETER_ELF 2
565 #define DLINFO_ITEMS 12
567 static inline void memcpy_fromfs(void *to
, const void *from
, unsigned long n
)
572 static int load_aout_interp(void *exptr
, int interp_fd
);
575 static void bswap_ehdr(struct elfhdr
*ehdr
)
577 bswap16s(&ehdr
->e_type
); /* Object file type */
578 bswap16s(&ehdr
->e_machine
); /* Architecture */
579 bswap32s(&ehdr
->e_version
); /* Object file version */
580 bswaptls(&ehdr
->e_entry
); /* Entry point virtual address */
581 bswaptls(&ehdr
->e_phoff
); /* Program header table file offset */
582 bswaptls(&ehdr
->e_shoff
); /* Section header table file offset */
583 bswap32s(&ehdr
->e_flags
); /* Processor-specific flags */
584 bswap16s(&ehdr
->e_ehsize
); /* ELF header size in bytes */
585 bswap16s(&ehdr
->e_phentsize
); /* Program header table entry size */
586 bswap16s(&ehdr
->e_phnum
); /* Program header table entry count */
587 bswap16s(&ehdr
->e_shentsize
); /* Section header table entry size */
588 bswap16s(&ehdr
->e_shnum
); /* Section header table entry count */
589 bswap16s(&ehdr
->e_shstrndx
); /* Section header string table index */
592 static void bswap_phdr(struct elf_phdr
*phdr
)
594 bswap32s(&phdr
->p_type
); /* Segment type */
595 bswaptls(&phdr
->p_offset
); /* Segment file offset */
596 bswaptls(&phdr
->p_vaddr
); /* Segment virtual address */
597 bswaptls(&phdr
->p_paddr
); /* Segment physical address */
598 bswaptls(&phdr
->p_filesz
); /* Segment size in file */
599 bswaptls(&phdr
->p_memsz
); /* Segment size in memory */
600 bswap32s(&phdr
->p_flags
); /* Segment flags */
601 bswaptls(&phdr
->p_align
); /* Segment alignment */
604 static void bswap_shdr(struct elf_shdr
*shdr
)
606 bswap32s(&shdr
->sh_name
);
607 bswap32s(&shdr
->sh_type
);
608 bswaptls(&shdr
->sh_flags
);
609 bswaptls(&shdr
->sh_addr
);
610 bswaptls(&shdr
->sh_offset
);
611 bswaptls(&shdr
->sh_size
);
612 bswap32s(&shdr
->sh_link
);
613 bswap32s(&shdr
->sh_info
);
614 bswaptls(&shdr
->sh_addralign
);
615 bswaptls(&shdr
->sh_entsize
);
618 static void bswap_sym(struct elf_sym
*sym
)
620 bswap32s(&sym
->st_name
);
621 bswaptls(&sym
->st_value
);
622 bswaptls(&sym
->st_size
);
623 bswap16s(&sym
->st_shndx
);
628 * 'copy_elf_strings()' copies argument/envelope strings from user
629 * memory to free pages in kernel mem. These are in a format ready
630 * to be put directly into the top of new user memory.
633 static abi_ulong
copy_elf_strings(int argc
, char **argv
, void **page
,
636 char *tmp
, *tmp1
, *pag
= NULL
;
640 return 0; /* bullet-proofing */
645 fprintf(stderr
, "VFS: argc is wrong");
651 if (p
< len
) { /* this shouldn't happen - 128kB */
657 offset
= p
% TARGET_PAGE_SIZE
;
658 pag
= (char *)page
[p
/ TARGET_PAGE_SIZE
];
660 pag
= g_try_malloc0(TARGET_PAGE_SIZE
);
661 page
[p
/ TARGET_PAGE_SIZE
] = pag
;
666 if (len
== 0 || offset
== 0) {
667 *(pag
+ offset
) = *tmp
;
670 int bytes_to_copy
= (len
> offset
) ? offset
: len
;
671 tmp
-= bytes_to_copy
;
673 offset
-= bytes_to_copy
;
674 len
-= bytes_to_copy
;
675 memcpy_fromfs(pag
+ offset
, tmp
, bytes_to_copy
+ 1);
682 static abi_ulong
setup_arg_pages(abi_ulong p
, struct bsd_binprm
*bprm
,
683 struct image_info
*info
)
685 abi_ulong stack_base
, size
, error
;
688 /* Create enough stack to hold everything. If we don't use
689 * it for args, we'll use it for something else...
691 size
= x86_stack_size
;
692 if (size
< MAX_ARG_PAGES
* TARGET_PAGE_SIZE
)
693 size
= MAX_ARG_PAGES
* TARGET_PAGE_SIZE
;
694 error
= target_mmap(0,
695 size
+ qemu_host_page_size
,
696 PROT_READ
| PROT_WRITE
,
697 MAP_PRIVATE
| MAP_ANON
,
703 /* we reserve one extra page at the top of the stack as guard */
704 target_mprotect(error
+ size
, qemu_host_page_size
, PROT_NONE
);
706 stack_base
= error
+ size
- MAX_ARG_PAGES
* TARGET_PAGE_SIZE
;
709 for (i
= 0 ; i
< MAX_ARG_PAGES
; i
++) {
712 /* FIXME - check return value of memcpy_to_target() for failure */
713 memcpy_to_target(stack_base
, bprm
->page
[i
], TARGET_PAGE_SIZE
);
714 g_free(bprm
->page
[i
]);
716 stack_base
+= TARGET_PAGE_SIZE
;
721 static void set_brk(abi_ulong start
, abi_ulong end
)
723 /* page-align the start and end addresses... */
724 start
= HOST_PAGE_ALIGN(start
);
725 end
= HOST_PAGE_ALIGN(end
);
728 if (target_mmap(start
, end
- start
,
729 PROT_READ
| PROT_WRITE
| PROT_EXEC
,
730 MAP_FIXED
| MAP_PRIVATE
| MAP_ANON
, -1, 0) == -1) {
731 perror("cannot mmap brk");
737 /* We need to explicitly zero any fractional pages after the data
738 section (i.e. bss). This would contain the junk from the file that
739 should not be in memory. */
740 static void padzero(abi_ulong elf_bss
, abi_ulong last_bss
)
744 if (elf_bss
>= last_bss
)
747 /* XXX: this is really a hack : if the real host page size is
748 smaller than the target page size, some pages after the end
749 of the file may not be mapped. A better fix would be to
750 patch target_mmap(), but it is more complicated as the file
751 size must be known */
752 if (qemu_real_host_page_size
< qemu_host_page_size
) {
753 abi_ulong end_addr
, end_addr1
;
754 end_addr1
= REAL_HOST_PAGE_ALIGN(elf_bss
);
755 end_addr
= HOST_PAGE_ALIGN(elf_bss
);
756 if (end_addr1
< end_addr
) {
757 mmap((void *)g2h_untagged(end_addr1
), end_addr
- end_addr1
,
758 PROT_READ
| PROT_WRITE
| PROT_EXEC
,
759 MAP_FIXED
| MAP_PRIVATE
| MAP_ANON
, -1, 0);
763 nbyte
= elf_bss
& (qemu_host_page_size
- 1);
765 nbyte
= qemu_host_page_size
- nbyte
;
767 /* FIXME - what to do if put_user() fails? */
768 put_user_u8(0, elf_bss
);
775 static abi_ulong
create_elf_tables(abi_ulong p
, int argc
, int envc
,
776 struct elfhdr
* exec
,
779 abi_ulong interp_load_addr
, int ibcs
,
780 struct image_info
*info
)
784 abi_ulong u_platform
;
785 const char *k_platform
;
786 const int n
= sizeof(elf_addr_t
);
790 k_platform
= ELF_PLATFORM
;
792 size_t len
= strlen(k_platform
) + 1;
793 sp
-= (len
+ n
- 1) & ~(n
- 1);
795 /* FIXME - check return value of memcpy_to_target() for failure */
796 memcpy_to_target(sp
, k_platform
, len
);
799 * Force 16 byte _final_ alignment here for generality.
801 sp
= sp
& ~(abi_ulong
)15;
802 size
= (DLINFO_ITEMS
+ 1) * 2;
805 #ifdef DLINFO_ARCH_ITEMS
806 size
+= DLINFO_ARCH_ITEMS
* 2;
808 size
+= envc
+ argc
+ 2;
809 size
+= (!ibcs
? 3 : 1); /* argc itself */
812 sp
-= 16 - (size
& 15);
814 /* This is correct because Linux defines
815 * elf_addr_t as Elf32_Off / Elf64_Off
817 #define NEW_AUX_ENT(id, val) do { \
818 sp -= n; put_user_ual(val, sp); \
819 sp -= n; put_user_ual(id, sp); \
822 NEW_AUX_ENT(AT_NULL
, 0);
824 /* There must be exactly DLINFO_ITEMS entries here. */
825 NEW_AUX_ENT(AT_PHDR
, (abi_ulong
)(load_addr
+ exec
->e_phoff
));
826 NEW_AUX_ENT(AT_PHENT
, (abi_ulong
)(sizeof(struct elf_phdr
)));
827 NEW_AUX_ENT(AT_PHNUM
, (abi_ulong
)(exec
->e_phnum
));
828 NEW_AUX_ENT(AT_PAGESZ
, (abi_ulong
)(TARGET_PAGE_SIZE
));
829 NEW_AUX_ENT(AT_BASE
, (abi_ulong
)(interp_load_addr
));
830 NEW_AUX_ENT(AT_FLAGS
, (abi_ulong
)0);
831 NEW_AUX_ENT(AT_ENTRY
, load_bias
+ exec
->e_entry
);
832 NEW_AUX_ENT(AT_UID
, (abi_ulong
) getuid());
833 NEW_AUX_ENT(AT_EUID
, (abi_ulong
) geteuid());
834 NEW_AUX_ENT(AT_GID
, (abi_ulong
) getgid());
835 NEW_AUX_ENT(AT_EGID
, (abi_ulong
) getegid());
836 NEW_AUX_ENT(AT_HWCAP
, (abi_ulong
) ELF_HWCAP
);
837 NEW_AUX_ENT(AT_CLKTCK
, (abi_ulong
) sysconf(_SC_CLK_TCK
));
839 NEW_AUX_ENT(AT_PLATFORM
, u_platform
);
842 * ARCH_DLINFO must come last so platform specific code can enforce
843 * special alignment requirements on the AUXV if necessary (eg. PPC).
849 sp
= loader_build_argptr(envc
, argc
, sp
, p
, !ibcs
);
854 static abi_ulong
load_elf_interp(struct elfhdr
*interp_elf_ex
,
856 abi_ulong
*interp_load_addr
)
858 struct elf_phdr
*elf_phdata
= NULL
;
859 struct elf_phdr
*eppnt
;
860 abi_ulong load_addr
= 0;
861 int load_addr_set
= 0;
863 abi_ulong last_bss
, elf_bss
;
872 bswap_ehdr(interp_elf_ex
);
874 /* First of all, some simple consistency checks */
875 if ((interp_elf_ex
->e_type
!= ET_EXEC
&&
876 interp_elf_ex
->e_type
!= ET_DYN
) ||
877 !elf_check_arch(interp_elf_ex
->e_machine
)) {
878 return ~((abi_ulong
)0UL);
882 /* Now read in all of the header information */
884 if (sizeof(struct elf_phdr
) * interp_elf_ex
->e_phnum
> TARGET_PAGE_SIZE
)
885 return ~(abi_ulong
)0UL;
887 elf_phdata
= (struct elf_phdr
*)
888 malloc(sizeof(struct elf_phdr
) * interp_elf_ex
->e_phnum
);
891 return ~((abi_ulong
)0UL);
894 * If the size of this structure has changed, then punt, since
895 * we will be doing the wrong thing.
897 if (interp_elf_ex
->e_phentsize
!= sizeof(struct elf_phdr
)) {
899 return ~((abi_ulong
)0UL);
902 retval
= lseek(interpreter_fd
, interp_elf_ex
->e_phoff
, SEEK_SET
);
904 retval
= read(interpreter_fd
,
906 sizeof(struct elf_phdr
) * interp_elf_ex
->e_phnum
);
909 perror("load_elf_interp");
916 for (i
= 0; i
<interp_elf_ex
->e_phnum
; i
++, eppnt
++) {
921 if (interp_elf_ex
->e_type
== ET_DYN
) {
922 /* in order to avoid hardcoding the interpreter load
923 address in qemu, we allocate a big enough memory zone */
924 error
= target_mmap(0, INTERP_MAP_SIZE
,
925 PROT_NONE
, MAP_PRIVATE
| MAP_ANON
,
936 for (i
= 0; i
< interp_elf_ex
->e_phnum
; i
++, eppnt
++)
937 if (eppnt
->p_type
== PT_LOAD
) {
938 int elf_type
= MAP_PRIVATE
| MAP_DENYWRITE
;
943 if (eppnt
->p_flags
& PF_R
) elf_prot
= PROT_READ
;
944 if (eppnt
->p_flags
& PF_W
) elf_prot
|= PROT_WRITE
;
945 if (eppnt
->p_flags
& PF_X
) elf_prot
|= PROT_EXEC
;
946 if (interp_elf_ex
->e_type
== ET_EXEC
|| load_addr_set
) {
947 elf_type
|= MAP_FIXED
;
948 vaddr
= eppnt
->p_vaddr
;
950 error
= target_mmap(load_addr
+ TARGET_ELF_PAGESTART(vaddr
),
951 eppnt
->p_filesz
+ TARGET_ELF_PAGEOFFSET(eppnt
->p_vaddr
),
955 eppnt
->p_offset
- TARGET_ELF_PAGEOFFSET(eppnt
->p_vaddr
));
959 close(interpreter_fd
);
961 return ~((abi_ulong
)0UL);
964 if (!load_addr_set
&& interp_elf_ex
->e_type
== ET_DYN
) {
970 * Find the end of the file mapping for this phdr, and keep
971 * track of the largest address we see for this.
973 k
= load_addr
+ eppnt
->p_vaddr
+ eppnt
->p_filesz
;
974 if (k
> elf_bss
) elf_bss
= k
;
977 * Do the same thing for the memory mapping - between
978 * elf_bss and last_bss is the bss section.
980 k
= load_addr
+ eppnt
->p_memsz
+ eppnt
->p_vaddr
;
981 if (k
> last_bss
) last_bss
= k
;
984 /* Now use mmap to map the library into memory. */
986 close(interpreter_fd
);
989 * Now fill out the bss section. First pad the last page up
990 * to the page boundary, and then perform a mmap to make sure
991 * that there are zeromapped pages up to and including the last
994 padzero(elf_bss
, last_bss
);
995 elf_bss
= TARGET_ELF_PAGESTART(elf_bss
+ qemu_host_page_size
- 1); /* What we have mapped so far */
997 /* Map the last of the bss segment */
998 if (last_bss
> elf_bss
) {
999 target_mmap(elf_bss
, last_bss
- elf_bss
,
1000 PROT_READ
| PROT_WRITE
| PROT_EXEC
,
1001 MAP_FIXED
| MAP_PRIVATE
| MAP_ANON
, -1, 0);
1005 *interp_load_addr
= load_addr
;
1006 return ((abi_ulong
) interp_elf_ex
->e_entry
) + load_addr
;
1009 static int symfind(const void *s0
, const void *s1
)
1011 target_ulong addr
= *(target_ulong
*)s0
;
1012 struct elf_sym
*sym
= (struct elf_sym
*)s1
;
1014 if (addr
< sym
->st_value
) {
1016 } else if (addr
>= sym
->st_value
+ sym
->st_size
) {
1022 static const char *lookup_symbolxx(struct syminfo
*s
, target_ulong orig_addr
)
1024 #if ELF_CLASS == ELFCLASS32
1025 struct elf_sym
*syms
= s
->disas_symtab
.elf32
;
1027 struct elf_sym
*syms
= s
->disas_symtab
.elf64
;
1031 struct elf_sym
*sym
;
1033 sym
= bsearch(&orig_addr
, syms
, s
->disas_num_syms
, sizeof(*syms
), symfind
);
1035 return s
->disas_strtab
+ sym
->st_name
;
1041 /* FIXME: This should use elf_ops.h */
1042 static int symcmp(const void *s0
, const void *s1
)
1044 struct elf_sym
*sym0
= (struct elf_sym
*)s0
;
1045 struct elf_sym
*sym1
= (struct elf_sym
*)s1
;
1046 return (sym0
->st_value
< sym1
->st_value
)
1048 : ((sym0
->st_value
> sym1
->st_value
) ? 1 : 0);
1051 /* Best attempt to load symbols from this ELF object. */
1052 static void load_symbols(struct elfhdr
*hdr
, int fd
)
1054 unsigned int i
, nsyms
;
1055 struct elf_shdr sechdr
, symtab
, strtab
;
1058 struct elf_sym
*syms
, *new_syms
;
1060 lseek(fd
, hdr
->e_shoff
, SEEK_SET
);
1061 for (i
= 0; i
< hdr
->e_shnum
; i
++) {
1062 if (read(fd
, &sechdr
, sizeof(sechdr
)) != sizeof(sechdr
))
1065 bswap_shdr(&sechdr
);
1067 if (sechdr
.sh_type
== SHT_SYMTAB
) {
1069 lseek(fd
, hdr
->e_shoff
1070 + sizeof(sechdr
) * sechdr
.sh_link
, SEEK_SET
);
1071 if (read(fd
, &strtab
, sizeof(strtab
))
1075 bswap_shdr(&strtab
);
1080 return; /* Shouldn't happen... */
1083 /* Now know where the strtab and symtab are. Snarf them. */
1084 s
= malloc(sizeof(*s
));
1085 syms
= malloc(symtab
.sh_size
);
1090 s
->disas_strtab
= strings
= malloc(strtab
.sh_size
);
1091 if (!s
->disas_strtab
) {
1097 lseek(fd
, symtab
.sh_offset
, SEEK_SET
);
1098 if (read(fd
, syms
, symtab
.sh_size
) != symtab
.sh_size
) {
1105 nsyms
= symtab
.sh_size
/ sizeof(struct elf_sym
);
1110 bswap_sym(syms
+ i
);
1112 // Throw away entries which we do not need.
1113 if (syms
[i
].st_shndx
== SHN_UNDEF
||
1114 syms
[i
].st_shndx
>= SHN_LORESERVE
||
1115 ELF_ST_TYPE(syms
[i
].st_info
) != STT_FUNC
) {
1118 syms
[i
] = syms
[nsyms
];
1122 #if defined(TARGET_ARM) || defined(TARGET_MIPS)
1123 /* The bottom address bit marks a Thumb or MIPS16 symbol. */
1124 syms
[i
].st_value
&= ~(target_ulong
)1;
1129 /* Attempt to free the storage associated with the local symbols
1130 that we threw away. Whether or not this has any effect on the
1131 memory allocation depends on the malloc implementation and how
1132 many symbols we managed to discard. */
1133 new_syms
= realloc(syms
, nsyms
* sizeof(*syms
));
1134 if (new_syms
== NULL
) {
1142 qsort(syms
, nsyms
, sizeof(*syms
), symcmp
);
1144 lseek(fd
, strtab
.sh_offset
, SEEK_SET
);
1145 if (read(fd
, strings
, strtab
.sh_size
) != strtab
.sh_size
) {
1151 s
->disas_num_syms
= nsyms
;
1152 #if ELF_CLASS == ELFCLASS32
1153 s
->disas_symtab
.elf32
= syms
;
1154 s
->lookup_symbol
= (lookup_symbol_t
)lookup_symbolxx
;
1156 s
->disas_symtab
.elf64
= syms
;
1157 s
->lookup_symbol
= (lookup_symbol_t
)lookup_symbolxx
;
1163 int load_elf_binary(struct bsd_binprm
*bprm
, struct target_pt_regs
*regs
,
1164 struct image_info
*info
)
1166 struct elfhdr elf_ex
;
1167 struct elfhdr interp_elf_ex
;
1168 struct exec interp_ex
;
1169 int interpreter_fd
= -1; /* avoid warning */
1170 abi_ulong load_addr
, load_bias
;
1171 int load_addr_set
= 0;
1172 unsigned int interpreter_type
= INTERPRETER_NONE
;
1173 unsigned char ibcs2_interpreter
;
1175 struct elf_phdr
* elf_ppnt
;
1176 struct elf_phdr
*elf_phdata
;
1177 abi_ulong elf_bss
, k
, elf_brk
;
1179 char * elf_interpreter
;
1180 abi_ulong elf_entry
, interp_load_addr
= 0;
1181 abi_ulong start_code
, end_code
, start_data
, end_data
;
1182 abi_ulong reloc_func_desc
= 0;
1183 #ifdef LOW_ELF_STACK
1184 abi_ulong elf_stack
= ~((abi_ulong
)0UL);
1186 char passed_fileno
[6];
1188 ibcs2_interpreter
= 0;
1191 elf_ex
= *((struct elfhdr
*) bprm
->buf
); /* exec-header */
1193 bswap_ehdr(&elf_ex
);
1196 /* First of all, some simple consistency checks */
1197 if ((elf_ex
.e_type
!= ET_EXEC
&& elf_ex
.e_type
!= ET_DYN
) ||
1198 (!elf_check_arch(elf_ex
.e_machine
))) {
1202 bprm
->p
= copy_elf_strings(1, &bprm
->filename
, bprm
->page
, bprm
->p
);
1203 bprm
->p
= copy_elf_strings(bprm
->envc
, bprm
->envp
, bprm
->page
,bprm
->p
);
1204 bprm
->p
= copy_elf_strings(bprm
->argc
, bprm
->argv
, bprm
->page
,bprm
->p
);
1209 /* Now read in all of the header information */
1210 elf_phdata
= (struct elf_phdr
*)malloc(elf_ex
.e_phentsize
*elf_ex
.e_phnum
);
1211 if (elf_phdata
== NULL
) {
1215 retval
= lseek(bprm
->fd
, elf_ex
.e_phoff
, SEEK_SET
);
1217 retval
= read(bprm
->fd
, (char *)elf_phdata
,
1218 elf_ex
.e_phentsize
* elf_ex
.e_phnum
);
1222 perror("load_elf_binary");
1229 elf_ppnt
= elf_phdata
;
1230 for (i
= 0; i
< elf_ex
.e_phnum
; i
++, elf_ppnt
++) {
1231 bswap_phdr(elf_ppnt
);
1234 elf_ppnt
= elf_phdata
;
1240 elf_interpreter
= NULL
;
1241 start_code
= ~((abi_ulong
)0UL);
1245 interp_ex
.a_info
= 0;
1247 for (i
= 0;i
< elf_ex
.e_phnum
; i
++) {
1248 if (elf_ppnt
->p_type
== PT_INTERP
) {
1249 if (elf_interpreter
!= NULL
)
1252 free(elf_interpreter
);
1257 /* This is the program interpreter used for
1258 * shared libraries - for now assume that this
1259 * is an a.out format binary
1262 elf_interpreter
= (char *)malloc(elf_ppnt
->p_filesz
);
1264 if (elf_interpreter
== NULL
) {
1270 retval
= lseek(bprm
->fd
, elf_ppnt
->p_offset
, SEEK_SET
);
1272 retval
= read(bprm
->fd
, elf_interpreter
, elf_ppnt
->p_filesz
);
1275 perror("load_elf_binary2");
1279 /* If the program interpreter is one of these two,
1280 then assume an iBCS2 image. Otherwise assume
1281 a native linux image. */
1283 /* JRP - Need to add X86 lib dir stuff here... */
1285 if (strcmp(elf_interpreter
, "/usr/lib/libc.so.1") == 0 ||
1286 strcmp(elf_interpreter
, "/usr/lib/ld.so.1") == 0) {
1287 ibcs2_interpreter
= 1;
1291 printf("Using ELF interpreter %s\n", path(elf_interpreter
));
1294 retval
= open(path(elf_interpreter
), O_RDONLY
);
1296 interpreter_fd
= retval
;
1299 perror(elf_interpreter
);
1301 /* retval = -errno; */
1306 retval
= lseek(interpreter_fd
, 0, SEEK_SET
);
1308 retval
= read(interpreter_fd
, bprm
->buf
, 128);
1312 interp_ex
= *((struct exec
*) bprm
->buf
); /* aout exec-header */
1313 interp_elf_ex
= *((struct elfhdr
*) bprm
->buf
); /* elf exec-header */
1316 perror("load_elf_binary3");
1319 free(elf_interpreter
);
1327 /* Some simple consistency checks for the interpreter */
1328 if (elf_interpreter
) {
1329 interpreter_type
= INTERPRETER_ELF
| INTERPRETER_AOUT
;
1331 /* Now figure out which format our binary is */
1332 if ((N_MAGIC(interp_ex
) != OMAGIC
) && (N_MAGIC(interp_ex
) != ZMAGIC
) &&
1333 (N_MAGIC(interp_ex
) != QMAGIC
)) {
1334 interpreter_type
= INTERPRETER_ELF
;
1337 if (interp_elf_ex
.e_ident
[0] != 0x7f ||
1338 strncmp((char *)&interp_elf_ex
.e_ident
[1], "ELF", 3) != 0) {
1339 interpreter_type
&= ~INTERPRETER_ELF
;
1342 if (!interpreter_type
) {
1343 free(elf_interpreter
);
1350 /* OK, we are done with that, now set up the arg stuff,
1351 and then start this sucker up */
1356 if (interpreter_type
== INTERPRETER_AOUT
) {
1357 snprintf(passed_fileno
, sizeof(passed_fileno
), "%d", bprm
->fd
);
1358 passed_p
= passed_fileno
;
1360 if (elf_interpreter
) {
1361 bprm
->p
= copy_elf_strings(1, &passed_p
, bprm
->page
, bprm
->p
);
1366 free(elf_interpreter
);
1373 /* OK, This is the point of no return */
1376 info
->start_mmap
= (abi_ulong
)ELF_START_MMAP
;
1378 elf_entry
= (abi_ulong
) elf_ex
.e_entry
;
1381 * In case where user has not explicitly set the guest_base, we
1382 * probe here that should we set it automatically.
1384 if (!have_guest_base
) {
1386 * Go through ELF program header table and find out whether
1387 * any of the segments drop below our current mmap_min_addr and
1388 * in that case set guest_base to corresponding address.
1390 for (i
= 0, elf_ppnt
= elf_phdata
; i
< elf_ex
.e_phnum
;
1392 if (elf_ppnt
->p_type
!= PT_LOAD
)
1394 if (HOST_PAGE_ALIGN(elf_ppnt
->p_vaddr
) < mmap_min_addr
) {
1395 guest_base
= HOST_PAGE_ALIGN(mmap_min_addr
);
1401 /* Do this so that we can load the interpreter, if need be. We will
1402 change some of these later */
1404 bprm
->p
= setup_arg_pages(bprm
->p
, bprm
, info
);
1405 info
->start_stack
= bprm
->p
;
1407 /* Now we do a little grungy work by mmaping the ELF image into
1408 * the correct location in memory. At this point, we assume that
1409 * the image should be loaded at fixed address, not at a variable
1413 for (i
= 0, elf_ppnt
= elf_phdata
; i
< elf_ex
.e_phnum
; i
++, elf_ppnt
++) {
1418 if (elf_ppnt
->p_type
!= PT_LOAD
)
1421 if (elf_ppnt
->p_flags
& PF_R
) elf_prot
|= PROT_READ
;
1422 if (elf_ppnt
->p_flags
& PF_W
) elf_prot
|= PROT_WRITE
;
1423 if (elf_ppnt
->p_flags
& PF_X
) elf_prot
|= PROT_EXEC
;
1424 elf_flags
= MAP_PRIVATE
| MAP_DENYWRITE
;
1425 if (elf_ex
.e_type
== ET_EXEC
|| load_addr_set
) {
1426 elf_flags
|= MAP_FIXED
;
1427 } else if (elf_ex
.e_type
== ET_DYN
) {
1428 /* Try and get dynamic programs out of the way of the default mmap
1429 base, as well as whatever program they might try to exec. This
1430 is because the brk will follow the loader, and is not movable. */
1431 /* NOTE: for qemu, we do a big mmap to get enough space
1432 without hardcoding any address */
1433 error
= target_mmap(0, ET_DYN_MAP_SIZE
,
1434 PROT_NONE
, MAP_PRIVATE
| MAP_ANON
,
1440 load_bias
= TARGET_ELF_PAGESTART(error
- elf_ppnt
->p_vaddr
);
1443 error
= target_mmap(TARGET_ELF_PAGESTART(load_bias
+ elf_ppnt
->p_vaddr
),
1444 (elf_ppnt
->p_filesz
+
1445 TARGET_ELF_PAGEOFFSET(elf_ppnt
->p_vaddr
)),
1447 (MAP_FIXED
| MAP_PRIVATE
| MAP_DENYWRITE
),
1449 (elf_ppnt
->p_offset
-
1450 TARGET_ELF_PAGEOFFSET(elf_ppnt
->p_vaddr
)));
1456 #ifdef LOW_ELF_STACK
1457 if (TARGET_ELF_PAGESTART(elf_ppnt
->p_vaddr
) < elf_stack
)
1458 elf_stack
= TARGET_ELF_PAGESTART(elf_ppnt
->p_vaddr
);
1461 if (!load_addr_set
) {
1463 load_addr
= elf_ppnt
->p_vaddr
- elf_ppnt
->p_offset
;
1464 if (elf_ex
.e_type
== ET_DYN
) {
1465 load_bias
+= error
-
1466 TARGET_ELF_PAGESTART(load_bias
+ elf_ppnt
->p_vaddr
);
1467 load_addr
+= load_bias
;
1468 reloc_func_desc
= load_bias
;
1471 k
= elf_ppnt
->p_vaddr
;
1476 k
= elf_ppnt
->p_vaddr
+ elf_ppnt
->p_filesz
;
1479 if ((elf_ppnt
->p_flags
& PF_X
) && end_code
< k
)
1483 k
= elf_ppnt
->p_vaddr
+ elf_ppnt
->p_memsz
;
1484 if (k
> elf_brk
) elf_brk
= k
;
1487 elf_entry
+= load_bias
;
1488 elf_bss
+= load_bias
;
1489 elf_brk
+= load_bias
;
1490 start_code
+= load_bias
;
1491 end_code
+= load_bias
;
1492 start_data
+= load_bias
;
1493 end_data
+= load_bias
;
1495 if (elf_interpreter
) {
1496 if (interpreter_type
& 1) {
1497 elf_entry
= load_aout_interp(&interp_ex
, interpreter_fd
);
1499 else if (interpreter_type
& 2) {
1500 elf_entry
= load_elf_interp(&interp_elf_ex
, interpreter_fd
,
1503 reloc_func_desc
= interp_load_addr
;
1505 close(interpreter_fd
);
1506 free(elf_interpreter
);
1508 if (elf_entry
== ~((abi_ulong
)0UL)) {
1509 printf("Unable to load interpreter\n");
1518 if (qemu_log_enabled())
1519 load_symbols(&elf_ex
, bprm
->fd
);
1521 if (interpreter_type
!= INTERPRETER_AOUT
) close(bprm
->fd
);
1522 info
->personality
= (ibcs2_interpreter
? PER_SVR4
: PER_LINUX
);
1524 #ifdef LOW_ELF_STACK
1525 info
->start_stack
= bprm
->p
= elf_stack
- 4;
1527 bprm
->p
= create_elf_tables(bprm
->p
,
1531 load_addr
, load_bias
,
1533 (interpreter_type
== INTERPRETER_AOUT
? 0 : 1),
1535 info
->load_addr
= reloc_func_desc
;
1536 info
->start_brk
= info
->brk
= elf_brk
;
1537 info
->end_code
= end_code
;
1538 info
->start_code
= start_code
;
1539 info
->start_data
= start_data
;
1540 info
->end_data
= end_data
;
1541 info
->start_stack
= bprm
->p
;
1543 /* Calling set_brk effectively mmaps the pages that we need for the bss and break
1545 set_brk(elf_bss
, elf_brk
);
1547 padzero(elf_bss
, elf_brk
);
1550 printf("(start_brk) %x\n" , info
->start_brk
);
1551 printf("(end_code) %x\n" , info
->end_code
);
1552 printf("(start_code) %x\n" , info
->start_code
);
1553 printf("(end_data) %x\n" , info
->end_data
);
1554 printf("(start_stack) %x\n" , info
->start_stack
);
1555 printf("(brk) %x\n" , info
->brk
);
1558 if (info
->personality
== PER_SVR4
)
1560 /* Why this, you ask??? Well SVr4 maps page 0 as read-only,
1561 and some applications "depend" upon this behavior.
1562 Since we do not have the power to recompile these, we
1563 emulate the SVr4 behavior. Sigh. */
1564 target_mmap(0, qemu_host_page_size
, PROT_READ
| PROT_EXEC
,
1565 MAP_FIXED
| MAP_PRIVATE
, -1, 0);
1568 info
->entry
= elf_entry
;
1573 static int load_aout_interp(void *exptr
, int interp_fd
)
1575 printf("a.out interpreter not yet supported\n");
1579 void do_init_thread(struct target_pt_regs
*regs
, struct image_info
*infop
)
1581 init_thread(regs
, infop
);