From nobody Tue Nov 26 06:55:12 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1709705826; cv=none; d=zohomail.com; s=zohoarc; b=M1Qt6fyKq0lFdSU+Slqja0TzG5J+dnb0oJz9kIvQJUCnV0BumFHXj2dFyC+ZooRCJp6LF/6ifrRQVslFpF+pPCAk5jtloYg5oqY//i3d0T8WXSyzbxFRD/a2GdUaQEwX77JpF9Vn3oMBWsyfxOgOTkWlywz/+jWEpPNS9JNBelc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1709705826; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=W8pmybqo3MF49nkGilqwgGL/v4Pl4OfK1iEYauJ4N5w=; b=Jk36UcTaY95ND6Y40r7lGF/R4JN1Qw7hS622U4PVtQP5K1pfjr0w88rnrBlDbhprBaX2eGvWFkiAgWGf8Yp65oP+Sr8zJvq9pXo+xSILmN1UKy5YgWXVqB/gnPbZxC8PqKbDJBm3vE53loT1pJijepXQtBGCnNkixilnk0JChvY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1709705826060408.1498422370121; Tue, 5 Mar 2024 22:17:06 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rhkWu-0005Wg-Qb; Wed, 06 Mar 2024 01:13:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rhkWH-0004yZ-OG for qemu-devel@nongnu.org; Wed, 06 Mar 2024 01:12:51 -0500 Received: from mail-pg1-x531.google.com ([2607:f8b0:4864:20::531]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rhkWC-0006GC-VI for qemu-devel@nongnu.org; Wed, 06 Mar 2024 01:12:48 -0500 Received: by mail-pg1-x531.google.com with SMTP id 41be03b00d2f7-5d8b70b39efso5864835a12.0 for ; Tue, 05 Mar 2024 22:12:41 -0800 (PST) Received: from localhost ([157.82.206.27]) by smtp.gmail.com with UTF8SMTPSA id n4-20020a170902968400b001db8145a1a2sm11663587plp.274.2024.03.05.22.12.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 05 Mar 2024 22:12:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709705561; x=1710310361; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=W8pmybqo3MF49nkGilqwgGL/v4Pl4OfK1iEYauJ4N5w=; b=wVsq6u8oc6NUNWXuEgEq1/j6YWOpe3c0+zbtlLjhJlNuTQKWbw6NTK96h/CLM3yizH 5nKoKNyUh2txKGUmmYf8WHJJQISMp7nLtul1hw8NObD451TNFrxVl6NceNBQieWn5Ucr J2siZHSY7cubgnpEBrfoRAzWrcMeAuv8XdWfWe8Zfq5+KpDBEVWZlsfZ9SNc69LZxHx0 0/2kt0CwtYGz9J9L6U0vqiJH0MHlwBq0b+ChyDg1fEE5Xh5vXnCr3A63w1RE7CTFB2dI zBGI9VaOXhh2aPCf8wG+63yYrhWJvIXOMLI+NIdoownQXNiUPNbalzLYf59vMXQG5Lfb 2fZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709705561; x=1710310361; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=W8pmybqo3MF49nkGilqwgGL/v4Pl4OfK1iEYauJ4N5w=; b=H3cSdX6VG0Q8jH80i22CVCax1yzqHN6z7b4LLJc5ZKuqJRKNRt7f5a3RQ83tE3qmGR piSpG7f22EzCFDrD/px837njvUUrV5pp2GSwHZAaqGvyrtc2mIeZ9XKfTGiwpCZhRx3C im3COcJWH3je2tg6r+PNJLI1ipKqdRFxf4SP0fsKbWmkD7vt1ZLL3g6PiqNa5d6UT4JN y1jKngBgHNpZue0DwlfQeJR3I61+RZrNXNe4yQDzV3rAwZGpA6JC8MCSuGlXxEw14Xqi DfvblZBOV3B9nZXxusoe6rQDwyt14vBmKXhkjTR8o0PQ2/lfWJzVJrQQHlL2AzJSih/0 MalQ== X-Gm-Message-State: AOJu0YxfFCgL1V7vKT0wBWHGJGxrIfPziP9Eyj2qSzxaYjMxrSYwKDam qq7AnaYPssPzNxtWIUPsA2kc6+b5wTVXeDn27WMwVLVfj3AkkqbfnRqf76S71K8a7mYXT+jcnm8 T X-Google-Smtp-Source: AGHT+IH2Pt/6cnxJSv7PWdJ5qf0lZxp2QWbcyyKibXynKkQjhvQx7MzzFlVBIzSZqkJnkE0x8DcURw== X-Received: by 2002:a05:6a20:729b:b0:1a1:4b3e:5ef1 with SMTP id o27-20020a056a20729b00b001a14b3e5ef1mr4653649pzk.26.1709705561056; Tue, 05 Mar 2024 22:12:41 -0800 (PST) From: Akihiko Odaki Date: Wed, 06 Mar 2024 15:12:15 +0900 Subject: [PATCH v3 09/19] contrib/elf2dmp: Fix error reporting style in main.c MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240306-elf2dmp-v3-9-d74e6c3da49c@daynix.com> References: <20240306-elf2dmp-v3-0-d74e6c3da49c@daynix.com> In-Reply-To: <20240306-elf2dmp-v3-0-d74e6c3da49c@daynix.com> To: Viktor Prutyanov , Peter Maydell Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::531; envelope-from=akihiko.odaki@daynix.com; helo=mail-pg1-x531.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @daynix-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1709705828171100011 include/qapi/error.h says: > We recommend > * bool-valued functions return true on success / false on failure, > ... Signed-off-by: Akihiko Odaki --- contrib/elf2dmp/main.c | 63 +++++++++++++++++++++++++---------------------= ---- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/contrib/elf2dmp/main.c b/contrib/elf2dmp/main.c index cb28971789e4..c290781feb18 100644 --- a/contrib/elf2dmp/main.c +++ b/contrib/elf2dmp/main.c @@ -186,13 +186,13 @@ static void win_context_init_from_qemu_cpu_state(WinC= ontext64 *ctx, * Finds paging-structure hierarchy base, * if previously set doesn't give access to kernel structures */ -static int fix_dtb(struct va_space *vs, QEMU_Elf *qe) +static bool fix_dtb(struct va_space *vs, QEMU_Elf *qe) { /* * Firstly, test previously set DTB. */ if (va_space_resolve(vs, SharedUserData)) { - return 0; + return true; } =20 /* @@ -206,7 +206,7 @@ static int fix_dtb(struct va_space *vs, QEMU_Elf *qe) va_space_set_dtb(vs, s->cr[3]); printf("DTB 0x%016"PRIx64" has been found from CPU #%zu" " as system task CR3\n", vs->dtb, i); - return !(va_space_resolve(vs, SharedUserData)); + return !!(va_space_resolve(vs, SharedUserData)); } } =20 @@ -220,16 +220,16 @@ static int fix_dtb(struct va_space *vs, QEMU_Elf *qe) uint64_t *cr3 =3D va_space_resolve(vs, Prcb + 0x7000); =20 if (!cr3) { - return 1; + return false; } =20 va_space_set_dtb(vs, *cr3); printf("DirectoryTableBase =3D 0x%016"PRIx64" has been found from = CPU #0" " as interrupt handling CR3\n", vs->dtb); - return !(va_space_resolve(vs, SharedUserData)); + return !!(va_space_resolve(vs, SharedUserData)); } =20 - return 1; + return true; } =20 static void try_merge_runs(struct pa_space *ps, @@ -268,9 +268,10 @@ static void try_merge_runs(struct pa_space *ps, } } =20 -static int fill_header(WinDumpHeader64 *hdr, struct pa_space *ps, - struct va_space *vs, uint64_t KdDebuggerDataBlock, - KDDEBUGGER_DATA64 *kdbg, uint64_t KdVersionBlock, int nr_cpus) +static bool fill_header(WinDumpHeader64 *hdr, struct pa_space *ps, + struct va_space *vs, uint64_t KdDebuggerDataBlock, + KDDEBUGGER_DATA64 *kdbg, uint64_t KdVersionBlock, + int nr_cpus) { uint32_t *suite_mask =3D va_space_resolve(vs, SharedUserData + KUSD_OFFSET_SUITE_MASK); @@ -283,12 +284,12 @@ static int fill_header(WinDumpHeader64 *hdr, struct p= a_space *ps, QEMU_BUILD_BUG_ON(KUSD_OFFSET_PRODUCT_TYPE >=3D ELF2DMP_PAGE_SIZE); =20 if (!suite_mask || !product_type) { - return 1; + return false; } =20 if (!va_space_rw(vs, KdVersionBlock, &kvb, sizeof(kvb), 0)) { eprintf("Failed to extract KdVersionBlock\n"); - return 1; + return false; } =20 h =3D (WinDumpHeader64) { @@ -333,7 +334,7 @@ static int fill_header(WinDumpHeader64 *hdr, struct pa_= space *ps, =20 *hdr =3D h; =20 - return 0; + return true; } =20 /* @@ -379,8 +380,8 @@ static void fill_context(KDDEBUGGER_DATA64 *kdbg, } } =20 -static int pe_get_data_dir_entry(uint64_t base, void *start_addr, int idx, - void *entry, size_t size, struct va_space *vs) +static bool pe_get_data_dir_entry(uint64_t base, void *start_addr, int idx, + void *entry, size_t size, struct va_spac= e *vs) { const char e_magic[2] =3D "MZ"; const char Signature[4] =3D "PE\0\0"; @@ -393,38 +394,38 @@ static int pe_get_data_dir_entry(uint64_t base, void = *start_addr, int idx, QEMU_BUILD_BUG_ON(sizeof(*dos_hdr) >=3D ELF2DMP_PAGE_SIZE); =20 if (memcmp(&dos_hdr->e_magic, e_magic, sizeof(e_magic))) { - return 1; + return false; } =20 if (!va_space_rw(vs, base + dos_hdr->e_lfanew, &nt_hdrs, sizeof(nt_hdrs), 0)) { - return 1; + return false; } =20 if (memcmp(&nt_hdrs.Signature, Signature, sizeof(Signature)) || file_hdr->Machine !=3D 0x8664 || opt_hdr->Magic !=3D 0x020b) { - return 1; + return false; } =20 if (!va_space_rw(vs, base + data_dir[idx].VirtualAddress, entry, size,= 0)) { - return 1; + return false; } =20 printf("Data directory entry #%d: RVA =3D 0x%08"PRIx32"\n", idx, (uint32_t)data_dir[idx].VirtualAddress); =20 - return 0; + return true; } =20 -static int write_dump(struct pa_space *ps, - WinDumpHeader64 *hdr, const char *name) +static bool write_dump(struct pa_space *ps, + WinDumpHeader64 *hdr, const char *name) { FILE *dmp_file =3D fopen(name, "wb"); size_t i; =20 if (!dmp_file) { eprintf("Failed to open output file \'%s\'\n", name); - return 1; + return false; } =20 printf("Writing header to file...\n"); @@ -432,7 +433,7 @@ static int write_dump(struct pa_space *ps, if (fwrite(hdr, sizeof(*hdr), 1, dmp_file) !=3D 1) { eprintf("Failed to write dump header\n"); fclose(dmp_file); - return 1; + return false; } =20 for (i =3D 0; i < ps->block_nr; i++) { @@ -443,11 +444,11 @@ static int write_dump(struct pa_space *ps, if (fwrite(b->addr, b->size, 1, dmp_file) !=3D 1) { eprintf("Failed to write block\n"); fclose(dmp_file); - return 1; + return false; } } =20 - return fclose(dmp_file); + return !fclose(dmp_file); } =20 static bool pe_check_pdb_name(uint64_t base, void *start_addr, @@ -457,8 +458,8 @@ static bool pe_check_pdb_name(uint64_t base, void *star= t_addr, IMAGE_DEBUG_DIRECTORY debug_dir; char pdb_name[sizeof(PDB_NAME)]; =20 - if (pe_get_data_dir_entry(base, start_addr, IMAGE_FILE_DEBUG_DIRECTORY, - &debug_dir, sizeof(debug_dir), vs)) { + if (!pe_get_data_dir_entry(base, start_addr, IMAGE_FILE_DEBUG_DIRECTOR= Y, + &debug_dir, sizeof(debug_dir), vs)) { eprintf("Failed to get Debug Directory\n"); return false; } @@ -546,7 +547,7 @@ int main(int argc, char *argv[]) printf("CPU #0 CR3 is 0x%016"PRIx64"\n", state->cr[3]); =20 va_space_create(&vs, &ps, state->cr[3]); - if (fix_dtb(&vs, &qemu_elf)) { + if (!fix_dtb(&vs, &qemu_elf)) { eprintf("Failed to find paging base\n"); goto out_elf; } @@ -611,14 +612,14 @@ int main(int argc, char *argv[]) goto out_pdb; } =20 - if (fill_header(&header, &ps, &vs, KdDebuggerDataBlock, kdbg, - KdVersionBlock, qemu_elf.state_nr)) { + if (!fill_header(&header, &ps, &vs, KdDebuggerDataBlock, kdbg, + KdVersionBlock, qemu_elf.state_nr)) { goto out_kdbg; } =20 fill_context(kdbg, &vs, &qemu_elf); =20 - if (write_dump(&ps, &header, argv[2])) { + if (!write_dump(&ps, &header, argv[2])) { eprintf("Failed to save dump\n"); goto out_kdbg; } --=20 2.44.0