From nobody Tue Nov 26 06:38:43 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