From 0c40c18ecd564a5c3f27f1408aaf9848fe210349 Mon Sep 17 00:00:00 2001 From: Ilya Leoshkevich Date: Tue, 3 Aug 2021 19:18:58 +0200 Subject: linux-user: fix guest/host address mixup in i386 setup_rt_frame() setup_rt_frame() passes siginfo and ucontext host addresses to guest signal handlers, causing problems when e.g. emulating x86_64 on s390x. Signed-off-by: Ilya Leoshkevich Reviewed-by: Richard Henderson Message-Id: <20210803171858.148394-1-iii@linux.ibm.com> Signed-off-by: Laurent Vivier --- linux-user/i386/signal.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'linux-user') diff --git a/linux-user/i386/signal.c b/linux-user/i386/signal.c index 8701774..841cd19 100644 --- a/linux-user/i386/signal.c +++ b/linux-user/i386/signal.c @@ -436,13 +436,13 @@ void setup_rt_frame(int sig, struct target_sigaction *ka, #ifndef TARGET_X86_64 env->regs[R_EAX] = sig; - env->regs[R_EDX] = (unsigned long)&frame->info; - env->regs[R_ECX] = (unsigned long)&frame->uc; + env->regs[R_EDX] = frame_addr + offsetof(struct rt_sigframe, info); + env->regs[R_ECX] = frame_addr + offsetof(struct rt_sigframe, uc); #else env->regs[R_EAX] = 0; env->regs[R_EDI] = sig; - env->regs[R_ESI] = (unsigned long)&frame->info; - env->regs[R_EDX] = (unsigned long)&frame->uc; + env->regs[R_ESI] = frame_addr + offsetof(struct rt_sigframe, info); + env->regs[R_EDX] = frame_addr + offsetof(struct rt_sigframe, uc); #endif cpu_x86_load_seg(env, R_DS, __USER_DS); -- cgit v1.1 From 030912e01c0385b6b09e76549c1a8a04b624f49a Mon Sep 17 00:00:00 2001 From: Ilya Leoshkevich Date: Tue, 3 Aug 2021 19:20:13 +0200 Subject: linux-user/elfload: byteswap i386 registers when dumping core MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Core dumps from emulating x86_64 on big-endian hosts contain incorrect register values. Signed-off-by: Ilya Leoshkevich Reviewed-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé Message-Id: <20210803172013.148446-1-iii@linux.ibm.com> Signed-off-by: Laurent Vivier --- linux-user/elfload.c | 88 ++++++++++++++++++++++++++-------------------------- 1 file changed, 44 insertions(+), 44 deletions(-) (limited to 'linux-user') diff --git a/linux-user/elfload.c b/linux-user/elfload.c index 42ef2a1..01e9a83 100644 --- a/linux-user/elfload.c +++ b/linux-user/elfload.c @@ -172,33 +172,33 @@ typedef target_elf_greg_t target_elf_gregset_t[ELF_NREG]; */ static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUX86State *env) { - (*regs)[0] = env->regs[15]; - (*regs)[1] = env->regs[14]; - (*regs)[2] = env->regs[13]; - (*regs)[3] = env->regs[12]; - (*regs)[4] = env->regs[R_EBP]; - (*regs)[5] = env->regs[R_EBX]; - (*regs)[6] = env->regs[11]; - (*regs)[7] = env->regs[10]; - (*regs)[8] = env->regs[9]; - (*regs)[9] = env->regs[8]; - (*regs)[10] = env->regs[R_EAX]; - (*regs)[11] = env->regs[R_ECX]; - (*regs)[12] = env->regs[R_EDX]; - (*regs)[13] = env->regs[R_ESI]; - (*regs)[14] = env->regs[R_EDI]; - (*regs)[15] = env->regs[R_EAX]; /* XXX */ - (*regs)[16] = env->eip; - (*regs)[17] = env->segs[R_CS].selector & 0xffff; - (*regs)[18] = env->eflags; - (*regs)[19] = env->regs[R_ESP]; - (*regs)[20] = env->segs[R_SS].selector & 0xffff; - (*regs)[21] = env->segs[R_FS].selector & 0xffff; - (*regs)[22] = env->segs[R_GS].selector & 0xffff; - (*regs)[23] = env->segs[R_DS].selector & 0xffff; - (*regs)[24] = env->segs[R_ES].selector & 0xffff; - (*regs)[25] = env->segs[R_FS].selector & 0xffff; - (*regs)[26] = env->segs[R_GS].selector & 0xffff; + (*regs)[0] = tswapreg(env->regs[15]); + (*regs)[1] = tswapreg(env->regs[14]); + (*regs)[2] = tswapreg(env->regs[13]); + (*regs)[3] = tswapreg(env->regs[12]); + (*regs)[4] = tswapreg(env->regs[R_EBP]); + (*regs)[5] = tswapreg(env->regs[R_EBX]); + (*regs)[6] = tswapreg(env->regs[11]); + (*regs)[7] = tswapreg(env->regs[10]); + (*regs)[8] = tswapreg(env->regs[9]); + (*regs)[9] = tswapreg(env->regs[8]); + (*regs)[10] = tswapreg(env->regs[R_EAX]); + (*regs)[11] = tswapreg(env->regs[R_ECX]); + (*regs)[12] = tswapreg(env->regs[R_EDX]); + (*regs)[13] = tswapreg(env->regs[R_ESI]); + (*regs)[14] = tswapreg(env->regs[R_EDI]); + (*regs)[15] = tswapreg(env->regs[R_EAX]); /* XXX */ + (*regs)[16] = tswapreg(env->eip); + (*regs)[17] = tswapreg(env->segs[R_CS].selector & 0xffff); + (*regs)[18] = tswapreg(env->eflags); + (*regs)[19] = tswapreg(env->regs[R_ESP]); + (*regs)[20] = tswapreg(env->segs[R_SS].selector & 0xffff); + (*regs)[21] = tswapreg(env->segs[R_FS].selector & 0xffff); + (*regs)[22] = tswapreg(env->segs[R_GS].selector & 0xffff); + (*regs)[23] = tswapreg(env->segs[R_DS].selector & 0xffff); + (*regs)[24] = tswapreg(env->segs[R_ES].selector & 0xffff); + (*regs)[25] = tswapreg(env->segs[R_FS].selector & 0xffff); + (*regs)[26] = tswapreg(env->segs[R_GS].selector & 0xffff); } #else @@ -244,23 +244,23 @@ typedef target_elf_greg_t target_elf_gregset_t[ELF_NREG]; */ static void elf_core_copy_regs(target_elf_gregset_t *regs, const CPUX86State *env) { - (*regs)[0] = env->regs[R_EBX]; - (*regs)[1] = env->regs[R_ECX]; - (*regs)[2] = env->regs[R_EDX]; - (*regs)[3] = env->regs[R_ESI]; - (*regs)[4] = env->regs[R_EDI]; - (*regs)[5] = env->regs[R_EBP]; - (*regs)[6] = env->regs[R_EAX]; - (*regs)[7] = env->segs[R_DS].selector & 0xffff; - (*regs)[8] = env->segs[R_ES].selector & 0xffff; - (*regs)[9] = env->segs[R_FS].selector & 0xffff; - (*regs)[10] = env->segs[R_GS].selector & 0xffff; - (*regs)[11] = env->regs[R_EAX]; /* XXX */ - (*regs)[12] = env->eip; - (*regs)[13] = env->segs[R_CS].selector & 0xffff; - (*regs)[14] = env->eflags; - (*regs)[15] = env->regs[R_ESP]; - (*regs)[16] = env->segs[R_SS].selector & 0xffff; + (*regs)[0] = tswapreg(env->regs[R_EBX]); + (*regs)[1] = tswapreg(env->regs[R_ECX]); + (*regs)[2] = tswapreg(env->regs[R_EDX]); + (*regs)[3] = tswapreg(env->regs[R_ESI]); + (*regs)[4] = tswapreg(env->regs[R_EDI]); + (*regs)[5] = tswapreg(env->regs[R_EBP]); + (*regs)[6] = tswapreg(env->regs[R_EAX]); + (*regs)[7] = tswapreg(env->segs[R_DS].selector & 0xffff); + (*regs)[8] = tswapreg(env->segs[R_ES].selector & 0xffff); + (*regs)[9] = tswapreg(env->segs[R_FS].selector & 0xffff); + (*regs)[10] = tswapreg(env->segs[R_GS].selector & 0xffff); + (*regs)[11] = tswapreg(env->regs[R_EAX]); /* XXX */ + (*regs)[12] = tswapreg(env->eip); + (*regs)[13] = tswapreg(env->segs[R_CS].selector & 0xffff); + (*regs)[14] = tswapreg(env->eflags); + (*regs)[15] = tswapreg(env->regs[R_ESP]); + (*regs)[16] = tswapreg(env->segs[R_SS].selector & 0xffff); } #endif -- cgit v1.1