From nobody Sat May 18 15:49:31 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1635019410215993.3193419190985; Sat, 23 Oct 2021 13:03:30 -0700 (PDT) Received: from localhost ([::1]:56596 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1meNEm-0007AH-9D for importer@patchew.org; Sat, 23 Oct 2021 16:03:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48884) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meNBU-0006Bv-Bl for qemu-devel@nongnu.org; Sat, 23 Oct 2021 16:00:04 -0400 Received: from orthanc.universe-factory.net ([104.238.176.138]:48790) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1meNBS-0004S8-2T for qemu-devel@nongnu.org; Sat, 23 Oct 2021 16:00:04 -0400 Received: from avalon.. (unknown [IPv6:2001:19f0:6c01:100::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by orthanc.universe-factory.net (Postfix) with ESMTPSA id C42871F4BB; Sat, 23 Oct 2021 21:59:58 +0200 (CEST) From: Matthias Schiffer To: Laurent Vivier Subject: [PATCH] linux-user/signal: Map exit signals in SIGCHLD siginfo_t Date: Sat, 23 Oct 2021 21:59:10 +0200 Message-Id: <81534fde7cdfc6acea4889d886fbefdd606630fb.1635019124.git.mschiffer@universe-factory.net> X-Mailer: git-send-email 2.33.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=104.238.176.138; envelope-from=mschiffer@universe-factory.net; helo=orthanc.universe-factory.net X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Matthias Schiffer , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1635019411954100001 Content-Type: text/plain; charset="utf-8" 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 #include #include #include int main() { pid_t pid =3D fork(); if (pid =3D=3D 0) { exit(12); } else { siginfo_t siginfo =3D {}; waitid(P_PID, pid, &siginfo, WEXITED); printf("Code: %d, status: %d\n", (int)siginfo.si_code, (int)siginfo.s= i_status); } pid =3D fork(); if (pid =3D=3D 0) { raise(SIGUSR2); } else { siginfo_t siginfo =3D {}; waitid(P_PID, pid, &siginfo, WEXITED); printf("Code: %d, status: %d\n", (int)siginfo.si_code, (int)siginfo.s= i_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 Reviewed-by: Laurent Vivier --- 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 14d8fdfde152..8e3af98ec0a7 100644 --- a/linux-user/signal.c +++ b/linux-user/signal.c @@ -403,7 +403,12 @@ static inline void host_to_target_siginfo_noswap(targe= t_siginfo_t *tinfo, case TARGET_SIGCHLD: tinfo->_sifields._sigchld._pid =3D info->si_pid; tinfo->_sifields._sigchld._uid =3D info->si_uid; - tinfo->_sifields._sigchld._status =3D info->si_status; + if (si_code =3D=3D CLD_EXITED) + tinfo->_sifields._sigchld._status =3D info->si_status; + else + tinfo->_sifields._sigchld._status + =3D host_to_target_signal(info->si_status & 0x7f) + | (info->si_status & ~0x7f); tinfo->_sifields._sigchld._utime =3D info->si_utime; tinfo->_sifields._sigchld._stime =3D info->si_stime; si_type =3D QEMU_SI_CHLD; --=20 2.33.1