Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1jEc5v-0006rh-F0 for mharc-qemu-trivial@gnu.org; Wed, 18 Mar 2020 13:03:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54891) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jEc5s-0006kr-QB for qemu-trivial@nongnu.org; Wed, 18 Mar 2020 13:03:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jEc5r-0001FE-M7 for qemu-trivial@nongnu.org; Wed, 18 Mar 2020 13:03:00 -0400 Received: from xes-mad.com ([162.248.234.2]:51539 helo=mail.xes-mad.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jEc5m-00019Q-PC; Wed, 18 Mar 2020 13:02:54 -0400 Received: from vfazio1.xes-mad.com (vfazio1.xes-mad.com [10.52.16.140]) by mail.xes-mad.com (Postfix) with ESMTP id AD86F201BE; Wed, 18 Mar 2020 12:02:53 -0500 (CDT) From: Vincent Fazio To: qemu-devel@nongnu.org Cc: Laurent Vivier , Riku Voipio , David Gibson , qemu-ppc@nongnu.org, qemu-trivial@nongnu.org, Vincent Fazio Subject: [PATCH v2 1/1] target/ppc: don't byte swap ELFv2 signal handler Date: Wed, 18 Mar 2020 12:01:16 -0500 Message-Id: <20200318170116.1922-1-vfazio@xes-inc.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 162.248.234.2 X-BeenThere: qemu-trivial@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 Mar 2020 17:03:02 -0000 From: Vincent Fazio 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=3D0x4c2c061000000000) at qemu/includ= e/qemu/bswap.h:351 351 __builtin_memcpy(&r, ptr, sizeof(r)); #0 0x00000000600a9257 in ldl_he_p (ptr=3D0x4c2c061000000000) at qemu/in= clude/qemu/bswap.h:351 #1 0x00000000600a92fe in ldl_be_p (ptr=3D0x4c2c061000000000) at qemu/in= clude/qemu/bswap.h:449 #2 0x00000000600c0790 in translator_ldl_swap at qemu/include/exec/trans= lator.h:201 #3 0x000000006011c1ab in ppc_tr_translate_insn at qemu/target/ppc/trans= late.c:7856 #4 0x000000006005ae70 in translator_loop at qemu/accel/tcg/translator.c= :102 Now, no swap is performed and execution continues properly. Signed-off-by: Vincent Fazio Reviewed-by: Laurent Vivier --- Changes since v1: - Drop host/target endianness callouts - Drop unnecessary pointer cast - Clarify commit message linux-user/ppc/signal.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/linux-user/ppc/signal.c b/linux-user/ppc/signal.c index 5b82af6cb6..b8613c5e1b 100644 --- a/linux-user/ppc/signal.c +++ b/linux-user/ppc/signal.c @@ -567,10 +567,8 @@ void setup_rt_frame(int sig, struct target_sigaction= *ka, env->nip =3D tswapl(handler->entry); env->gpr[2] =3D tswapl(handler->toc); } else { - /* ELFv2 PPC64 function pointers are entry points, but R12 - * must also be set */ - env->nip =3D tswapl((target_ulong) ka->_sa_handler); - env->gpr[12] =3D env->nip; + /* ELFv2 PPC64 function pointers are entry points. R12 must also= be set. */ + env->gpr[12] =3D env->nip =3D ka->_sa_handler; } #else env->nip =3D (target_ulong) ka->_sa_handler; --=20 2.25.1