From: Laurent Vivier <laurent@vivier.eu>
To: Vincent Fazio <vfazio@xes-inc.com>, qemu-devel@nongnu.org
Cc: qemu-trivial@nongnu.org, Riku Voipio <riku.voipio@iki.fi>,
qemu-ppc@nongnu.org, Vincent Fazio <vfazio@gmail.com>,
David Gibson <david@gibson.dropbear.id.au>
Subject: Re: [PATCH 1/1] target/ppc: fix ELFv2 signal handler endianness
Date: Sun, 15 Mar 2020 19:10:14 +0100 [thread overview]
Message-ID: <346e47c8-4a80-860c-ec55-e38d2021d63d@vivier.eu> (raw)
In-Reply-To: <20200315155202.13107-1-vfazio@xes-inc.com>
Le 15/03/2020 à 16:52, Vincent Fazio a écrit :
> From: Vincent Fazio <vfazio@gmail.com>
>
> In ELFv2, function pointers are entry points and are in host endianness.
"host endianness" is misleading here. "target endianness" is better.
>
> Previously, the signal handler would be swapped if the target CPU was a
> different endianness than the host. This would cause a SIGSEGV when
> attempting to translate the opcode pointed to by the swapped address.
This is correct.
> 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
>
> Now, no swap is performed and execution continues properly.
>
> Signed-off-by: Vincent Fazio <vfazio@gmail.com>
> ---
> linux-user/ppc/signal.c | 10 +++++++---
> 1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/linux-user/ppc/signal.c b/linux-user/ppc/signal.c
> index 5b82af6cb6..c7f6455170 100644
> --- a/linux-user/ppc/signal.c
> +++ b/linux-user/ppc/signal.c
> @@ -567,9 +567,13 @@ void setup_rt_frame(int sig, struct target_sigaction *ka,
> env->nip = tswapl(handler->entry);
> env->gpr[2] = tswapl(handler->toc);
> } else {
> - /* ELFv2 PPC64 function pointers are entry points, but R12
> - * must also be set */
> - env->nip = tswapl((target_ulong) ka->_sa_handler);
> + /*
> + * ELFv2 PPC64 function pointers are entry points and are in host
> + * endianness so should not to be swapped.
"target endianness"
> + *
> + * Note: R12 must also be set.
> + */
> + env->nip = (target_ulong) ka->_sa_handler;
The cast is not needed: nip and _sa_handler are abi_ulong.
> env->gpr[12] = env->nip;
> }
> #else
>
If you repost with the fix I've reported above you can add my:
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Thanks,
Laurent
next prev parent reply other threads:[~2020-03-15 18:15 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-15 15:52 [PATCH 1/1] target/ppc: fix ELFv2 signal handler endianness Vincent Fazio
2020-03-15 18:10 ` Laurent Vivier [this message]
2020-03-16 0:29 ` Vincent Fazio
2020-03-16 2:21 ` David Gibson
2020-03-18 15:00 ` Vincent Fazio
2020-03-19 5:17 ` David Gibson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=346e47c8-4a80-860c-ec55-e38d2021d63d@vivier.eu \
--to=laurent@vivier.eu \
--cc=david@gibson.dropbear.id.au \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=qemu-trivial@nongnu.org \
--cc=riku.voipio@iki.fi \
--cc=vfazio@gmail.com \
--cc=vfazio@xes-inc.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).