All of lore.kernel.org
 help / color / mirror / Atom feed
From: Laurent Vivier <laurent@vivier.eu>
To: qemu-devel@nongnu.org
Cc: Matthias Schiffer <mschiffer@universe-factory.net>,
	Laurent Vivier <laurent@vivier.eu>
Subject: [PULL 13/27] linux-user/signal: Map exit signals in SIGCHLD siginfo_t
Date: Thu,  6 Jan 2022 11:41:23 +0100	[thread overview]
Message-ID: <20220106104137.732883-14-laurent@vivier.eu> (raw)
In-Reply-To: <20220106104137.732883-1-laurent@vivier.eu>

From: Matthias Schiffer <mschiffer@universe-factory.net>

When converting a siginfo_t from waitid(), the interpretation of si_status
depends on the value of si_code: For CLD_EXITED, it is an exit code and
should be copied verbatim. For other codes, it is a signal number
(possibly with additional high bits from ptrace) that should be mapped.

This code was previously changed in commit 1c3dfb506ea3
("linux-user/signal: Decode waitid si_code"), but the fix was
incomplete.

Tested with the following test program:

    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    #include <sys/wait.h>

    int main() {
    	pid_t pid = fork();
    	if (pid == 0) {
    		exit(12);
    	} else {
    		siginfo_t siginfo = {};
    		waitid(P_PID, pid, &siginfo, WEXITED);
    		printf("Code: %d, status: %d\n", (int)siginfo.si_code, (int)siginfo.si_status);
    	}

    	pid = fork();
    	if (pid == 0) {
    		raise(SIGUSR2);
    	} else {
    		siginfo_t siginfo = {};
    		waitid(P_PID, pid, &siginfo, WEXITED);
    		printf("Code: %d, status: %d\n", (int)siginfo.si_code, (int)siginfo.si_status);
    	}
    }

Output with an x86_64 host and mips64el target before 1c3dfb506ea3
(incorrect: exit code 12 is translated like a signal):

    Code: 1, status: 17
    Code: 2, status: 17

After 1c3dfb506ea3 (incorrect: signal number is not translated):

    Code: 1, status: 12
    Code: 2, status: 12

With this patch:

    Code: 1, status: 12
    Code: 2, status: 17

Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <81534fde7cdfc6acea4889d886fbefdd606630fb.1635019124.git.mschiffer@universe-factory.net>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/signal.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/linux-user/signal.c b/linux-user/signal.c
index 510db73c3424..1229fecf5cd4 100644
--- a/linux-user/signal.c
+++ b/linux-user/signal.c
@@ -406,7 +406,12 @@ static inline void host_to_target_siginfo_noswap(target_siginfo_t *tinfo,
         case TARGET_SIGCHLD:
             tinfo->_sifields._sigchld._pid = info->si_pid;
             tinfo->_sifields._sigchld._uid = info->si_uid;
-            tinfo->_sifields._sigchld._status = info->si_status;
+            if (si_code == CLD_EXITED)
+                tinfo->_sifields._sigchld._status = info->si_status;
+            else
+                tinfo->_sifields._sigchld._status
+                    = host_to_target_signal(info->si_status & 0x7f)
+                        | (info->si_status & ~0x7f);
             tinfo->_sifields._sigchld._utime = info->si_utime;
             tinfo->_sifields._sigchld._stime = info->si_stime;
             si_type = QEMU_SI_CHLD;
-- 
2.33.1



  parent reply	other threads:[~2022-01-06 10:44 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-06 10:41 [PULL 00/27] Linux user for 7.0 patches Laurent Vivier
2022-01-06 10:41 ` [PULL 01/27] qemu-binfmt-conf.sh: fix -F option Laurent Vivier
2022-01-06 10:41 ` [PULL 02/27] linux-user/hexagon: Use generic target_stat64 structure Laurent Vivier
2022-01-06 10:41 ` [PULL 03/27] linux-user: Mark cpu_loop() with noreturn attribute Laurent Vivier
2022-01-06 10:41 ` [PULL 04/27] linux-user: Move target_signal.h generic definitions to generic/signal.h Laurent Vivier
2022-01-06 10:41 ` [PULL 05/27] linux-user: target_syscall.h remove definition TARGET_MINSIGSTKSZ Laurent Vivier
2022-01-06 10:41 ` [PULL 06/27] linux-user: Remove TARGET_SIGSTKSZ Laurent Vivier
2022-01-06 10:41 ` [PULL 07/27] linux-user: Split out do_prctl and subroutines Laurent Vivier
2022-01-06 10:41 ` [PULL 08/27] linux-user: Disable more prctl subcodes Laurent Vivier
2022-01-06 10:41 ` [PULL 09/27] linux-user: Add code for PR_GET/SET_UNALIGN Laurent Vivier
2022-01-06 10:41 ` [PULL 10/27] target/alpha: Implement prctl_unalign_sigbus Laurent Vivier
2022-01-06 10:41 ` [PULL 11/27] target/hppa: " Laurent Vivier
2022-01-06 10:41 ` [PULL 12/27] target/sh4: " Laurent Vivier
2022-01-06 10:41 ` Laurent Vivier [this message]
2022-01-06 10:41 ` [PULL 14/27] linux-user: add sched_getattr support Laurent Vivier
2022-01-06 10:41 ` [PULL 15/27] linux-user: call set/getscheduler set/getparam directly Laurent Vivier
2022-01-06 10:41 ` [PULL 16/27] linux-user/syscall.c: fix missed flag for shared memory in open_self_maps Laurent Vivier
2022-01-06 10:41 ` [PULL 17/27] linux-user/nios2: Properly emulate EXCP_TRAP Laurent Vivier
2022-01-06 10:41 ` [PULL 18/27] linux-user/nios2: Fixes for signal frame setup Laurent Vivier
2022-01-06 10:41 ` [PULL 19/27] linux-user/elfload: Rename ARM_COMMPAGE to HI_COMMPAGE Laurent Vivier
2022-01-06 10:41 ` [PULL 20/27] linux-user/nios2: Map a real kuser page Laurent Vivier
2022-01-10 13:22   ` Peter Maydell
2022-01-06 10:41 ` [PULL 21/27] linux-user/nios2: Fix EA vs PC confusion Laurent Vivier
2022-01-06 10:41 ` [PULL 22/27] linux-user/nios2: Fix sigmask in setup_rt_frame Laurent Vivier
2022-01-06 10:41 ` [PULL 23/27] linux-user/nios2: Use set_sigmask in do_rt_sigreturn Laurent Vivier
2022-01-06 10:41 ` [PULL 24/27] linux-user/syscall.c: malloc to g_try_malloc Laurent Vivier
2022-01-06 10:41 ` [PULL 25/27] linux-user: netlink: update IFLA entries Laurent Vivier
2022-01-06 10:41 ` [PULL 26/27] linux-user: netlink: Add IFLA_VFINFO_LIST Laurent Vivier
2022-01-06 10:41 ` [PULL 27/27] linux-user: netlink: update IFLA_BRPORT entries Laurent Vivier
2022-01-06 21:15 ` [PULL 00/27] Linux user for 7.0 patches Richard Henderson

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=20220106104137.732883-14-laurent@vivier.eu \
    --to=laurent@vivier.eu \
    --cc=mschiffer@universe-factory.net \
    --cc=qemu-devel@nongnu.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.