From nobody Sat May 4 15:51:23 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 ARC-Seal: i=1; a=rsa-sha256; t=1594221977; cv=none; d=zohomail.com; s=zohoarc; b=XwaMzZYvPo6b98emA3ZA4QIrpkIT+u0n/lmXqlTR9lJVlrA/YWkSuytNJDy8jULIqh+QCGb5N9VpiRdMUCneJux2bYcLRJzaewd9uCKmy1DB2HAgrthv11qFi8KzBnd/1Oq06frrtghazBA5tJFGKdjX58iWXU1TJI327LAcM1A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594221977; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=65l84sDBM+UB/uA2oUASOG53kszVBFcoFCZqJ2Nvgh8=; b=Hp4z66McSo/Wb8C2YA201pht21KUF+hvyP4dkPuZUcwOklovs3gs/F6IFBMksCiQlvJPEHbG2EAQiQmgg1AWqAj1tpwSSe2Un9Ju+NE1PW9UMU3fT2jZ1h14kZozgsVTJjJlEs+iT9sMFHtkVYjhAz08CIehmAgd+sWVt2Adfc0= ARC-Authentication-Results: i=1; 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 1594221976968916.6324798821623; Wed, 8 Jul 2020 08:26:16 -0700 (PDT) Received: from localhost ([::1]:48840 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jtBxe-00025G-Bc for importer@patchew.org; Wed, 08 Jul 2020 11:26:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57806) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jtBwI-0000jG-AR for qemu-devel@nongnu.org; Wed, 08 Jul 2020 11:24:50 -0400 Received: from mout.kundenserver.de ([212.227.126.133]:37951) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jtBwG-0003rN-Hc for qemu-devel@nongnu.org; Wed, 08 Jul 2020 11:24:50 -0400 Received: from localhost.localdomain ([82.252.135.106]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MPXxi-1kFgtj0fyc-00MaZS; Wed, 08 Jul 2020 17:24:45 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PATCH v2 1/2] linux-user: fix the errno value in print_syscall_err() Date: Wed, 8 Jul 2020 17:24:34 +0200 Message-Id: <20200708152435.706070-2-laurent@vivier.eu> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200708152435.706070-1-laurent@vivier.eu> References: <20200708152435.706070-1-laurent@vivier.eu> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:VHD9ehhBaWuKdpbNajPOHdzu+ebTX4PFxPkHtCs6Hovgx+0cpcK 4DLmKJdyzf6PoQmDc18oF7dL/C44LLiLAgWylzgwRmf/0p1LH21i01ycBgfLAdBG7Gm4/p7 y6EiNNKorhUW7JNnRV5Tb+NEWQuzuKtQ0L3WM+4vbEAXdtuM6iOtuImjkuqiRJmKdMu18J4 N1WdJrNG9wPUktN2+LHww== X-UI-Out-Filterresults: notjunk:1;V03:K0:8yHDU6Z+D8s=:8wkcHH1x+ALEDFbjqmeSi5 S75Fv4hNwcZAKy4xMedCJe1BqVe1Y5EpOhmzuVrjM/9B1YVULI2gd8FNIbqvXWgrQ8fe8O8jZ HTIOssGcME3BupInb+4c05pfQZRWGNNrG58HAC8sa7mv8dQqJ2NDHPljx5UWoz4NYcMSpq/80 HIfvPfliwKLMw9vCtPYBsd2gNvI/Ols7ZYskmS4mgOwRiGGO06PP9bDNX6yl6/JeSoKzSkgmW f8kv/oFhiiU0ftFaNgM53aQrntcZQa2fWpuuREd/DtZ3483BNOcHGe3D7kEB+MA4aJyKD70MM DUsDsk7nAMnHJaAVhJiqsqPBdSoLB4W7kZw/14C2I7EiFv0Wu4K/KWUiJ6lgFccl0ZsezrUHe VHnDRufG4hT8721wxf8/NzyfIO6Pf9UOK5vgho72PGkcay8c3yxScdHoD35MACMA9KnLV9DUt dSEFel0tJ69a+P9NPCjLmVmWFvz2bfvUnXkoWAd0wHzk1L7fhrhN5YgOUpdG5865LRmM8n0bR OY8BLYC2y78VgAsYunoXUXU+OKjEXa49tsMqYGbxrCU19w0o76hqT2R6XoNJ9Xe3u2e70y6Uh KFAJcuEZzG0zgNEENF/FZBRhwNqB3rq0miPFAex1F2X1AvCzOuTmDnQh8SLZ0135eXKlWYc1L L+n4aS6RdCbS3SHBIhJecTGtalCMhjCKYcOCOFyKKwr+zG0EwdTgFDEdBuidLI7/SFwO/XXU2 0Ev9Tpoe9JTBlEuOuPNSvsdevHHH/h/LnHHrWPup6zV0q1biZtFRvBhqGHQvUpBjanfO4EqNX ZrwhIcCGD9jYvJow2aO8fc9xsswy5dVRe8+nZlkEl7uBDAdswSy/2Q5LqwF8CXRnmV5LA/P 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: none client-ip=212.227.126.133; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/08 11:24:46 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_NONE=0.001, SPF_NONE=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: Laurent Vivier , Filip Bozuta Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" errno of the target is returned as a negative value by the syscall, not in the host errno variable. The emulation of the target syscall can return an error while the host doesn't set an errno value. Target errnos and host errnos can also differ in some cases. Fixes: c84be71f6854 ("linux-user: Extend strace support to enable argument = printing after syscall execution") Cc: Filip.Bozuta@syrmia.com Signed-off-by: Laurent Vivier Reviewed-by: Filip Bozuta Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson --- linux-user/strace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux-user/strace.c b/linux-user/strace.c index 5235b2260cdd..b42664bbd180 100644 --- a/linux-user/strace.c +++ b/linux-user/strace.c @@ -731,7 +731,7 @@ print_syscall_err(abi_long ret) =20 qemu_log(" =3D "); if (ret < 0) { - qemu_log("-1 errno=3D%d", errno); + qemu_log("-1 errno=3D%d", (int)-ret); errstr =3D target_strerror(-ret); if (errstr) { qemu_log(" (%s)", errstr); --=20 2.26.2 From nobody Sat May 4 15:51:23 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 ARC-Seal: i=1; a=rsa-sha256; t=1594221977; cv=none; d=zohomail.com; s=zohoarc; b=N/wuEjF8xDJME+ZVuItjtEFBDXfJByF1z15tA5dCDOpocje3NjRNsU/zpdlt0/2u9B8i2o+EwtPjvVCmcMTecDNznNCkYNlVi8mMWORj2VLmbc5+jk1r7v0NG+kNRrGdtsJ82/9/11s6GpOgcv+VbF8E30DPKz4hQMK2HHIBzcc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594221977; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Mhvf5ZNM9Eok6OWanJZOdSHFzX7sklPArbNvPvUOlVk=; b=NfZjvtQVeh5tFQ1AkHeMR/rc8eNWz+sMMAv97PlIHoZeCRxRbty+v/EVfgpVU6P1TUOzNVc6Y4w6PnS4Q+JkXI5Ol4cti5SInyd7rcN/3TOev/PhDhCCG46zLDq8qs3Er3cY4NCAJTOLGLNRiKJxrpsLB/oRr0SLwOkTEiprHN8= ARC-Authentication-Results: i=1; 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 1594221977498849.7437330896057; Wed, 8 Jul 2020 08:26:17 -0700 (PDT) Received: from localhost ([::1]:48990 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jtBxg-00028x-9Q for importer@patchew.org; Wed, 08 Jul 2020 11:26:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57830) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jtBwJ-0000k3-SD for qemu-devel@nongnu.org; Wed, 08 Jul 2020 11:24:51 -0400 Received: from mout.kundenserver.de ([212.227.126.131]:33413) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jtBwG-0003rj-Hd for qemu-devel@nongnu.org; Wed, 08 Jul 2020 11:24:51 -0400 Received: from localhost.localdomain ([82.252.135.106]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.167]) with ESMTPSA (Nemesis) id 1MryCb-1ke3Oi2Y9F-00nyk5; Wed, 08 Jul 2020 17:24:45 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PATCH v2 2/2] linux-user: fix print_syscall_err() when syscall returned value is negative Date: Wed, 8 Jul 2020 17:24:35 +0200 Message-Id: <20200708152435.706070-3-laurent@vivier.eu> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200708152435.706070-1-laurent@vivier.eu> References: <20200708152435.706070-1-laurent@vivier.eu> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:SlgJvoPbMIPRGZqKxi52xr+quYCcDCXIErC0wCyf+Ir2Yr29VYo ZB3s7qqyzN5pgoXhvH+NvxR0KyVa/c2aKvYdUycjOEJ1DfeAMLAoFlpelJRuivwG1xElZW6 RaMVWCw6DcaupVESJBY3EKA+Squ5xOEhlUY6hbDh8Ij8kqKJdXRCbMzi0bWKedXpgNwiaw/ l4Oq+X95ZGoOzOxI1s7Vw== X-UI-Out-Filterresults: notjunk:1;V03:K0:1yZvhYdCusY=:vgX2h1pxeyx/F85cGtE2on weLOe4HuP4FB1X+1OhsWitn/xUXABCOYWIOW8g6nc/2kW2D4do1fP0CUP7b2ClcztoV39ZJM7 VL0zHBlSRfT73dchhfUBwNgcrvYV9oaT/8OH3/j9u4Tzi5an83RrtiHEcEe47wegLovIbVNPT I0AeRpQe9VA1PrLsZVrze5LOGleMy8oAiz3sLCJTMxZITzVUdtkf+Q64UmXYU0UGuQp8gLw3k WjzLzY3Be9VdkRS4f6ILN6aGTsvHtbOioQYjqi94PXi2GbB+4UlqWwUdBz+UIUnpZmYc0vUHU jIK0DZp+yeXIeUnWbvbsZWCn9LFutucDyimWwvdAx2nSgCz7vKGWlIcJjYThO5jRyzD6ZoDl9 9J9eiKuNNXqJcIEne2XY5+2LjpgumuXS9wVOopyljU7/DYeYvTdxg/gmJUbDDlcyh0ucwA0f2 LCC8AfUGwUOhVbLchv8nz/xVdGmaJz6rUd0ud2OHP5qq4/qycXJ8m9NhIcAabCvSApQnxBHy2 FhGTsCP2gSXUM0xx7+ET1JYqXb/PPaOfbndG1lXJflsb69+9DUbmkpmtCvHQdwN5EzAwuccwR j+EWZizMRdKXAgM/Pu/r8affTjgWBPqfsBJdymTErmqs1UEwWEV87ydZAMVvvQRRIRwc1GRWi LM8/hG2UOYpiSLufbp1ESPfleAUn1YoKffCtv/S1EfOrd6kIMBPKgDTA5hxV9jCm8gMyEZ4Nf FgmGY6QZlGjHLTMFPmQDn1ygqojrztG/nrLH2MPu+RKWsO9IK3RBBYYJeJEAZmpy2UyAj0Rbm OxnWPVczpMnyWFWzihE+bqWYwqzeGN+iZG5J59yqzSv5SW2ckbYhNuTaI9bBV7xDgKspoJt 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: none client-ip=212.227.126.131; envelope-from=laurent@vivier.eu; helo=mout.kundenserver.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/08 11:24:47 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_NONE=0.001, SPF_NONE=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: Laurent Vivier , Filip Bozuta Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" print_syscall_err() relies on the sign of the returned value to know if it is an errno value or not. But in some cases the returned value can have the most signicant bit set without being an errno. This patch restores previous behaviour that was also checking if we can decode the errno to validate it. This patch fixes this kind of problem (qemu-m68k): root@sid:/# QEMU_STRACE=3D ls 3 brk(NULL) =3D -1 errno=3D21473607683 uname(0x407fff8a) =3D 0 to become: root@sid:/# QEMU_STRACE=3D ls 3 brk(NULL) =3D 0x8001e000 3 uname(0xffffdf8a) =3D 0 Fixes: c84be71f6854 ("linux-user: Extend strace support to enable argument = printing after syscall execution") Cc: Filip.Bozuta@syrmia.com Signed-off-by: Laurent Vivier --- linux-user/strace.c | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/linux-user/strace.c b/linux-user/strace.c index b42664bbd180..17f2554643f0 100644 --- a/linux-user/strace.c +++ b/linux-user/strace.c @@ -724,19 +724,20 @@ print_ipc(const struct syscallname *name, * Variants for the return value output function */ =20 -static void +static bool print_syscall_err(abi_long ret) { - const char *errstr =3D NULL; + const char *errstr; =20 qemu_log(" =3D "); if (ret < 0) { - qemu_log("-1 errno=3D%d", (int)-ret); errstr =3D target_strerror(-ret); if (errstr) { - qemu_log(" (%s)", errstr); + qemu_log("-1 errno=3D%d (%s)", (int)-ret, errstr); + return true; } } + return false; } =20 static void @@ -744,11 +745,10 @@ print_syscall_ret_addr(const struct syscallname *name= , abi_long ret, abi_long arg0, abi_long arg1, abi_long arg2, abi_long arg3, abi_long arg4, abi_long arg5) { - print_syscall_err(ret); - - if (ret >=3D 0) { - qemu_log("0x" TARGET_ABI_FMT_lx "\n", ret); + if (!print_syscall_err(ret)) { + qemu_log("0x" TARGET_ABI_FMT_lx, ret); } + qemu_log("\n"); } =20 #if 0 /* currently unused */ @@ -765,9 +765,7 @@ print_syscall_ret_newselect(const struct syscallname *n= ame, abi_long ret, abi_long arg0, abi_long arg1, abi_long arg2, abi_long arg3, abi_long arg4, abi_long arg5) { - print_syscall_err(ret); - - if (ret >=3D 0) { + if (!print_syscall_err(ret)) { qemu_log(" =3D 0x" TARGET_ABI_FMT_lx " (", ret); print_fdset(arg0, arg1); qemu_log(","); @@ -796,9 +794,7 @@ print_syscall_ret_adjtimex(const struct syscallname *na= me, abi_long ret, abi_long arg0, abi_long arg1, abi_long arg2, abi_long arg3, abi_long arg4, abi_long arg5) { - print_syscall_err(ret); - - if (ret >=3D 0) { + if (!print_syscall_err(ret)) { qemu_log(TARGET_ABI_FMT_ld, ret); switch (ret) { case TARGET_TIME_OK: @@ -833,9 +829,7 @@ print_syscall_ret_listxattr(const struct syscallname *n= ame, abi_long ret, abi_long arg0, abi_long arg1, abi_long arg2, abi_long arg3, abi_long arg4, abi_long arg5) { - print_syscall_err(ret); - - if (ret >=3D 0) { + if (!print_syscall_err(ret)) { qemu_log(TARGET_ABI_FMT_ld, ret); qemu_log(" (list =3D "); if (arg1 !=3D 0) { @@ -866,9 +860,7 @@ print_syscall_ret_ioctl(const struct syscallname *name,= abi_long ret, abi_long arg0, abi_long arg1, abi_long arg2, abi_long arg3, abi_long arg4, abi_long arg5) { - print_syscall_err(ret); - - if (ret >=3D 0) { + if (!print_syscall_err(ret)) { qemu_log(TARGET_ABI_FMT_ld, ret); =20 const IOCTLEntry *ie; @@ -3189,9 +3181,7 @@ print_syscall_ret(int num, abi_long ret, arg1, arg2, arg3, arg4, arg5, arg6); } else { - print_syscall_err(ret); - - if (ret >=3D 0) { + if (!print_syscall_err(ret)) { qemu_log(TARGET_ABI_FMT_ld, ret); } qemu_log("\n"); --=20 2.26.2