From nobody Tue Nov 26 04:30:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=1709705583; cv=none; d=zohomail.com; s=zohoarc; b=DqV9DPFp/SDHPKHzgWZWUX6kIyWW8r6uxi0C301u9dnj7geHDTJzINPuhFprgKMOxc+NclipQwynIvFU6sR0FAjE+AVOjl6KE0gKMF+eaA2I89XGMGT9CYPMDNYvgx7IHJJnyPY1ZLkS2lUvTCxNaZHBkq5iswmo0poKB1E55Oo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709705583; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=D5kUM6n9+j+qbS1SUPTKf/+dgcMdpwuEc/L8WCg7irw=; b=F18wH9qPV9DHb0etolJgZBioJnb8cDd9rQpVzrVlS8U4jMy/39VgIXb5bhwr71UCXXqcZm4YfH4R0INrGurjbkZJ7wWoyyJG/rkn/J4LFSxyLIXmuet0gOpnDVwcCnkwe2lce6B9fepHlQtf6vC88UAZ4nZcDsFsijse8TN5CYs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 1709705583033916.440211682467; Tue, 5 Mar 2024 22:13:03 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rhkVz-0004sP-No; Wed, 06 Mar 2024 01:12:33 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rhkVl-0004r9-Kj for qemu-devel@nongnu.org; Wed, 06 Mar 2024 01:12:17 -0500 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rhkVk-0006EG-2E for qemu-devel@nongnu.org; Wed, 06 Mar 2024 01:12:17 -0500 Received: by mail-pl1-x629.google.com with SMTP id d9443c01a7336-1dc1ff58fe4so5122725ad.1 for ; Tue, 05 Mar 2024 22:12:15 -0800 (PST) Received: from localhost ([157.82.206.27]) by smtp.gmail.com with UTF8SMTPSA id z19-20020a170903409300b001d913992d8csm11625037plc.242.2024.03.05.22.12.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 05 Mar 2024 22:12:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709705535; x=1710310335; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=D5kUM6n9+j+qbS1SUPTKf/+dgcMdpwuEc/L8WCg7irw=; b=qzYdz+B3bhg6deitxqgQQpvrww9xtNEtmYvo9RD+IHj5E/9PiYZZA3ICaKekAu3yFD +m8ekUqyX6oNSGb15CQtPY95lhGrGHcT/yAlQNTovZK/P9H7u1nQGr89BgX5S+aoq72e xmJPQT/WrPw/cXQPtuZxBqRZzlycd85MP5LE/Vjk846Yd+e8lo+hpIVRqDMadGiY9e/e VTdWZbKexLhhv2tXYxN4/vsPQAayxqzcLjo+inLExjYfGm6F4U+drdZAveFnrW1L9HPJ ApOONmHot9p7t2rKLANi/P0V/pB6qgYXlZf/IJWBr2Avv73IkfVN8/XoP8yRC9nilMoC CaPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709705535; x=1710310335; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=D5kUM6n9+j+qbS1SUPTKf/+dgcMdpwuEc/L8WCg7irw=; b=uC3glGOLKUgaaAFLJHstSe23p+tmb/qoOv7lIX2LS71eXsNnizxrD7n9PXi0N1z5NE sn6td+/UZPsZ/IaCIi3uE726aCwacaSL4BZWn2+9Sfw/X4zLdrLelW5+WAAQTStBrK7u 3Ntl8ghasY3kKx3S7O49ocWPvzG/4cUtJcS0lRwPp4QmtaQPfmSXtIN1nDiKmlX3csoZ +r3/p1w/FOobH+M2IJwxE4iaL9I0Yb9As6VVJYuqOYPYxz+lhYFuAYauUW/HpS/vAu3G HaagdqCFIEoUDXWVPyrg0yag4FHGXNKBz4vR8mJHb+MdV48MUQSnznc7ZRbqsMR6+j+o gAlg== X-Gm-Message-State: AOJu0YzyLwFv5ja5iUz0oK1tBO5N1MwXqxAMjMFMHgj4BwilLOGlB73O Wih3AWS1HAAqqGBsWvZzEufnqzHUPBHoD4pz7wb4qeZ41YgzAA3EULlz5cnmzLU= X-Google-Smtp-Source: AGHT+IF8OqExUQQ6CavhinnjOtEXRdeV9Gm7Gn2xwByK1EE3PxUW+Wm0MVhZ66EDdZYUGMNrMwMJuQ== X-Received: by 2002:a17:902:ee8b:b0:1dd:22e8:bdb5 with SMTP id a11-20020a170902ee8b00b001dd22e8bdb5mr3888794pld.16.1709705534774; Tue, 05 Mar 2024 22:12:14 -0800 (PST) From: Akihiko Odaki Date: Wed, 06 Mar 2024 15:12:07 +0900 Subject: [PATCH v3 01/19] contrib/elf2dmp: Remove unnecessary err flags MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240306-elf2dmp-v3-1-d74e6c3da49c@daynix.com> References: <20240306-elf2dmp-v3-0-d74e6c3da49c@daynix.com> In-Reply-To: <20240306-elf2dmp-v3-0-d74e6c3da49c@daynix.com> To: Viktor Prutyanov , Peter Maydell Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 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=2607:f8b0:4864:20::629; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x629.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1709705585173100004 They are always evaluated to 1. Signed-off-by: Akihiko Odaki Reviewed-by: Peter Maydell --- contrib/elf2dmp/pdb.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/contrib/elf2dmp/pdb.c b/contrib/elf2dmp/pdb.c index 40991f5f4c34..abf17c2e7c12 100644 --- a/contrib/elf2dmp/pdb.c +++ b/contrib/elf2dmp/pdb.c @@ -177,7 +177,6 @@ static int pdb_init_segments(struct pdb_reader *r) =20 static int pdb_init_symbols(struct pdb_reader *r) { - int err =3D 0; PDB_SYMBOLS *symbols; =20 symbols =3D pdb_ds_read_file(r, 3); @@ -196,7 +195,6 @@ static int pdb_init_symbols(struct pdb_reader *r) /* Read global symbol table */ r->modimage =3D pdb_ds_read_file(r, symbols->gsym_file); if (!r->modimage) { - err =3D 1; goto out_symbols; } =20 @@ -205,7 +203,7 @@ static int pdb_init_symbols(struct pdb_reader *r) out_symbols: g_free(symbols); =20 - return err; + return 1; } =20 static int pdb_reader_ds_init(struct pdb_reader *r, PDB_DS_HEADER *hdr) @@ -228,7 +226,6 @@ static int pdb_reader_ds_init(struct pdb_reader *r, PDB= _DS_HEADER *hdr) =20 static int pdb_reader_init(struct pdb_reader *r, void *data) { - int err =3D 0; const char pdb7[] =3D "Microsoft C/C++ MSF 7.00"; =20 if (memcmp(data, pdb7, sizeof(pdb7) - 1)) { @@ -241,17 +238,14 @@ static int pdb_reader_init(struct pdb_reader *r, void= *data) =20 r->ds.root =3D pdb_ds_read_file(r, 1); if (!r->ds.root) { - err =3D 1; goto out_ds; } =20 if (pdb_init_symbols(r)) { - err =3D 1; goto out_root; } =20 if (pdb_init_segments(r)) { - err =3D 1; goto out_sym; } =20 @@ -264,7 +258,7 @@ out_root: out_ds: pdb_reader_ds_exit(r); =20 - return err; + return 1; } =20 static void pdb_reader_exit(struct pdb_reader *r) @@ -278,7 +272,6 @@ static void pdb_reader_exit(struct pdb_reader *r) int pdb_init_from_file(const char *name, struct pdb_reader *reader) { GError *gerr =3D NULL; - int err =3D 0; void *map; =20 reader->gmf =3D g_mapped_file_new(name, TRUE, &gerr); @@ -291,7 +284,6 @@ int pdb_init_from_file(const char *name, struct pdb_rea= der *reader) reader->file_size =3D g_mapped_file_get_length(reader->gmf); map =3D g_mapped_file_get_contents(reader->gmf); if (pdb_reader_init(reader, map)) { - err =3D 1; goto out_unmap; } =20 @@ -300,7 +292,7 @@ int pdb_init_from_file(const char *name, struct pdb_rea= der *reader) out_unmap: g_mapped_file_unref(reader->gmf); =20 - return err; + return 1; } =20 void pdb_exit(struct pdb_reader *reader) --=20 2.44.0 From nobody Tue Nov 26 04:30:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=1709705879; cv=none; d=zohomail.com; s=zohoarc; b=nkFqHkn5NqQvmO6+48z09/sGS9M/Fz/GZlTY7/FaynhiDjXkuUg/R1wZ/Ux7oJgN4//s2I6cUqcF8thCZvt+u8gGQZql4VxjpXrRZ7/YBaFdTKtVF3a/a7a2e9aErNqakmayp+eWjI462fnSHenq3QfGMu/n5rt0MsDJm3OlRK0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709705879; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=WBQ8wkR+EtpXcrRFUmJL0m8euRcerqarx8Jtcq9C72A=; b=IBJdfA3csJNozKS6TKYlBTUk2ymeb8c3YrOt5JVIwGVeuPbRiqchwh6TfH5OMfShmDuBZeAHxrNptk1ro1jglqOGN7t+9AuAfyMisqLeMTGL+W2vLgewTYaH7qpTh63coZ7AGjZRNo9cRFdB7yZXfNvQHue/Hx+sUQXibBa7E28= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 170970587938732.23976431355561; Tue, 5 Mar 2024 22:17:59 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rhkWA-0004ui-L6; Wed, 06 Mar 2024 01:12:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rhkVo-0004rx-MF for qemu-devel@nongnu.org; Wed, 06 Mar 2024 01:12:23 -0500 Received: from mail-pg1-x52d.google.com ([2607:f8b0:4864:20::52d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rhkVn-0006EW-27 for qemu-devel@nongnu.org; Wed, 06 Mar 2024 01:12:20 -0500 Received: by mail-pg1-x52d.google.com with SMTP id 41be03b00d2f7-5dbf7b74402so5044431a12.0 for ; Tue, 05 Mar 2024 22:12:18 -0800 (PST) Received: from localhost ([157.82.206.27]) by smtp.gmail.com with UTF8SMTPSA id mm12-20020a1709030a0c00b001dc96d1a662sm11646117plb.197.2024.03.05.22.12.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 05 Mar 2024 22:12:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709705537; x=1710310337; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=WBQ8wkR+EtpXcrRFUmJL0m8euRcerqarx8Jtcq9C72A=; b=m+tGelhNmNlAanBrZzij9XJZvXOk1Y314VSTCbEaxf3jc2bIUHs34YgwfI7Z52zA8s KF23YFLGKux27vOr7prQOc/OZFhml3GKRLLN1S/YpiI7AOlE2fBdmI3/3Omd1als40VQ eC69yRmO6K+ipBY7cQR5OC/kYhLf+Nx4VXpUSiNqH3kIlnqWL3RWgeLuNz1ChgT8Zl8h SHM918i9PTraXWt5ypWrW3cSMBybx+PlTJRp+UKFJCLKIAVIkP4zgWkKq5ssw1iXcP/Q OJDtrkeZRIDtLGIKrgdMVldDp4sBgh6B1C6FrHhzrbKA2zkRcY73deyeR8l848if1xbw qv8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709705537; x=1710310337; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WBQ8wkR+EtpXcrRFUmJL0m8euRcerqarx8Jtcq9C72A=; b=eJcHdywgEfo58sbnMvExduKlzzAkYwVnsSJ0z3eb+6O0eQFNF2Ci0XzKwHGXd7t6QJ DFwf8GwIuIQ5+dAp6nm3ErShQyiYNgMv7XaxNKRAxQW4pp8X0RQXATao6dFNuoskwNzr 71ef0KC6lvwI5hwHvWPT7nJbVNjdJXipml3QO/QpqD/g4zbZ7v7HblRYHNIvnM63HFE6 FilnJBuZl9Vhl0/l/64g38m0PX3Hh8ReO84EG/ZlRdWrXf4RVlEXqs2Hz/mGWa8ro+BS h8vXEdvUV5vOHNweuc7hhd+N1y7iz22VasqOMjhwiNZytI7saLN5rU3bw8aKSVNtI+a8 ELkQ== X-Gm-Message-State: AOJu0YyweOG4uukyX3EBWMrG03FUF+xS1ELfoJXBP31ZaQzn6ZL5YPf4 /rBgqEzfjAYArWup4xmyQF57uMXqVzKwFIJ3XZLd/znfgvV/A29LOBHmQu3dJXaDKhAYLozVuOZ W X-Google-Smtp-Source: AGHT+IFahrNPfKTTM6khN4VxVixXHJ9gz5wNPqxzqetlgCi8BcLgd7BKAp/DoA+HPd3eqE8i3p5euQ== X-Received: by 2002:a17:902:e805:b0:1dc:f916:6b07 with SMTP id u5-20020a170902e80500b001dcf9166b07mr4511069plg.20.1709705537598; Tue, 05 Mar 2024 22:12:17 -0800 (PST) From: Akihiko Odaki Date: Wed, 06 Mar 2024 15:12:08 +0900 Subject: [PATCH v3 02/19] contrib/elf2dmp: Assume error by default MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240306-elf2dmp-v3-2-d74e6c3da49c@daynix.com> References: <20240306-elf2dmp-v3-0-d74e6c3da49c@daynix.com> In-Reply-To: <20240306-elf2dmp-v3-0-d74e6c3da49c@daynix.com> To: Viktor Prutyanov , Peter Maydell Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 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=2607:f8b0:4864:20::52d; envelope-from=akihiko.odaki@daynix.com; helo=mail-pg1-x52d.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1709705880413100005 A common construct in contrib/elf2dmp is to set "err" flag and goto in error paths. In such a construct, there is only one successful path while there are several error paths, so it will be more simpler to initialize "err" flag set, and clear it in the successful path. Signed-off-by: Akihiko Odaki Reviewed-by: Peter Maydell --- contrib/elf2dmp/download.c | 4 +--- contrib/elf2dmp/main.c | 15 +++------------ 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/contrib/elf2dmp/download.c b/contrib/elf2dmp/download.c index bd7650a7a27f..902dc04ffa5c 100644 --- a/contrib/elf2dmp/download.c +++ b/contrib/elf2dmp/download.c @@ -11,7 +11,7 @@ =20 int download_url(const char *name, const char *url) { - int err =3D 0; + int err =3D 1; FILE *file; CURL *curl =3D curl_easy_init(); =20 @@ -21,7 +21,6 @@ int download_url(const char *name, const char *url) =20 file =3D fopen(name, "wb"); if (!file) { - err =3D 1; goto out_curl; } =20 @@ -33,7 +32,6 @@ int download_url(const char *name, const char *url) || curl_easy_perform(curl) !=3D CURLE_OK) { unlink(name); fclose(file); - err =3D 1; } else { err =3D fclose(file); } diff --git a/contrib/elf2dmp/main.c b/contrib/elf2dmp/main.c index cbc38a7c103a..9b278f392e39 100644 --- a/contrib/elf2dmp/main.c +++ b/contrib/elf2dmp/main.c @@ -511,7 +511,7 @@ static void pe_get_pdb_symstore_hash(OMFSignatureRSDS *= rsds, char *hash) =20 int main(int argc, char *argv[]) { - int err =3D 0; + int err =3D 1; QEMU_Elf qemu_elf; struct pa_space ps; struct va_space vs; @@ -542,7 +542,6 @@ int main(int argc, char *argv[]) =20 if (pa_space_create(&ps, &qemu_elf)) { eprintf("Failed to initialize physical address space\n"); - err =3D 1; goto out_elf; } =20 @@ -552,7 +551,6 @@ int main(int argc, char *argv[]) va_space_create(&vs, &ps, state->cr[3]); if (fix_dtb(&vs, &qemu_elf)) { eprintf("Failed to find paging base\n"); - err =3D 1; goto out_elf; } =20 @@ -561,7 +559,6 @@ int main(int argc, char *argv[]) if (va_space_rw(&vs, state->idt.base, &first_idt_desc, sizeof(first_idt_desc), 0)) { eprintf("Failed to get CPU #0 IDT[0]\n"); - err =3D 1; goto out_ps; } printf("CPU #0 IDT[0] -> 0x%016"PRIx64"\n", idt_desc_addr(first_idt_de= sc)); @@ -586,7 +583,6 @@ int main(int argc, char *argv[]) =20 if (!kernel_found) { eprintf("Failed to find NT kernel image\n"); - err =3D 1; goto out_ps; } =20 @@ -600,45 +596,40 @@ int main(int argc, char *argv[]) =20 if (download_url(PDB_NAME, pdb_url)) { eprintf("Failed to download PDB file\n"); - err =3D 1; goto out_ps; } =20 if (pdb_init_from_file(PDB_NAME, &pdb)) { eprintf("Failed to initialize PDB reader\n"); - err =3D 1; goto out_pdb_file; } =20 if (!SYM_RESOLVE(KernBase, &pdb, KdDebuggerDataBlock) || !SYM_RESOLVE(KernBase, &pdb, KdVersionBlock)) { - err =3D 1; goto out_pdb; } =20 kdbg =3D get_kdbg(KernBase, &pdb, &vs, KdDebuggerDataBlock); if (!kdbg) { - err =3D 1; goto out_pdb; } =20 if (fill_header(&header, &ps, &vs, KdDebuggerDataBlock, kdbg, KdVersionBlock, qemu_elf.state_nr)) { - err =3D 1; goto out_kdbg; } =20 if (fill_context(kdbg, &vs, &qemu_elf)) { - err =3D 1; goto out_kdbg; } =20 if (write_dump(&ps, &header, argv[2])) { eprintf("Failed to save dump\n"); - err =3D 1; goto out_kdbg; } =20 + err =3D 0; + out_kdbg: g_free(kdbg); out_pdb: --=20 2.44.0 From nobody Tue Nov 26 04:30:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=1709705610; cv=none; d=zohomail.com; s=zohoarc; b=fcRHtNBUKQW8IrEJY6r+jJi4CU4uZ+o5cwmog7BhpNJ33cVNlHGIJhnSeiJGuVKhtVAJAeVSzVQdwRIm1D0/ZUD7PpJob2l25fvmIcCiAUHqMCGTw2PV/7r5wZ54XByF8HoL/KcQOTflyRq51TTdpdvgFmCyTD7/XrEtDr9FYQc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709705610; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=uEl9gr+JRIy2uRLCAmnmdcgL5kP09OBXfeuQ6yoOxrY=; b=U2JLCo5RuhJU9fAsrPwyP9CmOqEYsXWbB3j5sh5qUR/3TBrKY6YKH1yzWB9x+2gPkXkz25BjA5YNL2Su+6tOx3zIDFtjZMGcJB13/3kyg6thx7PLKtiXbrFzwdMKFvp8RhCJIZT7WlHDzN7ish0KtL/E9L+zCrA7Ok92ZXXOW3k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 1709705610829225.0443928139498; Tue, 5 Mar 2024 22:13:30 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rhkWG-0004yE-Ey; Wed, 06 Mar 2024 01:12:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rhkW1-0004tG-VA for qemu-devel@nongnu.org; Wed, 06 Mar 2024 01:12:34 -0500 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rhkVq-0006En-QG for qemu-devel@nongnu.org; Wed, 06 Mar 2024 01:12:31 -0500 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-1dd2dca2007so11351295ad.2 for ; Tue, 05 Mar 2024 22:12:22 -0800 (PST) Received: from localhost ([157.82.206.27]) by smtp.gmail.com with UTF8SMTPSA id kz12-20020a170902f9cc00b001db8f7720e2sm11647298plb.288.2024.03.05.22.12.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 05 Mar 2024 22:12:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709705541; x=1710310341; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=uEl9gr+JRIy2uRLCAmnmdcgL5kP09OBXfeuQ6yoOxrY=; b=rQrAES2FrN53fNKZs9iGNtBiY/cuhz73CxP+Z5StyrungnV6cyLwJXJawEF0yXmziQ uLD2urLqcGYVYFSDVlAa38iI1SDRBDaOD0xRgJ+mJcK4cRJNi67QAjaCm8ZbhNWu2T5L Glh4Qc8lRyt6yLrjasn8vqhwg8iG15xnqEYndbyTw/AY4pA1vNCMZBVwFGPVdYpy1kmS UorGyu8p5xIVonfh6gg4jT5aUySXY90gsfZYaeugzcz1CUhuLOiXXzoKabZxkzWYN5mR q/vDVyYJsPMKLjfPoTXWWcUyXb8xe26EClEP2w1cd/Q7yvZM21aihHEgNKxcifcMbUSS QC/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709705541; x=1710310341; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uEl9gr+JRIy2uRLCAmnmdcgL5kP09OBXfeuQ6yoOxrY=; b=nVQ6jNJSOGk71uOpsciNNqH1gXitTbhqrbJIek6Lv4bHVI0TxZHu+35PbN5C98dGxl b8+biOCAjimZ79CUopOSJF4HA1szWEhPeJ1L4xaJ7JIuVxIKvfcLcNunuOGC8ZEKQSwG 5BhN3O7mR5ytFzZU5cBpyGlC76iEvBZUSOKu9/IxbwDuzNmTaVEh8Amy6HV75LtSoD7r Ja4XJvW3qrvMPaoVa7Eyq3JuhoD+QD+c+5cF2sgHXIns3CLkpmuszrigeAmXTCjGCarK hE+c73wBr1qrZk2vT8IpcLg34bdQN6S1V3fECOXPFWRKqJjluoLi9iyV+dKQGIL9T8r1 Rsiw== X-Gm-Message-State: AOJu0YykSB3AVlcmKFs7qh8iiMcUb32BCwmOQiP7pabVOqQq6VaCn8tT JGZRukpDjz340k9H48VSoPfQUK4Xhke+hfsndQTdYPPm0PLRsiUCppGuJ6zcGko= X-Google-Smtp-Source: AGHT+IGnrQtv9CU49UlrunUwPuisZ0cy6FKJehTDJv0w89pgyt9DfJRJLYbIIWyzbgZ4h3MoPRdWug== X-Received: by 2002:a17:902:6b02:b0:1dc:af82:98b2 with SMTP id o2-20020a1709026b0200b001dcaf8298b2mr3772218plk.43.1709705541061; Tue, 05 Mar 2024 22:12:21 -0800 (PST) From: Akihiko Odaki Date: Wed, 06 Mar 2024 15:12:09 +0900 Subject: [PATCH v3 03/19] contrib/elf2dmp: Continue even contexts are lacking MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240306-elf2dmp-v3-3-d74e6c3da49c@daynix.com> References: <20240306-elf2dmp-v3-0-d74e6c3da49c@daynix.com> In-Reply-To: <20240306-elf2dmp-v3-0-d74e6c3da49c@daynix.com> To: Viktor Prutyanov , Peter Maydell Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 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=2607:f8b0:4864:20::632; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x632.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1709705611304100001 Let fill_context() continue even if it fails to fill contexts of some CPUs. A dump may still contain valuable information even if it lacks contexts of some CPUs due to dump corruption or a failure before starting CPUs. Signed-off-by: Akihiko Odaki Reviewed-by: Peter Maydell --- contrib/elf2dmp/main.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/contrib/elf2dmp/main.c b/contrib/elf2dmp/main.c index 9b278f392e39..86e709e6da3a 100644 --- a/contrib/elf2dmp/main.c +++ b/contrib/elf2dmp/main.c @@ -336,8 +336,13 @@ static int fill_header(WinDumpHeader64 *hdr, struct pa= _space *ps, return 0; } =20 -static int fill_context(KDDEBUGGER_DATA64 *kdbg, - struct va_space *vs, QEMU_Elf *qe) +/* + * fill_context() continues even if it fails to fill contexts of some CPUs. + * A dump may still contain valuable information even if it lacks contexts= of + * some CPUs due to dump corruption or a failure before starting CPUs. + */ +static void fill_context(KDDEBUGGER_DATA64 *kdbg, + struct va_space *vs, QEMU_Elf *qe) { int i; =20 @@ -350,7 +355,7 @@ static int fill_context(KDDEBUGGER_DATA64 *kdbg, if (va_space_rw(vs, kdbg->KiProcessorBlock + sizeof(Prcb) * i, &Prcb, sizeof(Prcb), 0)) { eprintf("Failed to read CPU #%d PRCB location\n", i); - return 1; + continue; } =20 if (!Prcb) { @@ -361,7 +366,7 @@ static int fill_context(KDDEBUGGER_DATA64 *kdbg, if (va_space_rw(vs, Prcb + kdbg->OffsetPrcbContext, &Context, sizeof(Context), 0)) { eprintf("Failed to read CPU #%d ContextFrame location\n", i); - return 1; + continue; } =20 printf("Filling context for CPU #%d...\n", i); @@ -369,11 +374,9 @@ static int fill_context(KDDEBUGGER_DATA64 *kdbg, =20 if (va_space_rw(vs, Context, &ctx, sizeof(ctx), 1)) { eprintf("Failed to fill CPU #%d context\n", i); - return 1; + continue; } } - - return 0; } =20 static int pe_get_data_dir_entry(uint64_t base, void *start_addr, int idx, @@ -619,9 +622,7 @@ int main(int argc, char *argv[]) goto out_kdbg; } =20 - if (fill_context(kdbg, &vs, &qemu_elf)) { - goto out_kdbg; - } + fill_context(kdbg, &vs, &qemu_elf); =20 if (write_dump(&ps, &header, argv[2])) { eprintf("Failed to save dump\n"); --=20 2.44.0 From nobody Tue Nov 26 04:30:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=1709705584; cv=none; d=zohomail.com; s=zohoarc; b=VPq813hIYo4NH/QtjJYFyV+Hgzdf2gzxA3Ribf8qjfmz74pv+IlLlLvo8U43k+f5bm6v+nVEVqaL46a8bBFRni+IPdWVF3I/q8o8oWZ88ovWI5bvKp1rtyO5Jg0j1MmWFsoYS8e6UFcXIoHV/9mJO7rCDvtIL74E8rqKhq+1A94= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709705584; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=A243LVbp1AwfUXsMdD+blJLZP6SXZ8l0TiQS7QSUs3I=; b=GvL6qLMQenT60tp0id7FPRcGDELyw4KRN7dls4mDTgeJZ7jxOJ8lS8bGGZbdLZSBwieYHm+InCYt+A+00APYunWYw1YDBZavdq3XyO5O8UuQL8X0IfRCQmLvFv36CIYcabo6CwjTAQ9uoeeQOx38zqqgwW6Ro4H5+Lbjad8ng5w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 1709705584316495.3623581070882; Tue, 5 Mar 2024 22:13:04 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rhkW9-0004uU-4U; Wed, 06 Mar 2024 01:12:42 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rhkVv-0004sl-Vm for qemu-devel@nongnu.org; Wed, 06 Mar 2024 01:12:30 -0500 Received: from mail-ot1-x32b.google.com ([2607:f8b0:4864:20::32b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rhkVu-0006Es-0g for qemu-devel@nongnu.org; Wed, 06 Mar 2024 01:12:27 -0500 Received: by mail-ot1-x32b.google.com with SMTP id 46e09a7af769-6e4f8f140c1so544025a34.2 for ; Tue, 05 Mar 2024 22:12:25 -0800 (PST) Received: from localhost ([157.82.206.27]) by smtp.gmail.com with UTF8SMTPSA id b22-20020a63cf56000000b005dc884e9f5bsm10328337pgj.38.2024.03.05.22.12.23 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 05 Mar 2024 22:12:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709705544; x=1710310344; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=A243LVbp1AwfUXsMdD+blJLZP6SXZ8l0TiQS7QSUs3I=; b=0ey7GjYD8BO8VBFAWirzUhGeZBZ/g8MJ51yCQX24p7Fd927WCwnUSMY05nLb8WCQj1 yfxPIervzMHyHMx/DDl48yCEqlMM5v+siiuVUQCZ/PeAvlxY7tolL0VLeXfcXZPCv0S1 q1Uoyq4g0kJxYKPMs5bckO+jCGJkxIfL78aY1KjTd4X/E2RTNUQvCvckAwxt6PVtW4n4 80NwJZuf2/hcSE2ETsUsIa+25yBhE+2HoyImig8o683m1NAq7pcAIA9IXoXVbcV/IXLB 6HR9LQhI1xhHpVHGeX9ToQeLrG+HumfITVHpk3rmEt5vnJBiyLGMhMXa7xKsflL0w6gL ec0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709705544; x=1710310344; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=A243LVbp1AwfUXsMdD+blJLZP6SXZ8l0TiQS7QSUs3I=; b=ROul20OUhvuqhcZ0sxMsTPZL9FNCkyqR4r9MVXXzMkIX42CBRU6K+BnnDjEXzqyNAn hJOha8vgblYKDpgFNjBdPMXdrnH5c6a88XZ0cxV5QmrPsP/GxDuKUdfbOq16KgJPvXTe yu7aU9qzcqYBlkq35j0HaHv6TCkrGGQoLezgcW9RjK8Q8pmdjKi4Y/olGvqe0qfcOVso cfxN8d6rBam0YXlZ//z2b9Af0WmPTe8nQJ7TtHbH/Lhl+xD7+HGBSK2pYYB5/yVEGggt EB+RqVJgur3XO95QryelTEcCE7KDt42ppM37+miPnh0ElWE3CIV7s//V8Joi5bI13Qwg hMKA== X-Gm-Message-State: AOJu0YztLm3rDVvngSzspTTrgM6FuFK9SNh7/lLEEILR8VmhlRyOZhvb P2U3anmegbalJ0GqU7IsgsW+dBMqvln49khp0C0CRhbyNEq34MhuzfNzC88llUg= X-Google-Smtp-Source: AGHT+IGIuNTAzeTjpTyz4eoSmNr4CNTwQROCJ7aTf8C06E27X0rBrChP7GI38YwD+YE4BxFZAKo95A== X-Received: by 2002:a05:6830:61b:b0:6e4:b891:c9eb with SMTP id w27-20020a056830061b00b006e4b891c9ebmr4685323oti.30.1709705544507; Tue, 05 Mar 2024 22:12:24 -0800 (PST) From: Akihiko Odaki Date: Wed, 06 Mar 2024 15:12:10 +0900 Subject: [PATCH v3 04/19] contrib/elf2dmp: Change pa_space_create() signature MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240306-elf2dmp-v3-4-d74e6c3da49c@daynix.com> References: <20240306-elf2dmp-v3-0-d74e6c3da49c@daynix.com> In-Reply-To: <20240306-elf2dmp-v3-0-d74e6c3da49c@daynix.com> To: Viktor Prutyanov , Peter Maydell Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 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=2607:f8b0:4864:20::32b; envelope-from=akihiko.odaki@daynix.com; helo=mail-ot1-x32b.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1709705585171100003 pa_space_create() used to return an integer to propagate error, but it never fails so let it return void. Signed-off-by: Akihiko Odaki --- contrib/elf2dmp/addrspace.h | 2 +- contrib/elf2dmp/addrspace.c | 4 +--- contrib/elf2dmp/main.c | 5 +---- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/contrib/elf2dmp/addrspace.h b/contrib/elf2dmp/addrspace.h index 039c70c5b079..c868d6473873 100644 --- a/contrib/elf2dmp/addrspace.h +++ b/contrib/elf2dmp/addrspace.h @@ -33,7 +33,7 @@ struct va_space { struct pa_space *ps; }; =20 -int pa_space_create(struct pa_space *ps, QEMU_Elf *qemu_elf); +void pa_space_create(struct pa_space *ps, QEMU_Elf *qemu_elf); void pa_space_destroy(struct pa_space *ps); =20 void va_space_create(struct va_space *vs, struct pa_space *ps, uint64_t dt= b); diff --git a/contrib/elf2dmp/addrspace.c b/contrib/elf2dmp/addrspace.c index 6f608a517b1e..4c127c9b1ec4 100644 --- a/contrib/elf2dmp/addrspace.c +++ b/contrib/elf2dmp/addrspace.c @@ -57,7 +57,7 @@ static void pa_block_align(struct pa_block *b) b->paddr +=3D low_align; } =20 -int pa_space_create(struct pa_space *ps, QEMU_Elf *qemu_elf) +void pa_space_create(struct pa_space *ps, QEMU_Elf *qemu_elf) { Elf64_Half phdr_nr =3D elf_getphdrnum(qemu_elf->map); Elf64_Phdr *phdr =3D elf64_getphdr(qemu_elf->map); @@ -87,8 +87,6 @@ int pa_space_create(struct pa_space *ps, QEMU_Elf *qemu_e= lf) } =20 ps->block_nr =3D block_i; - - return 0; } =20 void pa_space_destroy(struct pa_space *ps) diff --git a/contrib/elf2dmp/main.c b/contrib/elf2dmp/main.c index 86e709e6da3a..8a71e2efd281 100644 --- a/contrib/elf2dmp/main.c +++ b/contrib/elf2dmp/main.c @@ -543,10 +543,7 @@ int main(int argc, char *argv[]) return 1; } =20 - if (pa_space_create(&ps, &qemu_elf)) { - eprintf("Failed to initialize physical address space\n"); - goto out_elf; - } + pa_space_create(&ps, &qemu_elf); =20 state =3D qemu_elf.state[0]; printf("CPU #0 CR3 is 0x%016"PRIx64"\n", state->cr[3]); --=20 2.44.0 From nobody Tue Nov 26 04:30:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=1709705633; cv=none; d=zohomail.com; s=zohoarc; b=AUSlNM977pgmPZYdvfgKvgqWjpV4BEjvZE5eZfqz1EgGvoUdBnKqxrGFsImGX9XXq8VWP4+tP95tXrKTm07MP+HZ5fAwyQsizX1vT2kOheb8f4dk9x15F9COGRc8r+OwPfysIxVJwr3VaW4hdlehM6apz9YNM4ZClzgJWOyOgW4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709705633; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=DA8YPsa0OXQme2Bi1zvzEkGMO6/tiDahixJX2f3DNcQ=; b=FuV/JyXg3uvnJG1K8M/czNLhk6JJFm8nWxmweZEIfhZS0zLmQqT0bHaiuvB2Q1QcQ7+WPDvF0R6v1T3V8ATY6QOHpf5t8cCdbRvtJJmfDBnTWrxoNku79M2Xv8+IIJoo81+ZSmxBseg6cLLVE4M4vUBbR7NYD9RmZwB5H03f004= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 1709705633198154.81894043147224; Tue, 5 Mar 2024 22:13:53 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rhkWS-000543-2V; Wed, 06 Mar 2024 01:13:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rhkW1-0004tH-Vt for qemu-devel@nongnu.org; Wed, 06 Mar 2024 01:12:34 -0500 Received: from mail-ot1-x330.google.com ([2607:f8b0:4864:20::330]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rhkVx-0006F3-MO for qemu-devel@nongnu.org; Wed, 06 Mar 2024 01:12:33 -0500 Received: by mail-ot1-x330.google.com with SMTP id 46e09a7af769-6e4f7c0e723so588844a34.3 for ; Tue, 05 Mar 2024 22:12:28 -0800 (PST) Received: from localhost ([157.82.206.27]) by smtp.gmail.com with UTF8SMTPSA id p8-20020a63e648000000b005d68962e1a7sm10224837pgj.24.2024.03.05.22.12.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 05 Mar 2024 22:12:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709705548; x=1710310348; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=DA8YPsa0OXQme2Bi1zvzEkGMO6/tiDahixJX2f3DNcQ=; b=avChtoVtUHkYyqVht28y3RfXU5US87NUqi9M/pQUnnZDK7YxYnLWqxXX7ojcN9aaji bQkogFYO9T6e6WTkoKTAviA8RGP+FABLCweahu0T1JKWssh62+DPs8sfcIp2UYnts4wt lXpqBZRVZtHKMy+qFghOGHCpu8R0kqQSAemT1SqtPyoU4PDTtrSzuZOyDyRU50ndBplX 7YociyseNVNusW46qz2QnMdn0sqUxkyf9HVjVebp9dRxT6KFBIWu5qcJooPp3JCu5gN/ Oj/HIAmY81s3rCC4FBATTQHq/wPL/IXKP/i06jg6529Vp2He35Q4E+tK/38R3V3mi6E9 Tp6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709705548; x=1710310348; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DA8YPsa0OXQme2Bi1zvzEkGMO6/tiDahixJX2f3DNcQ=; b=pgS7EX79kEyx2Pzo0y1kAOtF8yMnIWvfBZwqSv26pFSOxg/xnOPCKZTkDHmSr9qJVF y0XMIRdW50dhRmFBKJmkMhOb7z2opC64+nAJjpxeMKBh7vtBNmwAF2NNBwJXHmOoGXff jWj3EEOL20iV/vkvkxmMPKHZOSkEM5jY6854JEUk5B5hjIMFyiSbJPrVanbHRlPlqgWL HCwXM0qOBrlF9ZsyEApzl4RIZakJaV1Tv4RyAAg3DpJbB9v/aJeKFAl90gIH6S5Huz/n jsL8Z9ambOYMZ3wDsGCb94zADlx5iROHMtN/zIZSOsMZbaOS4PCFwd09WcoaRIGwQYCj iXkg== X-Gm-Message-State: AOJu0YxfIkLWAmzC3zI+cOVbQmJCl92Mc7UC+jvdrKz7avOGK1S+5iZY fj/Isq8LMgFvxjUWlq18duR9C+LXr5eRP5FqyhQ+LPjS9JOklWzt6THYAGUkPVU= X-Google-Smtp-Source: AGHT+IHwRHAzqX7ZbBLGAt6Y5El8jJrsihgD/oOojtW8gTurTLx6+1SWBKmuh7rhj41V5kljEd4/2A== X-Received: by 2002:a9d:750b:0:b0:6e4:f48b:c468 with SMTP id r11-20020a9d750b000000b006e4f48bc468mr4446355otk.35.1709705547856; Tue, 05 Mar 2024 22:12:27 -0800 (PST) From: Akihiko Odaki Date: Wed, 06 Mar 2024 15:12:11 +0900 Subject: [PATCH v3 05/19] contrib/elf2dmp: Fix error reporting style in addrspace.c MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240306-elf2dmp-v3-5-d74e6c3da49c@daynix.com> References: <20240306-elf2dmp-v3-0-d74e6c3da49c@daynix.com> In-Reply-To: <20240306-elf2dmp-v3-0-d74e6c3da49c@daynix.com> To: Viktor Prutyanov , Peter Maydell Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 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=2607:f8b0:4864:20::330; envelope-from=akihiko.odaki@daynix.com; helo=mail-ot1-x330.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1709705633389100002 include/qapi/error.h says: > We recommend > * bool-valued functions return true on success / false on failure, > ... Signed-off-by: Akihiko Odaki --- contrib/elf2dmp/addrspace.h | 4 ++-- contrib/elf2dmp/addrspace.c | 8 ++++---- contrib/elf2dmp/main.c | 47 +++++++++++++++++++++--------------------= ---- 3 files changed, 28 insertions(+), 31 deletions(-) diff --git a/contrib/elf2dmp/addrspace.h b/contrib/elf2dmp/addrspace.h index c868d6473873..2ad30a9da48a 100644 --- a/contrib/elf2dmp/addrspace.h +++ b/contrib/elf2dmp/addrspace.h @@ -39,7 +39,7 @@ void pa_space_destroy(struct pa_space *ps); void va_space_create(struct va_space *vs, struct pa_space *ps, uint64_t dt= b); void va_space_set_dtb(struct va_space *vs, uint64_t dtb); void *va_space_resolve(struct va_space *vs, uint64_t va); -int va_space_rw(struct va_space *vs, uint64_t addr, - void *buf, size_t size, int is_write); +bool va_space_rw(struct va_space *vs, uint64_t addr, + void *buf, size_t size, int is_write); =20 #endif /* ADDRSPACE_H */ diff --git a/contrib/elf2dmp/addrspace.c b/contrib/elf2dmp/addrspace.c index 4c127c9b1ec4..c995c723ae80 100644 --- a/contrib/elf2dmp/addrspace.c +++ b/contrib/elf2dmp/addrspace.c @@ -226,8 +226,8 @@ void *va_space_resolve(struct va_space *vs, uint64_t va) return pa_space_resolve(vs->ps, pa); } =20 -int va_space_rw(struct va_space *vs, uint64_t addr, - void *buf, size_t size, int is_write) +bool va_space_rw(struct va_space *vs, uint64_t addr, + void *buf, size_t size, int is_write) { while (size) { uint64_t page =3D addr & ELF2DMP_PFN_MASK; @@ -238,7 +238,7 @@ int va_space_rw(struct va_space *vs, uint64_t addr, =20 ptr =3D va_space_resolve(vs, addr); if (!ptr) { - return 1; + return false; } =20 if (is_write) { @@ -252,5 +252,5 @@ int va_space_rw(struct va_space *vs, uint64_t addr, addr +=3D s; } =20 - return 0; + return true; } diff --git a/contrib/elf2dmp/main.c b/contrib/elf2dmp/main.c index 8a71e2efd281..09af39422f1e 100644 --- a/contrib/elf2dmp/main.c +++ b/contrib/elf2dmp/main.c @@ -79,9 +79,9 @@ static KDDEBUGGER_DATA64 *get_kdbg(uint64_t KernBase, str= uct pdb_reader *pdb, bool decode =3D false; uint64_t kwn, kwa, KdpDataBlockEncoded; =20 - if (va_space_rw(vs, - KdDebuggerDataBlock + offsetof(KDDEBUGGER_DATA64, Header), - &kdbg_hdr, sizeof(kdbg_hdr), 0)) { + if (!va_space_rw(vs, + KdDebuggerDataBlock + offsetof(KDDEBUGGER_DATA64, Hea= der), + &kdbg_hdr, sizeof(kdbg_hdr), 0)) { eprintf("Failed to extract KDBG header\n"); return NULL; } @@ -97,8 +97,8 @@ static KDDEBUGGER_DATA64 *get_kdbg(uint64_t KernBase, str= uct pdb_reader *pdb, return NULL; } =20 - if (va_space_rw(vs, KiWaitNever, &kwn, sizeof(kwn), 0) || - va_space_rw(vs, KiWaitAlways, &kwa, sizeof(kwa), 0)) { + if (!va_space_rw(vs, KiWaitNever, &kwn, sizeof(kwn), 0) || + !va_space_rw(vs, KiWaitAlways, &kwa, sizeof(kwa), 0)) { return NULL; } =20 @@ -122,7 +122,7 @@ static KDDEBUGGER_DATA64 *get_kdbg(uint64_t KernBase, s= truct pdb_reader *pdb, =20 kdbg =3D g_malloc(kdbg_hdr.Size); =20 - if (va_space_rw(vs, KdDebuggerDataBlock, kdbg, kdbg_hdr.Size, 0)) { + if (!va_space_rw(vs, KdDebuggerDataBlock, kdbg, kdbg_hdr.Size, 0)) { eprintf("Failed to extract entire KDBG\n"); g_free(kdbg); return NULL; @@ -286,7 +286,7 @@ static int fill_header(WinDumpHeader64 *hdr, struct pa_= space *ps, return 1; } =20 - if (va_space_rw(vs, KdVersionBlock, &kvb, sizeof(kvb), 0)) { + if (!va_space_rw(vs, KdVersionBlock, &kvb, sizeof(kvb), 0)) { eprintf("Failed to extract KdVersionBlock\n"); return 1; } @@ -352,8 +352,8 @@ static void fill_context(KDDEBUGGER_DATA64 *kdbg, WinContext64 ctx; QEMUCPUState *s =3D qe->state[i]; =20 - if (va_space_rw(vs, kdbg->KiProcessorBlock + sizeof(Prcb) * i, - &Prcb, sizeof(Prcb), 0)) { + if (!va_space_rw(vs, kdbg->KiProcessorBlock + sizeof(Prcb) * i, + &Prcb, sizeof(Prcb), 0)) { eprintf("Failed to read CPU #%d PRCB location\n", i); continue; } @@ -363,8 +363,8 @@ static void fill_context(KDDEBUGGER_DATA64 *kdbg, continue; } =20 - if (va_space_rw(vs, Prcb + kdbg->OffsetPrcbContext, - &Context, sizeof(Context), 0)) { + if (!va_space_rw(vs, Prcb + kdbg->OffsetPrcbContext, + &Context, sizeof(Context), 0)) { eprintf("Failed to read CPU #%d ContextFrame location\n", i); continue; } @@ -372,7 +372,7 @@ static void fill_context(KDDEBUGGER_DATA64 *kdbg, printf("Filling context for CPU #%d...\n", i); win_context_init_from_qemu_cpu_state(&ctx, s); =20 - if (va_space_rw(vs, Context, &ctx, sizeof(ctx), 1)) { + if (!va_space_rw(vs, Context, &ctx, sizeof(ctx), 1)) { eprintf("Failed to fill CPU #%d context\n", i); continue; } @@ -396,8 +396,8 @@ static int pe_get_data_dir_entry(uint64_t base, void *s= tart_addr, int idx, return 1; } =20 - if (va_space_rw(vs, base + dos_hdr->e_lfanew, - &nt_hdrs, sizeof(nt_hdrs), 0)) { + if (!va_space_rw(vs, base + dos_hdr->e_lfanew, + &nt_hdrs, sizeof(nt_hdrs), 0)) { return 1; } =20 @@ -406,9 +406,7 @@ static int pe_get_data_dir_entry(uint64_t base, void *s= tart_addr, int idx, return 1; } =20 - if (va_space_rw(vs, - base + data_dir[idx].VirtualAddress, - entry, size, 0)) { + if (!va_space_rw(vs, base + data_dir[idx].VirtualAddress, entry, size,= 0)) { return 1; } =20 @@ -470,9 +468,8 @@ static bool pe_check_pdb_name(uint64_t base, void *star= t_addr, return false; } =20 - if (va_space_rw(vs, - base + debug_dir.AddressOfRawData, - rsds, sizeof(*rsds), 0)) { + if (!va_space_rw(vs, base + debug_dir.AddressOfRawData, + rsds, sizeof(*rsds), 0)) { eprintf("Failed to resolve OMFSignatureRSDS\n"); return false; } @@ -488,9 +485,9 @@ static bool pe_check_pdb_name(uint64_t base, void *star= t_addr, return false; } =20 - if (va_space_rw(vs, base + debug_dir.AddressOfRawData + - offsetof(OMFSignatureRSDS, name), pdb_name, sizeof(PDB_NAM= E), - 0)) { + if (!va_space_rw(vs, base + debug_dir.AddressOfRawData + + offsetof(OMFSignatureRSDS, name), + pdb_name, sizeof(PDB_NAME), 0)) { eprintf("Failed to resolve PDB name\n"); return false; } @@ -556,8 +553,8 @@ int main(int argc, char *argv[]) =20 printf("CPU #0 IDT is at 0x%016"PRIx64"\n", state->idt.base); =20 - if (va_space_rw(&vs, state->idt.base, - &first_idt_desc, sizeof(first_idt_desc), 0)) { + if (!va_space_rw(&vs, state->idt.base, + &first_idt_desc, sizeof(first_idt_desc), 0)) { eprintf("Failed to get CPU #0 IDT[0]\n"); goto out_ps; } --=20 2.44.0 From nobody Tue Nov 26 04:30:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=1709705635; cv=none; d=zohomail.com; s=zohoarc; b=ewxT1J48Q1Hr9B75gzmkxS6CjPO1MMLuGu9xqaXyy4gWxibRIgSqixxOwLLS34grK+70Vm5c6z/ilOIHvE6SvtyqQXnx8joAW6tzXkwefrXMsFl5sU6i4UpRBv1Sxf0TdsGmnvOftwgCpSmb2qapOuXDDJG5I6RCiqcWh5Ej2Z0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709705635; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=kYp/u0+4A+fT95r0+Uw8gBS/wuGX08IOGh8a1eJEdws=; b=nAyUNlr3cwQf3Fsa/rFwWrHYbywmgC4DlXnJpetMxT40YlDx4xFGvZqdHyGPs/MOn3bfOwV4+FG38qnDlKH4uPeU8zJVqtPB92JSuueOZdPM59F0KkdMQIjn0yYX6qm3cPUFLeHK/KtwK0r5WDSDxXAGjr38Q9ri5KSERjZmQx8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 1709705635120480.7044955465226; Tue, 5 Mar 2024 22:13:55 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rhkWW-0005C1-LY; Wed, 06 Mar 2024 01:13:04 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rhkW3-0004u0-4A for qemu-devel@nongnu.org; Wed, 06 Mar 2024 01:12:35 -0500 Received: from mail-pg1-x535.google.com ([2607:f8b0:4864:20::535]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rhkW1-0006FP-M6 for qemu-devel@nongnu.org; Wed, 06 Mar 2024 01:12:34 -0500 Received: by mail-pg1-x535.google.com with SMTP id 41be03b00d2f7-5dcc4076c13so356611a12.0 for ; Tue, 05 Mar 2024 22:12:32 -0800 (PST) Received: from localhost ([157.82.206.27]) by smtp.gmail.com with UTF8SMTPSA id l3-20020a17090ac58300b0029b2e00359esm7610170pjt.36.2024.03.05.22.12.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 05 Mar 2024 22:12:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709705551; x=1710310351; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=kYp/u0+4A+fT95r0+Uw8gBS/wuGX08IOGh8a1eJEdws=; b=qzygfLxljA9A+vjeb4E9JtFPNYtUh492pYkr+g+h64tCrmirW+CNmiPb7kP/oWzDSz KjLYO2ojCWwQ981O/X9xVgbXbbwtPm5TVheRI+b/lP2pq0Et0HD3xwdzZ7bRmYSjfblJ 54OzSOQrPEjv3C6PNH7PpCD+Qz5NOqLM6alUBbjaXFGzkBaW3S+wVXh0/NHW9ZPRl3Oj jSkcwbTGvmaQr5A2CwJoUvS1vc2SAvMeOQevlHUSyez5EicXBIjX0vmJ6fpy/uc8Wki9 mqvAzwzhPR8+j5a6Egulx9n4DVv16KRihISNRR19wZACny8Zkney/sCQpBr3W+hn2CnA vq0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709705551; x=1710310351; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kYp/u0+4A+fT95r0+Uw8gBS/wuGX08IOGh8a1eJEdws=; b=CJ1ZNyGCXPRAsAEWwMtuUSCxf8gtcIpWvfwwkh/k82GysLzfOXErsf4woULbfELas1 h5UH9TcYLuNdkINA83xUycMyxuztB+fkjJBIRdAeEQ33h3iVshsjSVjZ2i8OVk03UYHw waKgAS7vGNN7kj08uCu9tLTWRZIZTJn0ePhjt/QiYkNoUqxA3mmWE9CRr8psGEBMKEhG 4U3HwXyq92ouGMWgw0hmvKcAdUT5mT0jPZ0WbiLDiNal4PWlvs+xrKjr+A9UKYFGcDNB tQXGo6lEbJbwNRhjd8XvlyKR5QgaAqYpSSZs8pkylPSGrS1Qr0kAyhvaI4zBZntDiqRO OuPQ== X-Gm-Message-State: AOJu0YwlIQE32V2SABhp+u8Eb4mIVg8N2RZFQkLwP5Ol5NmxmkhfjhSB JnGlwonDltTC90SURq7NeRYGbFbKU1z9xJVbyc4CVlXk5GO+5Yenh19xIYQakSd4fIsXgeJXtZB L X-Google-Smtp-Source: AGHT+IHXp3ls+rV/ctT2Zmam0oqVxE4TmZFzicSyAG68PYPi07riLYtOWECFY3y12NpvF77yWh3SlQ== X-Received: by 2002:a17:90b:b06:b0:299:3780:e9c7 with SMTP id bf6-20020a17090b0b0600b002993780e9c7mr6146334pjb.2.1709705551347; Tue, 05 Mar 2024 22:12:31 -0800 (PST) From: Akihiko Odaki Date: Wed, 06 Mar 2024 15:12:12 +0900 Subject: [PATCH v3 06/19] contrib/elf2dmp: Fix error reporting style in download.c MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240306-elf2dmp-v3-6-d74e6c3da49c@daynix.com> References: <20240306-elf2dmp-v3-0-d74e6c3da49c@daynix.com> In-Reply-To: <20240306-elf2dmp-v3-0-d74e6c3da49c@daynix.com> To: Viktor Prutyanov , Peter Maydell Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 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=2607:f8b0:4864:20::535; envelope-from=akihiko.odaki@daynix.com; helo=mail-pg1-x535.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1709705635389100011 include/qapi/error.h says: > We recommend > * bool-valued functions return true on success / false on failure, > ... Signed-off-by: Akihiko Odaki --- contrib/elf2dmp/download.h | 2 +- contrib/elf2dmp/download.c | 10 +++++----- contrib/elf2dmp/main.c | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/contrib/elf2dmp/download.h b/contrib/elf2dmp/download.h index 5c274925f7aa..f65adb5d0894 100644 --- a/contrib/elf2dmp/download.h +++ b/contrib/elf2dmp/download.h @@ -8,6 +8,6 @@ #ifndef DOWNLOAD_H #define DOWNLOAD_H =20 -int download_url(const char *name, const char *url); +bool download_url(const char *name, const char *url); =20 #endif /* DOWNLOAD_H */ diff --git a/contrib/elf2dmp/download.c b/contrib/elf2dmp/download.c index 902dc04ffa5c..21306b3fd4c4 100644 --- a/contrib/elf2dmp/download.c +++ b/contrib/elf2dmp/download.c @@ -9,14 +9,14 @@ #include #include "download.h" =20 -int download_url(const char *name, const char *url) +bool download_url(const char *name, const char *url) { - int err =3D 1; + bool success =3D false; FILE *file; CURL *curl =3D curl_easy_init(); =20 if (!curl) { - return 1; + return false; } =20 file =3D fopen(name, "wb"); @@ -33,11 +33,11 @@ int download_url(const char *name, const char *url) unlink(name); fclose(file); } else { - err =3D fclose(file); + success =3D !fclose(file); } =20 out_curl: curl_easy_cleanup(curl); =20 - return err; + return success; } diff --git a/contrib/elf2dmp/main.c b/contrib/elf2dmp/main.c index 09af39422f1e..d295fd92be2f 100644 --- a/contrib/elf2dmp/main.c +++ b/contrib/elf2dmp/main.c @@ -591,7 +591,7 @@ int main(int argc, char *argv[]) sprintf(pdb_url, "%s%s/%s/%s", SYM_URL_BASE, PDB_NAME, pdb_hash, PDB_N= AME); printf("PDB URL is %s\n", pdb_url); =20 - if (download_url(PDB_NAME, pdb_url)) { + if (!download_url(PDB_NAME, pdb_url)) { eprintf("Failed to download PDB file\n"); goto out_ps; } --=20 2.44.0 From nobody Tue Nov 26 04:30:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=1709705663; cv=none; d=zohomail.com; s=zohoarc; b=IUQ/eMiv5XekwoYSUA9NMvZbkD23g5fvWVJQVbbERBHwkChQSTjM47YR0E7NQpnnHzV8OMKFCpaz59zfT/TUExSzLqVnqq9kaXt8BV+DUaFeev//3S/Hyhm7BT3ahX6LHPSXgeCjsa1cTUwwCC6niPXk6441pdq/yvn7n7FPl5w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709705663; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=shZdRVaAuTUEJwuhgEsEU4+8uLO5iP81udj39ehMmZA=; b=IZe8akHHh5XRUsiF1HaITubyz3E/rKJMsii95jAwrY6G2pDiooHcvMfUALogGJ47aEDMODnLgRvWqzH9AulfY2vxcxYXVehSQOS45j/EtRRJJWKeKCj8s7vVD+wS7kfMDAWJx6NMym2SglL9N6AlExe9Fw50MAog/raADo8PItY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 1709705663724335.9620309690796; Tue, 5 Mar 2024 22:14:23 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rhkWJ-0004yS-GQ; Wed, 06 Mar 2024 01:12:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rhkW6-0004uV-41 for qemu-devel@nongnu.org; Wed, 06 Mar 2024 01:12:40 -0500 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rhkW3-0006Fi-SF for qemu-devel@nongnu.org; Wed, 06 Mar 2024 01:12:37 -0500 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1dccb2edc6dso53970145ad.3 for ; Tue, 05 Mar 2024 22:12:35 -0800 (PST) Received: from localhost ([157.82.206.27]) by smtp.gmail.com with UTF8SMTPSA id q7-20020a170902dac700b001dc23e877c9sm11661866plx.106.2024.03.05.22.12.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 05 Mar 2024 22:12:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709705554; x=1710310354; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=shZdRVaAuTUEJwuhgEsEU4+8uLO5iP81udj39ehMmZA=; b=d1fib84f03jhFllKdHSB8RxwTMZp6OTXJpdJVFO0UUTEFGWp/zE4QpH2YErhKpgZZz EEYUlRaZ4ky3yUbpJDYEkTU++u2Z/Tvecl4dH5daFuU4wbR66Us8CtLcSSP8yAFMmxNe VVbgVDnNDvDNzAJJydmMDoiqZc/3Tj60k/MofsTtPdduvr7zVCgBtdWamET47zoXWPtA G8dlArC4+SAj73aHDU9xhUjzKKXtKRra7GHQRooJlbAMx2de271SN13QLOiYTBOQ7p4E SVepcFZiFyaVAl46ygnoygrLWwV35qnKSswrEbWzX+vbVo1aIEkXVkL4qvPTSk2TtE57 isfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709705554; x=1710310354; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=shZdRVaAuTUEJwuhgEsEU4+8uLO5iP81udj39ehMmZA=; b=QONl+hyFczA9fXw2iPnx+gKArCe9wB+XkxQ7mQaA28PFLcmfSZnB7BMQ0FKFyE/Cp/ kBtvp0ovDt6vpoVnCmaKCnDv3EVI2ubuwFoInKt/qooX5iFFZjFPilQp6iuTWpe03p2b ZG4gj7PH5R8CJ6nayvwScT+evOYsvdVjvd94LP4ZIBzh2SsOYwjizBZC3Ml7M1L8+zlT 4rO0e5k8X+nPey/BHnjPlAx7p0ejL+8NYzdopY+n1kzyj9krQS72Ic/SOImK2niaP4NY VV08N3pwoo0FvjjK8GSw2MOwKkQDKuruALsA28RWiBQKk6Rids58sE/7hDEtN4bEs3W4 S4rw== X-Gm-Message-State: AOJu0YyDb9+XEGyhNRMZVOVQYfAGQBmsGwbVQjbF4qfzmshp1vVmpec+ L7aKzq+7acxbRkparDO6e7j/m9Zagh9GWsy8YV8KSxHWWUg2J0CZ/A/FtEXBeXI= X-Google-Smtp-Source: AGHT+IEPJUR1SmkG8FJsP4YIlUvXJuhewAiEeALXs188Ky0siTvP6xA2pZrC6TagwXq1zFPCeDYMhg== X-Received: by 2002:a17:902:8a83:b0:1d7:2e86:fb2a with SMTP id p3-20020a1709028a8300b001d72e86fb2amr3583576plo.65.1709705554387; Tue, 05 Mar 2024 22:12:34 -0800 (PST) From: Akihiko Odaki Date: Wed, 06 Mar 2024 15:12:13 +0900 Subject: [PATCH v3 07/19] contrib/elf2dmp: Fix error reporting style in pdb.c MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240306-elf2dmp-v3-7-d74e6c3da49c@daynix.com> References: <20240306-elf2dmp-v3-0-d74e6c3da49c@daynix.com> In-Reply-To: <20240306-elf2dmp-v3-0-d74e6c3da49c@daynix.com> To: Viktor Prutyanov , Peter Maydell Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 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=2607:f8b0:4864:20::62c; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x62c.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1709705665511100003 include/qapi/error.h says: > We recommend > * bool-valued functions return true on success / false on failure, > ... Signed-off-by: Akihiko Odaki --- contrib/elf2dmp/pdb.h | 2 +- contrib/elf2dmp/main.c | 2 +- contrib/elf2dmp/pdb.c | 50 +++++++++++++++++++++++++---------------------= ---- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/contrib/elf2dmp/pdb.h b/contrib/elf2dmp/pdb.h index 2a50da56ac96..feddf1862f08 100644 --- a/contrib/elf2dmp/pdb.h +++ b/contrib/elf2dmp/pdb.h @@ -233,7 +233,7 @@ struct pdb_reader { size_t segs_size; }; =20 -int pdb_init_from_file(const char *name, struct pdb_reader *reader); +bool pdb_init_from_file(const char *name, struct pdb_reader *reader); void pdb_exit(struct pdb_reader *reader); uint64_t pdb_resolve(uint64_t img_base, struct pdb_reader *r, const char *= name); uint64_t pdb_find_public_v3_symbol(struct pdb_reader *reader, const char *= name); diff --git a/contrib/elf2dmp/main.c b/contrib/elf2dmp/main.c index d295fd92be2f..7a3a7225905e 100644 --- a/contrib/elf2dmp/main.c +++ b/contrib/elf2dmp/main.c @@ -596,7 +596,7 @@ int main(int argc, char *argv[]) goto out_ps; } =20 - if (pdb_init_from_file(PDB_NAME, &pdb)) { + if (!pdb_init_from_file(PDB_NAME, &pdb)) { eprintf("Failed to initialize PDB reader\n"); goto out_pdb_file; } diff --git a/contrib/elf2dmp/pdb.c b/contrib/elf2dmp/pdb.c index abf17c2e7c12..1c5051425185 100644 --- a/contrib/elf2dmp/pdb.c +++ b/contrib/elf2dmp/pdb.c @@ -158,30 +158,30 @@ static void *pdb_ds_read_file(struct pdb_reader* r, u= int32_t file_number) return pdb_ds_read(r->ds.header, block_list, file_size[file_number]); } =20 -static int pdb_init_segments(struct pdb_reader *r) +static bool pdb_init_segments(struct pdb_reader *r) { unsigned stream_idx =3D r->segments; =20 r->segs =3D pdb_ds_read_file(r, stream_idx); if (!r->segs) { - return 1; + return false; } =20 r->segs_size =3D pdb_get_file_size(r, stream_idx); if (!r->segs_size) { - return 1; + return false; } =20 - return 0; + return true; } =20 -static int pdb_init_symbols(struct pdb_reader *r) +static bool pdb_init_symbols(struct pdb_reader *r) { PDB_SYMBOLS *symbols; =20 symbols =3D pdb_ds_read_file(r, 3); if (!symbols) { - return 1; + return false; } =20 r->symbols =3D symbols; @@ -198,18 +198,18 @@ static int pdb_init_symbols(struct pdb_reader *r) goto out_symbols; } =20 - return 0; + return true; =20 out_symbols: g_free(symbols); =20 - return 1; + return false; } =20 -static int pdb_reader_ds_init(struct pdb_reader *r, PDB_DS_HEADER *hdr) +static bool pdb_reader_ds_init(struct pdb_reader *r, PDB_DS_HEADER *hdr) { if (hdr->block_size =3D=3D 0) { - return 1; + return false; } =20 memset(r->file_used, 0, sizeof(r->file_used)); @@ -218,22 +218,22 @@ static int pdb_reader_ds_init(struct pdb_reader *r, P= DB_DS_HEADER *hdr) hdr->toc_page * hdr->block_size), hdr->toc_size); =20 if (!r->ds.toc) { - return 1; + return false; } =20 - return 0; + return true; } =20 -static int pdb_reader_init(struct pdb_reader *r, void *data) +static bool pdb_reader_init(struct pdb_reader *r, void *data) { const char pdb7[] =3D "Microsoft C/C++ MSF 7.00"; =20 if (memcmp(data, pdb7, sizeof(pdb7) - 1)) { - return 1; + return false; } =20 - if (pdb_reader_ds_init(r, data)) { - return 1; + if (!pdb_reader_ds_init(r, data)) { + return false; } =20 r->ds.root =3D pdb_ds_read_file(r, 1); @@ -241,15 +241,15 @@ static int pdb_reader_init(struct pdb_reader *r, void= *data) goto out_ds; } =20 - if (pdb_init_symbols(r)) { + if (!pdb_init_symbols(r)) { goto out_root; } =20 - if (pdb_init_segments(r)) { + if (!pdb_init_segments(r)) { goto out_sym; } =20 - return 0; + return true; =20 out_sym: pdb_exit_symbols(r); @@ -258,7 +258,7 @@ out_root: out_ds: pdb_reader_ds_exit(r); =20 - return 1; + return false; } =20 static void pdb_reader_exit(struct pdb_reader *r) @@ -269,7 +269,7 @@ static void pdb_reader_exit(struct pdb_reader *r) pdb_reader_ds_exit(r); } =20 -int pdb_init_from_file(const char *name, struct pdb_reader *reader) +bool pdb_init_from_file(const char *name, struct pdb_reader *reader) { GError *gerr =3D NULL; void *map; @@ -278,21 +278,21 @@ int pdb_init_from_file(const char *name, struct pdb_r= eader *reader) if (gerr) { eprintf("Failed to map PDB file \'%s\'\n", name); g_error_free(gerr); - return 1; + return false; } =20 reader->file_size =3D g_mapped_file_get_length(reader->gmf); map =3D g_mapped_file_get_contents(reader->gmf); - if (pdb_reader_init(reader, map)) { + if (!pdb_reader_init(reader, map)) { goto out_unmap; } =20 - return 0; + return true; =20 out_unmap: g_mapped_file_unref(reader->gmf); =20 - return 1; + return false; } =20 void pdb_exit(struct pdb_reader *reader) --=20 2.44.0 From nobody Tue Nov 26 04:30:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=1709705826; cv=none; d=zohomail.com; s=zohoarc; b=jaBw2n6W18LENdrQ7gocbLeRdYGPx/AOBtfVCtdwAyoVL4SsP5YszpZzhIJnd5hP7eETkvY9oOAEEe8H3ufPcWYYWXgd51xbSu+a2N3actNebpy43G9a7SbsfzznAtkHlgIwHF7pbtB6IOYhUx+uTw/nOl6Ms1VwJIZhP6DnH0c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709705826; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=g0+eTNzDAfP/I8pMSpLdPirrAbqQUuAszFkDupkQLY8=; b=PbPumNTtuSQUVJ3mID5mcylnbz5WixajiP4nS0TQY2CURECchASOWzoHebg9cD5s06/0XuVgT7XODYJIUOx8D2ZDo2S6kqAZoQzbixA+g3gaCq/0g8zQ1Jplhw/eRRdluXqHfEU1FVqyUcSORGRxZmd3Q46hj/xH5JEBfzfQmsM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 1709705826033927.4544159439163; Tue, 5 Mar 2024 22:17:06 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rhkWJ-0004yT-Hh; Wed, 06 Mar 2024 01:12:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rhkW8-0004ug-JH for qemu-devel@nongnu.org; Wed, 06 Mar 2024 01:12:40 -0500 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rhkW6-0006Fw-Sb for qemu-devel@nongnu.org; Wed, 06 Mar 2024 01:12:40 -0500 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1dc3b4b9b62so4130215ad.1 for ; Tue, 05 Mar 2024 22:12:38 -0800 (PST) Received: from localhost ([157.82.206.27]) by smtp.gmail.com with UTF8SMTPSA id z3-20020a170902708300b001dcc0d06959sm11598502plk.245.2024.03.05.22.12.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 05 Mar 2024 22:12:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709705557; x=1710310357; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=g0+eTNzDAfP/I8pMSpLdPirrAbqQUuAszFkDupkQLY8=; b=i/8c8RhlncBkFKQClT6JXGGPFAU9mOZK0f2Mgf+RDz+HGV34ItR4NGrs5JSc+5J3Cd EaQuRXtCWRASZI9/Vv8I/FE2HWMP0yHMvsIptCpyWtzDrgBNXCuy2ZGhIzgitCx4Js+7 AJrR3AqvV9JtmYIqgIShOPVftJLLcQT/eb0O7ZJNx8KCv0K8fNDo92O0E/hMtKSyUk62 wM0jSZ+yj6grhif2W8YjypWoB9KuaioS4oNa1dATtBxgQI4A+G5wio3sl7Ued/cTukOA jaMr+tXq9YCOH+A/xWN14iHqbRjy0cWPydmJb96DNMEWcwpsI0qEmNLK1JnDPb374I+R LolQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709705557; x=1710310357; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=g0+eTNzDAfP/I8pMSpLdPirrAbqQUuAszFkDupkQLY8=; b=e4PgjZDJuBEslITeOPVqYkz9de4T0fVcXUIrJs+pNvkHqS4M4yUoWnXBdd3gpPKAtm PWbJDcc8XluFynrJ9AtLtDcZDQzomtCwl8tR/IYog+3OEKDxSldohPL6lAbnFLbKiYKo +/CvSomuOVpEvbvX9vtjk7FHZlGqeeKkvZTEKTV8Po+NU0LSOrFy1BqAuYDtnGhTRq9f wWUPpmkYWALBHKzV0lQfslOfj0OGSjFk3yNwBEQGnfmdXlPMlfUoqCJboqtRnQmUEML9 BqXVFB20rwEsXAXJrmRIJ+i9RkQiGP8qXRTs1xJ0oZXyzB59h2wysbIuDRwzTI6Vv6Sw zhPw== X-Gm-Message-State: AOJu0YyA55iFWFcpWJehq+tXJReFyUYdbrDkmfSkbUK8Sb0VFDPQdZAA eg3L+XS8LZZWLsQXXvqRz3ed/1BYNMZ4PGeMywKI/EvgEkRAEarizW6r6gux6Kc= X-Google-Smtp-Source: AGHT+IHbM2F+BRdhsU+fa3EHe9K3ovl/QnbPrj4jXua0I4f0FoAjjkmltm2aRhioi7iMJ3BnaLDQDQ== X-Received: by 2002:a17:903:2594:b0:1db:dd24:9962 with SMTP id jb20-20020a170903259400b001dbdd249962mr4412087plb.21.1709705557499; Tue, 05 Mar 2024 22:12:37 -0800 (PST) From: Akihiko Odaki Date: Wed, 06 Mar 2024 15:12:14 +0900 Subject: [PATCH v3 08/19] contrib/elf2dmp: Fix error reporting style in qemu_elf.c MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240306-elf2dmp-v3-8-d74e6c3da49c@daynix.com> References: <20240306-elf2dmp-v3-0-d74e6c3da49c@daynix.com> In-Reply-To: <20240306-elf2dmp-v3-0-d74e6c3da49c@daynix.com> To: Viktor Prutyanov , Peter Maydell Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 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=2607:f8b0:4864:20::62b; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x62b.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1709705828146100009 include/qapi/error.h says: > We recommend > * bool-valued functions return true on success / false on failure, > ... Signed-off-by: Akihiko Odaki --- contrib/elf2dmp/qemu_elf.h | 2 +- contrib/elf2dmp/main.c | 2 +- contrib/elf2dmp/qemu_elf.c | 32 ++++++++++++++++---------------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/contrib/elf2dmp/qemu_elf.h b/contrib/elf2dmp/qemu_elf.h index afa75f10b2d2..adc50238b46b 100644 --- a/contrib/elf2dmp/qemu_elf.h +++ b/contrib/elf2dmp/qemu_elf.h @@ -42,7 +42,7 @@ typedef struct QEMU_Elf { int has_kernel_gs_base; } QEMU_Elf; =20 -int QEMU_Elf_init(QEMU_Elf *qe, const char *filename); +bool QEMU_Elf_init(QEMU_Elf *qe, const char *filename); void QEMU_Elf_exit(QEMU_Elf *qe); =20 Elf64_Phdr *elf64_getphdr(void *map); diff --git a/contrib/elf2dmp/main.c b/contrib/elf2dmp/main.c index 7a3a7225905e..cb28971789e4 100644 --- a/contrib/elf2dmp/main.c +++ b/contrib/elf2dmp/main.c @@ -535,7 +535,7 @@ int main(int argc, char *argv[]) return 1; } =20 - if (QEMU_Elf_init(&qemu_elf, argv[1])) { + if (!QEMU_Elf_init(&qemu_elf, argv[1])) { eprintf("Failed to initialize QEMU ELF dump\n"); return 1; } diff --git a/contrib/elf2dmp/qemu_elf.c b/contrib/elf2dmp/qemu_elf.c index 055e6f8792e9..a22c057d3ec3 100644 --- a/contrib/elf2dmp/qemu_elf.c +++ b/contrib/elf2dmp/qemu_elf.c @@ -60,7 +60,7 @@ Elf64_Half elf_getphdrnum(void *map) return ehdr->e_phnum; } =20 -static int init_states(QEMU_Elf *qe) +static bool init_states(QEMU_Elf *qe) { Elf64_Phdr *phdr =3D elf64_getphdr(qe->map); Elf64_Nhdr *start =3D (void *)((uint8_t *)qe->map + phdr[0].p_offset); @@ -70,7 +70,7 @@ static int init_states(QEMU_Elf *qe) =20 if (phdr[0].p_type !=3D PT_NOTE) { eprintf("Failed to find PT_NOTE\n"); - return 1; + return false; } =20 qe->has_kernel_gs_base =3D 1; @@ -107,7 +107,7 @@ static int init_states(QEMU_Elf *qe) =20 qe->state_nr =3D cpu_nr; =20 - return 0; + return true; } =20 static void exit_states(QEMU_Elf *qe) @@ -162,7 +162,7 @@ static bool check_ehdr(QEMU_Elf *qe) return true; } =20 -static int QEMU_Elf_map(QEMU_Elf *qe, const char *filename) +static bool QEMU_Elf_map(QEMU_Elf *qe, const char *filename) { #ifdef CONFIG_LINUX struct stat st; @@ -173,13 +173,13 @@ static int QEMU_Elf_map(QEMU_Elf *qe, const char *fil= ename) fd =3D open(filename, O_RDONLY, 0); if (fd =3D=3D -1) { eprintf("Failed to open ELF dump file \'%s\'\n", filename); - return 1; + return false; } =20 if (fstat(fd, &st)) { eprintf("Failed to get size of ELF dump file\n"); close(fd); - return 1; + return false; } qe->size =3D st.st_size; =20 @@ -188,7 +188,7 @@ static int QEMU_Elf_map(QEMU_Elf *qe, const char *filen= ame) if (qe->map =3D=3D MAP_FAILED) { eprintf("Failed to map ELF file\n"); close(fd); - return 1; + return false; } =20 close(fd); @@ -201,14 +201,14 @@ static int QEMU_Elf_map(QEMU_Elf *qe, const char *fil= ename) if (gerr) { eprintf("Failed to map ELF dump file \'%s\'\n", filename); g_error_free(gerr); - return 1; + return false; } =20 qe->map =3D g_mapped_file_get_contents(qe->gmf); qe->size =3D g_mapped_file_get_length(qe->gmf); #endif =20 - return 0; + return true; } =20 static void QEMU_Elf_unmap(QEMU_Elf *qe) @@ -220,25 +220,25 @@ static void QEMU_Elf_unmap(QEMU_Elf *qe) #endif } =20 -int QEMU_Elf_init(QEMU_Elf *qe, const char *filename) +bool QEMU_Elf_init(QEMU_Elf *qe, const char *filename) { - if (QEMU_Elf_map(qe, filename)) { - return 1; + if (!QEMU_Elf_map(qe, filename)) { + return false; } =20 if (!check_ehdr(qe)) { eprintf("Input file has the wrong format\n"); QEMU_Elf_unmap(qe); - return 1; + return false; } =20 - if (init_states(qe)) { + if (!init_states(qe)) { eprintf("Failed to extract QEMU CPU states\n"); QEMU_Elf_unmap(qe); - return 1; + return false; } =20 - return 0; + return true; } =20 void QEMU_Elf_exit(QEMU_Elf *qe) --=20 2.44.0 From nobody Tue Nov 26 04:30:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=1709705826; cv=none; d=zohomail.com; s=zohoarc; b=M1Qt6fyKq0lFdSU+Slqja0TzG5J+dnb0oJz9kIvQJUCnV0BumFHXj2dFyC+ZooRCJp6LF/6ifrRQVslFpF+pPCAk5jtloYg5oqY//i3d0T8WXSyzbxFRD/a2GdUaQEwX77JpF9Vn3oMBWsyfxOgOTkWlywz/+jWEpPNS9JNBelc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709705826; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=W8pmybqo3MF49nkGilqwgGL/v4Pl4OfK1iEYauJ4N5w=; b=Jk36UcTaY95ND6Y40r7lGF/R4JN1Qw7hS622U4PVtQP5K1pfjr0w88rnrBlDbhprBaX2eGvWFkiAgWGf8Yp65oP+Sr8zJvq9pXo+xSILmN1UKy5YgWXVqB/gnPbZxC8PqKbDJBm3vE53loT1pJijepXQtBGCnNkixilnk0JChvY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 1709705826060408.1498422370121; Tue, 5 Mar 2024 22:17:06 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rhkWu-0005Wg-Qb; Wed, 06 Mar 2024 01:13:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rhkWH-0004yZ-OG for qemu-devel@nongnu.org; Wed, 06 Mar 2024 01:12:51 -0500 Received: from mail-pg1-x531.google.com ([2607:f8b0:4864:20::531]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rhkWC-0006GC-VI for qemu-devel@nongnu.org; Wed, 06 Mar 2024 01:12:48 -0500 Received: by mail-pg1-x531.google.com with SMTP id 41be03b00d2f7-5d8b70b39efso5864835a12.0 for ; Tue, 05 Mar 2024 22:12:41 -0800 (PST) Received: from localhost ([157.82.206.27]) by smtp.gmail.com with UTF8SMTPSA id n4-20020a170902968400b001db8145a1a2sm11663587plp.274.2024.03.05.22.12.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 05 Mar 2024 22:12:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709705561; x=1710310361; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=W8pmybqo3MF49nkGilqwgGL/v4Pl4OfK1iEYauJ4N5w=; b=wVsq6u8oc6NUNWXuEgEq1/j6YWOpe3c0+zbtlLjhJlNuTQKWbw6NTK96h/CLM3yizH 5nKoKNyUh2txKGUmmYf8WHJJQISMp7nLtul1hw8NObD451TNFrxVl6NceNBQieWn5Ucr J2siZHSY7cubgnpEBrfoRAzWrcMeAuv8XdWfWe8Zfq5+KpDBEVWZlsfZ9SNc69LZxHx0 0/2kt0CwtYGz9J9L6U0vqiJH0MHlwBq0b+ChyDg1fEE5Xh5vXnCr3A63w1RE7CTFB2dI zBGI9VaOXhh2aPCf8wG+63yYrhWJvIXOMLI+NIdoownQXNiUPNbalzLYf59vMXQG5Lfb 2fZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709705561; x=1710310361; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=W8pmybqo3MF49nkGilqwgGL/v4Pl4OfK1iEYauJ4N5w=; b=H3cSdX6VG0Q8jH80i22CVCax1yzqHN6z7b4LLJc5ZKuqJRKNRt7f5a3RQ83tE3qmGR piSpG7f22EzCFDrD/px837njvUUrV5pp2GSwHZAaqGvyrtc2mIeZ9XKfTGiwpCZhRx3C im3COcJWH3je2tg6r+PNJLI1ipKqdRFxf4SP0fsKbWmkD7vt1ZLL3g6PiqNa5d6UT4JN y1jKngBgHNpZue0DwlfQeJR3I61+RZrNXNe4yQDzV3rAwZGpA6JC8MCSuGlXxEw14Xqi DfvblZBOV3B9nZXxusoe6rQDwyt14vBmKXhkjTR8o0PQ2/lfWJzVJrQQHlL2AzJSih/0 MalQ== X-Gm-Message-State: AOJu0YxfFCgL1V7vKT0wBWHGJGxrIfPziP9Eyj2qSzxaYjMxrSYwKDam qq7AnaYPssPzNxtWIUPsA2kc6+b5wTVXeDn27WMwVLVfj3AkkqbfnRqf76S71K8a7mYXT+jcnm8 T X-Google-Smtp-Source: AGHT+IH2Pt/6cnxJSv7PWdJ5qf0lZxp2QWbcyyKibXynKkQjhvQx7MzzFlVBIzSZqkJnkE0x8DcURw== X-Received: by 2002:a05:6a20:729b:b0:1a1:4b3e:5ef1 with SMTP id o27-20020a056a20729b00b001a14b3e5ef1mr4653649pzk.26.1709705561056; Tue, 05 Mar 2024 22:12:41 -0800 (PST) From: Akihiko Odaki Date: Wed, 06 Mar 2024 15:12:15 +0900 Subject: [PATCH v3 09/19] contrib/elf2dmp: Fix error reporting style in main.c MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240306-elf2dmp-v3-9-d74e6c3da49c@daynix.com> References: <20240306-elf2dmp-v3-0-d74e6c3da49c@daynix.com> In-Reply-To: <20240306-elf2dmp-v3-0-d74e6c3da49c@daynix.com> To: Viktor Prutyanov , Peter Maydell Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 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=2607:f8b0:4864:20::531; envelope-from=akihiko.odaki@daynix.com; helo=mail-pg1-x531.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1709705828171100011 include/qapi/error.h says: > We recommend > * bool-valued functions return true on success / false on failure, > ... Signed-off-by: Akihiko Odaki --- contrib/elf2dmp/main.c | 63 +++++++++++++++++++++++++---------------------= ---- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/contrib/elf2dmp/main.c b/contrib/elf2dmp/main.c index cb28971789e4..c290781feb18 100644 --- a/contrib/elf2dmp/main.c +++ b/contrib/elf2dmp/main.c @@ -186,13 +186,13 @@ static void win_context_init_from_qemu_cpu_state(WinC= ontext64 *ctx, * Finds paging-structure hierarchy base, * if previously set doesn't give access to kernel structures */ -static int fix_dtb(struct va_space *vs, QEMU_Elf *qe) +static bool fix_dtb(struct va_space *vs, QEMU_Elf *qe) { /* * Firstly, test previously set DTB. */ if (va_space_resolve(vs, SharedUserData)) { - return 0; + return true; } =20 /* @@ -206,7 +206,7 @@ static int fix_dtb(struct va_space *vs, QEMU_Elf *qe) va_space_set_dtb(vs, s->cr[3]); printf("DTB 0x%016"PRIx64" has been found from CPU #%zu" " as system task CR3\n", vs->dtb, i); - return !(va_space_resolve(vs, SharedUserData)); + return !!(va_space_resolve(vs, SharedUserData)); } } =20 @@ -220,16 +220,16 @@ static int fix_dtb(struct va_space *vs, QEMU_Elf *qe) uint64_t *cr3 =3D va_space_resolve(vs, Prcb + 0x7000); =20 if (!cr3) { - return 1; + return false; } =20 va_space_set_dtb(vs, *cr3); printf("DirectoryTableBase =3D 0x%016"PRIx64" has been found from = CPU #0" " as interrupt handling CR3\n", vs->dtb); - return !(va_space_resolve(vs, SharedUserData)); + return !!(va_space_resolve(vs, SharedUserData)); } =20 - return 1; + return true; } =20 static void try_merge_runs(struct pa_space *ps, @@ -268,9 +268,10 @@ static void try_merge_runs(struct pa_space *ps, } } =20 -static int fill_header(WinDumpHeader64 *hdr, struct pa_space *ps, - struct va_space *vs, uint64_t KdDebuggerDataBlock, - KDDEBUGGER_DATA64 *kdbg, uint64_t KdVersionBlock, int nr_cpus) +static bool fill_header(WinDumpHeader64 *hdr, struct pa_space *ps, + struct va_space *vs, uint64_t KdDebuggerDataBlock, + KDDEBUGGER_DATA64 *kdbg, uint64_t KdVersionBlock, + int nr_cpus) { uint32_t *suite_mask =3D va_space_resolve(vs, SharedUserData + KUSD_OFFSET_SUITE_MASK); @@ -283,12 +284,12 @@ static int fill_header(WinDumpHeader64 *hdr, struct p= a_space *ps, QEMU_BUILD_BUG_ON(KUSD_OFFSET_PRODUCT_TYPE >=3D ELF2DMP_PAGE_SIZE); =20 if (!suite_mask || !product_type) { - return 1; + return false; } =20 if (!va_space_rw(vs, KdVersionBlock, &kvb, sizeof(kvb), 0)) { eprintf("Failed to extract KdVersionBlock\n"); - return 1; + return false; } =20 h =3D (WinDumpHeader64) { @@ -333,7 +334,7 @@ static int fill_header(WinDumpHeader64 *hdr, struct pa_= space *ps, =20 *hdr =3D h; =20 - return 0; + return true; } =20 /* @@ -379,8 +380,8 @@ static void fill_context(KDDEBUGGER_DATA64 *kdbg, } } =20 -static int pe_get_data_dir_entry(uint64_t base, void *start_addr, int idx, - void *entry, size_t size, struct va_space *vs) +static bool pe_get_data_dir_entry(uint64_t base, void *start_addr, int idx, + void *entry, size_t size, struct va_spac= e *vs) { const char e_magic[2] =3D "MZ"; const char Signature[4] =3D "PE\0\0"; @@ -393,38 +394,38 @@ static int pe_get_data_dir_entry(uint64_t base, void = *start_addr, int idx, QEMU_BUILD_BUG_ON(sizeof(*dos_hdr) >=3D ELF2DMP_PAGE_SIZE); =20 if (memcmp(&dos_hdr->e_magic, e_magic, sizeof(e_magic))) { - return 1; + return false; } =20 if (!va_space_rw(vs, base + dos_hdr->e_lfanew, &nt_hdrs, sizeof(nt_hdrs), 0)) { - return 1; + return false; } =20 if (memcmp(&nt_hdrs.Signature, Signature, sizeof(Signature)) || file_hdr->Machine !=3D 0x8664 || opt_hdr->Magic !=3D 0x020b) { - return 1; + return false; } =20 if (!va_space_rw(vs, base + data_dir[idx].VirtualAddress, entry, size,= 0)) { - return 1; + return false; } =20 printf("Data directory entry #%d: RVA =3D 0x%08"PRIx32"\n", idx, (uint32_t)data_dir[idx].VirtualAddress); =20 - return 0; + return true; } =20 -static int write_dump(struct pa_space *ps, - WinDumpHeader64 *hdr, const char *name) +static bool write_dump(struct pa_space *ps, + WinDumpHeader64 *hdr, const char *name) { FILE *dmp_file =3D fopen(name, "wb"); size_t i; =20 if (!dmp_file) { eprintf("Failed to open output file \'%s\'\n", name); - return 1; + return false; } =20 printf("Writing header to file...\n"); @@ -432,7 +433,7 @@ static int write_dump(struct pa_space *ps, if (fwrite(hdr, sizeof(*hdr), 1, dmp_file) !=3D 1) { eprintf("Failed to write dump header\n"); fclose(dmp_file); - return 1; + return false; } =20 for (i =3D 0; i < ps->block_nr; i++) { @@ -443,11 +444,11 @@ static int write_dump(struct pa_space *ps, if (fwrite(b->addr, b->size, 1, dmp_file) !=3D 1) { eprintf("Failed to write block\n"); fclose(dmp_file); - return 1; + return false; } } =20 - return fclose(dmp_file); + return !fclose(dmp_file); } =20 static bool pe_check_pdb_name(uint64_t base, void *start_addr, @@ -457,8 +458,8 @@ static bool pe_check_pdb_name(uint64_t base, void *star= t_addr, IMAGE_DEBUG_DIRECTORY debug_dir; char pdb_name[sizeof(PDB_NAME)]; =20 - if (pe_get_data_dir_entry(base, start_addr, IMAGE_FILE_DEBUG_DIRECTORY, - &debug_dir, sizeof(debug_dir), vs)) { + if (!pe_get_data_dir_entry(base, start_addr, IMAGE_FILE_DEBUG_DIRECTOR= Y, + &debug_dir, sizeof(debug_dir), vs)) { eprintf("Failed to get Debug Directory\n"); return false; } @@ -546,7 +547,7 @@ int main(int argc, char *argv[]) printf("CPU #0 CR3 is 0x%016"PRIx64"\n", state->cr[3]); =20 va_space_create(&vs, &ps, state->cr[3]); - if (fix_dtb(&vs, &qemu_elf)) { + if (!fix_dtb(&vs, &qemu_elf)) { eprintf("Failed to find paging base\n"); goto out_elf; } @@ -611,14 +612,14 @@ int main(int argc, char *argv[]) goto out_pdb; } =20 - if (fill_header(&header, &ps, &vs, KdDebuggerDataBlock, kdbg, - KdVersionBlock, qemu_elf.state_nr)) { + if (!fill_header(&header, &ps, &vs, KdDebuggerDataBlock, kdbg, + KdVersionBlock, qemu_elf.state_nr)) { goto out_kdbg; } =20 fill_context(kdbg, &vs, &qemu_elf); =20 - if (write_dump(&ps, &header, argv[2])) { + if (!write_dump(&ps, &header, argv[2])) { eprintf("Failed to save dump\n"); goto out_kdbg; } --=20 2.44.0 From nobody Tue Nov 26 04:30:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=1709705689; cv=none; d=zohomail.com; s=zohoarc; b=VI7IHV8rylA3iezJTFxLmggV+crnukAHKDIZ0RsqdHZIVtq3HTDNubuMoWPI4zQx3GIcq3QWFYAlMybP3xtu5r8GnlFq8vH1QpCWOtct8tB3lPxv3CsdrX5yljkWfprVRFna1YudRfEBJa+m2VrIY6k3miNtNICLOOCDdy1YowM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709705689; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=QP7weYtq4QbJF4sIXleLE+UckEHf7lBxF+Hq2Ng452s=; b=bj6pjs4KJNzJBU01WEFBeohTn33cwD9Ig5Cia+LF3Eoo5Mpjw6ihvh9MAfyf79RkawZxoZlulcusbqcVlU+bnyY9/eYpgqNv9x8fZhRMHmLwHzSua3rgGL149DnmtxHBdwf2IhOVIUJJdq+atRsHPUXRo9fF4hqK037bAPiVsSQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 1709705689181167.17514803944403; Tue, 5 Mar 2024 22:14:49 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rhkX8-00061J-Ri; Wed, 06 Mar 2024 01:13:42 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rhkWJ-0004zS-Kz for qemu-devel@nongnu.org; Wed, 06 Mar 2024 01:12:51 -0500 Received: from mail-il1-x12b.google.com ([2607:f8b0:4864:20::12b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rhkWE-0006GU-Vb for qemu-devel@nongnu.org; Wed, 06 Mar 2024 01:12:49 -0500 Received: by mail-il1-x12b.google.com with SMTP id e9e14a558f8ab-365c8257940so3160615ab.2 for ; Tue, 05 Mar 2024 22:12:45 -0800 (PST) Received: from localhost ([157.82.206.27]) by smtp.gmail.com with UTF8SMTPSA id y26-20020aa79e1a000000b006e6500001dfsm222947pfq.156.2024.03.05.22.12.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 05 Mar 2024 22:12:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709705564; x=1710310364; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=QP7weYtq4QbJF4sIXleLE+UckEHf7lBxF+Hq2Ng452s=; b=wNJN6Xq/O32kAhO4wjUmuVekbI2TYWHvkFHpmxkMHl0/bzU+I4uAHq2El6z0Y/7ytq DyXc9vYbhXz54nnTfTtZB/e6noD+8yLIXdX1/n+05E/4HwRM8ksleOqirXAV4dQkctPs JIIeIVaDKxqn74MwSO7o8hcbNLFiNFU47r1rnhlpLoHrwBoBuw8sKqwZ2n3/TfA5Kdr9 tmhelP0Mu9ahgrpYPl6xzs80UucO2P4OsJg3X5pmprRgCguZ4xCcUNYX7w3Sjr0CotA0 ZsuhKJHEOHAFimchFc1/3c41+8t8uXLWtYzumfMzU34CKS4s9iV8eegKZpnufk/iWvER xlJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709705565; x=1710310365; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QP7weYtq4QbJF4sIXleLE+UckEHf7lBxF+Hq2Ng452s=; b=e3weEBbZ5b8AmuXeeIFEfjsIwxCeRSIbEyBeV7NGFblexZyrP42+AkxIlUOMZ8J/vS IoEoNliGw+SsV/cFvhhNM/RwZEAQ3Nd1zOaRJR8YTLn3rsoigwfS4ns579Kdhr/wc8QM 2bkCyX6ewE1y251M0wv0k4RBqCGkIjMC+wQ7qTTiW4d3EGJiSNwBR57zE2AtcKgzMpjO fUf+mWV7n7Wg+TjQiexf22D+nGe6Hgxce7lbtqhvla76TSggEh3X213A66IEQy596bHg +gvFWSTr/RgajbnWLJs/Q4EgZ2kp8GfrmmXUJNv9ss7AJ67hkEHi/rwWh4kS2XDjkZOY B28A== X-Gm-Message-State: AOJu0YxAUXrT9P/sGsG4TECau8Ro1OqHdvz7AfMRhuBfjbou6A3bST8w T6XlR8O9U7T/1C3jng5y+zx62nqkYcWJGjVJk60uD7GdpkNqt6hxDh9M4GvPX4k= X-Google-Smtp-Source: AGHT+IHsyvEYi6+E69b0zeEt5tWRAeOB0JlwtxHpSNdLbVpy87W2fa2GSiE2wqnFFvxs7+EBADRiEw== X-Received: by 2002:a92:ca4e:0:b0:365:433f:0 with SMTP id q14-20020a92ca4e000000b00365433f0000mr16778978ilo.29.1709705564665; Tue, 05 Mar 2024 22:12:44 -0800 (PST) From: Akihiko Odaki Date: Wed, 06 Mar 2024 15:12:16 +0900 Subject: [PATCH v3 10/19] contrib/elf2dmp: Always check for PA resolution failure MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240306-elf2dmp-v3-10-d74e6c3da49c@daynix.com> References: <20240306-elf2dmp-v3-0-d74e6c3da49c@daynix.com> In-Reply-To: <20240306-elf2dmp-v3-0-d74e6c3da49c@daynix.com> To: Viktor Prutyanov , Peter Maydell Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 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=2607:f8b0:4864:20::12b; envelope-from=akihiko.odaki@daynix.com; helo=mail-il1-x12b.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1709705689679100001 Not checking PA resolution failure can result in NULL deference. Signed-off-by: Akihiko Odaki Reviewed-by: Peter Maydell --- contrib/elf2dmp/addrspace.c | 46 ++++++++++++++++++++++++++++-------------= ---- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/contrib/elf2dmp/addrspace.c b/contrib/elf2dmp/addrspace.c index c995c723ae80..e01860d15b07 100644 --- a/contrib/elf2dmp/addrspace.c +++ b/contrib/elf2dmp/addrspace.c @@ -22,7 +22,7 @@ static struct pa_block *pa_space_find_block(struct pa_spa= ce *ps, uint64_t pa) return NULL; } =20 -static uint8_t *pa_space_resolve(struct pa_space *ps, uint64_t pa) +static void *pa_space_resolve(struct pa_space *ps, uint64_t pa) { struct pa_block *block =3D pa_space_find_block(ps, pa); =20 @@ -33,6 +33,19 @@ static uint8_t *pa_space_resolve(struct pa_space *ps, ui= nt64_t pa) return block->addr + (pa - block->paddr); } =20 +static bool pa_space_read64(struct pa_space *ps, uint64_t pa, uint64_t *va= lue) +{ + uint64_t *resolved =3D pa_space_resolve(ps, pa); + + if (!resolved) { + return false; + } + + *value =3D *resolved; + + return true; +} + static void pa_block_align(struct pa_block *b) { uint64_t low_align =3D ((b->paddr - 1) | ELF2DMP_PAGE_MASK) + 1 - b->p= addr; @@ -106,19 +119,20 @@ void va_space_create(struct va_space *vs, struct pa_s= pace *ps, uint64_t dtb) va_space_set_dtb(vs, dtb); } =20 -static uint64_t get_pml4e(struct va_space *vs, uint64_t va) +static bool get_pml4e(struct va_space *vs, uint64_t va, uint64_t *value) { uint64_t pa =3D (vs->dtb & 0xffffffffff000) | ((va & 0xff8000000000) >= > 36); =20 - return *(uint64_t *)pa_space_resolve(vs->ps, pa); + return pa_space_read64(vs->ps, pa, value); } =20 -static uint64_t get_pdpi(struct va_space *vs, uint64_t va, uint64_t pml4e) +static bool get_pdpi(struct va_space *vs, uint64_t va, uint64_t pml4e, + uint64_t *value) { uint64_t pdpte_paddr =3D (pml4e & 0xffffffffff000) | ((va & 0x7FC0000000) >> 27); =20 - return *(uint64_t *)pa_space_resolve(vs->ps, pdpte_paddr); + return pa_space_read64(vs->ps, pdpte_paddr, value); } =20 static uint64_t pde_index(uint64_t va) @@ -131,11 +145,12 @@ static uint64_t pdba_base(uint64_t pdpe) return pdpe & 0xFFFFFFFFFF000; } =20 -static uint64_t get_pgd(struct va_space *vs, uint64_t va, uint64_t pdpe) +static bool get_pgd(struct va_space *vs, uint64_t va, uint64_t pdpe, + uint64_t *value) { uint64_t pgd_entry =3D pdba_base(pdpe) + pde_index(va) * 8; =20 - return *(uint64_t *)pa_space_resolve(vs->ps, pgd_entry); + return pa_space_read64(vs->ps, pgd_entry, value); } =20 static uint64_t pte_index(uint64_t va) @@ -148,11 +163,12 @@ static uint64_t ptba_base(uint64_t pde) return pde & 0xFFFFFFFFFF000; } =20 -static uint64_t get_pte(struct va_space *vs, uint64_t va, uint64_t pgd) +static bool get_pte(struct va_space *vs, uint64_t va, uint64_t pgd, + uint64_t *value) { uint64_t pgd_val =3D ptba_base(pgd) + pte_index(va) * 8; =20 - return *(uint64_t *)pa_space_resolve(vs->ps, pgd_val); + return pa_space_read64(vs->ps, pgd_val, value); } =20 static uint64_t get_paddr(uint64_t va, uint64_t pte) @@ -184,13 +200,11 @@ static uint64_t va_space_va2pa(struct va_space *vs, u= int64_t va) { uint64_t pml4e, pdpe, pgd, pte; =20 - pml4e =3D get_pml4e(vs, va); - if (!is_present(pml4e)) { + if (!get_pml4e(vs, va, &pml4e) || !is_present(pml4e)) { return INVALID_PA; } =20 - pdpe =3D get_pdpi(vs, va, pml4e); - if (!is_present(pdpe)) { + if (!get_pdpi(vs, va, pml4e, &pdpe) || !is_present(pdpe)) { return INVALID_PA; } =20 @@ -198,8 +212,7 @@ static uint64_t va_space_va2pa(struct va_space *vs, uin= t64_t va) return get_1GB_paddr(va, pdpe); } =20 - pgd =3D get_pgd(vs, va, pdpe); - if (!is_present(pgd)) { + if (!get_pgd(vs, va, pdpe, &pgd) || !is_present(pgd)) { return INVALID_PA; } =20 @@ -207,8 +220,7 @@ static uint64_t va_space_va2pa(struct va_space *vs, uin= t64_t va) return get_2MB_paddr(va, pgd); } =20 - pte =3D get_pte(vs, va, pgd); - if (!is_present(pte)) { + if (!get_pte(vs, va, pgd, &pte) || !is_present(pte)) { return INVALID_PA; } =20 --=20 2.44.0 From nobody Tue Nov 26 04:30:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=1709705672; cv=none; d=zohomail.com; s=zohoarc; b=OGLerjlSq7tWEPWup8kQgbcoy/E4lIlHlzYkEtF1j8PwPYAiVWXpGehNA5kcLGslwi1O9RXLN1kyvhrfTrAN76bnViJJwHJmGWXQ88k8bEFAe6ccmNuCRYtBFB5slocArFaq84rMgxoRYPZxcTOsduujkev7regegmz4UzQgbdM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709705672; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=UXGMflu8bENqYfrFajkcEbsDHg6+XTRMDkWLE7IjkMY=; b=hbl1XedePPdkDJZV5PO9SbPPHjR1wuTd4ZxeYLL+8b3ee86FhSka1FKKnLEN+gDLX6dvO20c2TVAYIiAjybY0JwyjhgWYnv/1tGu+dbLo6J+IV5F8xm5xHPzEkuh8PuzYY4+ckL9ZwVuF2Q6VVUoyKH352zi9i0aH1H6DozLZRc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 1709705672051729.1577429782853; Tue, 5 Mar 2024 22:14:32 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rhkXB-0006Tq-LJ; Wed, 06 Mar 2024 01:13:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rhkWL-000504-IV for qemu-devel@nongnu.org; Wed, 06 Mar 2024 01:12:58 -0500 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rhkWH-0006Ge-HL for qemu-devel@nongnu.org; Wed, 06 Mar 2024 01:12:52 -0500 Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1dd3bdb6e9eso1509945ad.3 for ; Tue, 05 Mar 2024 22:12:48 -0800 (PST) Received: from localhost ([157.82.206.27]) by smtp.gmail.com with UTF8SMTPSA id kv14-20020a17090328ce00b001dcad9cbf8bsm11652154plb.239.2024.03.05.22.12.46 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 05 Mar 2024 22:12:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709705567; x=1710310367; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=UXGMflu8bENqYfrFajkcEbsDHg6+XTRMDkWLE7IjkMY=; b=IOHVMYsQgiKZiwALQqFHSxodbwSC3lx0qIyM6UlUtpbpV7FciI0Xi2rq+6mkN8VIHU 5XJSn6SeEPpKK/4r2WhbQEcixaVZTno+Toj70vek/lUndqEHK+e48h+sfsJOaenMmAWx eukvs4v5xDW8nEw+QSZQSppHFDE8dS9QII/xYWlLA2v87nPHw2jyg7kHuANplVQn2BDP lADJVVbS/wWlKD7gjQg+SsPFxnWH5mFj5hSZAPX3l90Y8v9wvSzYlYZo4kRkFUsMpCf9 yCMM93Wa5xVB2kMDKQr7lb5BrRG0SRTlonV1iUd+ZyvNSGCxsz5jwrkw8iI+qUcLa9KT BnXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709705567; x=1710310367; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UXGMflu8bENqYfrFajkcEbsDHg6+XTRMDkWLE7IjkMY=; b=lA8/nsqkS9cwd9rLKuqlFZn+PT7lDXBXjGTGVrBMt6AOvnLvAAPfVeK2waK6nEYaVW K1Tiv6urCC5y7y25C2hyvYM+WOgZDPElehq2SwZFh41hs9PPihP3/DAkragV2pnptyAc xaf5tWZJmvOBnGz0YTA+mMf1Z/xh7GcfZmrTPr/uq/ROGc0MGEwjQGNWxKrMPjqH+xZW ofbsbZIU7S6TgU8ST9LnsUOW2QHiAEdbK6rscs74cneUwdURoNb3MKZuift28yqRUZPl Ifbg3sCoAA1vbork9xssOWMIAvvkKALZ4sU1d4g7xZXCPqJLEELByV1p5XmfqPLBAo0e hm/g== X-Gm-Message-State: AOJu0Yw5/xXTSn3wWdRJQsEvnx2IK2RMvXvARaniQsLosj7qsBxxhTsd 8ZGFsIeQsKUTU4mAMnNWtU6gaosuko9+glZZVVNerIJl5luqaqCnCKVXctSHfyE= X-Google-Smtp-Source: AGHT+IEYL06qoCc7ep+BEc0qsCwIIki6YIvA0IDb9HSk323OaCuo5uWrxzluE616VWB+Cq872lnpww== X-Received: by 2002:a17:902:e74b:b0:1da:22d9:e7fd with SMTP id p11-20020a170902e74b00b001da22d9e7fdmr4703715plf.20.1709705567491; Tue, 05 Mar 2024 22:12:47 -0800 (PST) From: Akihiko Odaki Date: Wed, 06 Mar 2024 15:12:17 +0900 Subject: [PATCH v3 11/19] contrib/elf2dmp: Always destroy PA space MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240306-elf2dmp-v3-11-d74e6c3da49c@daynix.com> References: <20240306-elf2dmp-v3-0-d74e6c3da49c@daynix.com> In-Reply-To: <20240306-elf2dmp-v3-0-d74e6c3da49c@daynix.com> To: Viktor Prutyanov , Peter Maydell Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 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=2607:f8b0:4864:20::62f; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x62f.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1709705673550100001 Destroy PA space even if paging base couldn't be found, fixing memory leak. Signed-off-by: Akihiko Odaki Reviewed-by: Peter Maydell --- contrib/elf2dmp/main.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/contrib/elf2dmp/main.c b/contrib/elf2dmp/main.c index c290781feb18..51e1abe26a17 100644 --- a/contrib/elf2dmp/main.c +++ b/contrib/elf2dmp/main.c @@ -549,7 +549,7 @@ int main(int argc, char *argv[]) va_space_create(&vs, &ps, state->cr[3]); if (!fix_dtb(&vs, &qemu_elf)) { eprintf("Failed to find paging base\n"); - goto out_elf; + goto out_ps; } =20 printf("CPU #0 IDT is at 0x%016"PRIx64"\n", state->idt.base); @@ -634,7 +634,6 @@ out_pdb_file: unlink(PDB_NAME); out_ps: pa_space_destroy(&ps); -out_elf: QEMU_Elf_exit(&qemu_elf); =20 return err; --=20 2.44.0 From nobody Tue Nov 26 04:30:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=1709705633; cv=none; d=zohomail.com; s=zohoarc; b=c8aOWeJ2ASrXTw1/hh9yFTsZ2GTjK6xLZzUbcLcYTbDX/ns+WrN0G7V8JCS3XuDi6DHcA7uXsf9K6bVIese5zhcoT0INX7aRiIov+mIt2Jo4gMIX54fgQfCQzJSTwOoEB4os7ZIR5egBrwh4y3pjBkChl/yC8+UFv1IyPoOxX1g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709705633; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=DgfW3dC2BQFvXbkrpvVsfPqRuCKLeW6kZAejsXMFwME=; b=G/+VmWd/N0Al+lvlhnX5QwjsKQzRTg1GCCsYHN+AKTjOPgqgj1do6FW1pOVAj/sELdneG8dhiJ2wEj820u4/70A/y5JAo1I8Dc8Pk0kUaMfxNm5PseCmn3nQ2tvCRBL2HSF4HjybRs/rDbx6WG1WUIWzu5ROk0gOgES+ce7bG4c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 1709705633113618.2029999930604; Tue, 5 Mar 2024 22:13:53 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rhkWW-0005BI-H5; Wed, 06 Mar 2024 01:13:04 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rhkWN-00050A-FQ for qemu-devel@nongnu.org; Wed, 06 Mar 2024 01:12:58 -0500 Received: from mail-pg1-x530.google.com ([2607:f8b0:4864:20::530]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rhkWK-0006Gx-Jp for qemu-devel@nongnu.org; Wed, 06 Mar 2024 01:12:54 -0500 Received: by mail-pg1-x530.google.com with SMTP id 41be03b00d2f7-517ab9a4a13so5715309a12.1 for ; Tue, 05 Mar 2024 22:12:51 -0800 (PST) Received: from localhost ([157.82.206.27]) by smtp.gmail.com with UTF8SMTPSA id m2-20020a17090a858200b002997a5eea5bsm10474861pjn.31.2024.03.05.22.12.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 05 Mar 2024 22:12:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709705571; x=1710310371; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=DgfW3dC2BQFvXbkrpvVsfPqRuCKLeW6kZAejsXMFwME=; b=qKgJT6tJBenYKV/gKCcrjC65DtOu3QzamAcWWiuuvIO8yED737641YHBsMxNM/ABwQ rLTNkTf52zo+VIbayQJM1mBMYTo9Ga2r6YsZU8YVMSGaky+GCuOVjTbcl56zPngY3wrI 2woUgK/mXlNO2ix8jLQf7Tgdk6ZgzThwqDSCrpGYxwTPNgRqAnXpAKBTUMJ4QUx+fKf1 VdRQpCIB5kq83V7eDVPeXRTPkC31PO6FnW7oy9gAUzFR9OyqWOCC4EB297M4KYYSDxP+ SBs2CTSl1+KBPEUZ1A+DgRf0TcImwatR8Q08lb1WZPHOw2YYIWyABSE841qZmhv4DeuV Wa1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709705571; x=1710310371; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DgfW3dC2BQFvXbkrpvVsfPqRuCKLeW6kZAejsXMFwME=; b=q3I0Cs3jLM0fYgFuir6N5WXNWuZqwRq3Rj0+YlVA6G6a7suOQKk0VMNC07BBqi3o0v iXfiAMcTLAufpe8KjB85EyiqZNYrDUCD89N3GnK5ay4ix62+BgnVJn+3lt+jh7LDFmZv U8J+MH4Vk6Q1UPMdYLJG1QFU2Yyn2ZGqMLPkjcw9m7aVoosrgVWDy9huRtVF7UqYLaYc QGXc6VMxCPN87NFXXJQKs8i+EIvNjDeQi9FkljtBboBKrGPmb/nieotEC1q/WYinEO8b cVyRc43b9sTdPTbTST124FelCxodX8WIVBAjstA8YCnuPAfG286iCpYnjdJHAC1bkI9h Pflw== X-Gm-Message-State: AOJu0YxAAnQNeSjBqhtCXSSHbCJ0mnl7cGXhldWUSJJCnRAixthy1DUt 1NPdueCmhy+L5kqYprjS1uw5X7eDrrEQPUMP1QKsVzN7EblCoRFQlFQq6mOwdFk= X-Google-Smtp-Source: AGHT+IEEa7xDE0YMz/BAUAx9C4fmbda+pIxEjgTxSSJkPUNQGHgjGIj6XPoa3TKJMsk13zPEJtg8vg== X-Received: by 2002:a17:90a:a08d:b0:29a:cc76:2346 with SMTP id r13-20020a17090aa08d00b0029acc762346mr12162113pjp.24.1709705570899; Tue, 05 Mar 2024 22:12:50 -0800 (PST) From: Akihiko Odaki Date: Wed, 06 Mar 2024 15:12:18 +0900 Subject: [PATCH v3 12/19] contrib/elf2dmp: Ensure segment fits in file MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240306-elf2dmp-v3-12-d74e6c3da49c@daynix.com> References: <20240306-elf2dmp-v3-0-d74e6c3da49c@daynix.com> In-Reply-To: <20240306-elf2dmp-v3-0-d74e6c3da49c@daynix.com> To: Viktor Prutyanov , Peter Maydell Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 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=2607:f8b0:4864:20::530; envelope-from=akihiko.odaki@daynix.com; helo=mail-pg1-x530.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1709705633347100001 This makes elf2dmp more robust against corrupted inputs. Signed-off-by: Akihiko Odaki Reviewed-by: Peter Maydell --- contrib/elf2dmp/addrspace.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/contrib/elf2dmp/addrspace.c b/contrib/elf2dmp/addrspace.c index e01860d15b07..81295a11534a 100644 --- a/contrib/elf2dmp/addrspace.c +++ b/contrib/elf2dmp/addrspace.c @@ -88,11 +88,12 @@ void pa_space_create(struct pa_space *ps, QEMU_Elf *qem= u_elf) ps->block =3D g_new(struct pa_block, ps->block_nr); =20 for (i =3D 0; i < phdr_nr; i++) { - if (phdr[i].p_type =3D=3D PT_LOAD) { + if (phdr[i].p_type =3D=3D PT_LOAD && phdr[i].p_offset < qemu_elf->= size) { ps->block[block_i] =3D (struct pa_block) { .addr =3D (uint8_t *)qemu_elf->map + phdr[i].p_offset, .paddr =3D phdr[i].p_paddr, - .size =3D phdr[i].p_filesz, + .size =3D MIN(phdr[i].p_filesz, + qemu_elf->size - phdr[i].p_offset), }; pa_block_align(&ps->block[block_i]); block_i =3D ps->block[block_i].size ? (block_i + 1) : block_i; --=20 2.44.0 From nobody Tue Nov 26 04:30:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=1709705635; cv=none; d=zohomail.com; s=zohoarc; b=SdZFUkWW+PeLwM3aA4MNIYw6cA4YeCIR/7G4b7eU5ACoKFIPMhif1hfZkqBC5qCidx7DdfVzMuK3MZyOKd1jhKlHN8kaD5cAbqC9P+NTbs0R45/ipTWI6lDYmgprTHYAOi1Mu0G5Y8NdcqWneyC7F1plLrvvL+tNRipbAcg+29o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709705635; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Zd2GK/LwiDy+x5sdYIECrLQP++QUZzK/GPm/IzIIz+I=; b=BI9Kq9/ytuRT+R6yiwgOYFkNaJccQKDLzntOLpJwE81rofb9spuhmiRDbGEEAVlbiiaKvV1a5Z1GEoOS4xJ7jQD9RZ/3L5YuX/tDLct2y6oeeOTpFCYm9Ld/ayDURZcAvNR/jhRIUZF8yP+x3Nmxc1bLvyX6YLzDiKeyBZg2i8w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 1709705635131718.4788954863347; Tue, 5 Mar 2024 22:13:55 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rhkWy-0005Y4-8H; Wed, 06 Mar 2024 01:13:34 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rhkWP-000537-DW for qemu-devel@nongnu.org; Wed, 06 Mar 2024 01:12:59 -0500 Received: from mail-oi1-x232.google.com ([2607:f8b0:4864:20::232]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rhkWN-0006HH-82 for qemu-devel@nongnu.org; Wed, 06 Mar 2024 01:12:56 -0500 Received: by mail-oi1-x232.google.com with SMTP id 5614622812f47-3c1a1e1e539so1330788b6e.1 for ; Tue, 05 Mar 2024 22:12:54 -0800 (PST) Received: from localhost ([157.82.206.27]) by smtp.gmail.com with UTF8SMTPSA id d2-20020a63bd42000000b005dc832ed816sm8880860pgp.59.2024.03.05.22.12.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 05 Mar 2024 22:12:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709705574; x=1710310374; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Zd2GK/LwiDy+x5sdYIECrLQP++QUZzK/GPm/IzIIz+I=; b=scCFATSRbVvZ4Wd4InZJvDpdwm9y4Y8pWrwmPpkoGR9Dy0QMd8pildrUaXSPykBjhT Jx39wZFd74jPL7KuG0yF6linBi3CEJxoqrMIs7+CkQJk6AKF9b5zVgD/5izFeEWG4JaE YVIR99r0k9zv4kupMiQQNW8m+ErZHvAtj9Rw3ANFBvmAw3sEOXHfDbBbeC4LuHCOfPQP rVyCyxWXLd4oQpT1NuryrSvZWzKCp2ItunuKW3HPm0+iuKfHEIKfb5gCmjNrUrZDed3K Ecw8RtC55itYNpr8OsVFEb3rBZ4hDZid6NR/9jjEf0FDf7oVyBSwkPG4HOlGE3I+3z9o YH4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709705574; x=1710310374; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Zd2GK/LwiDy+x5sdYIECrLQP++QUZzK/GPm/IzIIz+I=; b=WJrcCWvoWQjVFfekpTxUQtNOmndHx3U1RJOfEBUxuIjZywW1RoTH1XLxhKSTO55gjZ L71vNmAjwu5ccve39+d6f+UrHgf1N8uSzygB2eF1yPxvL9jlszmDvJthPh+JeCmP72Uw WUtkhjaKsWRjQ2K3zHrHImcFZbtCh4yuHTQ6hrWbr4TPe2zbf5i7CoRjjtQs5OjUDu6b ZL5MNeTrs535VqoDeTjPjmw5foR0dduBkasbXGGTBXgoAkZMIApjpgUvXfAkmq+dNdtr s/e4RoDR/y8YxkyfpV79lTFD+c9zqkOzKVl/qtbhyrVXg/+/1gOYPmBX8LK2uSB5fS7I PRmw== X-Gm-Message-State: AOJu0Yz43Y6v+YMY7x3qq2w52Uk/dlgdBi2Tw7Vf4lQzp9pZrfM+4P5G 0VJ3yNLkWQwNlJsRgQf4No7dpNQMNoHmxGrt41XiwHQmfnJ670yj1vwCJkAodbg= X-Google-Smtp-Source: AGHT+IHzrKNiScXKnyD/9oOuKRZMbkjY4vBBvsWyeDl429zMwXljBOoJ+YCEKQ/gbDkfAY9zAzSW6A== X-Received: by 2002:a54:4687:0:b0:3c1:de7c:d6eb with SMTP id k7-20020a544687000000b003c1de7cd6ebmr3720948oic.49.1709705573852; Tue, 05 Mar 2024 22:12:53 -0800 (PST) From: Akihiko Odaki Date: Wed, 06 Mar 2024 15:12:19 +0900 Subject: [PATCH v3 13/19] contrib/elf2dmp: Use lduw_le_p() to read PDB MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240306-elf2dmp-v3-13-d74e6c3da49c@daynix.com> References: <20240306-elf2dmp-v3-0-d74e6c3da49c@daynix.com> In-Reply-To: <20240306-elf2dmp-v3-0-d74e6c3da49c@daynix.com> To: Viktor Prutyanov , Peter Maydell Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 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=2607:f8b0:4864:20::232; envelope-from=akihiko.odaki@daynix.com; helo=mail-oi1-x232.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1709705635374100010 The relevant value may be unaligned and is little-endian. Signed-off-by: Akihiko Odaki --- contrib/elf2dmp/pdb.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contrib/elf2dmp/pdb.c b/contrib/elf2dmp/pdb.c index 1c5051425185..492aca4434c8 100644 --- a/contrib/elf2dmp/pdb.c +++ b/contrib/elf2dmp/pdb.c @@ -19,6 +19,7 @@ */ =20 #include "qemu/osdep.h" +#include "qemu/bswap.h" =20 #include "pdb.h" #include "err.h" @@ -186,7 +187,7 @@ static bool pdb_init_symbols(struct pdb_reader *r) =20 r->symbols =3D symbols; =20 - r->segments =3D *(uint16_t *)((const char *)symbols + sizeof(PDB_SYMBO= LS) + + r->segments =3D lduw_le_p((const char *)symbols + sizeof(PDB_SYMBOLS) + symbols->module_size + symbols->offset_size + symbols->hash_size + symbols->srcmodule_size + symbols->pdbimport_size + symbols->unknown2_size + --=20 2.44.0 From nobody Tue Nov 26 04:30:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=1709705790; cv=none; d=zohomail.com; s=zohoarc; b=Ak1E+sZ6eNA6KoDStmktA+yt3NQ35jUby0rkaTeSY6GfG9vdMpcjCmD2/toCceMhp+dmv/u4X85z7osdueTxiWH3C9AKhC1bUBZLyl2VwXTgDYhbDGd6DgVULd6wz1PqzRBnj7Rh3FC898b5W1QM54cvyV04ejf2Vfse9tzUemQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709705790; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=yGeMs1iCZ0kYFimT5ghb04qtjFZ9LFucaNJHUGnodnI=; b=PeyvAHNrAbLrBtvCvm727ApEZKxPi26ELmK60s3fHVvFwhLcsPDiBs84gXoflqpUa9OAtBnmaXofkIQmerwxxc1Gaxa9TOXG52ObDxlJkbLJvy7DKgCGG95Q/QNgEQRs2maa1135BdEC/eqyK3iU+wTtg9yj+j/WiOqzV1w4sko= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 1709705790244737.5280043637282; Tue, 5 Mar 2024 22:16:30 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rhkWY-0005DN-2n; Wed, 06 Mar 2024 01:13:06 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rhkWS-00054f-B0 for qemu-devel@nongnu.org; Wed, 06 Mar 2024 01:13:00 -0500 Received: from mail-pg1-x530.google.com ([2607:f8b0:4864:20::530]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rhkWQ-0006HS-0j for qemu-devel@nongnu.org; Wed, 06 Mar 2024 01:13:00 -0500 Received: by mail-pg1-x530.google.com with SMTP id 41be03b00d2f7-5d8b519e438so6015059a12.1 for ; Tue, 05 Mar 2024 22:12:57 -0800 (PST) Received: from localhost ([157.82.206.27]) by smtp.gmail.com with UTF8SMTPSA id kw13-20020a170902f90d00b001dc90ac1cecsm11598573plb.284.2024.03.05.22.12.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 05 Mar 2024 22:12:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709705577; x=1710310377; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=yGeMs1iCZ0kYFimT5ghb04qtjFZ9LFucaNJHUGnodnI=; b=KrFz/HSMEuAYcW4zzh91quGXRXsCDYnR2Uo9t9p1yZsigRTtBK7I5Ocnzbzy2kTR85 AMXAWkwsOjR/RYf0uBerAe65q3KTQIR4YC0b4JM+5efhy/gr6SII9EHnHdPliAvzR2Sm 4nijgBlH4K5z11lQVWTCEuwKpHnY8typ5/BNDK/0XVCQc1r0WcsKJ5+wzuTsKRh1TEgD 9CNZdi+2piMe/S7Xv1I5qRAzNEKzmrMfleKvM18Q/XZiLjsMh7gAEhRrDw0FJcLGQ+O+ D/m4VlRDHbaeSq1DgEnMJ/l5P7VGa/+8wITcTzPFPEfo4aSJ9fGdlASRc06NHe5PDx5b 2J8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709705577; x=1710310377; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yGeMs1iCZ0kYFimT5ghb04qtjFZ9LFucaNJHUGnodnI=; b=Xtq4JiEGGQdzFSl0w1pO0znokVIe9aw5lIWkb5TQNvHdzZHL3x6rtDvltJxJQNVfMD yl059xRKL6f0Hn2lgLIO9dQHFVi4mvY6KpGfRHrJdY+DKtxRtrFqttI1XkTQHXvJu6Df S6+XI52BSCYc8x/EsKTaWJam5VTOCJ+/pyPaXed8GoqqVQZNMzIbV1WBP9snPxAOl2L5 KhVw7Wd/4Wyl6t50ZVKEeS/drk4Ys6pR92Eys6ssh8WDzMs+HummfK/0z0WfZGyBXwuz q52xc+zTb4UYi3S839XQJUOXjpzQxq60ZG769wiVE2QuHkeP6jSYqsrxQMwSjzNdWdRL R1eQ== X-Gm-Message-State: AOJu0Yz6MGZ9vvLqi91mQ8/NQCD0tktSp1obDUYLGgEAMHllmYItdGuk +UidRG81Pl5J8Ffwcl6bfrlaHwmW5jmC+Pt5WCyCJW3tbRA8KN6itakQO9yW0jg= X-Google-Smtp-Source: AGHT+IGrkiDILy/5lZjvpi5U7foXOTMdKbyQzXaBxkcKse70tbDLJjNMfb6HC17MBWa8fnZSspNF0w== X-Received: by 2002:a05:6a20:7350:b0:1a1:67b2:8cf7 with SMTP id v16-20020a056a20735000b001a167b28cf7mr614478pzc.31.1709705576740; Tue, 05 Mar 2024 22:12:56 -0800 (PST) From: Akihiko Odaki Date: Wed, 06 Mar 2024 15:12:20 +0900 Subject: [PATCH v3 14/19] contrib/elf2dmp: Use rol64() to decode MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240306-elf2dmp-v3-14-d74e6c3da49c@daynix.com> References: <20240306-elf2dmp-v3-0-d74e6c3da49c@daynix.com> In-Reply-To: <20240306-elf2dmp-v3-0-d74e6c3da49c@daynix.com> To: Viktor Prutyanov , Peter Maydell Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 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=2607:f8b0:4864:20::530; envelope-from=akihiko.odaki@daynix.com; helo=mail-pg1-x530.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1709705792014100003 rol64() is roubust against too large shift values and fixes UBSan warnings. Signed-off-by: Akihiko Odaki Reviewed-by: Peter Maydell --- contrib/elf2dmp/main.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/contrib/elf2dmp/main.c b/contrib/elf2dmp/main.c index 51e1abe26a17..e404612bec00 100644 --- a/contrib/elf2dmp/main.c +++ b/contrib/elf2dmp/main.c @@ -6,6 +6,7 @@ */ =20 #include "qemu/osdep.h" +#include "qemu/bitops.h" =20 #include "err.h" #include "addrspace.h" @@ -47,11 +48,6 @@ static const uint64_t SharedUserData =3D 0xfffff78000000= 000; s ? printf(#s" =3D 0x%016"PRIx64"\n", s) :\ eprintf("Failed to resolve "#s"\n"), s) =20 -static uint64_t rol(uint64_t x, uint64_t y) -{ - return (x << y) | (x >> (64 - y)); -} - /* * Decoding algorithm can be found in Volatility project */ @@ -64,7 +60,7 @@ static void kdbg_decode(uint64_t *dst, uint64_t *src, siz= e_t size, uint64_t block; =20 block =3D src[i]; - block =3D rol(block ^ kwn, (uint8_t)kwn); + block =3D rol64(block ^ kwn, kwn); block =3D __builtin_bswap64(block ^ kdbe) ^ kwa; dst[i] =3D block; } --=20 2.44.0 From nobody Tue Nov 26 04:30:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=1709705634; cv=none; d=zohomail.com; s=zohoarc; b=YNfm+Jo6lUHLPvFneWh3cKZARVyJV61B+Sox2PCVnZF7qx4ylJZJI3ucIApKSDHMNoLiDiQtAnFy5l3UIAXbgwZgCKY1jMEllUDknSHBFvrBUZ5ED/YeJYE+cw1hAlo6sWCuuaaVmP7NhHw1Q76W8QwaPFHBwKS/ryeVnr8hAVQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709705634; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=ahxRZ3SD7lLMx3muKeGeJx9aSeKYvKbViQJskOgE7S0=; b=JjsL21O03LN2oqIDvIPTPqP1ljnU6LRWb2WPJrY/fq/0XvdJp1C6kuKEMI+ycBePBVs+r0yEMvQQxZihQJQ9Ye2h61DQcRmwpSzua58HbVXhMhNl09hGmr4lOACN0fAHyZ65l+2vhPKqVsByJ7cy54V8GAzesgYz/ISTEBtcEbE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 1709705634929853.5189852340983; Tue, 5 Mar 2024 22:13:54 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rhkX9-00063i-25; Wed, 06 Mar 2024 01:13:43 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rhkWV-00057s-0Y for qemu-devel@nongnu.org; Wed, 06 Mar 2024 01:13:03 -0500 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rhkWT-0006Hp-Ho for qemu-devel@nongnu.org; Wed, 06 Mar 2024 01:13:02 -0500 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1dcce5e84bcso52583755ad.1 for ; Tue, 05 Mar 2024 22:13:00 -0800 (PST) Received: from localhost ([157.82.206.27]) by smtp.gmail.com with UTF8SMTPSA id o12-20020a170902bccc00b001dc486f0cbesm11569927pls.222.2024.03.05.22.12.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 05 Mar 2024 22:12:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709705579; x=1710310379; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=ahxRZ3SD7lLMx3muKeGeJx9aSeKYvKbViQJskOgE7S0=; b=cxr/aPYzdIXinC2AZHHHUP6bGgxFnX65waBbeJuWsfjfoTwrrkTtIOYxtZlFxGkyzk Uzzh+Ajuc6iC0kmex10u9qFF9daN9iKxmZNPKLy0sq8V7zlQnF2ejUvkG874O/1NvmmR ZMOGrLhRWncJpd+nF5hT/qloLM/E8gDgpwwYPIRFpLinSL4grfexBo7lyP0Q7cxkbznC Fwx4C670PytF16GAUMkATpAuMNyN1RHOWQ2kfEqodhaBy9gDPM+jGtdmpHCzREbh34q+ sCRzn7hFE8VPnMjF11pRbexaYMcvuKKoURDeQMVCvsG+3JjGkDHhsM/0jGRCxBSplnqG X0cA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709705579; x=1710310379; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ahxRZ3SD7lLMx3muKeGeJx9aSeKYvKbViQJskOgE7S0=; b=fcxcekxfxu9E73Pafj6NrM4e5oCf0sxsW2UtHLkx1+5EK3gz80JENNvZ3Gn/a2r4ec lGQhe/n135fHwxIb8aP+inwdXIkmqajO9xPFRmVZ8VpGyIi8U5XQet+/X7/cbalNOCOb dXbJuDJVu+XJsp8bTum+KqXa4xCUPHSLhpl07i7VhQY+zRrQs8Nk6epbuJ1KpzHPXqCk rZYko4UqW4TOvSFEmBk+SoXsXmAJep2GqSxoWldFPSEU1/p/VdY2ByikE11WTsDdll7N n9Bpl6IKyY06xQrtMvVdOSYuUg0PyEbolfHDaGTYdJFrdbaiOFDBFDrD40pLGn2Xm5Hi zzhQ== X-Gm-Message-State: AOJu0YzTFo3lk2UvIMemPnWmbYXnKEmjBexeYh+br6/LqibmhBzai8e5 5aBX3vqh9o04T9MG6Xz/unocWP9b4mP1SK8Ggp9sOcSJAwVSCQvT0w4uMkEIoJE7pv+SFgEgrtr r X-Google-Smtp-Source: AGHT+IHUdOqjMEk4lzZrCVvQ7wruyQPMJvSNJyVFBjpPqbE2BcGa+kfyv1Z2xgmaGl2DgCzvPOBdCg== X-Received: by 2002:a17:903:1cc:b0:1dc:b48f:3c8d with SMTP id e12-20020a17090301cc00b001dcb48f3c8dmr4562684plh.52.1709705579610; Tue, 05 Mar 2024 22:12:59 -0800 (PST) From: Akihiko Odaki Date: Wed, 06 Mar 2024 15:12:21 +0900 Subject: [PATCH v3 15/19] MAINTAINERS: Add Akihiko Odaki as a elf2dmp reviewer MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240306-elf2dmp-v3-15-d74e6c3da49c@daynix.com> References: <20240306-elf2dmp-v3-0-d74e6c3da49c@daynix.com> In-Reply-To: <20240306-elf2dmp-v3-0-d74e6c3da49c@daynix.com> To: Viktor Prutyanov , Peter Maydell Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 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=2607:f8b0:4864:20::62c; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x62c.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1709705635357100009 Signed-off-by: Akihiko Odaki Reviewed-by: Peter Maydell --- MAINTAINERS | 1 + 1 file changed, 1 insertion(+) diff --git a/MAINTAINERS b/MAINTAINERS index 65dfdc9677e4..d25403f3709b 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3583,6 +3583,7 @@ F: util/iova-tree.c =20 elf2dmp M: Viktor Prutyanov +R: Akihiko Odaki S: Maintained F: contrib/elf2dmp/ =20 --=20 2.44.0 From nobody Tue Nov 26 04:30:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=1709705649; cv=none; d=zohomail.com; s=zohoarc; b=Au+5O7qYgEjH7AmXvHb3f2kiZDgnVlRIy3eOovQDN22Ij08jGHZLMfJkMO2UYJukb6mcceMtOUMRdixpB9hu/GGgxuF4AQoDeVm31M0illzS9WmNBaPhsvg1Z9R2MGeWakCZR33g9I0fl16qhbZsyQtkLrIhk0j+b39lKi0Fb9k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709705649; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=5x59V7N2Snccc4Fu7ozWsaURAyB+hFzG8uxYs6vkbiI=; b=fls3K61L5pKG4FPhG1GeLJaTYv8DC4gze2mveTHlOcw38e3YIFD1HHQM3DMAr6zzGkVUvGI6ppRNNz7iqMl4UEIgP4OHh8MJc4IaA1FKuP3h8B9fvxIsNaL6nd28+ckJvLbSSaC+sMIeceu0Rw6zIlCDC/Sh/kBWrUdcmSSs5lQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 1709705649714779.6281624917057; Tue, 5 Mar 2024 22:14:09 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rhkXE-0006ud-Eg; Wed, 06 Mar 2024 01:13:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rhkWk-0005TQ-Sl for qemu-devel@nongnu.org; Wed, 06 Mar 2024 01:13:24 -0500 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rhkWV-0006IS-PS for qemu-devel@nongnu.org; Wed, 06 Mar 2024 01:13:18 -0500 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1d7232dcb3eso48111725ad.2 for ; Tue, 05 Mar 2024 22:13:03 -0800 (PST) Received: from localhost ([157.82.206.27]) by smtp.gmail.com with UTF8SMTPSA id z17-20020a170903019100b001db4433ef95sm11634125plg.152.2024.03.05.22.13.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 05 Mar 2024 22:13:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709705582; x=1710310382; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=5x59V7N2Snccc4Fu7ozWsaURAyB+hFzG8uxYs6vkbiI=; b=EZymIPUZ6B9CN35WktRTniw2euQInpVvwOLaKoymtDZ4q/S0+fHyF0FKRi9ijPW55O 7mPGdfFyozlW61LlBtwszka6KWhLzPkQZmoDfB5omnRYAY7sKqr+4GZQDuxLeI+wmXx/ sLfIbvvHjMkgVWfUTg2WqbBcKmAPnpgnoGmL3w3ARIk70dN5V+6J6CFhoPdAZAbEhonp c+J+X8m4cARZ1pvhu4II418L91pgCt808QiMj7U476HA3TskD8WXs7gQDCoKPfduZiJz Vv+sRdKoQFXZeW/LlXdP4HzCV6IWb0qwiayoO5w9Gj4B7S+bor+4l8SKzz5QAikfMQT0 PbCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709705582; x=1710310382; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5x59V7N2Snccc4Fu7ozWsaURAyB+hFzG8uxYs6vkbiI=; b=WYwuoOj7/g3xUNtaqGqnuJxGPVrTKTg/EiAIVjtVdyu/zYQ3/20MIWaGYZXHKQGKph ne9I+7RYGEQQXy06uVpaNCUZBLKjrJuJXmWMDJh3N95Bf2Uzbv2M1idbbC67HW9Wq4C0 IXFfJUJNP8Nv/plNyRvC9uj3szDgXvjUsWcJnyv2AbPMuSw1N9RuO56L+jZuB77IDAo8 E3dxU/6CX+ViO+UT2Wd+DGX1dLuJUnpCJwWl+BsW/dMPoOdCSW+Sq9zZQ++T02VAXjwJ 8KblsWRV0vlaiwUqWTNe5rbVV8520IejqakjmPESIhuyilQz0v8a6bDjtrWZxhWkpe4Q 2I5Q== X-Gm-Message-State: AOJu0YyLXT1FJni4dja8POw6ffAK/qfahU/ttkb7/4Y7VhF0N5pUOs+A 7elP0GfzOD2B9yI+WeQLfSCLMKJZIMB5n33e1L6CgKOJzQjzTe7IaEnvK2qnQfg= X-Google-Smtp-Source: AGHT+IFeyWe0XVm+dq5BTaZLncjWER7BX46F6Lw0ouHAnCAlp3Otus6gcTxJkh8SG0tBW9hWqBbuKA== X-Received: by 2002:a17:902:7c92:b0:1dc:cc09:ebad with SMTP id y18-20020a1709027c9200b001dccc09ebadmr3294534pll.28.1709705582485; Tue, 05 Mar 2024 22:13:02 -0800 (PST) From: Akihiko Odaki Date: Wed, 06 Mar 2024 15:12:22 +0900 Subject: [PATCH v3 16/19] contrib/elf2dmp: Build only for little endian host MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240306-elf2dmp-v3-16-d74e6c3da49c@daynix.com> References: <20240306-elf2dmp-v3-0-d74e6c3da49c@daynix.com> In-Reply-To: <20240306-elf2dmp-v3-0-d74e6c3da49c@daynix.com> To: Viktor Prutyanov , Peter Maydell Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 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=2607:f8b0:4864:20::62e; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x62e.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1709705651455100003 elf2dmp assumes little endian host in many places. Build it only for little endian hosts until they are fixed. Signed-off-by: Akihiko Odaki --- contrib/elf2dmp/meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/elf2dmp/meson.build b/contrib/elf2dmp/meson.build index 6707d43c4fa5..046569861f7a 100644 --- a/contrib/elf2dmp/meson.build +++ b/contrib/elf2dmp/meson.build @@ -1,4 +1,4 @@ -if curl.found() +if curl.found() and host_machine.endian() =3D=3D 'little' executable('elf2dmp', files('main.c', 'addrspace.c', 'download.c', 'pdb.= c', 'qemu_elf.c'), genh, dependencies: [glib, curl], install: true) --=20 2.44.0 From nobody Tue Nov 26 04:30:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=1709705877; cv=none; d=zohomail.com; s=zohoarc; b=Z3jPUriQrWzaVzjAmsxjNquYEfMAFBqIhq7sjdIZd5M8IHRuuQtNvKdu7FokEn7sKe4ZJZ1Bn1A7PvC4l3jumGx6DkbWOOZjkhssG9dUQDNZAzT83t+BQrJmwgXT4iGZEMTBI/t08mKZr49dmeP/OI/yaTQ40WZ+7doUGPGYF/o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709705877; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=SWv/n6ZKj2r4AuXL4UqGI23kMpuzOnRejuu9Q3uLHrw=; b=iQjqYKs847rav3KkBII9aG/GxUwNXDk74Lvwmwu5SoqiuY3M+I2Ednk1OEoCmDZKNcYmbF7scuYqSmOBv3g7TvT32hBNfjo1O15CwV3T1ImpqgomWCFKORa7ZVGjKr2RxF+gexxrfrIOEerMSvo6yot0r/Q/rKlX4SnBIO0Uip0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 1709705877527838.6883666676136; Tue, 5 Mar 2024 22:17:57 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rhkXA-0006GN-DQ; Wed, 06 Mar 2024 01:13:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rhkWc-0005Ni-Ai for qemu-devel@nongnu.org; Wed, 06 Mar 2024 01:13:14 -0500 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rhkWa-0006K1-Cl for qemu-devel@nongnu.org; Wed, 06 Mar 2024 01:13:09 -0500 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1dd178fc492so21316255ad.2 for ; Tue, 05 Mar 2024 22:13:07 -0800 (PST) Received: from localhost ([157.82.206.27]) by smtp.gmail.com with UTF8SMTPSA id s9-20020a170902988900b001dc3ef786f9sm11617879plp.308.2024.03.05.22.13.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 05 Mar 2024 22:13:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709705586; x=1710310386; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=SWv/n6ZKj2r4AuXL4UqGI23kMpuzOnRejuu9Q3uLHrw=; b=awIkjGG97cQD04nPmjSlI9R2DPp5Xo80X02aSklKkEsQWa8aAOh5Yj3O2TalRF5Xpo t2/pecNc7G/+0ksulMzFbfjZvwgO7RtTiC9YDxFaMzHUERZxIUaAMYN2q/hgj0qUoXtt frUk1bFBq+bwAsoi1hKqoHe8OorbvNSD00gI/OOddIr0Fg5aBB/zT8TjwgY3JcVmOJyr XJyyruoHlAIfagigTAXjaHgL/DYfyU/u2piAgiOkMyN06C542DiVzlU8hgdPT8LTzGX8 4tY+ypyxzByDvtC20fiXeFjN+cJx8gqSTDwlqCK3F6U51KYzC7Z5+1Jr4F6exVqfb6Lk GYJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709705586; x=1710310386; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SWv/n6ZKj2r4AuXL4UqGI23kMpuzOnRejuu9Q3uLHrw=; b=FI6EbCy56Nk2lAQgb/Shhos5kesvhgZTokumoBrVv6c03S+jHSB/J1XwSzt8sq0WB/ wMsEjRUO1VTFVquq+zv0ItvH3xtdDXlj97V9QpRqVSOP8mZyyqm3GO6tas8YhLwJfgEc FKilE8afETbMGI/SXL/8NVnORzHDQ1xOLlGUtQFrjqrQo4owmwOtugkktizAlgVLud2x bRICfqyHmapqJ2zhYmHTKYKntk+S+UEs95NaKzTDncGS1PwVyw67TYgWWTguzfQNWFNA ksBZLO9lM2eNueLSvpB9tJ4cKN5yBcC4IMpfcvVUnUnUFM0RBEqSnlO9StNKccengnMi SVig== X-Gm-Message-State: AOJu0YxAh1fjRgRMvfv2l165F9BUlhtb2+c9csWGvN9jXsnG2SGVXbNC rHVn7cfARsFMlpTJ90eaAe8+ZyAEoIn2QzuiIiclkHgQ5ucgWH0432upgtiVEc4= X-Google-Smtp-Source: AGHT+IH9pIVIF0ENYYG9PeRqLVnU1y/kU+LQR7lftfdwgK3RObineI/3jGNd83iaYMyO+qRGISfa9g== X-Received: by 2002:a17:902:c1c5:b0:1d9:8f6e:86e8 with SMTP id c5-20020a170902c1c500b001d98f6e86e8mr4057960plc.69.1709705585988; Tue, 05 Mar 2024 22:13:05 -0800 (PST) From: Akihiko Odaki Date: Wed, 06 Mar 2024 15:12:23 +0900 Subject: [PATCH v3 17/19] contrib/elf2dmp: Use GPtrArray MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240306-elf2dmp-v3-17-d74e6c3da49c@daynix.com> References: <20240306-elf2dmp-v3-0-d74e6c3da49c@daynix.com> In-Reply-To: <20240306-elf2dmp-v3-0-d74e6c3da49c@daynix.com> To: Viktor Prutyanov , Peter Maydell Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 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=2607:f8b0:4864:20::633; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x633.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1709705878359100001 This removes the need to enumarate QEMUCPUState twice and saves code. Signed-off-by: Akihiko Odaki Reviewed-by: Peter Maydell --- contrib/elf2dmp/qemu_elf.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/contrib/elf2dmp/qemu_elf.c b/contrib/elf2dmp/qemu_elf.c index a22c057d3ec3..7d896cac5b15 100644 --- a/contrib/elf2dmp/qemu_elf.c +++ b/contrib/elf2dmp/qemu_elf.c @@ -66,7 +66,7 @@ static bool init_states(QEMU_Elf *qe) Elf64_Nhdr *start =3D (void *)((uint8_t *)qe->map + phdr[0].p_offset); Elf64_Nhdr *end =3D (void *)((uint8_t *)start + phdr[0].p_memsz); Elf64_Nhdr *nhdr; - size_t cpu_nr =3D 0; + GPtrArray *states; =20 if (phdr[0].p_type !=3D PT_NOTE) { eprintf("Failed to find PT_NOTE\n"); @@ -74,38 +74,29 @@ static bool init_states(QEMU_Elf *qe) } =20 qe->has_kernel_gs_base =3D 1; + states =3D g_ptr_array_new(); =20 for (nhdr =3D start; nhdr < end; nhdr =3D nhdr_get_next(nhdr)) { if (!strcmp(nhdr_get_name(nhdr), QEMU_NOTE_NAME)) { QEMUCPUState *state =3D nhdr_get_desc(nhdr); =20 if (state->size < sizeof(*state)) { - eprintf("CPU #%zu: QEMU CPU state size %u doesn't match\n", - cpu_nr, state->size); + eprintf("CPU #%u: QEMU CPU state size %u doesn't match\n", + states->len, state->size); /* * We assume either every QEMU CPU state has KERNEL_GS_BAS= E or * no one has. */ qe->has_kernel_gs_base =3D 0; } - cpu_nr++; + g_ptr_array_add(states, state); } } =20 - printf("%zu CPU states has been found\n", cpu_nr); + printf("%u CPU states has been found\n", states->len); =20 - qe->state =3D g_new(QEMUCPUState*, cpu_nr); - - cpu_nr =3D 0; - - for (nhdr =3D start; nhdr < end; nhdr =3D nhdr_get_next(nhdr)) { - if (!strcmp(nhdr_get_name(nhdr), QEMU_NOTE_NAME)) { - qe->state[cpu_nr] =3D nhdr_get_desc(nhdr); - cpu_nr++; - } - } - - qe->state_nr =3D cpu_nr; + qe->state_nr =3D states->len; + qe->state =3D (void *)g_ptr_array_free(states, FALSE); =20 return true; } --=20 2.44.0 From nobody Tue Nov 26 04:30:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=1709705825; cv=none; d=zohomail.com; s=zohoarc; b=XEgngpLXnNzjy+eSKo0EIgcZb8oUjCUfe1VZITmLl/IRxhQN3Jzq4AoNCld6wKttap2rUyOiaAK6ApUNgjgXlo9C1G/TGvg6o4UAzZUIMuiar/T1psz+yjqBPSPJEvcRr1FfcnTgRxuQdhslhfnPbW6u1Wo77rgC9iv9S3GvxBs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709705825; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=CotLFv3JVXm6i3Wu/BAcc+rvRVqdPlzG06TuPB40/EU=; b=XUZgXsUT6W42Eb9tDbpbRlA6JwkXVaXNnGfOu5LcZS931p8iIHWLReNcidVrwDkpuZISxZTX6Y/JdFA2Vuf6pyPzu0PIFmUTa4VE1NOD9TV2u30oYWGWpooZMCQ28h91jJTRwS4c3xT9zU01xm34CSZhadrOcu+GisbcOxgDX8o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 1709705825918447.77195894592876; Tue, 5 Mar 2024 22:17:05 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rhkXC-0006aC-6G; Wed, 06 Mar 2024 01:13:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rhkWe-0005Qu-2B for qemu-devel@nongnu.org; Wed, 06 Mar 2024 01:13:15 -0500 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rhkWc-0006KE-8j for qemu-devel@nongnu.org; Wed, 06 Mar 2024 01:13:11 -0500 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1dcad814986so4887705ad.0 for ; Tue, 05 Mar 2024 22:13:09 -0800 (PST) Received: from localhost ([157.82.206.27]) by smtp.gmail.com with UTF8SMTPSA id li4-20020a170903294400b001d8f82c61cdsm11691289plb.231.2024.03.05.22.13.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 05 Mar 2024 22:13:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709705589; x=1710310389; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=CotLFv3JVXm6i3Wu/BAcc+rvRVqdPlzG06TuPB40/EU=; b=HlvHwOPy4H8SXmMpIy16jUcuQnJlKYcu1EJNTLEfJfimzwjnIzz94T6GzCAKo3t6AD OM/JPerOUdHeMevRUeA97LblG76hb/BtaAlN1BAa5yd6NoP0Y8xTJD5CJRGu4g6xxWxs o564gc6gZ1SJ6sklhCLWLUXpfMtckXB5JT9MX3wc87FRDFNiNo5GtfdL5HgzwCUOfqsp 4mSmmfGDowOSLcCWruzoKXMS+t4csqjZSGdZ3DcD5SEoteR2Xo9jmQEs1tehK3sTC7wt r5WfPQIrDHGu47049WFL055v809KXKKCh//k1GfdIwEfRllLPlZj4uIv4m3la4pqWnob LLfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709705589; x=1710310389; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CotLFv3JVXm6i3Wu/BAcc+rvRVqdPlzG06TuPB40/EU=; b=watFKbd2UAkzXtJPzxbqyPpWe/5Swt+mQr5Igg5BvlkyRDfGzc074URNKeSH4Lm/Gj 0gWFvYxQ08EgL4ApjL2ArZmgWUJmyFlkVmmVsX5z7xZpuqOmiDYJA1HfrGu5lplS3V0z ezgfaS7TSZ+F9bClMzl45vVs0VAvt9H5t8Pz6mRkyfM6xCL4b/r6Y0zafJJPXg/tXjCn YAnUcUxjMmrwDeMx+DQprZa6RqUGqHXj057PlaaKkRYlKk6OXSAEjtejOafsNOdsxfTj JIUHAJeb3rFKwrQJZRW2fk67HUunwvYtkMtJbav9n/uuqhI14cNwRIGhJvNlSBUF40gR ek5w== X-Gm-Message-State: AOJu0Yw8KIveCs7/CDkDeVMWsEgr+IR5H4ln+jEL7BsZpLJSXOcp3Ff+ LprqTsR/PSpYf0pqBKiyYR9r7bDPBqpE8EHZxOLrfdPLkAeoco7ugh/1AMVP49iqNBwfi77RSMT J X-Google-Smtp-Source: AGHT+IGdXbli+6LKCOWcDCTTDtp4kMd5BqmbVKf/r4Fi5z6jw0U3FU8H/XebNw7PrcQZWHPgltjyng== X-Received: by 2002:a17:902:6504:b0:1dc:8ba1:edc3 with SMTP id b4-20020a170902650400b001dc8ba1edc3mr4158612plk.9.1709705588741; Tue, 05 Mar 2024 22:13:08 -0800 (PST) From: Akihiko Odaki Date: Wed, 06 Mar 2024 15:12:24 +0900 Subject: [PATCH v3 18/19] contrib/elf2dmp: Clamp QEMU note to file size MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240306-elf2dmp-v3-18-d74e6c3da49c@daynix.com> References: <20240306-elf2dmp-v3-0-d74e6c3da49c@daynix.com> In-Reply-To: <20240306-elf2dmp-v3-0-d74e6c3da49c@daynix.com> To: Viktor Prutyanov , Peter Maydell Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 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=2607:f8b0:4864:20::62b; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x62b.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1709705826175100001 This fixes crashes with truncated dumps. Signed-off-by: Akihiko Odaki Reviewed-by: Peter Maydell --- contrib/elf2dmp/qemu_elf.c | 87 +++++++++++++++++++++++++++++-------------= ---- 1 file changed, 55 insertions(+), 32 deletions(-) diff --git a/contrib/elf2dmp/qemu_elf.c b/contrib/elf2dmp/qemu_elf.c index 7d896cac5b15..8d750adf904a 100644 --- a/contrib/elf2dmp/qemu_elf.c +++ b/contrib/elf2dmp/qemu_elf.c @@ -6,6 +6,7 @@ */ =20 #include "qemu/osdep.h" +#include "qemu/host-utils.h" #include "err.h" #include "qemu_elf.h" =20 @@ -15,36 +16,11 @@ #define ROUND_UP(n, d) (((n) + (d) - 1) & -(0 ? (n) : (d))) #endif =20 -#ifndef DIV_ROUND_UP -#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) -#endif - -#define ELF_NOTE_SIZE(hdr_size, name_size, desc_size) \ - ((DIV_ROUND_UP((hdr_size), 4) + \ - DIV_ROUND_UP((name_size), 4) + \ - DIV_ROUND_UP((desc_size), 4)) * 4) - int is_system(QEMUCPUState *s) { return s->gs.base >> 63; } =20 -static char *nhdr_get_name(Elf64_Nhdr *nhdr) -{ - return (char *)nhdr + ROUND_UP(sizeof(*nhdr), 4); -} - -static void *nhdr_get_desc(Elf64_Nhdr *nhdr) -{ - return nhdr_get_name(nhdr) + ROUND_UP(nhdr->n_namesz, 4); -} - -static Elf64_Nhdr *nhdr_get_next(Elf64_Nhdr *nhdr) -{ - return (void *)((uint8_t *)nhdr + ELF_NOTE_SIZE(sizeof(*nhdr), - nhdr->n_namesz, nhdr->n_descsz)); -} - Elf64_Phdr *elf64_getphdr(void *map) { Elf64_Ehdr *ehdr =3D map; @@ -60,13 +36,35 @@ Elf64_Half elf_getphdrnum(void *map) return ehdr->e_phnum; } =20 +static bool advance_note_offset(uint64_t *offsetp, uint64_t size, uint64_t= end) +{ + uint64_t offset =3D *offsetp; + + if (uadd64_overflow(offset, size, &offset) || offset > UINT64_MAX - 3)= { + return false; + } + + offset =3D ROUND_UP(offset, 4); + + if (offset > end) { + return false; + } + + *offsetp =3D offset; + + return true; +} + static bool init_states(QEMU_Elf *qe) { Elf64_Phdr *phdr =3D elf64_getphdr(qe->map); - Elf64_Nhdr *start =3D (void *)((uint8_t *)qe->map + phdr[0].p_offset); - Elf64_Nhdr *end =3D (void *)((uint8_t *)start + phdr[0].p_memsz); Elf64_Nhdr *nhdr; GPtrArray *states; + QEMUCPUState *state; + uint32_t state_size; + uint64_t offset; + uint64_t end_offset; + char *name; =20 if (phdr[0].p_type !=3D PT_NOTE) { eprintf("Failed to find PT_NOTE\n"); @@ -74,15 +72,40 @@ static bool init_states(QEMU_Elf *qe) } =20 qe->has_kernel_gs_base =3D 1; + offset =3D phdr[0].p_offset; states =3D g_ptr_array_new(); =20 - for (nhdr =3D start; nhdr < end; nhdr =3D nhdr_get_next(nhdr)) { - if (!strcmp(nhdr_get_name(nhdr), QEMU_NOTE_NAME)) { - QEMUCPUState *state =3D nhdr_get_desc(nhdr); + if (uadd64_overflow(offset, phdr[0].p_memsz, &end_offset) || + end_offset > qe->size) { + end_offset =3D qe->size; + } + + while (offset < end_offset) { + nhdr =3D (void *)((uint8_t *)qe->map + offset); + + if (!advance_note_offset(&offset, sizeof(*nhdr), end_offset)) { + break; + } + + name =3D (char *)qe->map + offset; + + if (!advance_note_offset(&offset, nhdr->n_namesz, end_offset)) { + break; + } + + state =3D (void *)((uint8_t *)qe->map + offset); + + if (!advance_note_offset(&offset, nhdr->n_descsz, end_offset)) { + break; + } + + if (!strcmp(name, QEMU_NOTE_NAME) && + nhdr->n_descsz >=3D offsetof(QEMUCPUState, kernel_gs_base)) { + state_size =3D MIN(state->size, nhdr->n_descsz); =20 - if (state->size < sizeof(*state)) { + if (state_size < sizeof(*state)) { eprintf("CPU #%u: QEMU CPU state size %u doesn't match\n", - states->len, state->size); + states->len, state_size); /* * We assume either every QEMU CPU state has KERNEL_GS_BAS= E or * no one has. --=20 2.44.0 From nobody Tue Nov 26 04:30:55 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=1709705792; cv=none; d=zohomail.com; s=zohoarc; b=njtwN0+TrOfKNqDR1NBmBDkjdYIrYjTjmq8Fo73/spx5kE0V9QI+P5n+WJwHrB8++C/aundtXZD4MHf73PgSZX3Ys++2uQ2vTubZqFHYpO9CXtIlQMG3n0e5qe5ZN5K5fBHATe5ovf0hegPqByg/eZtxRCILob+PD14I/RxxnIY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709705792; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=vWeSXxnvukh1qTIQXUJcznaqlBnX6VJYT1GjqHDMtek=; b=OLBKQuZ6ffTrHnOoOEhteHcV6sM9ChmzNk4lkJAmQ/m9l7M+tP7lo3nbttTsttyXAfk6detq6PtVKznJLpyRbR7FWU4uLiNykr1DWhm1Xffc9UxhJdMiYJTa9v3+fi+ds1a4wzCTQpGF3oZGOEUfgGN40c4kfTB8tOHyGplrONA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 170970579297341.99911721466651; Tue, 5 Mar 2024 22:16:32 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rhkX8-0005zO-M0; Wed, 06 Mar 2024 01:13:42 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rhkWi-0005SU-7D for qemu-devel@nongnu.org; Wed, 06 Mar 2024 01:13:18 -0500 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rhkWf-0006M8-Mh for qemu-devel@nongnu.org; Wed, 06 Mar 2024 01:13:15 -0500 Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1dd10a37d68so27382775ad.2 for ; Tue, 05 Mar 2024 22:13:13 -0800 (PST) Received: from localhost ([157.82.206.27]) by smtp.gmail.com with UTF8SMTPSA id l14-20020a170902f68e00b001c407fac227sm11584615plg.41.2024.03.05.22.13.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 05 Mar 2024 22:13:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709705592; x=1710310392; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=vWeSXxnvukh1qTIQXUJcznaqlBnX6VJYT1GjqHDMtek=; b=dhDpM6IRbgxb47pI5hrmD+/qnx+FF82VqZ//GokGv1HDVFhs06Ml6qCZEhnJo1M3eJ vqMcuIGrrqyncJzq0VZhNIz0R91HC4y3nI7pPgFuEiOWk2xPvxZzCzBXMKpzjEuuVsDg 8w6JKW12y5994355igUN6vTwWuTCMutB8Vi6C3ZmL6DesBh5y55yVJD8tWEF9FS+2S7P YWNtmth9C/QdD81R1BTaBntmC1SfL4vIMXvqmDSuaHzazSL38xUl7ZzYwbUxsiUYwCOj TK/7oMPeBMvS+hnawLMbcBa2JplEffaRCrYtDaHXZROiG7Xn8wJgZ+zT2dkz/h1++rTa /BMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709705592; x=1710310392; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vWeSXxnvukh1qTIQXUJcznaqlBnX6VJYT1GjqHDMtek=; b=SQLqVNnhD3KVEDs1Xj8+1TZ5/jlZ5n0pAJtCXDCTXjHzmPyIOjsh1dPA4Zuvm2dcLx mPfeyo4gA/zoIpffJJ+X9Glen9Dc9c0QqDhiYjA6KbFKxNxU+HrSrevVL//oMWbb3L8D oyUhboB41S4/tWWIpIt5aG+hi6ZERqDzyMmGeciOFvZGYebEjqdOehczVdfVY0DvPkjF XHpfZbSXP9GyF6Hut9hrKfd6TzqBHIVJn3Mxb44724BOgr2K7jj4o97Po7PfDX7+nbwE kX3q79UJJAMt62LddlsSFjEtPF57exVssrddseWZsyKyHv6wFloyWHY8Aug52fq1GHcd 9SZQ== X-Gm-Message-State: AOJu0YwJMsw0DSrKiRvrdp7tjQETDpC7DCmgOngRvPtewKvReHBC7HfA 9V0lDjmvcpC3Q3fTEH4tc6nVHxIm5lsH2sDWeZfvI4OpYPVx3X/LP0Ebbnv7e+Q= X-Google-Smtp-Source: AGHT+IEQaCP7Atw9WKvSqj7bSVsujj8hc1pUllt0aKPOEcwic7uWYrt346WbsIYi5vvH8/Un5e0AQA== X-Received: by 2002:a17:902:d50b:b0:1dc:d773:ac with SMTP id b11-20020a170902d50b00b001dcd77300acmr4613895plg.7.1709705592254; Tue, 05 Mar 2024 22:13:12 -0800 (PST) From: Akihiko Odaki Date: Wed, 06 Mar 2024 15:12:25 +0900 Subject: [PATCH v3 19/19] contrib/elf2dmp: Ensure phdrs fit in file MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240306-elf2dmp-v3-19-d74e6c3da49c@daynix.com> References: <20240306-elf2dmp-v3-0-d74e6c3da49c@daynix.com> In-Reply-To: <20240306-elf2dmp-v3-0-d74e6c3da49c@daynix.com> To: Viktor Prutyanov , Peter Maydell Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 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=2607:f8b0:4864:20::635; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x635.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1709705794050100001 Callers of elf64_getphdr() and elf_getphdrnum() assume phdrs are accessible. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2202 Signed-off-by: Akihiko Odaki --- contrib/elf2dmp/qemu_elf.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/contrib/elf2dmp/qemu_elf.c b/contrib/elf2dmp/qemu_elf.c index 8d750adf904a..c9bad6e82cf3 100644 --- a/contrib/elf2dmp/qemu_elf.c +++ b/contrib/elf2dmp/qemu_elf.c @@ -132,6 +132,7 @@ static void exit_states(QEMU_Elf *qe) static bool check_ehdr(QEMU_Elf *qe) { Elf64_Ehdr *ehdr =3D qe->map; + uint64_t phendoff; =20 if (sizeof(Elf64_Ehdr) > qe->size) { eprintf("Invalid input dump file size\n"); @@ -173,6 +174,13 @@ static bool check_ehdr(QEMU_Elf *qe) return false; } =20 + if (umul64_overflow(ehdr->e_phnum, sizeof(Elf64_Phdr), &phendoff) || + uadd64_overflow(phendoff, ehdr->e_phoff, &phendoff) || + phendoff > qe->size) { + eprintf("phdrs do not fit in file\n"); + return false; + } + return true; } =20 --=20 2.44.0