From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55762) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a0oW2-000693-Ef for qemu-devel@nongnu.org; Mon, 23 Nov 2015 05:38:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a0oVz-0005x3-8V for qemu-devel@nongnu.org; Mon, 23 Nov 2015 05:38:34 -0500 Received: from smtp4-g21.free.fr ([212.27.42.4]:29060) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a0oVz-0005wg-2L for qemu-devel@nongnu.org; Mon, 23 Nov 2015 05:38:31 -0500 From: Laurent Vivier Date: Mon, 23 Nov 2015 11:38:26 +0100 Message-Id: <1448275106-21493-1-git-send-email-laurent@vivier.eu> Subject: [Qemu-devel] [PATCH] linux-user,sh4: fix signal retcode address List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: riku.voipio@iki.fi, Laurent Vivier , glaubitz@physik.fu-berlin.de To return from a signal, setup_frame() puts an instruction to be executed in the stack. This sequence calls the syscall sigreturn(). The address of the instruction must be set in the PR register to be executed. This patch fixes this: the current code sets the register to the address of the instruction in the host address space (which can be 64bit whereas PR is only 32bit), but the virtual CPU can't access this address space, so we put in PR the address of the instruction in the guest address space. This patch also removes an useless variable (ret) in the modified functions. Signed-off-by: Laurent Vivier --- linux-user/signal.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/linux-user/signal.c b/linux-user/signal.c index 55e5405..5e8f6d8 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -3215,7 +3215,6 @@ static void setup_frame(int sig, struct target_sigaction *ka, struct target_sigframe *frame; abi_ulong frame_addr; int i; - int err = 0; frame_addr = get_sigframe(ka, regs->gregs[15], sizeof(*frame)); if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 0)) @@ -3233,15 +3232,14 @@ static void setup_frame(int sig, struct target_sigaction *ka, regs->pr = (unsigned long) ka->sa_restorer; } else { /* Generate return code (system call to sigreturn) */ + abi_ulong retcode_addr = frame_addr + + offsetof(struct target_sigframe, retcode); __put_user(MOVW(2), &frame->retcode[0]); __put_user(TRAP_NOARG, &frame->retcode[1]); __put_user((TARGET_NR_sigreturn), &frame->retcode[2]); - regs->pr = (unsigned long) frame->retcode; + regs->pr = (unsigned long) retcode_addr; } - if (err) - goto give_sigsegv; - /* Set up registers for signal handler */ regs->gregs[15] = frame_addr; regs->gregs[4] = sig; /* Arg for signal handler */ @@ -3264,7 +3262,6 @@ static void setup_rt_frame(int sig, struct target_sigaction *ka, struct target_rt_sigframe *frame; abi_ulong frame_addr; int i; - int err = 0; frame_addr = get_sigframe(ka, regs->gregs[15], sizeof(*frame)); if (!lock_user_struct(VERIFY_WRITE, frame, frame_addr, 0)) @@ -3293,15 +3290,14 @@ static void setup_rt_frame(int sig, struct target_sigaction *ka, regs->pr = (unsigned long) ka->sa_restorer; } else { /* Generate return code (system call to sigreturn) */ + abi_ulong retcode_addr = frame_addr + + offsetof(struct target_rt_sigframe, retcode); __put_user(MOVW(2), &frame->retcode[0]); __put_user(TRAP_NOARG, &frame->retcode[1]); __put_user((TARGET_NR_rt_sigreturn), &frame->retcode[2]); - regs->pr = (unsigned long) frame->retcode; + regs->pr = (unsigned long) retcode_addr; } - if (err) - goto give_sigsegv; - /* Set up registers for signal handler */ regs->gregs[15] = frame_addr; regs->gregs[4] = sig; /* Arg for signal handler */ -- 2.4.3