From nobody Tue Nov 26 04:42: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=1709624226; cv=none; d=zohomail.com; s=zohoarc; b=LCL+3L/kwD6pF1SO2yGzqE2Jty0sDxzyt//2EwmOoJHcN6bsAhphwXPrgmLgrICCtjg7IHN501UnBouFgTp+bR/vt7hGzfoGkAL02J9u8KNCCKK45jLPLo83IJcnhrfBQrnSFam6ZWkSv6EJZPyAx2aq24tJrTyO4+Du3/j4i2U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709624226; 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=cmLbJ+esOto+sw6Kux2WlDr6cZ4EBSoYVYY0hVqqE28=; b=eusbraaItNSJbWRZs0UuCd+P13Gl9fXRq6asPW3iO65v7VzZi1Y3c1NDEHgA2yx40QRKcN5GMjsixRwvelbhQvZRRyA5AsuNrwW1wSXcYxCdnxqM4b0Us5+O3i1LXRGgeFqACfq2dlqEIM2AvtTzGPhhoKx4Vn8EUC1KRR7HdFo= 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 1709624226508522.6486620483774; Mon, 4 Mar 2024 23:37:06 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rhPM3-000692-1g; Tue, 05 Mar 2024 02:36: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 1rhPLn-00067B-Bj for qemu-devel@nongnu.org; Tue, 05 Mar 2024 02:36:38 -0500 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rhPLl-0005ql-Gz for qemu-devel@nongnu.org; Tue, 05 Mar 2024 02:36:35 -0500 Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1dc09556599so50923585ad.1 for ; Mon, 04 Mar 2024 23:36:33 -0800 (PST) Received: from localhost ([157.82.203.206]) by smtp.gmail.com with UTF8SMTPSA id g7-20020a170902868700b001dca9b21267sm9755313plo.186.2024.03.04.23.36.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 04 Mar 2024 23:36:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709624192; x=1710228992; 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=cmLbJ+esOto+sw6Kux2WlDr6cZ4EBSoYVYY0hVqqE28=; b=VRqTLIJgIZaTzYjhc+OfxD1OpRn8Ou+W6U5mkJXZLizwHGTwThrrKuptlJ5qjOW61/ aKKqC1QgyqJqjQmKqBxnl6fQ1CluB27lZSq/e0gOKOFWjdfiW1DWQHsoJ8a/vf7fBesM Of3vWrsZIHLHLu6hZJOedOegwmk/oqKmmlmF9K5MNxzcNsMIKjSH4ud6gJeDOH+srUnY sUCCyoYORyCJBhxN5Dc/734GuvU7j3ZILAta7gMtfKp1k5GLnKPqqh25/mKSjMZWXqhM nU86edkS+jKaZ15Jw1Eln3y4PppB54rsiv97WGPsR86lsMOwRtPp9klqzKiI4Rh9+fPe 9ObA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709624192; x=1710228992; 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=cmLbJ+esOto+sw6Kux2WlDr6cZ4EBSoYVYY0hVqqE28=; b=RpIZvnTsjWJSmsjvHFz5Qggfbjgz3xe6GATUL5SHLwpce62QoFHsCOBBDS57QHHrby RaJEValACLvoCJV76xlflSTct4fl7TfUiS8RYeyjZCr5ZPt/g8SeKwzKEXbWv07QvKiK nXa+P2ejeOR/8dD5yxDY47aUSnhTmNvbgiMDckE0dlHgnXqIbdgh41Av/XwZQW5Wr/sJ iOZB2BTcHEvIVIgEFtzqNG+cVffAHr1HZvaZxKJB9sN6k0sJ1i/ShcV6qMfPyBECai3y l2YybrgsXmGePqlWBvWTLhtKKvEHOfo2t4c0o9+I5gJlajXt/bqHLzKm01Al+/t7+9Lc 6oHA== X-Gm-Message-State: AOJu0YzcoO7oGncUQWN6WwtkQYIcrbuluGxoQmxhjY2XkZ8Up8sfkKJ5 Nva0qMKfqTG/gv4s2JUNXDFme5YfQHFh1D6NvB8vSPZEJ/OImYUm+3m8u2+H8ABM8Ms2i9LWxks 8 X-Google-Smtp-Source: AGHT+IE8HDgHCaRHAIauPCvp7oS/+g+NrT7DNjoACgvxRHgyV6y40GQ3KNsimXRnX7lHDDqOadknOQ== X-Received: by 2002:a17:902:eb89:b0:1db:c90f:e189 with SMTP id q9-20020a170902eb8900b001dbc90fe189mr1027261plg.57.1709624191799; Mon, 04 Mar 2024 23:36:31 -0800 (PST) From: Akihiko Odaki Date: Tue, 05 Mar 2024 16:36:18 +0900 Subject: [PATCH v2 01/13] contrib/elf2dmp: Remove unnecessary err flags MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240305-elf2dmp-v2-1-86ff2163ad32@daynix.com> References: <20240305-elf2dmp-v2-0-86ff2163ad32@daynix.com> In-Reply-To: <20240305-elf2dmp-v2-0-86ff2163ad32@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::631; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x631.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: 1709624228532100003 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:42: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=1709624249; cv=none; d=zohomail.com; s=zohoarc; b=nOfkgVVX8shZ1MKXXBQEjxCUCruQ8Ip/RlmP0rCJGJuG1d9AiqxRz5JZNZGNuuLfDW6a62KS2DZ7RTVWo6ZDNRNL+tT4UJxCgxC0QCKwduIy4bzPAvoTbIFGozhipL6U+p54oamCZ7L/hyfMkjXlfC0/CnxgK28yYXAW7pfU1ks= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709624249; 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=3+MISxZtlwMc4Gir9xq5Ye6W+11swb1BIKOj0oAvifc=; b=WDL9d911tDk+gKA0TirgCWKO0d72ed7vj9p2KhrMEumtKYDNevNvhpuhK9Oz8vPLSqHvyh6/yJPiJP98VAuaw37qO9gJ8WEmPoWD825yxgljtXeInwSNlK1Assu9ibxo3173/M88ofFhL5sORKMeex7lTEW5nwwcyt5xL6CPG2M= 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 1709624249752569.0077744313251; Mon, 4 Mar 2024 23:37:29 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rhPMA-0006AT-N6; Tue, 05 Mar 2024 02:37:03 -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 1rhPLq-00067X-HM for qemu-devel@nongnu.org; Tue, 05 Mar 2024 02:36:41 -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 1rhPLo-0005r0-Hz for qemu-devel@nongnu.org; Tue, 05 Mar 2024 02:36:38 -0500 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1dcafff3c50so45399955ad.0 for ; Mon, 04 Mar 2024 23:36:35 -0800 (PST) Received: from localhost ([157.82.203.206]) by smtp.gmail.com with UTF8SMTPSA id s13-20020a170902ea0d00b001dcc0c84721sm9803962plg.99.2024.03.04.23.36.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 04 Mar 2024 23:36:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709624194; x=1710228994; 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=3+MISxZtlwMc4Gir9xq5Ye6W+11swb1BIKOj0oAvifc=; b=jAN0gZHCCbktr00EwleLS6AB8V9p6t2tIM6NU7GR69fxFHHIMn7cX3ijot0/yrF9ZK RWarvHK5vUNImaIvC82G4ccOj8GgTtrtutC4W/RL3M84uFtIxhlIqKo1OICWQzktEf7H yHt+6RE6LNCez+iv2RdD4HzUKWbq+QvH4noiEGzHuhxqcpOHqKA7PbgOmKj9X9b+P51W KZew4kPePoCf9DWyFb+gQ5Hly785WQEl8gNqNwtZJTwZGFFumAWsaiQOIsGOZ31jV94h Ob4wmk2JJWlsO5I+D7kgwMB2u/VBo3hRg7l5qg2bEMZCX1jPLUgQhjVLKTm4qiRCoT5y 4Deg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709624194; x=1710228994; 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=3+MISxZtlwMc4Gir9xq5Ye6W+11swb1BIKOj0oAvifc=; b=R7d0fj73WuZ3fB5Dee1mxl70Gex5fL/nqNjF19ftq9OZ0MgsrV1uAWQhCdRzZK6zZc 9ObcijtPhYi8vSvAqklO2RqcCZ1OkXn2V4ibP8N8QMh8ANy27W0yLRull4+6xAAAH4uk rii6nCwJaoao0VCCADiW89aOTJh8ssxcR8T5TBiGcuTt0mVprYZNwxvUR3QC2BI5v02h HDEhXrh8HkcLMZkTGXQl8s2GkxmfSI5/HFicptp+A/hjW9hySQzc3CKPyTaLoOiVKdeE N08+LPTEzzDYsjB++6UCRBd1EoZXontsKoGYqpTqb7tL4aivnHz0mV4QuYd502fVdrTS fdog== X-Gm-Message-State: AOJu0YxXbro99K5o5pYmiEo/5zpHVLd4b9ADW9gC2+2mJcQbUp5ybvCE uE03Wj9axqgq0ssFUM49aUThPk/iQyPn4dPtrxvjNEpFidZV+ZCZMXKJgFTTGzojlgDvCsv0eAT N X-Google-Smtp-Source: AGHT+IHmSrfJoLyrzvt0blBRQYEd5VBC9C6HKXHEig6HcAvhB5OoBpdiwbx0pkYRaeAmNQxSnJ+nlw== X-Received: by 2002:a17:902:e74d:b0:1dc:26a1:d1da with SMTP id p13-20020a170902e74d00b001dc26a1d1damr1413957plf.13.1709624194680; Mon, 04 Mar 2024 23:36:34 -0800 (PST) From: Akihiko Odaki Date: Tue, 05 Mar 2024 16:36:19 +0900 Subject: [PATCH v2 02/13] contrib/elf2dmp: Assume error by default MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240305-elf2dmp-v2-2-86ff2163ad32@daynix.com> References: <20240305-elf2dmp-v2-0-86ff2163ad32@daynix.com> In-Reply-To: <20240305-elf2dmp-v2-0-86ff2163ad32@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: 1709624250312100001 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:42: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=1709624289; cv=none; d=zohomail.com; s=zohoarc; b=F48ZW034dL9fuMeKYAbEbvdUFWLG+hOck3kyKhH1adNgsxHawnvG6UaLR3/G2yJwiKbd440V7Icxmicbl7MZMEo0KITTsJ9XR7qjbQK7M5QcYgh6gjuMnK2o8ZBQLHT9+RhnP2hqHkzkxT+UUQTweoxBNS+Z0NaSlO52DSDdulo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709624289; 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=dNi2CODBILcZJ3pornZRE2FYjihFpsMHPvoOvkX8mDc=; b=ND7s079Nj2z1gNlzLxV1auF2OXxxuvPhT+gcSIzBjHLp8jVhc8isbN+C4Ra9/A1hoQ+6YayZktGGprWMkmPv3u0rVJdu6fdzwOmzXdOhzBphmx0l5c4r8+yYc71qZCy8n76hv59o/T06jVx8T0BS4yTw8orqyLoaJH9MOiWjbAI= 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 1709624289357845.5991783587955; Mon, 4 Mar 2024 23:38:09 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rhPMj-0006X8-QU; Tue, 05 Mar 2024 02:37: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 1rhPLu-00067p-FM for qemu-devel@nongnu.org; Tue, 05 Mar 2024 02:36:43 -0500 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rhPLq-0005r7-VH for qemu-devel@nongnu.org; Tue, 05 Mar 2024 02:36:41 -0500 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1dc49b00bdbso48092875ad.3 for ; Mon, 04 Mar 2024 23:36:38 -0800 (PST) Received: from localhost ([157.82.203.206]) by smtp.gmail.com with UTF8SMTPSA id l12-20020a170903120c00b001db66f3748fsm9750555plh.182.2024.03.04.23.36.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 04 Mar 2024 23:36:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709624197; x=1710228997; 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=dNi2CODBILcZJ3pornZRE2FYjihFpsMHPvoOvkX8mDc=; b=YJtnwlH3TYKARwQTedLbVGSQNeuwx3NugHPWQEbXR9HAgvfr4S5Ux1bH/HQh1LVm8g BBM8RWo+28/fbIjTOQ2i6+U3xigRqWoN0RbC88ZHZQ2XrEUKqX2L4MS9FhQXFF6gAawj C9FrejFF0DWKeAQCkSNjTvLUR3wCa4O6LC2VI4bPrrt8Q2OKxfkL+EgcOJpyHkXgJ0R5 2GtxM+aMunFPcXUSfxU9mPEPGcFQwKvdRdbBmGPPXK8M2FdcSHF352jQf4DpIEXzjFPq 9opAnrFlx2krO+FOoFfAPaYk3ObELggUEKS9d/2HTQ2E5Umc3LtsSLQS5fC8hParGS63 QVLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709624197; x=1710228997; 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=dNi2CODBILcZJ3pornZRE2FYjihFpsMHPvoOvkX8mDc=; b=uUlAbyo3BT8omPjxl2JW5ujbX8f3p0UmlHSYbCPKWKd37iui/lD5zoYkR2nZ77ck6v deF3rELXwm67PSDt6G9J28G77hDrqHITpFmBlGT2z36ITMa131rrUUgxiprc//2RHpdk gdgxAfXwfR55+xW4r55ptF8qIcZ7qb8WxSU/OWOHWWRAzIPhcSHyd/wTVJ3YWnqCB8Sw zsbo5Bc1kBSYMa23tvkQljATCNCn4sviHu4h10cp/aUfvR9SHr0lveD/CMYwM7AMrZta xZ5p5gwKuEfuA3oP0xyiy2leukOk1qWrW0TNMAXmyIlS9rDIZ6gl02MGVjFyfIh5Zx4k MCJA== X-Gm-Message-State: AOJu0Yz2xuJ+paP6CT/QYBh86lX/h0PagUnMW5h13VulDinkwO38fby7 A69XuVixNjS2rgu+0OyI9HC85GXdZgJZ5cWYOHxnBzfTO/F2tm9fInY8RLTdZ3tC2y3oPhZmSiC b X-Google-Smtp-Source: AGHT+IEjw1wkFY0spBfs/nxee99IMG11NMdPDQs85sISzCkuBEVDYT6GwkbtvzNIejOc4L7hd3H9FQ== X-Received: by 2002:a17:902:a514:b0:1d9:7095:7e3c with SMTP id s20-20020a170902a51400b001d970957e3cmr1002127plq.57.1709624197590; Mon, 04 Mar 2024 23:36:37 -0800 (PST) From: Akihiko Odaki Date: Tue, 05 Mar 2024 16:36:20 +0900 Subject: [PATCH v2 03/13] 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: <20240305-elf2dmp-v2-3-86ff2163ad32@daynix.com> References: <20240305-elf2dmp-v2-0-86ff2163ad32@daynix.com> In-Reply-To: <20240305-elf2dmp-v2-0-86ff2163ad32@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::62d; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x62d.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: 1709624290538100003 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 | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/contrib/elf2dmp/main.c b/contrib/elf2dmp/main.c index 9b278f392e39..89bf4e23566b 100644 --- a/contrib/elf2dmp/main.c +++ b/contrib/elf2dmp/main.c @@ -336,7 +336,12 @@ static int fill_header(WinDumpHeader64 *hdr, struct pa= _space *ps, return 0; } =20 -static int fill_context(KDDEBUGGER_DATA64 *kdbg, +/* + * 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; @@ -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:42: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=1709624235; cv=none; d=zohomail.com; s=zohoarc; b=Mjjb6UucRhYF5SLGy7nneep9MB4B14mp6DArQ6MkuvUv0qYjCnWQqopODYQkM4LoEkWXHPKnKutF6feDFRnKuQCbtMlgUsKxO2mwvtgOFv9Nfy7QnRIu/teT271fcy5TCE92STwwL4+D6P3aI6kPLiLgvttxklCBcv1XoVR++Cg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709624235; 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=dwGsXBpC+XXtpI/9XX8zmAjUVw+s9LJdBLuOAnq82co=; b=PU1lSSpy71Qabi1d2gScLwRnJnsFDSpYm2HRSDb+LVkCsZCRJ5bAtJER7s6xmDYD4YsVnKvd9y8dSEEjwnow9KXSeFn9byuz2S7DB/H/hD/diVx9iD3wHWgTGi6bT9HoIMf5f1JdycaCWQRAgsIQhhK7FDjyotVZluemaOfleDE= 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 170962423597939.03220820692957; Mon, 4 Mar 2024 23:37:15 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rhPM9-0006AF-0R; Tue, 05 Mar 2024 02:36:57 -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 1rhPLx-00068C-2i for qemu-devel@nongnu.org; Tue, 05 Mar 2024 02:36:48 -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 1rhPLu-0005rG-7w for qemu-devel@nongnu.org; Tue, 05 Mar 2024 02:36:44 -0500 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1dd01ea35b5so14370355ad.0 for ; Mon, 04 Mar 2024 23:36:41 -0800 (PST) Received: from localhost ([157.82.203.206]) by smtp.gmail.com with UTF8SMTPSA id b8-20020a170903228800b001db81640315sm9762433plh.91.2024.03.04.23.36.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 04 Mar 2024 23:36:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709624201; x=1710229001; 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=dwGsXBpC+XXtpI/9XX8zmAjUVw+s9LJdBLuOAnq82co=; b=WSZV5j4qRP/IwelPqr9yjfuZ46YnqIIwr9FFUV9PVfgMuyqJmec1WUURUMQonFtE7P BxqQTHvuMp5VZH75cHX6ZitPx9nzT76/t/NjbXcasj1xJVEF4sW05Z7jeSytlw1gT4ft 790yajdd+dbDgcsj9mzDzi7aCpPrAwU8MWVxR1G+MR7G95+g8IumYtpsoApxAYyNXI77 xvPHAhJ/t30wUEKFGHkb9y+UwYqWKa5StcuMd+mCfUFuig7bVhJEhYtN2VgosvDvjM5Y tfuuzt6zVmnljZ2A444C81iAV6YdQDVqXSC8OeZL5/wTV7AuCkpzHlU5QPEQoC7mOz+M anlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709624201; x=1710229001; 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=dwGsXBpC+XXtpI/9XX8zmAjUVw+s9LJdBLuOAnq82co=; b=eyOWhCFP+MFRQO7uPIzWgZsZ2b58TRWC6ELlBWJO21KeL+E32bSh1Y/NgUw6yyP4dh 158Rl1c47nqnVAA2PQ01tfdEPW5qKiL183a17tYwkAbBp+ezvduEdbQdEm3jv1SAMErU EHMIwAc5Ztw2yviylf7vIPMXELovB1P0GtqCivS6iODYliJH3+i/7BlmjyVzK5qXln6S YqvHlI5zjSFoHSAsHTwLDxKXyYA/IHAYLbC04AaZPGb8oKg4MCj3XDO6TpZGAQHKJgBc hDtm8QYw39b81BSRNVCLvSKs7hkaHYS+0fqWttQuzl4kxGDVbAw55AIEN7Ssj1YlCmSc 2AhA== X-Gm-Message-State: AOJu0YyKecfZHO2GKHbxcOrBe86GcuwdcNtFLYncqLCHfnn9/WnRVxRI 97SoYNTrtKZo/dOCMiSB4Rr0cyfyGR089mnb99gOP9FfhnucptPidnasu6bpGmOY+T21GD7PRMB N X-Google-Smtp-Source: AGHT+IEifg8ly89hMFsPnJb1JPFtVToCwCvHBbYZn0pOC0mCxTUDHx2EZzCvXO3lBupd0Znq13XLbA== X-Received: by 2002:a17:902:d503:b0:1dc:696d:ec6e with SMTP id b3-20020a170902d50300b001dc696dec6emr1021143plg.21.1709624200647; Mon, 04 Mar 2024 23:36:40 -0800 (PST) From: Akihiko Odaki Date: Tue, 05 Mar 2024 16:36:21 +0900 Subject: [PATCH v2 04/13] contrib/elf2dmp: Conform to the error reporting pattern MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240305-elf2dmp-v2-4-86ff2163ad32@daynix.com> References: <20240305-elf2dmp-v2-0-86ff2163ad32@daynix.com> In-Reply-To: <20240305-elf2dmp-v2-0-86ff2163ad32@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: 1709624236329100002 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 | 6 +-- contrib/elf2dmp/download.h | 2 +- contrib/elf2dmp/pdb.h | 2 +- contrib/elf2dmp/qemu_elf.h | 2 +- contrib/elf2dmp/addrspace.c | 12 ++--- contrib/elf2dmp/download.c | 10 ++-- contrib/elf2dmp/main.c | 114 +++++++++++++++++++++-------------------= ---- contrib/elf2dmp/pdb.c | 50 +++++++++---------- contrib/elf2dmp/qemu_elf.c | 32 ++++++------- 9 files changed, 112 insertions(+), 118 deletions(-) diff --git a/contrib/elf2dmp/addrspace.h b/contrib/elf2dmp/addrspace.h index 039c70c5b079..2ad30a9da48a 100644 --- a/contrib/elf2dmp/addrspace.h +++ b/contrib/elf2dmp/addrspace.h @@ -33,13 +33,13 @@ 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); 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/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/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/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/addrspace.c b/contrib/elf2dmp/addrspace.c index 6f608a517b1e..c995c723ae80 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) @@ -228,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; @@ -240,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) { @@ -254,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/download.c b/contrib/elf2dmp/download.c index 902dc04ffa5c..ec8d33ba1e4b 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 success; } =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 89bf4e23566b..140ac6e00cfe 100644 --- a/contrib/elf2dmp/main.c +++ b/contrib/elf2dmp/main.c @@ -79,7 +79,7 @@ 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, + if (!va_space_rw(vs, KdDebuggerDataBlock + offsetof(KDDEBUGGER_DATA64, Header), &kdbg_hdr, sizeof(kdbg_hdr), 0)) { eprintf("Failed to extract KDBG header\n"); @@ -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; @@ -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 @@ -226,10 +226,10 @@ static int fix_dtb(struct va_space *vs, QEMU_Elf *qe) 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 false; } =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)) { + 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 /* @@ -352,8 +353,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 +364,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,15 +373,15 @@ 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; } } } =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,40 +394,39 @@ 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; + if (!va_space_rw(vs, base + dos_hdr->e_lfanew, + &nt_hdrs, sizeof(nt_hdrs), 0)) { + 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; + if (!va_space_rw(vs, base + data_dir[idx].VirtualAddress, + entry, size, 0)) { + 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"); @@ -434,7 +434,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++) { @@ -445,11 +445,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, @@ -459,8 +459,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; } @@ -470,9 +470,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 +487,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; } @@ -538,28 +537,25 @@ 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; } =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 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; } =20 printf("CPU #0 IDT is at 0x%016"PRIx64"\n", state->idt.base); =20 - if (va_space_rw(&vs, state->idt.base, + 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; @@ -597,12 +593,12 @@ 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 - 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; } @@ -617,14 +613,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; } 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) 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:42: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=1709624267; cv=none; d=zohomail.com; s=zohoarc; b=lUnGNGgO/Adv9PV6kNQ7m3SJmh3I3ym0Fsh0qQ40iuBICszmGHMtKPsLQzrJHTC87WoTC4MSggv7ggiat14aBeJmdjXVcxSr36B2jv6jbnTtb/TBDnKhzT3HO3wS4tgAeNYrkeT4EoNPGTmUIFcOXL5ppi23z4HGnskh0+4BOjo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709624267; 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=6W1zD/8uLpCTCiaWLd6Xa/456MMTWCq7KFm2ch3UxRE=; b=GgAFW9iBJ2pN9q+6XRVvQRLODjqIB5z2b437DFL54+XqZlnSpgb9EncxK9aqojPBLLeyQYlzHgzSGl8ZBMevAQ+MgyYnvPQ44YRz7zL2IAn2rWZ1lx2rWsExP7o4Ubpa8QmFTqkA/vUMM2CkwjCGp69LDuNAY8Y7uytbKVIlagE= 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 1709624267840680.5734414879087; Mon, 4 Mar 2024 23:37:47 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rhPMj-0006Y2-VZ; Tue, 05 Mar 2024 02:37: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 1rhPLy-00068J-LK for qemu-devel@nongnu.org; Tue, 05 Mar 2024 02:36:48 -0500 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rhPLx-0005rT-40 for qemu-devel@nongnu.org; Tue, 05 Mar 2024 02:36:46 -0500 Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-6e46dcd8feaso256654b3a.2 for ; Mon, 04 Mar 2024 23:36:44 -0800 (PST) Received: from localhost ([157.82.203.206]) by smtp.gmail.com with UTF8SMTPSA id x29-20020aa79a5d000000b006e3f09fd6a4sm8558372pfj.170.2024.03.04.23.36.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 04 Mar 2024 23:36:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709624203; x=1710229003; 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=6W1zD/8uLpCTCiaWLd6Xa/456MMTWCq7KFm2ch3UxRE=; b=bicB6OjJwL6Scpy8afptD8MEZaNuqZOIeIgtdg9Lt8E6ZitX88OCn3vE16gLniZwdg tT/EfmbXiA5X+Np/8XZniPi2l/8EWARVMIJzv133qzwT+ZQrZJgq/rMQVQkTTme1JW4U /ihgwEZYLhEO25m+kT0r7dNOgUWh2NzVP1XadpNLJjN1khWjSugDoVlB4uh2lrhaBSP6 /kMmulcH9s8LgNt0rak33Uas5PdYLTCcnlaFz5JnYTndfg1cJTUs/KKpgpXK6I1nHu10 0aLsxVS4DHGx3QtHBwK2efh0wx32j9UcPCkPbx0RapwroEx8zHQbPkgnsMV32JFnGKKN HMIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709624203; x=1710229003; 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=6W1zD/8uLpCTCiaWLd6Xa/456MMTWCq7KFm2ch3UxRE=; b=S3utQnRvp3ADj4UbCqnWEbElZxDev1fElPVRSr+tYHmwNnLkXKY0sToJ3TNyjJBGxt BM/vnvnJXTUqRyW7IANlrJyFwKUPv5YtYJlxbvb57xmGwG+5Qw7l7awZF4VvwS+YmCNP QkW3DUoFIH3M2TRFmIY9SHQYHHd6HsfGC8FhwrpAFX79xumMJekpfqYSDrSvEl34A5Ow BbPGdhVnI1ypDUgQRTsUqn55U+gAVgiW1PfbC7SzQDOAOiCaGvOT38ySgM/o7EGk7h9T uPRa80wHS2OXjdyLM9by4jfxFRJN/QMo0NFtyAzVvjUjcpBapgQA40+0fsWgaUQmbjMl CQxQ== X-Gm-Message-State: AOJu0YyQX58f61HpTzws3aA5xaTNUPds2mcX7XQwor4QEJ3K1sOzZes5 Yd+t0CwF1d4TX8We9CLgozgeSY6RhKn6Kn88R1UIszO5PbVtDOp8PeHzlmjy/+UkSoW0NdHRVQt c X-Google-Smtp-Source: AGHT+IHtVJNQXYKW6U8wBfnPulRZZwrAdj4fkR6CRZ9kLD52CODxLMuOVL0WDLtZoCM/4REvgNZtwg== X-Received: by 2002:a05:6a20:da8f:b0:1a1:1fee:5fea with SMTP id iy15-20020a056a20da8f00b001a11fee5feamr1196246pzb.12.1709624203672; Mon, 04 Mar 2024 23:36:43 -0800 (PST) From: Akihiko Odaki Date: Tue, 05 Mar 2024 16:36:22 +0900 Subject: [PATCH v2 05/13] 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: <20240305-elf2dmp-v2-5-86ff2163ad32@daynix.com> References: <20240305-elf2dmp-v2-0-86ff2163ad32@daynix.com> In-Reply-To: <20240305-elf2dmp-v2-0-86ff2163ad32@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::42f; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x42f.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: 1709624268408100001 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:42: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=1709624324; cv=none; d=zohomail.com; s=zohoarc; b=TpSBy7K5OORGPUEpknwatW7HmzxnPq2ubqGVh0D/kctNDrlF8QrAOAyRU+lcrAlVb/RVseT5BanfbkMaUzOXO457SuGOwC5/dYERJ/hsyvINh0rtC1DaReZkX4MBZ6mvFagODYcfHgDcrAre6Uk6dPgIhXN8Men76tVQ6fSSqYQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709624324; 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=4K2x48hCLz15Z0ohdnVCY+8gn/iTK7Pup23XDb2mA5k=; b=jwczdNws9abzClKrXYajERqglAUQpo+b/P7TSXeHDUAwUoDGIcb96YPQojJxgtNHMeNXJKZ+u20WHCEYF8bQUYxgOiFv9ZqXnX3W+sz00mywIKKvkz81t3CH+/lELqxyCm108G1VnbCo3yko8TjTXOxRHUrfe8Oj9ZwqVGkErsY= 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 1709624324397315.92209808456994; Mon, 4 Mar 2024 23:38:44 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rhPMx-00075I-Ct; Tue, 05 Mar 2024 02:37:47 -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 1rhPMJ-0006Eq-RW for qemu-devel@nongnu.org; Tue, 05 Mar 2024 02:37:13 -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 1rhPM0-0005rr-KE for qemu-devel@nongnu.org; Tue, 05 Mar 2024 02:36:59 -0500 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1dbae7b8ff2so24450195ad.3 for ; Mon, 04 Mar 2024 23:36:47 -0800 (PST) Received: from localhost ([157.82.203.206]) by smtp.gmail.com with UTF8SMTPSA id c5-20020a170902d48500b001db693d89fdsm9801068plg.179.2024.03.04.23.36.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 04 Mar 2024 23:36:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709624206; x=1710229006; 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=4K2x48hCLz15Z0ohdnVCY+8gn/iTK7Pup23XDb2mA5k=; b=B7MQ6KHRANffWda5oEemivhrpN2wQBCZ3Bp/OqASv1RsYOnBzxKroaOirqVZvDz67E GuELR2AaXCyp4tMWE7OM4dpwMyadXN/jVgHkXAgfD9+1pwDUuOUf9X2chLYtjEanHyEc vOSe06DpvjU6eeIkM4Cc+5zhdsrGMRpDdmR+bwh8Pdlwb5p7awAjLnJUDiXOfXhz6Cxc +csvH7ouimHMe31VhYKXsCCqXWPd64g5ocOcclh5M9VAR9ColloI031D6C17y5Yh8zgG gNipTWhuBzsiBDKQQ3uFF5Z+gf7f6CZwpMS7tZ1qiEZcUxAXy2VT4ngEU75Rv/uYOYUG dpsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709624206; x=1710229006; 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=4K2x48hCLz15Z0ohdnVCY+8gn/iTK7Pup23XDb2mA5k=; b=nuOH86H7rQYyJIl2Nl22Ezh5KG4cLnu7iyTCcYfZaKNB+dXontQ2jCmuDGANBAJJeS VPXjcBNDNdj3F4Xs1N+XtQ5pOJJPosrHP4yL3GsTxeyMP9fl5cnt4XJFLSdrAV7Jyj7M l9zWoePwJWsmC6AJv07i+ZZIPwn94F7ztQl2zWSIoafsLs7Upt8c7mWUGDO6/41u1fHT MLjB+rPjtbLH9XK2IiPg/EgxNKNZm7TOCiQZ55NyBrrwUYmT/Z7H+bu3pFPTd9ZJoGeJ Dg3iT+5j3wQo1Ia+OQlr+R4oqjxUDP9R94yyA3J3gcDB5jZKtws8IpiwGA5Mg190qPYt IbTw== X-Gm-Message-State: AOJu0YxKz+BvojeSRnuf6s5PQxpZ24HAhzvfW9VecM6sTtfbuXyppt5x J98f+wBcPc/ScXY1DclW1UgVones1BxogBfDB70CVIgj9HyxOpKaa/OKrrkTg0ZrfcwFUfq6Sol w X-Google-Smtp-Source: AGHT+IFhBmrVRJBwrGq//M6YuscsskLRUFHK1JNrL6teAky6kDTiFNUegy77uyzKmRONX/P2Pon2PA== X-Received: by 2002:a17:902:dac7:b0:1d5:f36c:8737 with SMTP id q7-20020a170902dac700b001d5f36c8737mr1042755plx.68.1709624206502; Mon, 04 Mar 2024 23:36:46 -0800 (PST) From: Akihiko Odaki Date: Tue, 05 Mar 2024 16:36:23 +0900 Subject: [PATCH v2 06/13] contrib/elf2dmp: Always destroy PA space MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240305-elf2dmp-v2-6-86ff2163ad32@daynix.com> References: <20240305-elf2dmp-v2-0-86ff2163ad32@daynix.com> In-Reply-To: <20240305-elf2dmp-v2-0-86ff2163ad32@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: 1709624324669100013 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 140ac6e00cfe..25cf0fdff724 100644 --- a/contrib/elf2dmp/main.c +++ b/contrib/elf2dmp/main.c @@ -550,7 +550,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); @@ -635,7 +635,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:42: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=1709624308; cv=none; d=zohomail.com; s=zohoarc; b=fbfCp38rFuxBKwMID76aVdcc56igg7ba3a8SqIPLK+fH81riBuNdgF1RvPisxXsiSRCmmyG0Ywyz34i8VEs5c7ApBxbRQ0a0pljUA5/c4gaILiQy7m/opfxZcMb+auUGy+42FwBuI0fHO6qDeSNidQ4Z7bS5flWFH0QnTHGzYdU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709624308; 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=9OhDS/T3Gx56oShsQS7FHNcWODYCE0LjRwel+5jTWOY=; b=REdfI2w7yy8WYOg81qcaHrxhFBnpH/NQEoBVphdKdQCdbiC8u8RIpr/jiekjCRMNhfpaV2S42VCH9hZAw00GYNHjNiCnBtdJ/7wl2+w+PsWzBsk+yKzLgTVnvGAYixbQsZwI+UGbCzTCt+NTFIheWr76hgb9pTRjnJdDe9tBKts= 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 17096243085971016.2454514372916; Mon, 4 Mar 2024 23:38:28 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rhPMq-0006mC-UR; Tue, 05 Mar 2024 02:37:41 -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 1rhPMK-0006Ho-W7 for qemu-devel@nongnu.org; Tue, 05 Mar 2024 02:37:13 -0500 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rhPM5-0005rz-5w for qemu-devel@nongnu.org; Tue, 05 Mar 2024 02:37:08 -0500 Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-6e558a67f70so4786006b3a.0 for ; Mon, 04 Mar 2024 23:36:50 -0800 (PST) Received: from localhost ([157.82.203.206]) by smtp.gmail.com with UTF8SMTPSA id n39-20020a056a000d6700b006e57defe737sm8396506pfv.76.2024.03.04.23.36.48 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 04 Mar 2024 23:36:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709624210; x=1710229010; 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=9OhDS/T3Gx56oShsQS7FHNcWODYCE0LjRwel+5jTWOY=; b=GES3jGdo7vtoyjckvE2PiNCxm8VSDSmslI/KJDynJRLOVAUMmyHmBYIr1skGzHEA1N SqWxREhqILxf4qA/eaeXYqXIsbiL49nnTU9LH+aZUjHymwq97LF5jSY8vVU7uV0Rsng/ sqPSLxuSZYMY341d1sQKg09/xUxWC12Xt9iFoxbTwPFDb8qkVs5dkBw/VcBaMoyjJ2NE GZ6JC8pF8aRd9qO4NOrJgOJ9oQGLj96l5pmwjyMVII/4XP5Ht++Q3DF14doddGMCQUzq wqiKELOykiLbOBW3Pn+zxdxfMTdBfEeMVpS26tUu+Gd3/HWArlj28O1vedkn/ZLZ0i7N Is5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709624210; x=1710229010; 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=9OhDS/T3Gx56oShsQS7FHNcWODYCE0LjRwel+5jTWOY=; b=Mp3lX1PksEEoQ556Rc6+a5O/+QEHwM2/pTqP3nBeDj+ucBp6h+OipWdzdHClvMJkWU /8BtjUmZuUfM4H0dQHWUst9bJerPRE+mN9mPNPciJ+aaUlX8Hln7ZsliDaewCKq87v9E RkuRq/XBqDh08K7qiG55C+q6VXX25vKHJvC3RFeh3sVdfUfq2bKAq4ZkIqEV57dKQRdy He/uQ392WpvC0RGwK6wNo0EwkJLOVi9H6BClpwLrX3P+6EQLdEupvCB5Rh0d357XouCR kBDY1tbtJ8u+YD1HGb5amQKgVxOiim1cZfjLVVewsK5phvUtimeEoat6HcsUdZVkdBZJ lUDQ== X-Gm-Message-State: AOJu0Yze0GiCx/iGFsoh36JfkVazi9MCZpY5hWGPHPpqEU2bW/aiLQlW 3QoyyVH6tBb+LcT6Czy/cJ1fek16kSS8ti3xnxaoi0Mxa8Ce1s0AVVlbQ0q9SBKNaZYXUmpzGm0 q X-Google-Smtp-Source: AGHT+IGvYv5h8OpOxOyVbmpw8qxtPaafTSUOffqI6gFm6yQErngvRvgJuZJRjrHT/ry/ifp6+sDzag== X-Received: by 2002:a05:6a20:914e:b0:1a1:4b62:a60a with SMTP id x14-20020a056a20914e00b001a14b62a60amr1223095pzc.7.1709624209958; Mon, 04 Mar 2024 23:36:49 -0800 (PST) From: Akihiko Odaki Date: Tue, 05 Mar 2024 16:36:24 +0900 Subject: [PATCH v2 07/13] 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: <20240305-elf2dmp-v2-7-86ff2163ad32@daynix.com> References: <20240305-elf2dmp-v2-0-86ff2163ad32@daynix.com> In-Reply-To: <20240305-elf2dmp-v2-0-86ff2163ad32@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::435; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x435.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: 1709624310591100006 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:42: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=1709624316; cv=none; d=zohomail.com; s=zohoarc; b=VsN2B75aLIqhPn/pDCg3S+gpz5igA2cavvu/E8hdHA4Br5Y6E16jlawMzlca+oy0g8rG3O40MpUk4ByTBxu98rGeEoE6hTxR2o1MQNnI/Wq0vtDZoAONIP2H2APF0i9zfY8qH9IZec3a81QxqHXe2/dEu+VyS2FpUngysjK9E9M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709624316; 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=47srLypA6/YZhwYJRpgA5+2zCaB4IopvknN5bNT/5jI=; b=hsNjHKOVUncOzT199v/Z1j9qR1MWLXWrCRWeICc27h6qG2Uy2W4Sl0xuKwseDndcssCWqkAA6MnSJN6H6c7FsW/F72HTw44hx2lNCq/Hs8b3VPWPAq9DALCVhgu03T3gDj75jebNnzeKlqmTo2NvzCKghv7Jo5q3Md4Uvg8PKlE= 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 1709624316734819.4857574060557; Mon, 4 Mar 2024 23:38:36 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rhPMp-0006k1-Ry; Tue, 05 Mar 2024 02:37:39 -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 1rhPML-0006Hp-0C for qemu-devel@nongnu.org; Tue, 05 Mar 2024 02:37:13 -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 1rhPMF-0005s6-UF for qemu-devel@nongnu.org; Tue, 05 Mar 2024 02:37:08 -0500 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1dcd0431f00so33201445ad.3 for ; Mon, 04 Mar 2024 23:36:53 -0800 (PST) Received: from localhost ([157.82.203.206]) by smtp.gmail.com with UTF8SMTPSA id t3-20020a170902b20300b001db5e807cd2sm9786767plr.82.2024.03.04.23.36.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 04 Mar 2024 23:36:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709624213; x=1710229013; 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=47srLypA6/YZhwYJRpgA5+2zCaB4IopvknN5bNT/5jI=; b=Snuk7rs2nn/ipUN/T5TuuEf3KJo3EDwQlp1al66888IKImVQwXbKcvzjiapFhq39Ad kXrWOEGNPR/6rqcvXvWOiU4pIPAI7tDqUGf5MLqtzNyB9FL9eymONE25DcnGZLiSPmky syg15SVgKKYRGHgCo4Yv+reoM7Avb44+8g9rIZGn2fdMGctJkpawHMjM7n6fwRoxWLex v9iTNPEeP1/dp8IgzDwDdU+qkmUwUfJhMou0xd1cMxbULO4ElyxQ2rsyLmaD8VQ48pHn 1MTErDFlCP+sldFnL+uJveqZR8acGd3cfwWT4dTxIq9QpKoC23FFD6gRiLJ+IRwuyeln 4RYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709624213; x=1710229013; 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=47srLypA6/YZhwYJRpgA5+2zCaB4IopvknN5bNT/5jI=; b=pAvBH1/cxd/nOEN66edi4kXlAV/5MTt2RRrpfQdyW85I1W9eIf5KPYc9bOdqmNFUn8 E9gonhtWxjgIq29okV8Gz4jMNsySJAQUdkjNizpKf88WJym6Yv+OvUrgfRaj4NtIcS8+ OG5m6RoqqrSDCF5yKQGbG7WJmCXmjd8fpZsQyb41vUboO4o6cWHUAwN8+kBCLl3JuC0/ IIknRyI6OmoEDV118hOHp3+kO1Tc+4FTnJat5f5MJtWEM3SyYCf8dIynhCBWEoFPZCaP erl2ZhRW3/pzTzhM8THCXDGp+Rf0tQzFqKPHyh2liORaubqvKH5WlyX9dMJIKh7GfROH 1a2A== X-Gm-Message-State: AOJu0YwZ3THsVru4kJ29RhFlD2itB0ACBdbZ41+wxLyWf8teWMitNO3+ SrhNBpCANlSKZcE1Lq19M3OGwHDNE619cohglrYHmcwfQs4dHbpE7+cLj+cp3w071HsD92RJNvT H X-Google-Smtp-Source: AGHT+IGJy11Yl/cTTakSnu0a8sZSO1jI+ZCpAY2/hS+zTr+xTkFC0seV2zLMAWbrUZ2ltFjCC33w7w== X-Received: by 2002:a17:902:c181:b0:1dc:c0c8:6bfa with SMTP id d1-20020a170902c18100b001dcc0c86bfamr912945pld.17.1709624212884; Mon, 04 Mar 2024 23:36:52 -0800 (PST) From: Akihiko Odaki Date: Tue, 05 Mar 2024 16:36:25 +0900 Subject: [PATCH v2 08/13] 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: <20240305-elf2dmp-v2-8-86ff2163ad32@daynix.com> References: <20240305-elf2dmp-v2-0-86ff2163ad32@daynix.com> In-Reply-To: <20240305-elf2dmp-v2-0-86ff2163ad32@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: 1709624318601100003 This resolved UBSan warnings. 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:42: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=1709624318; cv=none; d=zohomail.com; s=zohoarc; b=P//sKqkxA1zujUL5vCO1LQeGmZPHak61Jg5c5XAJqGmHvFbs16Y7bf6KDAHDZ3dFAqUJS3NaK3IuQtkCYTUbfZaZKoGQKQOoNMUNbjKnHohvlVvmBEST2P1AIaMcrX8Q0OANTTlOA1WjJFqQGlgocAwdQv8sv+J4EOG/2tq/4W4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709624318; 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=i3f3HL5yPh+B2f2TWI8nLswxD9Zg3vmdmgIkTXj+uig=; b=cYK06pp219D6aHNpFJrjd2i1qAz7FceqMAQymYvwOONvnQhV4NNzqVnrh+VSM1a0/mZVi37lZKTx3PPF9wgwfwovX13X4HtByQdl+j1jo9KIsBXkb7VQctp0Jc1SgocRwUujBAj/UQd4vJDVTKbS/I96XvTm5hJqMfj0a4JsCdI= 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 17096243189471017.0113766634944; Mon, 4 Mar 2024 23:38:38 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rhPMw-0006uO-3b; Tue, 05 Mar 2024 02:37: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 1rhPMM-0006Hv-4b for qemu-devel@nongnu.org; Tue, 05 Mar 2024 02:37:13 -0500 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rhPMI-0005sD-FB for qemu-devel@nongnu.org; Tue, 05 Mar 2024 02:37:09 -0500 Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-6e56d594b31so245261b3a.1 for ; Mon, 04 Mar 2024 23:36:57 -0800 (PST) Received: from localhost ([157.82.203.206]) by smtp.gmail.com with UTF8SMTPSA id j1-20020a62b601000000b006e64370ace9sm52664pff.195.2024.03.04.23.36.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 04 Mar 2024 23:36:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709624216; x=1710229016; 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=i3f3HL5yPh+B2f2TWI8nLswxD9Zg3vmdmgIkTXj+uig=; b=xhfoaqbupk9Tgn9DBe5/ySIM3GDph7OazMSWGfXpqB3egpEoqNkdPd5mNli4L+SBdU nnJBZ4+I3+WvuJDfoN+754zU/bGErbuT6nqND4Okh8yb6Vu+dtSX0lBr5OGUGd1gG8qa ZpSV3vaEt0AfhtuFg3qOOloCzAETjA0e2GlWDPmx8TzRgjy7ZRhCZ8Ub09o3auOb6iUa tZKDVSRLITIWhrQHYHlmeM9JwJ2HVq64qfl13TK9Cy/2h3U/mixDjrokctUwGs8OpuPN crhpgvYiNCL7yyMICUhMlwkIEX0n2CSZmtCGUmO/3ZPkQmxhQlVDYSxMhUsq7ESmyfm0 r75w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709624216; x=1710229016; 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=i3f3HL5yPh+B2f2TWI8nLswxD9Zg3vmdmgIkTXj+uig=; b=SD2ODU9Hr0U2MIDfOAW4Y3DhIqQ2SpI2kpwUs9+I12KbSawHQLe/10dAo9o24IR50D uY58u0z2S81lFQhbkKR4hWa7UDU2VvtZXFEUEKRnIADbRuTODraJZd1DNewt10WL1GkY IbAwNFrJWl1tT2lX4WZ+YvL5DJWcuYmqELd34uN+P0kyJWp/427ARCBYHFga/W8qM3TG hQO0Q/O+RQgIYdL3skaqeUjQvqQ0tUfpcED/lLHmOKDECJ9EzlWk+UGVOJrGsPPD1gm+ SSUgpggjHYOIysMQ9/RvDt6J6XHOKmIU1ZVWFJQct9GJEu3sIU3MKfLD32DTAomot7zo juZA== X-Gm-Message-State: AOJu0YwaR+ketQ0OJKFJAOE0Ah5Yy31lKZrNnCO9/e04pvHIhH87Kvv2 mCtnUSCwrLeailJ5GFew+Y6rDb3+9DD1/+Br10xFagua5qcSXLYPy4qkSZ1gfsHcIgPrIYnKIA3 N X-Google-Smtp-Source: AGHT+IHTkLIkjVo41zPM6rMVfI6Pw4doPdq5mpKXgGn0terhyFFQZsUnHkt4nT5wlvNe6ad0kDIHHA== X-Received: by 2002:a05:6a20:748d:b0:1a1:4bec:4841 with SMTP id p13-20020a056a20748d00b001a14bec4841mr1084100pzd.25.1709624216342; Mon, 04 Mar 2024 23:36:56 -0800 (PST) From: Akihiko Odaki Date: Tue, 05 Mar 2024 16:36:26 +0900 Subject: [PATCH v2 09/13] contrib/elf2dmp: Use rol64() to decode MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240305-elf2dmp-v2-9-86ff2163ad32@daynix.com> References: <20240305-elf2dmp-v2-0-86ff2163ad32@daynix.com> In-Reply-To: <20240305-elf2dmp-v2-0-86ff2163ad32@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::430; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x430.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: 1709624320639100007 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 25cf0fdff724..20547fd8f819 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:42: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=1709624320; cv=none; d=zohomail.com; s=zohoarc; b=Z/SvLwUvqDzQTbxKHSHG6SahRkrLWNbUOfH8a50yzT+Kn/q1n5D+Ejxc+pyztpjvC7pgUtBmvBHSpfaW1fIs4A7F3qbALq5xp/3ku0lSrClHc6Ec8A8bLvqCB27uS7RNC3/pCQ7W20W0j42YjQXP7DFAmjXkgwYB/TzNCsil9IE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709624320; 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=mnQkkfEPShhxU/vlxzjdDbkbMIAQY95DFHtbqDX4ZgNSX8hT+4hMIdBrJjZ0ZVDfas5LU+Oe/ZAefKQBE1WYJ4eiUTv2jeqIlbiwMZusmxRS988pZ2hrriPoryTAWGZyWetL8Dtc42r+FHr3r1JGnuoQCcHuvNOkUdOKiG8DBWI= 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 1709624320610958.9960771846253; Mon, 4 Mar 2024 23:38:40 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rhPN8-0007Nv-4W; Tue, 05 Mar 2024 02:37:59 -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 1rhPMM-0006Hw-5t for qemu-devel@nongnu.org; Tue, 05 Mar 2024 02:37:13 -0500 Received: from mail-pg1-x52b.google.com ([2607:f8b0:4864:20::52b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rhPMJ-0005sM-Ku for qemu-devel@nongnu.org; Tue, 05 Mar 2024 02:37:09 -0500 Received: by mail-pg1-x52b.google.com with SMTP id 41be03b00d2f7-5dca1efad59so4541848a12.2 for ; Mon, 04 Mar 2024 23:37:01 -0800 (PST) Received: from localhost ([157.82.203.206]) by smtp.gmail.com with UTF8SMTPSA id y6-20020a17090aca8600b0029a78f22bd2sm8124675pjt.33.2024.03.04.23.36.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 04 Mar 2024 23:36:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709624219; x=1710229019; 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=Oa/PNbwF0SKj7KXehM949DEN8a4XMJX3C4a7bnrxEimthsivB4hr4B6txDVxfXq5ta eIukSgo4nrRAcKVM2EoaC/eaL/n6ILPsESf0+r5c9WhU/Fi+jKBHJ9ttPYTg2dkAu/1h /8PcVBRZE/TYzJh7h8Waos2BG3DiyhJo8Od+1YpfO+XMwqB9/QHuj5U0uPs/qdDl+qW1 JktzpLsHGqlThMnSoSuh8FUfcjz4sDNr9lm78HpG76jrE4w6XNAiZzsjW3Lzb069fno0 xSCHveD+zsGVOO5xpWyen90xpfYkrAw22JfLMM0rJ3BF2Nf2524I3vgaGQIN1aQYxHVO fGXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709624219; x=1710229019; 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=IKhW9Jr5Gi/19GBuNGiGj+c+gjBZmTuvF4BSUG8+fcY3VqoCM7G3Ldj6XCwwaCYcoE 2PcMpEa0s+pHY+z7W0ldGNfQL3iGDkchVWKApbwz3Tfm6T2AelMsmRPuHiUzOkknkmfG t50bg/5MuVLlqh7F+4U5fNqfZYHqcvbKDBvI5LWIydAXucN42/qsn/t40oBq0tZr0cKX 6LvRakjXQnScPMSGEVg1JARwrRzUudMZlmS1iRNPPR5E6SCauSRG8J3iAB8dNTtZ6Yn8 BTUfuSBy+wUoIRoJBTuL/RTOzQklRO0EyE9tEyMyQqg7hjWC53uqe8ZFnco0+iukC2xy hLvg== X-Gm-Message-State: AOJu0Yx/kVp1CG2sgw9greX6QjLpdfDTr1CHIvPU8a5hRN9oODWV63Pb Rwmd5+WJnABrexR8viUvZbLNSont2/7o6SJFb1xRLe6BiX57i5xx8YUWdbYS+CRvmv05dEYCPWZ E X-Google-Smtp-Source: AGHT+IHjk9iVqVIqU6EKZxcZdf3M9FaxuxcKrK/ZhPjapLKmcZ8yCjDFAwcMKRLQTQs7g0ili6EX1w== X-Received: by 2002:a05:6a20:394f:b0:1a1:4e6b:185f with SMTP id r15-20020a056a20394f00b001a14e6b185fmr1246781pzg.25.1709624219253; Mon, 04 Mar 2024 23:36:59 -0800 (PST) From: Akihiko Odaki Date: Tue, 05 Mar 2024 16:36:27 +0900 Subject: [PATCH v2 10/13] 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: <20240305-elf2dmp-v2-10-86ff2163ad32@daynix.com> References: <20240305-elf2dmp-v2-0-86ff2163ad32@daynix.com> In-Reply-To: <20240305-elf2dmp-v2-0-86ff2163ad32@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::52b; envelope-from=akihiko.odaki@daynix.com; helo=mail-pg1-x52b.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: 1709624322644100011 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:42: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=1709624308; cv=none; d=zohomail.com; s=zohoarc; b=XxK8UZf32Mpg0293M1Rl4tfZsI3Py1U0yfepj7A+t7H0KayAcY4Tlwu7BaX3tNAuAW/2zWp9S0WL/d8r65WZVtX8Wh16vfyDauOICnM25+jWOEiJH0MzfHFpxseyYbURPf/cv92to6YXi8woWGSJAqQSAOkexXucczJ7sdinkgE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709624308; 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=oaZOxuMruCzpX9cG/05AqpvWpWeh3L71YtF+WLnYGuQ=; b=Nbu/kWhkE4PqwTBve//c5sJH9D7ChT4uZRzEk2uo7v4d86oJtYQn3p/iEiay/RJVmP2pPrJ2zvxaf6K1IQjf6+WJDcCn7WtZx0tetBHN8vW1Va47x3oEiukVqny5CU+DkfrMKF3CP5Sx1LZMerCgznuwe6PZUuTghAgMyjJD5P0= 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 1709624308493849.3415830576101; Mon, 4 Mar 2024 23:38:28 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rhPMw-0006xS-4Z; Tue, 05 Mar 2024 02:37: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 1rhPMM-0006Hy-85 for qemu-devel@nongnu.org; Tue, 05 Mar 2024 02:37:13 -0500 Received: from mail-oo1-xc32.google.com ([2607:f8b0:4864:20::c32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rhPMJ-0005sv-Jz for qemu-devel@nongnu.org; Tue, 05 Mar 2024 02:37:09 -0500 Received: by mail-oo1-xc32.google.com with SMTP id 006d021491bc7-5a0b1936400so2462888eaf.2 for ; Mon, 04 Mar 2024 23:37:03 -0800 (PST) Received: from localhost ([157.82.203.206]) by smtp.gmail.com with UTF8SMTPSA id i125-20020a639d83000000b005dc5129ba9dsm8564842pgd.72.2024.03.04.23.37.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 04 Mar 2024 23:37:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709624223; x=1710229023; 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=oaZOxuMruCzpX9cG/05AqpvWpWeh3L71YtF+WLnYGuQ=; b=D/OO7UprfeihY7W4L1cvUSN3/EnS9V9z6TFOoh5W7w0lcb7kf9zwLvOzLLeJBUZdGA Xv2pjAIWWtoqKaJiwxMn3iE1st3ptUTYtGKkNRPi4aUM/UVOZ3R7x0t6RV58AO98y++w obKs2cukktB7iyrOC3/bmaEM7rlMPZwEpB8mUq2VoWm4iWsFHJorYlMRn6KTFim/9IVI 01jL/+yAffeDU8XGSr9MjqU6/yNRVj2na2wpmC2P3Q1dW4wiqBm6t5bXANtd7CWZFtuh 5UzGRwiqVohIJH+NcCZPgn49FnDAM0T0Mn1h3ak2Uf51Tadg1s24H0UBtCzxAStBxLeM inoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709624223; x=1710229023; 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=oaZOxuMruCzpX9cG/05AqpvWpWeh3L71YtF+WLnYGuQ=; b=CuoXE5Rxg1YTguMTieXayZEKRnkLbOfd6nM8rHerSFpy4O640DaIkCq9U9Vx602QBc Dsek/DVUtLBWwXO+1wwqlbWbWjJdrhSZPb4MLBXsVpKT8jY9ogishye5yYmBesMuUKnN a98XPuyanBH54GFAut/t1F5xCS0Tqj5ata25g1NYZXJPfnss+7b/DG0yMlDADLO9IhEX ejIyCXtqGgr1QbApoRWuZUz8Q5RXq9qO9QzW5k7sdrBGYHBhYuSYEERjOo76AhkzzuEK cRjzO53RnAqu0udSaUSsf9xnthsvJXD4SvUUoESz0Tme6W3KgPHmfJRO6g1Cdwhr5BDD 8fPw== X-Gm-Message-State: AOJu0YzUGpYmmR8Ek2fw9XAXiX27WKnPcXvFcyxKme4JX18hpt5I9HN6 KIErfqu5L8hVjrvYgz4syEuI+F23EKN00RZewJyD0RUzx0KYu9KGtVBJZU70dqs3nZoMO/x8skB d X-Google-Smtp-Source: AGHT+IFD5V9C+rYlvE7xfnzq62Jhok5FWGVhkrdtetfQdPkAJsCibYir0qzDD/g5wLhA4zYTdyRSCg== X-Received: by 2002:a05:6358:7e42:b0:17b:c797:8a08 with SMTP id p2-20020a0563587e4200b0017bc7978a08mr1157066rwm.20.1709624222779; Mon, 04 Mar 2024 23:37:02 -0800 (PST) From: Akihiko Odaki Date: Tue, 05 Mar 2024 16:36:28 +0900 Subject: [PATCH v2 11/13] 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: <20240305-elf2dmp-v2-11-86ff2163ad32@daynix.com> References: <20240305-elf2dmp-v2-0-86ff2163ad32@daynix.com> In-Reply-To: <20240305-elf2dmp-v2-0-86ff2163ad32@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::c32; envelope-from=akihiko.odaki@daynix.com; helo=mail-oo1-xc32.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: 1709624310585100005 elf2dmp assumes little endian host in many places. 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:42: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=1709624324; cv=none; d=zohomail.com; s=zohoarc; b=lntyCF5LvG04wZI0FcNW6QPrKLWCxRQGxUsxf9QLEKB0cax866QQWduwE5dK5Nl+SgLOuJtP1acc0cIM/NceKFLUz6ap4b65iJjijRHwHbO/ZqfLa+zW65Q9tyo/0lMy/BAEJhhGSka8zwzHJckI3fkcRIblNjkWQ5wRzAh3MA0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709624324; 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=EWGUi9tBAet6Aqvwl5xC+YeARn1u1TklowkngVTL1c0=; b=OsQ6QgDGKuVrG2OHiC0yyfY4IowVLQ3++SIwtrkZ5ltBZ+6MtO3Cr8H0xUucL0sSnfQxRkU43E0/bB/iga8MTM/pHG5W/p408MqnmRoSoUUO7vZFR4UQrqXmd7WVD+MF2mCtHEvuLt4NTQX6FD630uBVOyWBkgw1C8Njw6SLKmM= 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 170962432463356.3167752720301; Mon, 4 Mar 2024 23:38:44 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rhPMo-0006jI-Uw; Tue, 05 Mar 2024 02:37:39 -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 1rhPMM-0006Hx-5y for qemu-devel@nongnu.org; Tue, 05 Mar 2024 02:37:13 -0500 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rhPMJ-0005u2-Kw for qemu-devel@nongnu.org; Tue, 05 Mar 2024 02:37:09 -0500 Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-6e5c0be115aso2443866b3a.3 for ; Mon, 04 Mar 2024 23:37:06 -0800 (PST) Received: from localhost ([157.82.203.206]) by smtp.gmail.com with UTF8SMTPSA id m2-20020a62f202000000b006e4432027d1sm8556709pfh.142.2024.03.04.23.37.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 04 Mar 2024 23:37:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709624226; x=1710229026; 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=EWGUi9tBAet6Aqvwl5xC+YeARn1u1TklowkngVTL1c0=; b=rZEWCnoFrhc1fq1WA+tsYYzLWl4oLU92u3e17bx78ZbfFkDUMnAUTuVC9rc+7VJawL w/xqYJOhUqPHAJfowHd+3oZvFCcOtHuI5xludGFfdkfMR3T/QczBM20qi3XN5MDz6N3S KEd3eg8Gh8/n+aJbh+TRqzhNCTRr8847+3zuakHzxKw8WmoxkpJEQHXv6RM6tavsbmwM P693AiZ52Zs3iv3YYY1HQ/HPmsWl+wVzm8L6DF33sMGteiVyHIQtGDCz5zf15ltcqZOR 5Hm5dLCJHW7NGe5B3grpaYT4LeJ5ZlaqntO/TMA9dC+VnoqnSU0IN4zTMUHl0sGMUHtY dqVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709624226; x=1710229026; 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=EWGUi9tBAet6Aqvwl5xC+YeARn1u1TklowkngVTL1c0=; b=MVXV4DOBjVRuPYVe/EZQKRmEYsitddyheL9DcVIkReb64ElCSpewWdrw93GYl/n4O4 Q74JUU3nDMvXfOp8WQel80JDk9vLwez0BZFVEdyCViOul0njLSrN8W0R9d4QoSnmn1mH /Lb1leI+RLrpfFCwKGLoMpv46/R8kCXyTEQ3Wu1Wd4KBADIT0CZT4mSPc3Y1b8PuYm4b aP6f8uE3ixsivRNKpDU8ZFc7SrTF/NOxfhhAPZb9DWl3sR2DRFUAoSl3T7GYegHCvdo2 Ys3Zy3ZsjiKYzDQW9G9X1qS2D1+xCM/FDPXJx//y5cWyy1bWgNGl3wTgVEWrje0iWwTl AW5Q== X-Gm-Message-State: AOJu0YxlmYRQ5FGr+WYVWnM0tA97QxhgT91y+vMxBY4XsceuQziIit6l E+Atuho1eU3tvUA7ATRmssjUUvnWxUO2eLFNb41zTVUDO9mZFfBryccbHYwvIAPxUrEY7/zfSr+ Z X-Google-Smtp-Source: AGHT+IFhe+5xYJKgv+ZBAaqU3+ea4R9YNpa9nD7ebbLRStjcBw1fWGQfoualvzkrAFBHfe2CCXvbig== X-Received: by 2002:a05:6a00:2d07:b0:6e5:f773:eb80 with SMTP id fa7-20020a056a002d0700b006e5f773eb80mr8723836pfb.24.1709624225669; Mon, 04 Mar 2024 23:37:05 -0800 (PST) From: Akihiko Odaki Date: Tue, 05 Mar 2024 16:36:29 +0900 Subject: [PATCH v2 12/13] contrib/elf2dmp: Use GPtrArray MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240305-elf2dmp-v2-12-86ff2163ad32@daynix.com> References: <20240305-elf2dmp-v2-0-86ff2163ad32@daynix.com> In-Reply-To: <20240305-elf2dmp-v2-0-86ff2163ad32@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::436; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x436.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: 1709624326650100019 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:42: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=1709624338; cv=none; d=zohomail.com; s=zohoarc; b=K61qJU9qiP+oE6PzMBm6WN18ofdXALITlYbaVjQNXtzwyUNqeSv+L1hW4SlVwEeMnZeJjLN/eEdsHXgFpZNQAH3Y6QeClYF5zZhU8spzeRQJTHxa04LQHkqbPSYPn/btTZ1TvG7jNFCRnN2FZDYYjZeVlsL7EVo9rGfk7uVmQE8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709624338; 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=R4GuE8qVzY179iy5jy7tbAhb1WE9AtUQ419atok2jy0=; b=f2fXpd9zSraKVOspwaEexZIskXo/dO5NJw9pTk9N7GVF5/P10D6MRq4dV3rsPqvJsIk0DEHWXliCgnlyfk/flZHVwWY42DaptfoFQpQDEOYUOHD0HWGKvnI1yNNfiGmfH6bSs7y2xkGiP4efvD1XbYeke/QNk7rhEg8dq4J0XHg= 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 1709624338538440.4981226354804; Mon, 4 Mar 2024 23:38:58 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rhPMm-0006fV-Kc; Tue, 05 Mar 2024 02:37:36 -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 1rhPMO-0006IK-Ms for qemu-devel@nongnu.org; Tue, 05 Mar 2024 02:37:18 -0500 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rhPMM-0005uR-Qs for qemu-devel@nongnu.org; Tue, 05 Mar 2024 02:37:12 -0500 Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-6e6381df003so528840b3a.0 for ; Mon, 04 Mar 2024 23:37:09 -0800 (PST) Received: from localhost ([157.82.203.206]) by smtp.gmail.com with UTF8SMTPSA id p20-20020a62ab14000000b006e47e57d976sm8316257pff.166.2024.03.04.23.37.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 04 Mar 2024 23:37:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709624228; x=1710229028; 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=R4GuE8qVzY179iy5jy7tbAhb1WE9AtUQ419atok2jy0=; b=Nk4NbaNPcAOAe7rA88LJqBsAfkX9kQm2XWtgHjvQ2PQebl123f2UvQea6THD8gfMLJ Fmo3boCfZnfigWVPWcVR9pP+NRwem5wjmOxd7Y6O/l4NW87RJlm2eyGqlfqwzkyWSL9o 0fl7Y51yaMIVUIlEAYwrRZQFfjzhbQPlhaZemEldhuAjFBF/Hzrlcw8i7PE+p+sQThE7 iuBIwGZw2InW1b+I1C8M86POFlRR3tsbr1+fZfsLrG23+a6oUUTpfy9m4hoR00l0MDDd zLSbAWl2NlVSY2LvRcBQhrz8rg6FUPB6Xn49uVo4QYRcavTl5mCljdtGx99AqYiZj1vt mTEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709624228; x=1710229028; 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=R4GuE8qVzY179iy5jy7tbAhb1WE9AtUQ419atok2jy0=; b=KMsLpGxLc6Zoid3ZxlSuurBoBu/e+pllFvSxjL1xkJa9EwC0dcHlcrKkNYF/1IHbVb hG/AjJw61C3JWQZsCvIYWwwqzxwTgqa+D6g5tr65R+n+ssHt3RXQzg16mmB3gaGhFd3Z uRWRfBkHomwySbiIMAGv72qrMICGLJr5hFiA5YrUUS5mzEtEKOL+lzm9UnypwXl+V3Gk zIj9au77SOn2zHYCpXhJmerIN3ERD3/lVyiQ1pTNYWHQpRAB2CtvOX3TtZVQ28uYm9hH qwWltfzFiCfkG4Us4rO00EXjlrvev1Ztx1kydOteOJD0kL1NxW2aOmCNJ2Jj9WTd3pB8 q52g== X-Gm-Message-State: AOJu0YxeLC2PKBUysCzjotyw/FR2yGi+TGeD68n2vSoqckryte/zttQu uxTmoKbu3TanSlVD7qqiOpN7EjXujne+9IriMDTE4kwA3opxRmNbfqs3Etant0qgrjV76agRpSF s X-Google-Smtp-Source: AGHT+IHbZtnMGuxi2w9npBKJM6n8ElnOz1TfvXN9fBOyE+/hbK1klK3+dDESGEEzQEna4gcuSXeTbA== X-Received: by 2002:a05:6a00:928a:b0:6e6:2176:fd5 with SMTP id jw10-20020a056a00928a00b006e621760fd5mr6834926pfb.28.1709624228689; Mon, 04 Mar 2024 23:37:08 -0800 (PST) From: Akihiko Odaki Date: Tue, 05 Mar 2024 16:36:30 +0900 Subject: [PATCH v2 13/13] 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: <20240305-elf2dmp-v2-13-86ff2163ad32@daynix.com> References: <20240305-elf2dmp-v2-0-86ff2163ad32@daynix.com> In-Reply-To: <20240305-elf2dmp-v2-0-86ff2163ad32@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::42e; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x42e.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: 1709624340766100003 This fixes crashes with truncated dumps. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2202 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