Skip to content

Commit feb39b6

Browse files
vfaziodgibson
authored andcommitted
target/ppc: don't byte swap ELFv2 signal handler
Previously, the signal handler would be byte swapped if the target and host CPU used different endianness. This would cause a SIGSEGV when attempting to translate the opcode pointed to by the swapped address. Thread 1 "qemu-ppc64" received signal SIGSEGV, Segmentation fault. 0x00000000600a9257 in ldl_he_p (ptr=0x4c2c061000000000) at qemu/include/qemu/bswap.h:351 351 __builtin_memcpy(&r, ptr, sizeof(r)); #0 0x00000000600a9257 in ldl_he_p (ptr=0x4c2c061000000000) at qemu/include/qemu/bswap.h:351 #1 0x00000000600a92fe in ldl_be_p (ptr=0x4c2c061000000000) at qemu/include/qemu/bswap.h:449 #2 0x00000000600c0790 in translator_ldl_swap at qemu/include/exec/translator.h:201 #3 0x000000006011c1ab in ppc_tr_translate_insn at qemu/target/ppc/translate.c:7856 #4 0x000000006005ae70 in translator_loop at qemu/accel/tcg/translator.c:102 The signal handler will be byte swapped as a result of the __get_user() call in sigaction() if it is necessary, no additional swap is required. Signed-off-by: Vincent Fazio <[email protected]> Reviewed-by: Laurent Vivier <[email protected]> Reviewed-by: Richard Henderson <[email protected]> Message-Id: <[email protected]> Signed-off-by: David Gibson <[email protected]>
1 parent 0418bf7 commit feb39b6

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

linux-user/ppc/signal.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -567,10 +567,8 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
567567
env->nip = tswapl(handler->entry);
568568
env->gpr[2] = tswapl(handler->toc);
569569
} else {
570-
/* ELFv2 PPC64 function pointers are entry points, but R12
571-
* must also be set */
572-
env->nip = tswapl((target_ulong) ka->_sa_handler);
573-
env->gpr[12] = env->nip;
570+
/* ELFv2 PPC64 function pointers are entry points. R12 must also be set. */
571+
env->gpr[12] = env->nip = ka->_sa_handler;
574572
}
575573
#else
576574
env->nip = (target_ulong) ka->_sa_handler;

0 commit comments

Comments
 (0)