Lines Matching +full:areg +full:- +full:supply

1 /* This is the Linux kernel elf-loading code, ported into user space */
10 #include "user/tswap-target.h"
11 #include "exec/page-protection.h"
12 #include "user/guest-base.h"
13 #include "user-internals.h"
14 #include "signal-common.h"
16 #include "user-mmap.h"
21 #include "qemu/guest-random.h"
26 #include "qemu/error-report.h"
31 #include "target/arm/cpu-features.h"
101 PER_IRIX32 = 0x0009 | STICKY_TIMEOUTS,/* IRIX5 32-bit */
102 PER_IRIXN32 = 0x000a | STICKY_TIMEOUTS,/* IRIX6 new 32-bit */
103 PER_IRIX64 = 0x000b | STICKY_TIMEOUTS,/* IRIX6 64-bit */
119 return info->personality == PER_LINUX_FDPIC; in info_is_fdpic()
163 return cpu->env.features[FEAT_1_EDX]; in get_elf_hwcap()
174 regs->rax = 0; in init_thread()
175 regs->rsp = infop->start_stack; in init_thread()
176 regs->rip = infop->entry; in init_thread()
191 (*regs)[0] = tswapreg(env->regs[15]); in elf_core_copy_regs()
192 (*regs)[1] = tswapreg(env->regs[14]); in elf_core_copy_regs()
193 (*regs)[2] = tswapreg(env->regs[13]); in elf_core_copy_regs()
194 (*regs)[3] = tswapreg(env->regs[12]); in elf_core_copy_regs()
195 (*regs)[4] = tswapreg(env->regs[R_EBP]); in elf_core_copy_regs()
196 (*regs)[5] = tswapreg(env->regs[R_EBX]); in elf_core_copy_regs()
197 (*regs)[6] = tswapreg(env->regs[11]); in elf_core_copy_regs()
198 (*regs)[7] = tswapreg(env->regs[10]); in elf_core_copy_regs()
199 (*regs)[8] = tswapreg(env->regs[9]); in elf_core_copy_regs()
200 (*regs)[9] = tswapreg(env->regs[8]); in elf_core_copy_regs()
201 (*regs)[10] = tswapreg(env->regs[R_EAX]); in elf_core_copy_regs()
202 (*regs)[11] = tswapreg(env->regs[R_ECX]); in elf_core_copy_regs()
203 (*regs)[12] = tswapreg(env->regs[R_EDX]); in elf_core_copy_regs()
204 (*regs)[13] = tswapreg(env->regs[R_ESI]); in elf_core_copy_regs()
205 (*regs)[14] = tswapreg(env->regs[R_EDI]); in elf_core_copy_regs()
206 (*regs)[15] = tswapreg(get_task_state(env_cpu_const(env))->orig_ax); in elf_core_copy_regs()
207 (*regs)[16] = tswapreg(env->eip); in elf_core_copy_regs()
208 (*regs)[17] = tswapreg(env->segs[R_CS].selector & 0xffff); in elf_core_copy_regs()
209 (*regs)[18] = tswapreg(env->eflags); in elf_core_copy_regs()
210 (*regs)[19] = tswapreg(env->regs[R_ESP]); in elf_core_copy_regs()
211 (*regs)[20] = tswapreg(env->segs[R_SS].selector & 0xffff); in elf_core_copy_regs()
212 (*regs)[21] = tswapreg(env->segs[R_FS].selector & 0xffff); in elf_core_copy_regs()
213 (*regs)[22] = tswapreg(env->segs[R_GS].selector & 0xffff); in elf_core_copy_regs()
214 (*regs)[23] = tswapreg(env->segs[R_DS].selector & 0xffff); in elf_core_copy_regs()
215 (*regs)[24] = tswapreg(env->segs[R_ES].selector & 0xffff); in elf_core_copy_regs()
216 (*regs)[25] = tswapreg(env->segs[R_FS].selector & 0xffff); in elf_core_copy_regs()
217 (*regs)[26] = tswapreg(env->segs[R_GS].selector & 0xffff); in elf_core_copy_regs()
228 * has specified -R reserved_va, which would trigger an assert(). in init_guest_commpage()
231 TARGET_VSYSCALL_PAGE + TARGET_PAGE_SIZE - 1 > reserved_va) { in init_guest_commpage()
273 regs->esp = infop->start_stack; in init_thread()
274 regs->eip = infop->entry; in init_thread()
276 /* SVR4/i386 ABI (pages 3-31, 3-32) says that when the program in init_thread()
283 regs->edx = 0; in init_thread()
298 (*regs)[0] = tswapreg(env->regs[R_EBX]); in elf_core_copy_regs()
299 (*regs)[1] = tswapreg(env->regs[R_ECX]); in elf_core_copy_regs()
300 (*regs)[2] = tswapreg(env->regs[R_EDX]); in elf_core_copy_regs()
301 (*regs)[3] = tswapreg(env->regs[R_ESI]); in elf_core_copy_regs()
302 (*regs)[4] = tswapreg(env->regs[R_EDI]); in elf_core_copy_regs()
303 (*regs)[5] = tswapreg(env->regs[R_EBP]); in elf_core_copy_regs()
304 (*regs)[6] = tswapreg(env->regs[R_EAX]); in elf_core_copy_regs()
305 (*regs)[7] = tswapreg(env->segs[R_DS].selector & 0xffff); in elf_core_copy_regs()
306 (*regs)[8] = tswapreg(env->segs[R_ES].selector & 0xffff); in elf_core_copy_regs()
307 (*regs)[9] = tswapreg(env->segs[R_FS].selector & 0xffff); in elf_core_copy_regs()
308 (*regs)[10] = tswapreg(env->segs[R_GS].selector & 0xffff); in elf_core_copy_regs()
309 (*regs)[11] = tswapreg(get_task_state(env_cpu_const(env))->orig_ax); in elf_core_copy_regs()
310 (*regs)[12] = tswapreg(env->eip); in elf_core_copy_regs()
311 (*regs)[13] = tswapreg(env->segs[R_CS].selector & 0xffff); in elf_core_copy_regs()
312 (*regs)[14] = tswapreg(env->eflags); in elf_core_copy_regs()
313 (*regs)[15] = tswapreg(env->regs[R_ESP]); in elf_core_copy_regs()
314 (*regs)[16] = tswapreg(env->segs[R_SS].selector & 0xffff); in elf_core_copy_regs()
319 * All others only supply AT_SYSINFO_EHDR.
325 NEW_AUX_ENT(AT_SYSINFO, vdso_info->entry); \
350 abi_long stack = infop->start_stack; in init_thread()
353 regs->uregs[16] = ARM_CPU_MODE_USR; in init_thread()
354 if (infop->entry & 1) { in init_thread()
355 regs->uregs[16] |= CPSR_T; in init_thread()
357 regs->uregs[15] = infop->entry & 0xfffffffe; in init_thread()
358 regs->uregs[13] = infop->start_stack; in init_thread()
359 /* FIXME - what to for failure of get_user()? */ in init_thread()
360 get_user_ual(regs->uregs[2], stack + 8); /* envp */ in init_thread()
361 get_user_ual(regs->uregs[1], stack + 4); /* envp */ in init_thread()
363 regs->uregs[0] = 0; in init_thread()
366 regs->uregs[10] = infop->start_data; in init_thread()
376 regs->uregs[7] = infop->loadmap_addr; in init_thread()
377 if (infop->interpreter_loadmap_addr) { in init_thread()
379 regs->uregs[8] = infop->interpreter_loadmap_addr; in init_thread()
380 regs->uregs[9] = infop->interpreter_pt_dynamic_addr; in init_thread()
382 regs->uregs[8] = 0; in init_thread()
383 regs->uregs[9] = infop->pt_dynamic_addr; in init_thread()
393 (*regs)[0] = tswapreg(env->regs[0]); in elf_core_copy_regs()
394 (*regs)[1] = tswapreg(env->regs[1]); in elf_core_copy_regs()
395 (*regs)[2] = tswapreg(env->regs[2]); in elf_core_copy_regs()
396 (*regs)[3] = tswapreg(env->regs[3]); in elf_core_copy_regs()
397 (*regs)[4] = tswapreg(env->regs[4]); in elf_core_copy_regs()
398 (*regs)[5] = tswapreg(env->regs[5]); in elf_core_copy_regs()
399 (*regs)[6] = tswapreg(env->regs[6]); in elf_core_copy_regs()
400 (*regs)[7] = tswapreg(env->regs[7]); in elf_core_copy_regs()
401 (*regs)[8] = tswapreg(env->regs[8]); in elf_core_copy_regs()
402 (*regs)[9] = tswapreg(env->regs[9]); in elf_core_copy_regs()
403 (*regs)[10] = tswapreg(env->regs[10]); in elf_core_copy_regs()
404 (*regs)[11] = tswapreg(env->regs[11]); in elf_core_copy_regs()
405 (*regs)[12] = tswapreg(env->regs[12]); in elf_core_copy_regs()
406 (*regs)[13] = tswapreg(env->regs[13]); in elf_core_copy_regs()
407 (*regs)[14] = tswapreg(env->regs[14]); in elf_core_copy_regs()
408 (*regs)[15] = tswapreg(env->regs[15]); in elf_core_copy_regs()
411 (*regs)[17] = tswapreg(env->regs[0]); /* XXX */ in elf_core_copy_regs()
472 * M-profile allocates maximum of 2GB address space, so can never in init_guest_commpage()
475 if (arm_feature(&cpu->env, ARM_FEATURE_M)) { in init_guest_commpage()
479 commpage = HI_COMMPAGE & -host_page_size; in init_guest_commpage()
484 -1, 0); in init_guest_commpage()
502 page_set_flags(commpage, commpage | (host_page_size - 1), in init_guest_commpage()
522 do { if (arm_feature(&cpu->env, feat)) { hwcaps |= hwcap; } } while (0) in get_elf_hwcap()
664 #include "vdso-be8.c.inc"
665 #include "vdso-be32.c.inc"
676 # define VDSO_HEADER "vdso-le.c.inc"
693 abi_long stack = infop->start_stack; in init_thread()
696 regs->pc = infop->entry & ~0x3ULL; in init_thread()
697 regs->sp = stack; in init_thread()
709 (*regs)[i] = tswapreg(env->xregs[i]); in elf_core_copy_regs()
711 (*regs)[32] = tswapreg(env->pc); in elf_core_copy_regs()
979 # define VDSO_HEADER "vdso-be.c.inc"
981 # define VDSO_HEADER "vdso-le.c.inc"
1007 /* There are not many sparc32 hwcap bits -- we have all of them. */ in get_elf_hwcap()
1013 uint32_t features = env->def.features; in get_elf_hwcap()
1035 regs->pc = infop->entry; in init_thread()
1036 regs->npc = regs->pc + 4; in init_thread()
1037 regs->y = 0; in init_thread()
1038 regs->u_regs[14] = (infop->start_stack - 16 * sizeof(abi_ulong) in init_thread()
1039 - TARGET_STACK_BIAS); in init_thread()
1105 QEMU_PPC_FEATURE2_HAS_IEEE128 = 0x00400000, /* VSX IEEE Bin Float 128-bit */
1110 QEMU_PPC_FEATURE2_MMA = 0x00020000, /* Matrix-Multiply Assist */
1123 do { if (cpu->env.insns_flags & flag) { features |= feature; } } while (0) in get_elf_hwcap()
1126 if ((cpu->env.insns_flags2 & flags) == flags) { \ in get_elf_hwcap()
1157 do { if (cpu->env.insns_flags & flag) { features |= feature; } } while (0) in get_elf_hwcap2()
1159 do { if (cpu->env.insns_flags2 & flag) { features |= feature; } } while (0) in get_elf_hwcap2()
1179 * - keep the final alignment of sp (sp & 0xf)
1180 * - make sure the 32-bit value at the first 16 byte aligned position of
1183 * - for compatibility with glibc ARCH_DLINFO must always be defined on PPC,
1196 NEW_AUX_ENT(AT_DCACHEBSIZE, cpu->env.dcache_line_size); \
1197 NEW_AUX_ENT(AT_ICACHEBSIZE, cpu->env.icache_line_size); \
1203 _regs->gpr[1] = infop->start_stack; in init_thread()
1207 get_user_u64(val, infop->entry + 8); in init_thread()
1208 _regs->gpr[2] = val + infop->load_bias; in init_thread()
1209 get_user_u64(val, infop->entry); in init_thread()
1210 infop->entry = val + infop->load_bias; in init_thread()
1212 _regs->gpr[12] = infop->entry; /* r12 set to global entry address */ in init_thread()
1215 _regs->nip = infop->entry; in init_thread()
1227 for (i = 0; i < ARRAY_SIZE(env->gpr); i++) { in elf_core_copy_regs()
1228 (*regs)[i] = tswapreg(env->gpr[i]); in elf_core_copy_regs()
1231 (*regs)[32] = tswapreg(env->nip); in elf_core_copy_regs()
1232 (*regs)[33] = tswapreg(env->msr); in elf_core_copy_regs()
1233 (*regs)[35] = tswapreg(env->ctr); in elf_core_copy_regs()
1234 (*regs)[36] = tswapreg(env->lr); in elf_core_copy_regs()
1245 # define VDSO_HEADER "vdso-32.c.inc"
1247 # define VDSO_HEADER "vdso-64.c.inc"
1249 # define VDSO_HEADER "vdso-64le.c.inc"
1268 regs->csr.crmd = 2 << 3; in init_thread()
1269 regs->csr.era = infop->entry; in init_thread()
1270 regs->regs[3] = infop->start_stack; in init_thread()
1290 for (i = 1; i < ARRAY_SIZE(env->gpr); i++) { in elf_core_copy_regs()
1291 (*regs)[TARGET_EF_R0 + i] = tswapreg(env->gpr[i]); in elf_core_copy_regs()
1294 (*regs)[TARGET_EF_CSR_ERA] = tswapreg(env->pc); in elf_core_copy_regs()
1295 (*regs)[TARGET_EF_CSR_BADV] = tswapreg(env->CSR_BADV); in elf_core_copy_regs()
1327 if (FIELD_EX32(cpu->env.cpucfg[1], CPUCFG1, UAL)) { in get_elf_hwcap()
1331 if (FIELD_EX32(cpu->env.cpucfg[2], CPUCFG2, FP)) { in get_elf_hwcap()
1335 if (FIELD_EX32(cpu->env.cpucfg[2], CPUCFG2, LAM)) { in get_elf_hwcap()
1339 if (FIELD_EX32(cpu->env.cpucfg[2], CPUCFG2, LSX)) { in get_elf_hwcap()
1343 if (FIELD_EX32(cpu->env.cpucfg[2], CPUCFG2, LASX)) { in get_elf_hwcap()
1373 do { if ((cpu->env.insn_flags & (_flags)) == _flags) \
1404 regs->cp0_status = 2 << CP0St_KSU; in init_thread()
1405 regs->cp0_epc = infop->entry; in init_thread()
1406 regs->regs[29] = infop->start_stack; in init_thread()
1440 for (i = 1; i < ARRAY_SIZE(env->active_tc.gpr); i++) { in elf_core_copy_regs()
1441 (*regs)[TARGET_EF_R0 + i] = tswapreg(env->active_tc.gpr[i]); in elf_core_copy_regs()
1446 (*regs)[TARGET_EF_LO] = tswapreg(env->active_tc.LO[0]); in elf_core_copy_regs()
1447 (*regs)[TARGET_EF_HI] = tswapreg(env->active_tc.HI[0]); in elf_core_copy_regs()
1448 (*regs)[TARGET_EF_CP0_EPC] = tswapreg(env->active_tc.PC); in elf_core_copy_regs()
1449 (*regs)[TARGET_EF_CP0_BADVADDR] = tswapreg(env->CP0_BadVAddr); in elf_core_copy_regs()
1450 (*regs)[TARGET_EF_CP0_STATUS] = tswapreg(env->CP0_Status); in elf_core_copy_regs()
1451 (*regs)[TARGET_EF_CP0_CAUSE] = tswapreg(env->CP0_Cause); in elf_core_copy_regs()
1479 do { if (cpu->env.insn_flags & (_flag)) { hwcaps |= _hwcap; } } while (0)
1482 do { if (cpu->env._reg & (_mask)) { hwcaps |= _hwcap; } } while (0)
1486 if (extract32(cpu->env._reg, (_start), (_length)) == (_val)) { \
1521 regs->pc = infop->entry; in init_thread()
1522 regs->r1 = infop->start_stack; in init_thread()
1538 (*regs)[pos++] = tswapreg(env->regs[i]); in elf_core_copy_regs()
1541 (*regs)[pos++] = tswapreg(env->pc); in elf_core_copy_regs()
1544 (*regs)[pos++] = tswapreg(env->ear); in elf_core_copy_regs()
1546 (*regs)[pos++] = tswapreg(env->esr); in elf_core_copy_regs()
1560 regs->pc = infop->entry; in init_thread()
1561 regs->gpr[1] = infop->start_stack; in init_thread()
1579 (*regs)[32] = tswapreg(env->pc); in elf_core_copy_regs()
1596 regs->pc = infop->entry; in init_thread()
1597 regs->regs[15] = infop->start_stack; in init_thread()
1621 (*regs)[i] = tswapreg(env->gregs[i]); in elf_core_copy_regs()
1624 (*regs)[TARGET_REG_PC] = tswapreg(env->pc); in elf_core_copy_regs()
1625 (*regs)[TARGET_REG_PR] = tswapreg(env->pr); in elf_core_copy_regs()
1626 (*regs)[TARGET_REG_SR] = tswapreg(env->sr); in elf_core_copy_regs()
1627 (*regs)[TARGET_REG_GBR] = tswapreg(env->gbr); in elf_core_copy_regs()
1628 (*regs)[TARGET_REG_MACH] = tswapreg(env->mach); in elf_core_copy_regs()
1629 (*regs)[TARGET_REG_MACL] = tswapreg(env->macl); in elf_core_copy_regs()
1640 SH_CPU_HAS_DSP = 0x0008, /* SH-DSP: DSP support */
1645 SH_CPU_HAS_OP32 = 0x0100, /* 32-bit instruction support */
1658 if (cpu->env.features & SH_FEATURE_SH4A) { in get_elf_hwcap()
1678 regs->usp = infop->start_stack; in init_thread()
1679 regs->sr = 0; in init_thread()
1680 regs->pc = infop->entry; in init_thread()
1689 (*regs)[0] = tswapreg(env->dregs[1]); in elf_core_copy_regs()
1690 (*regs)[1] = tswapreg(env->dregs[2]); in elf_core_copy_regs()
1691 (*regs)[2] = tswapreg(env->dregs[3]); in elf_core_copy_regs()
1692 (*regs)[3] = tswapreg(env->dregs[4]); in elf_core_copy_regs()
1693 (*regs)[4] = tswapreg(env->dregs[5]); in elf_core_copy_regs()
1694 (*regs)[5] = tswapreg(env->dregs[6]); in elf_core_copy_regs()
1695 (*regs)[6] = tswapreg(env->dregs[7]); in elf_core_copy_regs()
1696 (*regs)[7] = tswapreg(env->aregs[0]); in elf_core_copy_regs()
1697 (*regs)[8] = tswapreg(env->aregs[1]); in elf_core_copy_regs()
1698 (*regs)[9] = tswapreg(env->aregs[2]); in elf_core_copy_regs()
1699 (*regs)[10] = tswapreg(env->aregs[3]); in elf_core_copy_regs()
1700 (*regs)[11] = tswapreg(env->aregs[4]); in elf_core_copy_regs()
1701 (*regs)[12] = tswapreg(env->aregs[5]); in elf_core_copy_regs()
1702 (*regs)[13] = tswapreg(env->aregs[6]); in elf_core_copy_regs()
1703 (*regs)[14] = tswapreg(env->dregs[0]); in elf_core_copy_regs()
1704 (*regs)[15] = tswapreg(env->aregs[7]); in elf_core_copy_regs()
1705 (*regs)[16] = tswapreg(env->dregs[0]); /* FIXME: orig_d0 */ in elf_core_copy_regs()
1706 (*regs)[17] = tswapreg(env->sr); in elf_core_copy_regs()
1707 (*regs)[18] = tswapreg(env->pc); in elf_core_copy_regs()
1708 (*regs)[19] = 0; /* FIXME: regs->format | regs->vector */ in elf_core_copy_regs()
1724 regs->pc = infop->entry; in init_thread()
1725 regs->ps = 8; in init_thread()
1726 regs->usp = infop->start_stack; in init_thread()
1750 * 31-bit processes can use 64-bit registers (high gprs). in get_elf_hwcap()
1801 regs->psw.addr = infop->entry; in init_thread()
1802 regs->psw.mask = PSW_MASK_DAT | PSW_MASK_IO | PSW_MASK_EXT | \ in init_thread()
1805 regs->gprs[15] = infop->start_stack; in init_thread()
1826 (*regs)[TARGET_REG_PSWM] = tswapreg(env->psw.mask); in elf_core_copy_regs()
1827 (*regs)[TARGET_REG_PSWA] = tswapreg(env->psw.addr); in elf_core_copy_regs()
1829 (*regs)[TARGET_REG_GPRS + i] = tswapreg(env->regs[i]); in elf_core_copy_regs()
1833 aregs[i] = tswap32(env->aregs[i]); in elf_core_copy_regs()
1851 #define VDSO_HEADER "vdso-32.c.inc"
1854 #define VDSO_HEADER "vdso-64.c.inc"
1861 #define MISA_BIT(EXT) (1 << (EXT - 'A')) in get_elf_hwcap()
1867 return cpu->env.misa_ext & mask; in get_elf_hwcap()
1874 regs->sepc = infop->entry; in init_thread()
1875 regs->sp = infop->start_stack; in init_thread()
1895 regs->iaoq[0] = infop->entry | PRIV_USER; in init_thread()
1896 regs->iaoq[1] = regs->iaoq[0] + 4; in init_thread()
1897 regs->gr[23] = 0; in init_thread()
1898 regs->gr[24] = infop->argv; in init_thread()
1899 regs->gr[25] = infop->argc; in init_thread()
1900 /* The top-of-stack contains a linkage buffer. */ in init_thread()
1901 regs->gr[30] = infop->start_stack + 64; in init_thread()
1902 regs->gr[31] = infop->entry; in init_thread()
1915 MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED_NOREPLACE, -1, 0); in init_guest_commpage()
1947 regs->windowbase = 0; in init_thread()
1948 regs->windowstart = 1; in init_thread()
1949 regs->areg[1] = infop->start_stack; in init_thread()
1950 regs->pc = infop->entry; in init_thread()
1952 regs->areg[4] = infop->loadmap_addr; in init_thread()
1953 regs->areg[5] = infop->interpreter_loadmap_addr; in init_thread()
1954 if (infop->interpreter_loadmap_addr) { in init_thread()
1955 regs->areg[6] = infop->interpreter_pt_dynamic_addr; in init_thread()
1957 regs->areg[6] = infop->pt_dynamic_addr; in init_thread()
1984 (*regs)[TARGET_REG_PC] = tswapreg(env->pc); in elf_core_copy_regs()
1985 (*regs)[TARGET_REG_PS] = tswapreg(env->sregs[PS] & ~PS_EXCM); in elf_core_copy_regs()
1986 (*regs)[TARGET_REG_LBEG] = tswapreg(env->sregs[LBEG]); in elf_core_copy_regs()
1987 (*regs)[TARGET_REG_LEND] = tswapreg(env->sregs[LEND]); in elf_core_copy_regs()
1988 (*regs)[TARGET_REG_LCOUNT] = tswapreg(env->sregs[LCOUNT]); in elf_core_copy_regs()
1989 (*regs)[TARGET_REG_SAR] = tswapreg(env->sregs[SAR]); in elf_core_copy_regs()
1990 (*regs)[TARGET_REG_WINDOWSTART] = tswapreg(env->sregs[WINDOW_START]); in elf_core_copy_regs()
1991 (*regs)[TARGET_REG_WINDOWBASE] = tswapreg(env->sregs[WINDOW_BASE]); in elf_core_copy_regs()
1992 (*regs)[TARGET_REG_THREADPTR] = tswapreg(env->uregs[THREADPTR]); in elf_core_copy_regs()
1994 for (i = 0; i < env->config->nareg; ++i) { in elf_core_copy_regs()
1995 (*regs)[TARGET_REG_AR0 + i] = tswapreg(env->phys_regs[i]); in elf_core_copy_regs()
2012 regs->sepc = infop->entry; in init_thread()
2013 regs->sp = infop->start_stack; in init_thread()
2073 error_setg(errp, "Ill-formed GNU_PROPERTY_AARCH64_FEATURE_1_AND"); in arch_parse_elf_property()
2077 info->note_flags = *data; in arch_parse_elf_property()
2125 bswap16s(&ehdr->e_type); /* Object file type */ in bswap_ehdr()
2126 bswap16s(&ehdr->e_machine); /* Architecture */ in bswap_ehdr()
2127 bswap32s(&ehdr->e_version); /* Object file version */ in bswap_ehdr()
2128 bswaptls(&ehdr->e_entry); /* Entry point virtual address */ in bswap_ehdr()
2129 bswaptls(&ehdr->e_phoff); /* Program header table file offset */ in bswap_ehdr()
2130 bswaptls(&ehdr->e_shoff); /* Section header table file offset */ in bswap_ehdr()
2131 bswap32s(&ehdr->e_flags); /* Processor-specific flags */ in bswap_ehdr()
2132 bswap16s(&ehdr->e_ehsize); /* ELF header size in bytes */ in bswap_ehdr()
2133 bswap16s(&ehdr->e_phentsize); /* Program header table entry size */ in bswap_ehdr()
2134 bswap16s(&ehdr->e_phnum); /* Program header table entry count */ in bswap_ehdr()
2135 bswap16s(&ehdr->e_shentsize); /* Section header table entry size */ in bswap_ehdr()
2136 bswap16s(&ehdr->e_shnum); /* Section header table entry count */ in bswap_ehdr()
2137 bswap16s(&ehdr->e_shstrndx); /* Section header string table index */ in bswap_ehdr()
2144 bswap32s(&phdr->p_type); /* Segment type */ in bswap_phdr()
2145 bswap32s(&phdr->p_flags); /* Segment flags */ in bswap_phdr()
2146 bswaptls(&phdr->p_offset); /* Segment file offset */ in bswap_phdr()
2147 bswaptls(&phdr->p_vaddr); /* Segment virtual address */ in bswap_phdr()
2148 bswaptls(&phdr->p_paddr); /* Segment physical address */ in bswap_phdr()
2149 bswaptls(&phdr->p_filesz); /* Segment size in file */ in bswap_phdr()
2150 bswaptls(&phdr->p_memsz); /* Segment size in memory */ in bswap_phdr()
2151 bswaptls(&phdr->p_align); /* Segment alignment */ in bswap_phdr()
2159 bswap32s(&shdr->sh_name); in bswap_shdr()
2160 bswap32s(&shdr->sh_type); in bswap_shdr()
2161 bswaptls(&shdr->sh_flags); in bswap_shdr()
2162 bswaptls(&shdr->sh_addr); in bswap_shdr()
2163 bswaptls(&shdr->sh_offset); in bswap_shdr()
2164 bswaptls(&shdr->sh_size); in bswap_shdr()
2165 bswap32s(&shdr->sh_link); in bswap_shdr()
2166 bswap32s(&shdr->sh_info); in bswap_shdr()
2167 bswaptls(&shdr->sh_addralign); in bswap_shdr()
2168 bswaptls(&shdr->sh_entsize); in bswap_shdr()
2174 bswap32s(&sym->st_name); in bswap_sym()
2175 bswaptls(&sym->st_value); in bswap_sym()
2176 bswaptls(&sym->st_size); in bswap_sym()
2177 bswap16s(&sym->st_shndx); in bswap_sym()
2183 bswap16s(&abiflags->version); in bswap_mips_abiflags()
2184 bswap32s(&abiflags->ases); in bswap_mips_abiflags()
2185 bswap32s(&abiflags->isa_ext); in bswap_mips_abiflags()
2186 bswap32s(&abiflags->flags1); in bswap_mips_abiflags()
2187 bswap32s(&abiflags->flags2); in bswap_mips_abiflags()
2210 return (ehdr->e_ident[EI_MAG0] == ELFMAG0 in elf_check_ident()
2211 && ehdr->e_ident[EI_MAG1] == ELFMAG1 in elf_check_ident()
2212 && ehdr->e_ident[EI_MAG2] == ELFMAG2 in elf_check_ident()
2213 && ehdr->e_ident[EI_MAG3] == ELFMAG3 in elf_check_ident()
2214 && ehdr->e_ident[EI_CLASS] == ELF_CLASS in elf_check_ident()
2215 && ehdr->e_ident[EI_DATA] == ELF_DATA in elf_check_ident()
2216 && ehdr->e_ident[EI_VERSION] == EV_CURRENT); in elf_check_ident()
2223 return (elf_check_arch(ehdr->e_machine) in elf_check_ehdr()
2224 && elf_check_abi(ehdr->e_flags) in elf_check_ehdr()
2225 && ehdr->e_ehsize == sizeof(struct elfhdr) in elf_check_ehdr()
2226 && ehdr->e_phentsize == sizeof(struct elf_phdr) in elf_check_ehdr()
2227 && (ehdr->e_type == ET_EXEC || ehdr->e_type == ET_DYN)); in elf_check_ehdr()
2244 return 0; /* bullet-proofing */ in copy_elf_strings()
2248 int offset = ((p - 1) % TARGET_PAGE_SIZE) + 1; in copy_elf_strings()
2249 for (i = argc - 1; i >= 0; --i) { in copy_elf_strings()
2253 exit(-1); in copy_elf_strings()
2258 if (len > (p - stack_limit)) { in copy_elf_strings()
2263 tmp -= bytes_to_copy; in copy_elf_strings()
2264 p -= bytes_to_copy; in copy_elf_strings()
2265 offset -= bytes_to_copy; in copy_elf_strings()
2266 len -= bytes_to_copy; in copy_elf_strings()
2271 memcpy_to_target(p, scratch, top - p); in copy_elf_strings()
2278 memcpy_to_target(p, scratch + offset, top - p); in copy_elf_strings()
2281 int remaining = TARGET_PAGE_SIZE - (p % TARGET_PAGE_SIZE); in copy_elf_strings()
2286 exit(-1); in copy_elf_strings()
2289 if (len > (stack_limit - p)) { in copy_elf_strings()
2295 memcpy_fromfs(scratch + (p - top), tmp, bytes_to_copy); in copy_elf_strings()
2298 remaining -= bytes_to_copy; in copy_elf_strings()
2300 len -= bytes_to_copy; in copy_elf_strings()
2303 memcpy_to_target(top, scratch, p - top); in copy_elf_strings()
2310 memcpy_to_target(top, scratch, p - top); in copy_elf_strings()
2346 if (info->exec_stack) { in setup_arg_pages()
2350 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); in setup_arg_pages()
2351 if (error == -1) { in setup_arg_pages()
2353 exit(-1); in setup_arg_pages()
2359 info->stack_limit = error + guard; in setup_arg_pages()
2360 return info->stack_limit + size - sizeof(void *); in setup_arg_pages()
2362 info->stack_limit = error + size; in setup_arg_pages()
2380 error_setg(errp, "PT_LOAD with non-writable bss"); in zero_bss()
2399 align_bss -= TARGET_PAGE_SIZE; in zero_bss()
2409 "non-writable page"); in zero_bss()
2414 memset(g2h_untagged(start_bss), 0, align_bss - start_bss); in zero_bss()
2419 target_mmap(align_bss, end_bss - align_bss, prot, in zero_bss()
2420 MAP_FIXED | MAP_PRIVATE | MAP_ANON, -1, 0) == -1) { in zero_bss()
2430 return exec->e_ident[EI_OSABI] == ELFOSABI_ARM_FDPIC; in elf_is_fdpic()
2435 return exec->e_ident[EI_OSABI] == ELFOSABI_XTENSA_FDPIC; in elf_is_fdpic()
2448 struct elf32_fdpic_loadseg *loadsegs = info->loadsegs; in loader_build_fdpic_loadmap()
2451 n = info->nsegs; in loader_build_fdpic_loadmap()
2452 while (n--) { in loader_build_fdpic_loadmap()
2453 sp -= 12; in loader_build_fdpic_loadmap()
2460 sp -= 4; in loader_build_fdpic_loadmap()
2462 put_user_u16(info->nsegs, sp+2); /* nsegs */ in loader_build_fdpic_loadmap()
2464 info->personality = PER_LINUX_FDPIC; in loader_build_fdpic_loadmap()
2465 info->loadmap_addr = sp; in loader_build_fdpic_loadmap()
2493 info->other_info = interp_info; in create_elf_tables()
2495 interp_info->other_info = info; in create_elf_tables()
2497 info->interpreter_loadmap_addr = interp_info->loadmap_addr; in create_elf_tables()
2498 info->interpreter_pt_dynamic_addr = interp_info->pt_dynamic_addr; in create_elf_tables()
2500 info->interpreter_loadmap_addr = 0; in create_elf_tables()
2501 info->interpreter_pt_dynamic_addr = 0; in create_elf_tables()
2510 sp -= (len + n - 1) & ~(n - 1); in create_elf_tables()
2512 /* FIXME - check return value of memcpy_to_target() for failure */ in create_elf_tables()
2526 sp -= (len + n - 1) & ~(n - 1); in create_elf_tables()
2528 /* FIXME - check return value of memcpy_to_target() for failure */ in create_elf_tables()
2551 sp -= 16; in create_elf_tables()
2553 /* FIXME - check return value of memcpy_to_target() for failure */ in create_elf_tables()
2577 info->auxv_len = size * n; in create_elf_tables()
2585 u_argc = QEMU_ALIGN_DOWN(sp - size, STACK_ALIGNMENT); in create_elf_tables()
2595 info->saved_auxv = u_auxv; in create_elf_tables()
2596 info->argc = argc; in create_elf_tables()
2597 info->envc = envc; in create_elf_tables()
2598 info->argv = u_argv; in create_elf_tables()
2599 info->envp = u_envp; in create_elf_tables()
2617 * on info->auxv_len will trigger. in create_elf_tables()
2619 NEW_AUX_ENT(AT_PHDR, (abi_ulong)(info->load_addr + exec->e_phoff)); in create_elf_tables()
2621 NEW_AUX_ENT(AT_PHNUM, (abi_ulong)(exec->e_phnum)); in create_elf_tables()
2623 NEW_AUX_ENT(AT_BASE, (abi_ulong)(interp_info ? interp_info->load_addr : 0)); in create_elf_tables()
2625 NEW_AUX_ENT(AT_ENTRY, info->entry); in create_elf_tables()
2634 NEW_AUX_ENT(AT_EXECFN, info->file_string); in create_elf_tables()
2647 NEW_AUX_ENT(AT_SYSINFO_EHDR, vdso_info->load_addr); in create_elf_tables()
2655 assert(info->auxv_len == u_auxv - info->saved_auxv); in create_elf_tables()
2659 p = info->arg_strings; in create_elf_tables()
2667 p = info->env_strings; in create_elf_tables()
2679 #define LO_COMMPAGE -1
2684 #define LO_COMMPAGE -1
2697 * return 0 if it is not available to map, and -1 on mmap error.
2702 size_t size = addr_last - addr + 1; in pgb_try_mmap()
2705 MAP_NORESERVE | MAP_FIXED_NOREPLACE, -1, 0); in pgb_try_mmap()
2709 return errno == EEXIST ? 0 : -1; in pgb_try_mmap()
2729 uintptr_t brk_last = brk + 16 * MiB - 1; in pgb_try_mmap_skip_brk()
2755 for (int i = ga->nbounds - 1; i >= 0; --i) { in pgb_try_mmap_set()
2756 if (pgb_try_mmap_skip_brk(ga->bounds[i][0] + base, in pgb_try_mmap_set()
2757 ga->bounds[i][1] + base, in pgb_try_mmap_set()
2784 if (LO_COMMPAGE != -1 && LO_COMMPAGE < mmap_min_addr) { in pgb_addr_set()
2796 ga->bounds[n][0] = try_identity ? mmap_min_addr : 0; in pgb_addr_set()
2797 ga->bounds[n][1] = reserved_va; in pgb_addr_set()
2802 if (LO_COMMPAGE != -1) { in pgb_addr_set()
2803 ga->bounds[n][0] = 0; in pgb_addr_set()
2804 ga->bounds[n][1] = LO_COMMPAGE + TARGET_PAGE_SIZE - 1; in pgb_addr_set()
2807 ga->bounds[n][0] = 0; in pgb_addr_set()
2808 ga->bounds[n][1] = TARGET_PAGE_SIZE - 1; in pgb_addr_set()
2814 ga->bounds[n][0] = guest_loaddr; in pgb_addr_set()
2815 ga->bounds[n][1] = guest_hiaddr; in pgb_addr_set()
2826 #pragma GCC diagnostic ignored "-Wtype-limits" in pgb_addr_set()
2830 ga->bounds[n][0] = HI_COMMPAGE & qemu_real_host_page_mask(); in pgb_addr_set()
2831 ga->bounds[n][1] = HI_COMMPAGE + TARGET_PAGE_SIZE - 1; in pgb_addr_set()
2837 ga->nbounds = n; in pgb_addr_set()
2844 "(omit the -B option or choose a different value)", in pgb_fail_in_use()
2887 if (base >= -skip) { in pgb_find_fallback()
2888 return -1; in pgb_find_fallback()
2896 for (int i = ga->nbounds - 1; i >= 0; --i) { in pgb_try_itree()
2897 uintptr_t s = base + ga->bounds[i][0]; in pgb_try_itree()
2898 uintptr_t l = base + ga->bounds[i][1]; in pgb_try_itree()
2903 return mmap_min_addr - s; in pgb_try_itree()
2909 return n->last - s + 1; in pgb_try_itree()
2924 return -1; in pgb_find_itree()
2934 return -1; in pgb_find_itree()
2944 return pgb_try_mmap_set(ga, base, brk) ? base : -1; in pgb_find_itree()
2964 * Rebuild the address set for non-identity map. in pgb_dynamic()
2982 b->start = brk; in pgb_dynamic()
2983 b->last = brk + 16 * MiB - 1; in pgb_dynamic()
2990 if (ret == -1) { in pgb_dynamic()
2997 error_printf(" %0*" PRIx64 "-%0*" PRIx64 "\n", in pgb_dynamic()
3067 datasz -= *off; in parse_elf_property()
3076 datasz -= 2 * sizeof(uint32_t); in parse_elf_property()
3101 error_setg(errp, "Ill-formed property in PT_GNU_PROPERTY"); in parse_elf_property()
3126 n = phdr->p_filesz; in parse_elf_properties()
3136 if (!imgsrc_read(&note, phdr->p_offset, n, src, errp)) { in parse_elf_properties()
3222 phdr = imgsrc_read_alloc(ehdr->e_phoff, in load_elf_image()
3223 ehdr->e_phnum * sizeof(struct elf_phdr), in load_elf_image()
3228 bswap_phdr(phdr, ehdr->e_phnum); in load_elf_image()
3230 info->nsegs = 0; in load_elf_image()
3231 info->pt_dynamic_addr = 0; in load_elf_image()
3239 loaddr = -1, hiaddr = 0; in load_elf_image()
3241 info->exec_stack = EXSTACK_DEFAULT; in load_elf_image()
3242 for (i = 0; i < ehdr->e_phnum; ++i) { in load_elf_image()
3244 if (eppnt->p_type == PT_LOAD) { in load_elf_image()
3245 abi_ulong a = eppnt->p_vaddr & TARGET_PAGE_MASK; in load_elf_image()
3249 a = eppnt->p_vaddr + eppnt->p_memsz - 1; in load_elf_image()
3253 ++info->nsegs; in load_elf_image()
3254 align |= eppnt->p_align; in load_elf_image()
3255 } else if (eppnt->p_type == PT_INTERP && pinterp_name) { in load_elf_image()
3263 interp_name = imgsrc_read_alloc(eppnt->p_offset, eppnt->p_filesz, in load_elf_image()
3268 if (interp_name[eppnt->p_filesz - 1] != 0) { in load_elf_image()
3273 } else if (eppnt->p_type == PT_GNU_PROPERTY) { in load_elf_image()
3277 } else if (eppnt->p_type == PT_GNU_STACK) { in load_elf_image()
3278 info->exec_stack = eppnt->p_flags & PF_X; in load_elf_image()
3287 if (ehdr->e_type == ET_EXEC) { in load_elf_image()
3298 probe_guest_base(image_name, 0, hiaddr - loaddr); in load_elf_image()
3313 load_addr &= -align; in load_elf_image()
3321 * In the case of ET_EXEC, we supply MAP_FIXED_NOREPLACE so that we get in load_elf_image()
3329 * pre-linked, LOAD_ADDR will be non-zero, and the kernel should in load_elf_image()
3335 reserve_size = (size_t)hiaddr - loaddr + 1; in load_elf_image()
3338 if (ehdr->e_type != ET_EXEC && align > qemu_real_host_page_size()) { in load_elf_image()
3339 align_size += align - 1; in load_elf_image()
3344 (ehdr->e_type == ET_EXEC ? MAP_FIXED_NOREPLACE : 0), in load_elf_image()
3345 -1, 0); in load_elf_image()
3346 if (load_addr == -1) { in load_elf_image()
3356 target_munmap(load_addr, align_addr - load_addr); in load_elf_image()
3359 target_munmap(align_end, load_end - align_end); in load_elf_image()
3364 load_bias = load_addr - loaddr; in load_elf_image()
3367 struct elf32_fdpic_loadseg *loadsegs = info->loadsegs = in load_elf_image()
3368 g_malloc(sizeof(*loadsegs) * info->nsegs); in load_elf_image()
3370 for (i = 0; i < ehdr->e_phnum; ++i) { in load_elf_image()
3373 info->pt_dynamic_addr = phdr[i].p_vaddr + load_bias; in load_elf_image()
3376 loadsegs->addr = phdr[i].p_vaddr + load_bias; in load_elf_image()
3377 loadsegs->p_vaddr = phdr[i].p_vaddr; in load_elf_image()
3378 loadsegs->p_memsz = phdr[i].p_memsz; in load_elf_image()
3385 info->load_bias = load_bias; in load_elf_image()
3386 info->code_offset = load_bias; in load_elf_image()
3387 info->data_offset = load_bias; in load_elf_image()
3388 info->load_addr = load_addr; in load_elf_image()
3389 info->entry = ehdr->e_entry + load_bias; in load_elf_image()
3390 info->start_code = -1; in load_elf_image()
3391 info->end_code = 0; in load_elf_image()
3392 info->start_data = -1; in load_elf_image()
3393 info->end_data = 0; in load_elf_image()
3395 info->brk = TARGET_PAGE_ALIGN(hiaddr + load_bias); in load_elf_image()
3396 info->elf_flags = ehdr->e_flags; in load_elf_image()
3411 if ((info->note_flags & GNU_PROPERTY_AARCH64_FEATURE_1_BTI) in load_elf_image()
3418 for (i = 0; i < ehdr->e_phnum; i++) { in load_elf_image()
3420 if (eppnt->p_type == PT_LOAD) { in load_elf_image()
3424 if (eppnt->p_flags & PF_R) { in load_elf_image()
3427 if (eppnt->p_flags & PF_W) { in load_elf_image()
3430 if (eppnt->p_flags & PF_X) { in load_elf_image()
3434 vaddr = load_bias + eppnt->p_vaddr; in load_elf_image()
3438 vaddr_ef = vaddr + eppnt->p_filesz; in load_elf_image()
3439 vaddr_em = vaddr + eppnt->p_memsz; in load_elf_image()
3442 * Some segments may be completely empty, with a non-zero p_memsz in load_elf_image()
3445 if (eppnt->p_filesz != 0) { in load_elf_image()
3446 error = imgsrc_mmap(vaddr_ps, eppnt->p_filesz + vaddr_po, in load_elf_image()
3448 src, eppnt->p_offset - vaddr_po); in load_elf_image()
3449 if (error == -1) { in load_elf_image()
3462 if (vaddr < info->start_code) { in load_elf_image()
3463 info->start_code = vaddr; in load_elf_image()
3465 if (vaddr_ef > info->end_code) { in load_elf_image()
3466 info->end_code = vaddr_ef; in load_elf_image()
3470 if (vaddr < info->start_data) { in load_elf_image()
3471 info->start_data = vaddr; in load_elf_image()
3473 if (vaddr_ef > info->end_data) { in load_elf_image()
3474 info->end_data = vaddr_ef; in load_elf_image()
3478 } else if (eppnt->p_type == PT_MIPS_ABIFLAGS) { in load_elf_image()
3481 if (!imgsrc_read(&abiflags, eppnt->p_offset, sizeof(abiflags), in load_elf_image()
3486 info->fp_abi = abiflags.fp_abi; in load_elf_image()
3491 if (info->end_data == 0) { in load_elf_image()
3492 info->start_data = info->end_code; in load_elf_image()
3493 info->end_data = info->end_code; in load_elf_image()
3500 debuginfo_report_elf(image_name, src->fd, load_bias); in load_elf_image()
3504 close(src->fd); in load_elf_image()
3512 exit(-1); in load_elf_image()
3527 exit(-1); in load_elf_interp()
3534 exit(-1); in load_elf_interp()
3559 src.fd = -1; in load_elf_vdso()
3560 src.cache = vdso->image; in load_elf_vdso()
3561 src.cache_size = vdso->image_size; in load_elf_vdso()
3563 load_elf_image("<internal-vdso>", &src, info, &ehdr, NULL); in load_elf_vdso()
3564 load_addr = info->load_addr; in load_elf_vdso()
3565 load_bias = info->load_bias; in load_elf_vdso()
3571 * We pre-processed the image to locate all of the addresses that need in load_elf_vdso()
3574 for (unsigned i = 0, n = vdso->reloc_count; i < n; i++) { in load_elf_vdso()
3575 abi_ulong *addr = g2h_untagged(load_addr + vdso->relocs[i]); in load_elf_vdso()
3580 if (vdso->sigreturn_ofs) { in load_elf_vdso()
3581 default_sigreturn = load_addr + vdso->sigreturn_ofs; in load_elf_vdso()
3583 if (vdso->rt_sigreturn_ofs) { in load_elf_vdso()
3584 default_rt_sigreturn = load_addr + vdso->rt_sigreturn_ofs; in load_elf_vdso()
3588 target_mprotect(info->start_data, info->end_data - info->start_data, in load_elf_vdso()
3595 __typeof(sym->st_value) addr = *(uint64_t *)s0; in symfind()
3598 if (addr < sym->st_value) { in symfind()
3599 result = -1; in symfind()
3600 } else if (addr >= sym->st_value + sym->st_size) { in symfind()
3609 struct elf_sym *syms = s->disas_symtab.elf32; in lookup_symbolxx()
3611 struct elf_sym *syms = s->disas_symtab.elf64; in lookup_symbolxx()
3617 sym = bsearch(&orig_addr, syms, s->disas_num_syms, sizeof(*syms), symfind); in lookup_symbolxx()
3619 return s->disas_strtab + sym->st_name; in lookup_symbolxx()
3630 return (sym0->st_value < sym1->st_value) in symcmp()
3631 ? -1 in symcmp()
3632 : ((sym0->st_value > sym1->st_value) ? 1 : 0); in symcmp()
3646 shnum = hdr->e_shnum; in load_symbols()
3647 shdr = imgsrc_read_alloc(hdr->e_shoff, shnum * sizeof(struct elf_shdr), in load_symbols()
3700 if (i < --nsyms) { in load_symbols()
3735 s->disas_strtab = strings; in load_symbols()
3736 s->disas_num_syms = nsyms; in load_symbols()
3738 s->disas_symtab.elf32 = syms; in load_symbols()
3740 s->disas_symtab.elf64 = syms; in load_symbols()
3742 s->lookup_symbol = lookup_symbolxx; in load_symbols()
3743 s->next = syminfos; in load_symbols()
3761 if (offset == (off_t) -1) { in get_elf_eflags()
3769 if (offset == (off_t) -1) { in get_elf_eflags()
3792 * We will have overwritten the original when we re-use bprm->buf in load_elf_binary()
3806 load_elf_image(bprm->filename, &bprm->src, info, &ehdr, &elf_interpreter); in load_elf_binary()
3810 bprm->p = setup_arg_pages(bprm, info); in load_elf_binary()
3814 bprm->p = copy_elf_strings(1, &bprm->filename, scratch, in load_elf_binary()
3815 bprm->p, info->stack_limit); in load_elf_binary()
3816 info->file_string = bprm->p; in load_elf_binary()
3817 bprm->p = copy_elf_strings(bprm->envc, bprm->envp, scratch, in load_elf_binary()
3818 bprm->p, info->stack_limit); in load_elf_binary()
3819 info->env_strings = bprm->p; in load_elf_binary()
3820 bprm->p = copy_elf_strings(bprm->argc, bprm->argv, scratch, in load_elf_binary()
3821 bprm->p, info->stack_limit); in load_elf_binary()
3822 info->arg_strings = bprm->p; in load_elf_binary()
3824 info->arg_strings = bprm->p; in load_elf_binary()
3825 bprm->p = copy_elf_strings(bprm->argc, bprm->argv, scratch, in load_elf_binary()
3826 bprm->p, info->stack_limit); in load_elf_binary()
3827 info->env_strings = bprm->p; in load_elf_binary()
3828 bprm->p = copy_elf_strings(bprm->envc, bprm->envp, scratch, in load_elf_binary()
3829 bprm->p, info->stack_limit); in load_elf_binary()
3830 info->file_string = bprm->p; in load_elf_binary()
3831 bprm->p = copy_elf_strings(1, &bprm->filename, scratch, in load_elf_binary()
3832 bprm->p, info->stack_limit); in load_elf_binary()
3837 if (!bprm->p) { in load_elf_binary()
3838 fprintf(stderr, "%s: %s\n", bprm->filename, strerror(E2BIG)); in load_elf_binary()
3839 exit(-1); in load_elf_binary()
3843 load_elf_interp(elf_interpreter, &interp_info, bprm->buf); in load_elf_binary()
3853 if (interp_info.brk > info->brk && in load_elf_binary()
3854 interp_info.load_bias - info->brk < 16 * MiB) { in load_elf_binary()
3855 info->brk = interp_info.brk; in load_elf_binary()
3863 info->personality = PER_SVR4; in load_elf_binary()
3865 /* Why this, you ask??? Well SVr4 maps page 0 as read-only, in load_elf_binary()
3871 -1, 0); in load_elf_binary()
3874 info->interp_fp_abi = interp_info.fp_abi; in load_elf_binary()
3882 const VdsoImageInfo *vdso = vdso_image_info(info->elf_flags); in load_elf_binary()
3885 info->vdso = vdso_info.load_bias; in load_elf_binary()
3889 MAP_PRIVATE | MAP_ANON, -1, 0); in load_elf_binary()
3890 if (tramp_page == -1) { in load_elf_binary()
3891 return -errno; in load_elf_binary()
3898 bprm->p = create_elf_tables(bprm->p, bprm->argc, bprm->envc, &ehdr, info, in load_elf_binary()
3901 info->start_stack = bprm->p; in load_elf_binary()
3908 info->load_bias = interp_info.load_bias; in load_elf_binary()
3909 info->entry = interp_info.entry; in load_elf_binary()
3914 bprm->core_dump = &elf_core_dump; in load_elf_binary()
3921 #include "exec/translate-all.h"
3924 * Definitions to generate Intel SVR4-like core files.
3931 * Fields we don't dump (their contents is zero) in linux-user qemu
3956 * regs - copy register values into here (allocated and zeroed by caller)
3957 * env - copy registers from here
4004 prstatus->pr_info.si_signo = tswap32(prstatus->pr_info.si_signo); in bswap_prstatus()
4005 prstatus->pr_info.si_code = tswap32(prstatus->pr_info.si_code); in bswap_prstatus()
4006 prstatus->pr_info.si_errno = tswap32(prstatus->pr_info.si_errno); in bswap_prstatus()
4007 prstatus->pr_cursig = tswap16(prstatus->pr_cursig); in bswap_prstatus()
4008 prstatus->pr_sigpend = tswapal(prstatus->pr_sigpend); in bswap_prstatus()
4009 prstatus->pr_sighold = tswapal(prstatus->pr_sighold); in bswap_prstatus()
4010 prstatus->pr_pid = tswap32(prstatus->pr_pid); in bswap_prstatus()
4011 prstatus->pr_ppid = tswap32(prstatus->pr_ppid); in bswap_prstatus()
4012 prstatus->pr_pgrp = tswap32(prstatus->pr_pgrp); in bswap_prstatus()
4013 prstatus->pr_sid = tswap32(prstatus->pr_sid); in bswap_prstatus()
4016 prstatus->pr_fpvalid = tswap32(prstatus->pr_fpvalid); in bswap_prstatus()
4021 psinfo->pr_flag = tswapal(psinfo->pr_flag); in bswap_psinfo()
4022 psinfo->pr_uid = tswap16(psinfo->pr_uid); in bswap_psinfo()
4023 psinfo->pr_gid = tswap16(psinfo->pr_gid); in bswap_psinfo()
4024 psinfo->pr_pid = tswap32(psinfo->pr_pid); in bswap_psinfo()
4025 psinfo->pr_ppid = tswap32(psinfo->pr_ppid); in bswap_psinfo()
4026 psinfo->pr_pgrp = tswap32(psinfo->pr_pgrp); in bswap_psinfo()
4027 psinfo->pr_sid = tswap32(psinfo->pr_sid); in bswap_psinfo()
4032 bswap32s(&en->n_namesz); in bswap_note()
4033 bswap32s(&en->n_descsz); in bswap_note()
4034 bswap32s(&en->n_type); in bswap_note()
4055 * non-writable code that debugger can read directly from in vma_dump_size()
4064 return end - start; in vma_dump_size()
4083 n->n_namesz = namesz; in fill_note()
4084 n->n_descsz = datasz; in fill_note()
4085 n->n_type = type; in fill_note()
4101 memcpy(elf->e_ident, ELFMAG, SELFMAG); in fill_elf_header()
4103 elf->e_ident[EI_CLASS] = ELF_CLASS; in fill_elf_header()
4104 elf->e_ident[EI_DATA] = ELF_DATA; in fill_elf_header()
4105 elf->e_ident[EI_VERSION] = EV_CURRENT; in fill_elf_header()
4106 elf->e_ident[EI_OSABI] = ELF_OSABI; in fill_elf_header()
4108 elf->e_type = ET_CORE; in fill_elf_header()
4109 elf->e_machine = machine; in fill_elf_header()
4110 elf->e_version = EV_CURRENT; in fill_elf_header()
4111 elf->e_phoff = sizeof(struct elfhdr); in fill_elf_header()
4112 elf->e_flags = flags; in fill_elf_header()
4113 elf->e_ehsize = sizeof(struct elfhdr); in fill_elf_header()
4114 elf->e_phentsize = sizeof(struct elf_phdr); in fill_elf_header()
4115 elf->e_phnum = segs; in fill_elf_header()
4122 phdr->p_type = PT_NOTE; in fill_elf_note_phdr()
4123 phdr->p_offset = offset; in fill_elf_note_phdr()
4124 phdr->p_filesz = sz; in fill_elf_note_phdr()
4139 .pr_pid = get_task_state(cpu)->ts_tid, in fill_prstatus_note()
4168 len = ts->info->env_strings - ts->info->arg_strings; in fill_prpsinfo_note()
4170 memcpy(&psinfo.pr_psargs, g2h_untagged(ts->info->arg_strings), len); in fill_prpsinfo_note()
4177 base_filename = g_path_get_basename(ts->bprm->filename); in fill_prpsinfo_note()
4179 * Using strncpy here is fine: at max-length, in fill_prpsinfo_note()
4180 * this field is not NUL-terminated. in fill_prpsinfo_note()
4191 memcpy(data, g2h_untagged(ts->info->saved_auxv), ts->info->auxv_len); in fill_auxv_note()
4197 * qemu_<basename-of-target-binary>_<date>-<time>_<pid>.core
4204 g_autofree char *nowstr = g_date_time_format(now, "%Y%m%d-%H%M%S"); in core_dump_filename()
4205 g_autofree char *base_filename = g_path_get_basename(ts->bprm->filename); in core_dump_filename()
4228 return (-1); in dump_write()
4230 return (-1); in dump_write()
4233 bytes_left -= bytes_written; in dump_write()
4247 if (end - start <= step) { in wmr_page_unprotect_regions()
4266 css->count++; in wmr_count_and_size_regions()
4267 css->size += vma_dump_size(start, end, flags); in wmr_count_and_size_regions()
4280 struct elf_phdr *phdr = d->phdr; in wmr_fill_region_phdr()
4282 phdr->p_type = PT_LOAD; in wmr_fill_region_phdr()
4283 phdr->p_vaddr = start; in wmr_fill_region_phdr()
4284 phdr->p_paddr = 0; in wmr_fill_region_phdr()
4285 phdr->p_filesz = vma_dump_size(start, end, flags); in wmr_fill_region_phdr()
4286 phdr->p_offset = d->offset; in wmr_fill_region_phdr()
4287 d->offset += phdr->p_filesz; in wmr_fill_region_phdr()
4288 phdr->p_memsz = end - start; in wmr_fill_region_phdr()
4289 phdr->p_flags = (flags & PAGE_READ ? PF_R : 0) in wmr_fill_region_phdr()
4292 phdr->p_align = ELF_EXEC_PAGESIZE; in wmr_fill_region_phdr()
4295 d->phdr = phdr + 1; in wmr_fill_region_phdr()
4319 * 0 +----------------------+ \
4321 * +----------------------+ |
4322 * | ELF program headers | |--- headers
4323 * | - NOTE section | |
4324 * | - PT_LOAD sections | |
4325 * +----------------------+ /
4327 * | - NT_PRSTATUS |
4328 * | - NT_PRSINFO |
4329 * | - NT_AUXV |
4330 * +----------------------+ <-- aligned to target page
4336 * +----------------------+
4338 * NT_PRSTATUS -> struct elf_prstatus (per thread)
4339 * NT_PRSINFO -> struct elf_prpsinfo
4344 * - no floating point registers are dumped
4363 int fd = -1; in elf_core_dump()
4396 offset += size_note("CORE", ts->info->auxv_len); in elf_core_dump()
4399 note_size = offset - note_offset; in elf_core_dump()
4444 dptr = fill_note(&hptr, NT_AUXV, "CORE", ts->info->auxv_len); in elf_core_dump()
4471 ret = -errno; in elf_core_dump()