From patchwork Thu Mar 7 10:20:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1909160 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20230601.gappssmtp.com header.i=@daynix-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=X5NkaWZS; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Tr5281pY4z23qX for ; Thu, 7 Mar 2024 21:21:52 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1riAs1-0004Ro-Cf; Thu, 07 Mar 2024 05:21:01 -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 1riArx-0004OV-IK for qemu-devel@nongnu.org; Thu, 07 Mar 2024 05:20:59 -0500 Received: from mail-pg1-x52a.google.com ([2607:f8b0:4864:20::52a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1riArw-0006qc-2l for qemu-devel@nongnu.org; Thu, 07 Mar 2024 05:20:57 -0500 Received: by mail-pg1-x52a.google.com with SMTP id 41be03b00d2f7-5ca29c131ebso630097a12.0 for ; Thu, 07 Mar 2024 02:20:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709806853; x=1710411653; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=D5kUM6n9+j+qbS1SUPTKf/+dgcMdpwuEc/L8WCg7irw=; b=X5NkaWZSsSZhQo7NIesYwNStXrDDOQStBZExsIR8KarZrWWt/5SvgsrSfzc1Fow6u1 gJpfux2/LVWIQE2cLvWyQqHl8amEHBJac6wY2B62gwkAdBBRWfe0AfioSO3tsGbTHn6D x9Hw7IqOyqZNPuzoKHP+HzXcgoAfPG+DntNN1AnAty9gFpEo5gAH2L/byYqq072vwnhi MiESO4U/NvS1zdGZqsSeRGFo2BcjBD3CD9uNUym7pevrosyBDTBG60hxietMc8ZBCN93 MlB+0/97Wmefk0B6CNuFf3ydKo621xpp/szCvRek5pViOYPSLcZ4rz56f/UZyHGcBxaz rwJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709806853; x=1710411653; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=D5kUM6n9+j+qbS1SUPTKf/+dgcMdpwuEc/L8WCg7irw=; b=UtQGz8hU/UL2Ytt50AbJLKR+f+PqJDxIo/d662z3TFY3uTusYkZC0LOjgcbWyM2472 kOPZ38zoKtFPCv9PHQBu6GnWAceG92PRQih3DN20qr4NF9yrYMhxFbaeI1QDIiRudiX1 GmPpzTOkRqGOo0uQx2TJQI8jZomN+rtzYGAwf/8LALmihWt9XdITLiZAFZytZssMnWz6 53+u9QrQwgZoOehLFMxBQvHyFqem1kW1EG5GnGwU7YMDQPpgItWC2/EHzZ+No2/sMAMD R0LYVmD2WRIwTmMEeP1L2QUz+ejsFbi6/J1pPdltyDMGwttqZy1we8ZYNN9tH9cix9Hv uDBg== X-Gm-Message-State: AOJu0Ywju54pkHT+hrgRuvQPxxwWR7j5xCT53fQbMgAwdf79o+9g2TEZ D2k09jRdWjWnKlU5iMJ4WZmgsAgsq0HcCJ2U0wui0OMbH4qSaCSvcKVbIOTdp8qxX2JhHZapKUM 4 X-Google-Smtp-Source: AGHT+IG/BP+CMvtNKeNBxVJNQQQPYRwZajj1WLf5260/BULR9evmpbMyeimALlMxFDqkx/MjPm384A== X-Received: by 2002:a05:6a20:3c9f:b0:1a1:45e4:845a with SMTP id b31-20020a056a203c9f00b001a145e4845amr8091556pzj.11.1709806853183; Thu, 07 Mar 2024 02:20:53 -0800 (PST) Received: from localhost ([2400:4050:a840:1e00:9ac7:6d57:2b16:6932]) by smtp.gmail.com with UTF8SMTPSA id h15-20020a170902680f00b001dd090a7c00sm8800575plk.292.2024.03.07.02.20.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 07 Mar 2024 02:20:52 -0800 (PST) From: Akihiko Odaki Date: Thu, 07 Mar 2024 19:20:44 +0900 Subject: [PATCH v4 01/19] contrib/elf2dmp: Remove unnecessary err flags MIME-Version: 1.0 Message-Id: <20240307-elf2dmp-v4-1-4f324ad4d99d@daynix.com> References: <20240307-elf2dmp-v4-0-4f324ad4d99d@daynix.com> In-Reply-To: <20240307-elf2dmp-v4-0-4f324ad4d99d@daynix.com> To: Viktor Prutyanov , Peter Maydell Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 Received-SPF: none client-ip=2607:f8b0:4864:20::52a; envelope-from=akihiko.odaki@daynix.com; helo=mail-pg1-x52a.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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) static int pdb_init_symbols(struct pdb_reader *r) { - int err = 0; PDB_SYMBOLS *symbols; symbols = 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 = pdb_ds_read_file(r, symbols->gsym_file); if (!r->modimage) { - err = 1; goto out_symbols; } @@ -205,7 +203,7 @@ static int pdb_init_symbols(struct pdb_reader *r) out_symbols: g_free(symbols); - return err; + return 1; } 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) static int pdb_reader_init(struct pdb_reader *r, void *data) { - int err = 0; const char pdb7[] = "Microsoft C/C++ MSF 7.00"; if (memcmp(data, pdb7, sizeof(pdb7) - 1)) { @@ -241,17 +238,14 @@ static int pdb_reader_init(struct pdb_reader *r, void *data) r->ds.root = pdb_ds_read_file(r, 1); if (!r->ds.root) { - err = 1; goto out_ds; } if (pdb_init_symbols(r)) { - err = 1; goto out_root; } if (pdb_init_segments(r)) { - err = 1; goto out_sym; } @@ -264,7 +258,7 @@ out_root: out_ds: pdb_reader_ds_exit(r); - return err; + return 1; } 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 = NULL; - int err = 0; void *map; reader->gmf = g_mapped_file_new(name, TRUE, &gerr); @@ -291,7 +284,6 @@ int pdb_init_from_file(const char *name, struct pdb_reader *reader) reader->file_size = g_mapped_file_get_length(reader->gmf); map = g_mapped_file_get_contents(reader->gmf); if (pdb_reader_init(reader, map)) { - err = 1; goto out_unmap; } @@ -300,7 +292,7 @@ int pdb_init_from_file(const char *name, struct pdb_reader *reader) out_unmap: g_mapped_file_unref(reader->gmf); - return err; + return 1; } void pdb_exit(struct pdb_reader *reader) From patchwork Thu Mar 7 10:20:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1909167 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20230601.gappssmtp.com header.i=@daynix-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=Kn6e5KWw; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Tr53R5tssz1yX3 for ; Thu, 7 Mar 2024 21:22:59 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1riAs2-0004T2-3c; Thu, 07 Mar 2024 05:21:02 -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 1riAs1-0004RL-7P for qemu-devel@nongnu.org; Thu, 07 Mar 2024 05:21:01 -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 1riArx-0006qr-BM for qemu-devel@nongnu.org; Thu, 07 Mar 2024 05:21:00 -0500 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1dc29f1956cso5291585ad.0 for ; Thu, 07 Mar 2024 02:20:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709806856; x=1710411656; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=WBQ8wkR+EtpXcrRFUmJL0m8euRcerqarx8Jtcq9C72A=; b=Kn6e5KWwBK7WM0OwcVmR3L7+rvbpMRuMoSsKqHhVil/yjojMUuKShKbdHmeJzGfKVr yCykZZLLIER+W9YUkAOw2vQZShc2atdvPn6EIuXzxEzKbMxobbm7JZ8tGBJ6j/5CO7XA VBcFrxahp9hjuv9SxlBsbm+9y9hxXmgWjlmAT5os/TDIi9bp9YzcWxlP83zKtKRhJe7j qTXPYHa2597P0ZFOKOfd5LM7MS7uDF2jIEoaEltymVhWp1vJfjpaSd4IQE8WFfdfRliP DEBTcj5iqCQ/iYtzkkhJij/IxF8sDfMBVDOzh8OaBOpkUgw09FR7seyluEIIa7e+3fvl Lbsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709806856; x=1710411656; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WBQ8wkR+EtpXcrRFUmJL0m8euRcerqarx8Jtcq9C72A=; b=TU8xPmmAN6dQLRUjZZRNqx2OZAUPDSUo1ZRAz+mhDgNDoPfeY1ZaDYGDoNbuqeKV7u d4pfGXreYhjFlkJBz9BoOnb3pWVcIPoLZyWGt+b8VhJZqPqCqO3b3ipGqwmX8qijhUlY DIBtjV2CL12vtE6ZpImCxvrA5QxSRrs+U30e++bKkDhwzmNXot4tjhf1mmmMvK0MLUC2 MCyhKVP8vjV89DCjNHUSW2p9umJxZGJ2gZwIwIyu6TOpd1AvoJOHLCNAbOB8qP9Y4YjP qEpruJ0d0A91DjrdJrtHWzgnLBeHMUAUiJ/IC00AzZQ9cHY8pT0iRMsxDhS1x2QukGRQ hxvg== X-Gm-Message-State: AOJu0Yx0KCxfGM7/cUude3/+QeHvrbIMFtFSzKFnqJK+Rk0rnEk/REBp S3ZLaeAjgLQAzTqOWYXOJXS6yzj1PQAV4iaGhGc5umrJKu4Fh/vV9c8Cp/SUwKk= X-Google-Smtp-Source: AGHT+IH7LtUCCaMRojonRof2MgK29sUVz9nymfvxPhS9MuGx48/VthnsbjgDs/bjCBpHETxdo4Y5Ig== X-Received: by 2002:a17:902:ea04:b0:1db:92e1:2e53 with SMTP id s4-20020a170902ea0400b001db92e12e53mr9633335plg.40.1709806856083; Thu, 07 Mar 2024 02:20:56 -0800 (PST) Received: from localhost ([2400:4050:a840:1e00:9ac7:6d57:2b16:6932]) by smtp.gmail.com with UTF8SMTPSA id f12-20020a170902e98c00b001dd5f5b1ca4sm210323plb.309.2024.03.07.02.20.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 07 Mar 2024 02:20:55 -0800 (PST) From: Akihiko Odaki Date: Thu, 07 Mar 2024 19:20:45 +0900 Subject: [PATCH v4 02/19] contrib/elf2dmp: Assume error by default MIME-Version: 1.0 Message-Id: <20240307-elf2dmp-v4-2-4f324ad4d99d@daynix.com> References: <20240307-elf2dmp-v4-0-4f324ad4d99d@daynix.com> In-Reply-To: <20240307-elf2dmp-v4-0-4f324ad4d99d@daynix.com> To: Viktor Prutyanov , Peter Maydell Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 @@ int download_url(const char *name, const char *url) { - int err = 0; + int err = 1; FILE *file; CURL *curl = curl_easy_init(); @@ -21,7 +21,6 @@ int download_url(const char *name, const char *url) file = fopen(name, "wb"); if (!file) { - err = 1; goto out_curl; } @@ -33,7 +32,6 @@ int download_url(const char *name, const char *url) || curl_easy_perform(curl) != CURLE_OK) { unlink(name); fclose(file); - err = 1; } else { err = 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) int main(int argc, char *argv[]) { - int err = 0; + int err = 1; QEMU_Elf qemu_elf; struct pa_space ps; struct va_space vs; @@ -542,7 +542,6 @@ int main(int argc, char *argv[]) if (pa_space_create(&ps, &qemu_elf)) { eprintf("Failed to initialize physical address space\n"); - err = 1; goto out_elf; } @@ -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 = 1; goto out_elf; } @@ -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 = 1; goto out_ps; } printf("CPU #0 IDT[0] -> 0x%016"PRIx64"\n", idt_desc_addr(first_idt_desc)); @@ -586,7 +583,6 @@ int main(int argc, char *argv[]) if (!kernel_found) { eprintf("Failed to find NT kernel image\n"); - err = 1; goto out_ps; } @@ -600,45 +596,40 @@ int main(int argc, char *argv[]) if (download_url(PDB_NAME, pdb_url)) { eprintf("Failed to download PDB file\n"); - err = 1; goto out_ps; } if (pdb_init_from_file(PDB_NAME, &pdb)) { eprintf("Failed to initialize PDB reader\n"); - err = 1; goto out_pdb_file; } if (!SYM_RESOLVE(KernBase, &pdb, KdDebuggerDataBlock) || !SYM_RESOLVE(KernBase, &pdb, KdVersionBlock)) { - err = 1; goto out_pdb; } kdbg = get_kdbg(KernBase, &pdb, &vs, KdDebuggerDataBlock); if (!kdbg) { - err = 1; goto out_pdb; } if (fill_header(&header, &ps, &vs, KdDebuggerDataBlock, kdbg, KdVersionBlock, qemu_elf.state_nr)) { - err = 1; goto out_kdbg; } if (fill_context(kdbg, &vs, &qemu_elf)) { - err = 1; goto out_kdbg; } if (write_dump(&ps, &header, argv[2])) { eprintf("Failed to save dump\n"); - err = 1; goto out_kdbg; } + err = 0; + out_kdbg: g_free(kdbg); out_pdb: From patchwork Thu Mar 7 10:20:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1909171 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20230601.gappssmtp.com header.i=@daynix-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=IlSgeCT+; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Tr5463cgJz1yX3 for ; Thu, 7 Mar 2024 21:23:34 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1riAs6-0004Uc-72; Thu, 07 Mar 2024 05:21:06 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1riAs2-0004TI-Ic for qemu-devel@nongnu.org; Thu, 07 Mar 2024 05:21:04 -0500 Received: from mail-il1-x12b.google.com ([2607:f8b0:4864:20::12b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1riAs0-0006sS-3C for qemu-devel@nongnu.org; Thu, 07 Mar 2024 05:21:01 -0500 Received: by mail-il1-x12b.google.com with SMTP id e9e14a558f8ab-36524116e30so2167995ab.0 for ; Thu, 07 Mar 2024 02:20:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709806859; x=1710411659; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=uEl9gr+JRIy2uRLCAmnmdcgL5kP09OBXfeuQ6yoOxrY=; b=IlSgeCT+IgbWmhIYxtWxki7OzulPpSYYKhxo0cvNDcP3+eUpMK8ETeHPgb3kwYXzzy BbMuwwXM26y5Vpg+kxCtfLuD8iTLosbxQPqlWYtnJ5IqJvL6mN1vXkOCiMGZhN0NuQH5 7PxaV9LWf005A0IndAACj94lTDgvS2e6Za71oDl+0newWk+NbIPMvzeR4iLXes2B2axv aMXZXzwku728mPOg+7RcZfH/eZi1JmnLR9hzkSI8XSjnxfkOHGT7fU3IheWYDtrvmFCA upK1M1Z6r3V7TWY4jMOCYGYwFr3Gx0+HE6xuNWkaupoSVtnLrIa6WWRl0VzaD4NoPuOF I0vA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709806859; x=1710411659; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uEl9gr+JRIy2uRLCAmnmdcgL5kP09OBXfeuQ6yoOxrY=; b=KScGlt7/bCgYwqsyJ4AWg91BIln/O27TboMZkvjXVq7HhJzcKpV4JnHC9tHmDdUxGS hS9eXrY/d4cFgRMY30lY6rqC+z7It2w8DPsFWV/7mWcSQ9LiLG5CoV+3+fxBXkjFUl2a LjssJntmU5c7UoMJK6RdGy/abIGkS0g+ZPI0sOelK/gscYsyTPh4wFbb99lsBNHelA6y qMRTUTAlDELfSadSfyAt2TOIP9nwDdW7WExiCFLVkdU1otTSoGYJIuqpfRTt+QCLu8Z/ 2xkovHzU8XRVTQUpSgFOsWd/Ist8bkX+VSfPYdg/VbU1t26e2QcNbnFWJjeeA5vA6dDl EKHw== X-Gm-Message-State: AOJu0YxL0ciVeijjs1adY4f85FWLChT6fR/V2QJ15DNHxGEHtf4IeYrE WT5OpWLTofwegDoTKqF74SQX8xBNez1qeKbWuUhFf4uNUB5w01sXdPqcDzLAg78= X-Google-Smtp-Source: AGHT+IGRW0hSswWHM2ZEut1OSa1J0rnS3lDqIjbzvi7ENgqRHBtrlyAtis7Wf7vXWnsQab9lnxZijA== X-Received: by 2002:a05:6e02:1d09:b0:365:1985:dda5 with SMTP id i9-20020a056e021d0900b003651985dda5mr21153102ila.14.1709806859024; Thu, 07 Mar 2024 02:20:59 -0800 (PST) Received: from localhost ([2400:4050:a840:1e00:9ac7:6d57:2b16:6932]) by smtp.gmail.com with UTF8SMTPSA id bg1-20020a056a02010100b005dc9ab425c2sm10865270pgb.35.2024.03.07.02.20.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 07 Mar 2024 02:20:58 -0800 (PST) From: Akihiko Odaki Date: Thu, 07 Mar 2024 19:20:46 +0900 Subject: [PATCH v4 03/19] contrib/elf2dmp: Continue even contexts are lacking MIME-Version: 1.0 Message-Id: <20240307-elf2dmp-v4-3-4f324ad4d99d@daynix.com> References: <20240307-elf2dmp-v4-0-4f324ad4d99d@daynix.com> In-Reply-To: <20240307-elf2dmp-v4-0-4f324ad4d99d@daynix.com> To: Viktor Prutyanov , Peter Maydell Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 Received-SPF: none client-ip=2607:f8b0:4864:20::12b; envelope-from=akihiko.odaki@daynix.com; helo=mail-il1-x12b.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Let fill_context() continue even if it fails to fill contexts of some CPUs. A dump may still contain valuable information even if it lacks contexts of some CPUs due to dump corruption or a failure before starting CPUs. Signed-off-by: Akihiko Odaki Reviewed-by: Peter Maydell --- contrib/elf2dmp/main.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/contrib/elf2dmp/main.c b/contrib/elf2dmp/main.c index 9b278f392e39..86e709e6da3a 100644 --- a/contrib/elf2dmp/main.c +++ b/contrib/elf2dmp/main.c @@ -336,8 +336,13 @@ static int fill_header(WinDumpHeader64 *hdr, struct pa_space *ps, return 0; } -static int fill_context(KDDEBUGGER_DATA64 *kdbg, - struct va_space *vs, QEMU_Elf *qe) +/* + * fill_context() continues even if it fails to fill contexts of some CPUs. + * A dump may still contain valuable information even if it lacks contexts of + * some CPUs due to dump corruption or a failure before starting CPUs. + */ +static void fill_context(KDDEBUGGER_DATA64 *kdbg, + struct va_space *vs, QEMU_Elf *qe) { int i; @@ -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; } 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; } printf("Filling context for CPU #%d...\n", i); @@ -369,11 +374,9 @@ static int fill_context(KDDEBUGGER_DATA64 *kdbg, if (va_space_rw(vs, Context, &ctx, sizeof(ctx), 1)) { eprintf("Failed to fill CPU #%d context\n", i); - return 1; + continue; } } - - return 0; } 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; } - if (fill_context(kdbg, &vs, &qemu_elf)) { - goto out_kdbg; - } + fill_context(kdbg, &vs, &qemu_elf); if (write_dump(&ps, &header, argv[2])) { eprintf("Failed to save dump\n"); From patchwork Thu Mar 7 10:20:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1909158 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20230601.gappssmtp.com header.i=@daynix-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=UWRMnzh/; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Tr5274BJ2z23hR for ; Thu, 7 Mar 2024 21:21:51 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1riAs8-0004VT-91; Thu, 07 Mar 2024 05:21:08 -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 1riAs6-0004Ue-AV for qemu-devel@nongnu.org; Thu, 07 Mar 2024 05:21:06 -0500 Received: from mail-pg1-x529.google.com ([2607:f8b0:4864:20::529]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1riAs4-0006wo-PD for qemu-devel@nongnu.org; Thu, 07 Mar 2024 05:21:06 -0500 Received: by mail-pg1-x529.google.com with SMTP id 41be03b00d2f7-5cdbc4334edso447045a12.3 for ; Thu, 07 Mar 2024 02:21:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709806862; x=1710411662; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=A243LVbp1AwfUXsMdD+blJLZP6SXZ8l0TiQS7QSUs3I=; b=UWRMnzh/F4b9L8Pq8eqgnVks7/8o0ay0RDn9WeAg5EKCivtjEIDDc1x5SzT43IW6CL 8G7AkWnsAFKSTWV7XXC1NLJoX5gxZDNSQsIJfnNyvoRunONi94b2OVaEUBzMhmKT9i/u 7FvcbDLiqUR6VT1q8C5T56os3LCcpPu9O/VDKRlLeLVXe4lA2ekha06WK5KUZhsZ6ukt Xali47RS6sVbcCBQ2KUJAG/YmQx0P7mlOjDoyGokl3jjo5hk6qOKtN4G6mbLnb/FYSsW lLDnoJZWjKvtDTQen57/1cf0fRurh+c8epwsw5O9lkAEFu7ynbo9IVNRcF3lD0H5vulq qdxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709806862; x=1710411662; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=A243LVbp1AwfUXsMdD+blJLZP6SXZ8l0TiQS7QSUs3I=; b=uAfT3S0cnJkvez4q4EDLbnpltdBtGzkCLTk92uo5AZ/liFk5gt2ayMhFX8RQ/uVVH8 RBPNPb7zKj9Z8iT5zT+DD8XeqdMEkxzFe6T6F5KztFeU+yolA6C7AazoNZtuhF2JqeyT oMEXvNvG2A1sDJADJxl/lenLJXfuQEqWQ2II9PXIglozRwazy3/DK1fCqZuZfXnvowVu XGz2bHNHrM2ehVRBn7zJ5Gf69jnKoI6+FYJTtzrwWBvr9gD69npGBSPHq3grdoTmdLIW /7hS7PPfrrerfWEWrKZL0Ch+DZV44dmvuTY4M35jz6av3FO4tSz6a4HD4pCPP7fzd9ri 9TYw== X-Gm-Message-State: AOJu0YwaNRNVdOPvcieAfq15KgQUiqe6VYgFUEYnquSXfVWNsAu3Yfdm DG5OLWwtDwkKipU0H9C7alGoZcyAgikChfvSqF1/I4F3ZT4O1GIbnueAolPGhxw= X-Google-Smtp-Source: AGHT+IGUCFoQOtFxB2kfMcmD4JSLZQKCfT7IcmiLym6Jv0rYE0VcfgpL6we/hPnrwDnD0GxC6XsfJg== X-Received: by 2002:a05:6a20:8422:b0:1a1:4ebd:db with SMTP id c34-20020a056a20842200b001a14ebd00dbmr9029900pzd.24.1709806862357; Thu, 07 Mar 2024 02:21:02 -0800 (PST) Received: from localhost ([2400:4050:a840:1e00:9ac7:6d57:2b16:6932]) by smtp.gmail.com with UTF8SMTPSA id ei16-20020a17090ae55000b0029b73ccf4fesm1200735pjb.30.2024.03.07.02.21.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 07 Mar 2024 02:21:02 -0800 (PST) From: Akihiko Odaki Date: Thu, 07 Mar 2024 19:20:47 +0900 Subject: [PATCH v4 04/19] contrib/elf2dmp: Change pa_space_create() signature MIME-Version: 1.0 Message-Id: <20240307-elf2dmp-v4-4-4f324ad4d99d@daynix.com> References: <20240307-elf2dmp-v4-0-4f324ad4d99d@daynix.com> In-Reply-To: <20240307-elf2dmp-v4-0-4f324ad4d99d@daynix.com> To: Viktor Prutyanov , Peter Maydell Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 Received-SPF: none client-ip=2607:f8b0:4864:20::529; envelope-from=akihiko.odaki@daynix.com; helo=mail-pg1-x529.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org pa_space_create() used to return an integer to propagate error, but it never fails so let it return void. Signed-off-by: Akihiko Odaki Reviewed-by: Philippe Mathieu-Daudé --- contrib/elf2dmp/addrspace.h | 2 +- contrib/elf2dmp/addrspace.c | 4 +--- contrib/elf2dmp/main.c | 5 +---- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/contrib/elf2dmp/addrspace.h b/contrib/elf2dmp/addrspace.h index 039c70c5b079..c868d6473873 100644 --- a/contrib/elf2dmp/addrspace.h +++ b/contrib/elf2dmp/addrspace.h @@ -33,7 +33,7 @@ struct va_space { struct pa_space *ps; }; -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); void va_space_create(struct va_space *vs, struct pa_space *ps, uint64_t dtb); diff --git a/contrib/elf2dmp/addrspace.c b/contrib/elf2dmp/addrspace.c index 6f608a517b1e..4c127c9b1ec4 100644 --- a/contrib/elf2dmp/addrspace.c +++ b/contrib/elf2dmp/addrspace.c @@ -57,7 +57,7 @@ static void pa_block_align(struct pa_block *b) b->paddr += low_align; } -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 = elf_getphdrnum(qemu_elf->map); Elf64_Phdr *phdr = elf64_getphdr(qemu_elf->map); @@ -87,8 +87,6 @@ int pa_space_create(struct pa_space *ps, QEMU_Elf *qemu_elf) } ps->block_nr = block_i; - - return 0; } void pa_space_destroy(struct pa_space *ps) diff --git a/contrib/elf2dmp/main.c b/contrib/elf2dmp/main.c index 86e709e6da3a..8a71e2efd281 100644 --- a/contrib/elf2dmp/main.c +++ b/contrib/elf2dmp/main.c @@ -543,10 +543,7 @@ int main(int argc, char *argv[]) return 1; } - if (pa_space_create(&ps, &qemu_elf)) { - eprintf("Failed to initialize physical address space\n"); - goto out_elf; - } + pa_space_create(&ps, &qemu_elf); state = qemu_elf.state[0]; printf("CPU #0 CR3 is 0x%016"PRIx64"\n", state->cr[3]); From patchwork Thu Mar 7 10:20:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1909165 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20230601.gappssmtp.com header.i=@daynix-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=He+VTJZu; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Tr52t3YzTz23hR for ; Thu, 7 Mar 2024 21:22:30 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1riAsC-0004Vp-QG; Thu, 07 Mar 2024 05:21:12 -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 1riAsB-0004Vh-AZ for qemu-devel@nongnu.org; Thu, 07 Mar 2024 05:21:11 -0500 Received: from mail-il1-x133.google.com ([2607:f8b0:4864:20::133]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1riAs6-00072u-LG for qemu-devel@nongnu.org; Thu, 07 Mar 2024 05:21:11 -0500 Received: by mail-il1-x133.google.com with SMTP id e9e14a558f8ab-365a681e949so1585785ab.3 for ; Thu, 07 Mar 2024 02:21:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709806865; x=1710411665; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=DA8YPsa0OXQme2Bi1zvzEkGMO6/tiDahixJX2f3DNcQ=; b=He+VTJZui/xLc39E48O+a+Ca81ApVDhULELKPVgSVUfSldDF1U2ZKQeWEX/Y3oEsM7 lhHrWf43tk7GGjixPPTXPlSLpf+b9rYrks8V9f+ZtY6SG9e3rjj+iDxBNlvEUzxBAkbp GvLoKNKwiHX7J/eep8SAkXxstiDO0vr30EP6yy4LetVC8DygmWOm6rtEqNHicze0AXgF arKGnccW8DZYg9cZFd+Hbho66hc9xqtAOFOoW+IFcHMAzl5h+6UM/oznGaFFjn89YCNU SbjgzKmCnptZpRYYDsMA2WW5mOV093YOnBzMMkGC8mz8G+1LQvhvgPRKE9lps3CCqa0k VrMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709806865; x=1710411665; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DA8YPsa0OXQme2Bi1zvzEkGMO6/tiDahixJX2f3DNcQ=; b=i82whMGC16k7+wiTPrKu2WET4n88EsdS3dhb21Ivinadyl+ua68OrhKhfImo2CNyYB G/gNVh1jtIRFMcpRFvols6yZkQ/Y9LwLM/VmmLKLPuKvu1xiPU4/H/PnCY4vhVnAULbZ PcI37sEuMrdH0dJHuhG9BtE16h2onA0cZuP2hJd/0FysyZzwRJoFM5bAApHqAes+CQHf AivNiX8febd8/KD0WS/wZvEQos8qAT1rUu5K2Xs5S8j1G4JMsUDavrT2tKD3tyDyAu4t tC9OT/ZAIMu68Ziz4kW8ZVkryyzU0int5DhkOfu6hYFKnY3TnhVyKmomD+4OLuccu6YT stgQ== X-Gm-Message-State: AOJu0Yz+wrCkqvSU13UcF2AAk0Jwxww36nb6Vmqi/kigRA7xQvZ4/O2L Nb8y8FhMdEKYe4LJaOWvlIXF11lz7XyEhktl3tIRW7cvFvxrR9kytQC/+/g7EeE= X-Google-Smtp-Source: AGHT+IGY35H0kGzyRGQTj7kRLdVmiY1xv1badnMu1En0zNsKUyAtBW+1f5vZyo+xAI1PW7PnZVDrKg== X-Received: by 2002:a92:ca0c:0:b0:365:ff00:dc6a with SMTP id j12-20020a92ca0c000000b00365ff00dc6amr7896587ils.13.1709806865241; Thu, 07 Mar 2024 02:21:05 -0800 (PST) Received: from localhost ([2400:4050:a840:1e00:9ac7:6d57:2b16:6932]) by smtp.gmail.com with UTF8SMTPSA id x19-20020a056a00189300b006e65d4679d2sm838039pfh.153.2024.03.07.02.21.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 07 Mar 2024 02:21:04 -0800 (PST) From: Akihiko Odaki Date: Thu, 07 Mar 2024 19:20:48 +0900 Subject: [PATCH v4 05/19] contrib/elf2dmp: Fix error reporting style in addrspace.c MIME-Version: 1.0 Message-Id: <20240307-elf2dmp-v4-5-4f324ad4d99d@daynix.com> References: <20240307-elf2dmp-v4-0-4f324ad4d99d@daynix.com> In-Reply-To: <20240307-elf2dmp-v4-0-4f324ad4d99d@daynix.com> To: Viktor Prutyanov , Peter Maydell Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 Received-SPF: none client-ip=2607:f8b0:4864:20::133; envelope-from=akihiko.odaki@daynix.com; helo=mail-il1-x133.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org include/qapi/error.h says: > We recommend > * bool-valued functions return true on success / false on failure, > ... Signed-off-by: Akihiko Odaki Reviewed-by: Philippe Mathieu-Daudé --- contrib/elf2dmp/addrspace.h | 4 ++-- contrib/elf2dmp/addrspace.c | 8 ++++---- contrib/elf2dmp/main.c | 47 +++++++++++++++++++++------------------------ 3 files changed, 28 insertions(+), 31 deletions(-) diff --git a/contrib/elf2dmp/addrspace.h b/contrib/elf2dmp/addrspace.h index c868d6473873..2ad30a9da48a 100644 --- a/contrib/elf2dmp/addrspace.h +++ b/contrib/elf2dmp/addrspace.h @@ -39,7 +39,7 @@ void pa_space_destroy(struct pa_space *ps); void va_space_create(struct va_space *vs, struct pa_space *ps, uint64_t dtb); 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); #endif /* ADDRSPACE_H */ diff --git a/contrib/elf2dmp/addrspace.c b/contrib/elf2dmp/addrspace.c index 4c127c9b1ec4..c995c723ae80 100644 --- a/contrib/elf2dmp/addrspace.c +++ b/contrib/elf2dmp/addrspace.c @@ -226,8 +226,8 @@ void *va_space_resolve(struct va_space *vs, uint64_t va) return pa_space_resolve(vs->ps, pa); } -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 = addr & ELF2DMP_PFN_MASK; @@ -238,7 +238,7 @@ int va_space_rw(struct va_space *vs, uint64_t addr, ptr = va_space_resolve(vs, addr); if (!ptr) { - return 1; + return false; } if (is_write) { @@ -252,5 +252,5 @@ int va_space_rw(struct va_space *vs, uint64_t addr, addr += s; } - return 0; + return true; } diff --git a/contrib/elf2dmp/main.c b/contrib/elf2dmp/main.c index 8a71e2efd281..09af39422f1e 100644 --- a/contrib/elf2dmp/main.c +++ b/contrib/elf2dmp/main.c @@ -79,9 +79,9 @@ static KDDEBUGGER_DATA64 *get_kdbg(uint64_t KernBase, struct pdb_reader *pdb, bool decode = false; uint64_t kwn, kwa, KdpDataBlockEncoded; - if (va_space_rw(vs, - KdDebuggerDataBlock + offsetof(KDDEBUGGER_DATA64, Header), - &kdbg_hdr, sizeof(kdbg_hdr), 0)) { + if (!va_space_rw(vs, + KdDebuggerDataBlock + offsetof(KDDEBUGGER_DATA64, Header), + &kdbg_hdr, sizeof(kdbg_hdr), 0)) { eprintf("Failed to extract KDBG header\n"); return NULL; } @@ -97,8 +97,8 @@ static KDDEBUGGER_DATA64 *get_kdbg(uint64_t KernBase, struct pdb_reader *pdb, return NULL; } - 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; } @@ -122,7 +122,7 @@ static KDDEBUGGER_DATA64 *get_kdbg(uint64_t KernBase, struct pdb_reader *pdb, kdbg = g_malloc(kdbg_hdr.Size); - if (va_space_rw(vs, KdDebuggerDataBlock, kdbg, kdbg_hdr.Size, 0)) { + if (!va_space_rw(vs, KdDebuggerDataBlock, kdbg, kdbg_hdr.Size, 0)) { eprintf("Failed to extract entire KDBG\n"); g_free(kdbg); return NULL; @@ -286,7 +286,7 @@ static int fill_header(WinDumpHeader64 *hdr, struct pa_space *ps, return 1; } - if (va_space_rw(vs, KdVersionBlock, &kvb, sizeof(kvb), 0)) { + if (!va_space_rw(vs, KdVersionBlock, &kvb, sizeof(kvb), 0)) { eprintf("Failed to extract KdVersionBlock\n"); return 1; } @@ -352,8 +352,8 @@ static void fill_context(KDDEBUGGER_DATA64 *kdbg, WinContext64 ctx; QEMUCPUState *s = qe->state[i]; - if (va_space_rw(vs, kdbg->KiProcessorBlock + sizeof(Prcb) * i, - &Prcb, sizeof(Prcb), 0)) { + if (!va_space_rw(vs, kdbg->KiProcessorBlock + sizeof(Prcb) * i, + &Prcb, sizeof(Prcb), 0)) { eprintf("Failed to read CPU #%d PRCB location\n", i); continue; } @@ -363,8 +363,8 @@ static void fill_context(KDDEBUGGER_DATA64 *kdbg, continue; } - if (va_space_rw(vs, Prcb + kdbg->OffsetPrcbContext, - &Context, sizeof(Context), 0)) { + if (!va_space_rw(vs, Prcb + kdbg->OffsetPrcbContext, + &Context, sizeof(Context), 0)) { eprintf("Failed to read CPU #%d ContextFrame location\n", i); continue; } @@ -372,7 +372,7 @@ static void fill_context(KDDEBUGGER_DATA64 *kdbg, printf("Filling context for CPU #%d...\n", i); win_context_init_from_qemu_cpu_state(&ctx, s); - if (va_space_rw(vs, Context, &ctx, sizeof(ctx), 1)) { + if (!va_space_rw(vs, Context, &ctx, sizeof(ctx), 1)) { eprintf("Failed to fill CPU #%d context\n", i); continue; } @@ -396,8 +396,8 @@ static int pe_get_data_dir_entry(uint64_t base, void *start_addr, int idx, return 1; } - if (va_space_rw(vs, base + dos_hdr->e_lfanew, - &nt_hdrs, sizeof(nt_hdrs), 0)) { + if (!va_space_rw(vs, base + dos_hdr->e_lfanew, + &nt_hdrs, sizeof(nt_hdrs), 0)) { return 1; } @@ -406,9 +406,7 @@ static int pe_get_data_dir_entry(uint64_t base, void *start_addr, int idx, return 1; } - if (va_space_rw(vs, - base + data_dir[idx].VirtualAddress, - entry, size, 0)) { + if (!va_space_rw(vs, base + data_dir[idx].VirtualAddress, entry, size, 0)) { return 1; } @@ -470,9 +468,8 @@ static bool pe_check_pdb_name(uint64_t base, void *start_addr, return false; } - if (va_space_rw(vs, - base + debug_dir.AddressOfRawData, - rsds, sizeof(*rsds), 0)) { + if (!va_space_rw(vs, base + debug_dir.AddressOfRawData, + rsds, sizeof(*rsds), 0)) { eprintf("Failed to resolve OMFSignatureRSDS\n"); return false; } @@ -488,9 +485,9 @@ static bool pe_check_pdb_name(uint64_t base, void *start_addr, return false; } - if (va_space_rw(vs, base + debug_dir.AddressOfRawData + - offsetof(OMFSignatureRSDS, name), pdb_name, sizeof(PDB_NAME), - 0)) { + if (!va_space_rw(vs, base + debug_dir.AddressOfRawData + + offsetof(OMFSignatureRSDS, name), + pdb_name, sizeof(PDB_NAME), 0)) { eprintf("Failed to resolve PDB name\n"); return false; } @@ -556,8 +553,8 @@ int main(int argc, char *argv[]) printf("CPU #0 IDT is at 0x%016"PRIx64"\n", state->idt.base); - if (va_space_rw(&vs, state->idt.base, - &first_idt_desc, sizeof(first_idt_desc), 0)) { + if (!va_space_rw(&vs, state->idt.base, + &first_idt_desc, sizeof(first_idt_desc), 0)) { eprintf("Failed to get CPU #0 IDT[0]\n"); goto out_ps; } From patchwork Thu Mar 7 10:20:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1909169 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20230601.gappssmtp.com header.i=@daynix-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=3QSm+eq6; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Tr53v1j9Lz1yX3 for ; Thu, 7 Mar 2024 21:23:23 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1riAsL-0004WY-IC; Thu, 07 Mar 2024 05:21:22 -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 1riAsI-0004WJ-VV for qemu-devel@nongnu.org; Thu, 07 Mar 2024 05:21:19 -0500 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1riAsH-00079P-FQ for qemu-devel@nongnu.org; Thu, 07 Mar 2024 05:21:18 -0500 Received: by mail-pg1-x536.google.com with SMTP id 41be03b00d2f7-5d8b276979aso547711a12.2 for ; Thu, 07 Mar 2024 02:21:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709806876; x=1710411676; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=kYp/u0+4A+fT95r0+Uw8gBS/wuGX08IOGh8a1eJEdws=; b=3QSm+eq6HoPJ3kZc7iZEV4S75npi9IQkLig9rQTUFt+rIt1eCHNI6Iu6PQrOWL+t0s aUxdfmlggf7e6VWnLEAzaGxW5F+Yvc19y0ptwdH/OkDSgiAAZtREofEib8+981qX2dVU IXRh5Pcbatzx5VnFy9sX558THxncAdf30BukRQqSi4GtHx45tNX567Iy8jm2k+IcS4bK OQLgBUXCNlLAjubcAM7U8rPkEPc5IHpkroglKb0MT8oAAy2kWXQEXEtG1CkDtWJT+DtU ctwlWnbtKul7p5hm0EyWtyByf46lBvQWmJHcDkx6DDImf8OhBsjc3QzvAL5FJLZNxpyI HgWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709806876; x=1710411676; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kYp/u0+4A+fT95r0+Uw8gBS/wuGX08IOGh8a1eJEdws=; b=ZLo+YHCOLL4DNlGcj1ZzrzIiuHbM19GLXBTg4/aE9UNvzgH+o5q7akLixqE4EWdDjS uLkUZlj885u71lMVy3Voin465XJzCODoeEPRUUrBHufHzBr/W4QGtbMKaQoqBOjc3DLj 7dgzJKQiLSc1RdsPwqXknE7nKLYcqvXocYP8wgaoEircyBrHITfL4/1fH4VIR04kxVJy ri+KZ0OL5TEOs4qhuPa84UBmeKio7lYovOMvxXrEkrxHe3WLBk5v63qTtsPfRoW56H74 QHYt79R7WktJyRk87GiFyxZ3SRmO7eHrtvsCfMHAe57Jmh08aNG3pTMaN+uch+i5aqPi ynzQ== X-Gm-Message-State: AOJu0Yzz0OXLMOLsCpfnpvsEfnpF9iZaDj+xULD4ysrTkvnk2uJTz2cz DocaGk21wn0xnhTy8NzGJX5xy+NcPxyNw7LMYrEDugUECx4+jF7L5An5GC0IO1T1T6HHepxT3Kt t X-Google-Smtp-Source: AGHT+IGp0m4QZkAdHAahk/AwPLAAL/IdDQCwtFPNRvYGUWBGYQe0FWOceLpi957RqAMAKNvM05AGww== X-Received: by 2002:a05:6a20:938f:b0:1a1:52d5:d17 with SMTP id x15-20020a056a20938f00b001a152d50d17mr8671578pzh.35.1709806876210; Thu, 07 Mar 2024 02:21:16 -0800 (PST) Received: from localhost ([2400:4050:a840:1e00:9ac7:6d57:2b16:6932]) by smtp.gmail.com with UTF8SMTPSA id m19-20020aa78a13000000b006e509762bc2sm12250118pfa.26.2024.03.07.02.21.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 07 Mar 2024 02:21:07 -0800 (PST) From: Akihiko Odaki Date: Thu, 07 Mar 2024 19:20:49 +0900 Subject: [PATCH v4 06/19] contrib/elf2dmp: Fix error reporting style in download.c MIME-Version: 1.0 Message-Id: <20240307-elf2dmp-v4-6-4f324ad4d99d@daynix.com> References: <20240307-elf2dmp-v4-0-4f324ad4d99d@daynix.com> In-Reply-To: <20240307-elf2dmp-v4-0-4f324ad4d99d@daynix.com> To: Viktor Prutyanov , Peter Maydell Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 Received-SPF: none client-ip=2607:f8b0:4864:20::536; envelope-from=akihiko.odaki@daynix.com; helo=mail-pg1-x536.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org include/qapi/error.h says: > We recommend > * bool-valued functions return true on success / false on failure, > ... Signed-off-by: Akihiko Odaki Reviewed-by: Peter Maydell --- contrib/elf2dmp/download.h | 2 +- contrib/elf2dmp/download.c | 10 +++++----- contrib/elf2dmp/main.c | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/contrib/elf2dmp/download.h b/contrib/elf2dmp/download.h index 5c274925f7aa..f65adb5d0894 100644 --- a/contrib/elf2dmp/download.h +++ b/contrib/elf2dmp/download.h @@ -8,6 +8,6 @@ #ifndef DOWNLOAD_H #define DOWNLOAD_H -int download_url(const char *name, const char *url); +bool download_url(const char *name, const char *url); #endif /* DOWNLOAD_H */ diff --git a/contrib/elf2dmp/download.c b/contrib/elf2dmp/download.c index 902dc04ffa5c..21306b3fd4c4 100644 --- a/contrib/elf2dmp/download.c +++ b/contrib/elf2dmp/download.c @@ -9,14 +9,14 @@ #include #include "download.h" -int download_url(const char *name, const char *url) +bool download_url(const char *name, const char *url) { - int err = 1; + bool success = false; FILE *file; CURL *curl = curl_easy_init(); if (!curl) { - return 1; + return false; } file = fopen(name, "wb"); @@ -33,11 +33,11 @@ int download_url(const char *name, const char *url) unlink(name); fclose(file); } else { - err = fclose(file); + success = !fclose(file); } out_curl: curl_easy_cleanup(curl); - return err; + return success; } diff --git a/contrib/elf2dmp/main.c b/contrib/elf2dmp/main.c index 09af39422f1e..d295fd92be2f 100644 --- a/contrib/elf2dmp/main.c +++ b/contrib/elf2dmp/main.c @@ -591,7 +591,7 @@ int main(int argc, char *argv[]) sprintf(pdb_url, "%s%s/%s/%s", SYM_URL_BASE, PDB_NAME, pdb_hash, PDB_NAME); printf("PDB URL is %s\n", pdb_url); - if (download_url(PDB_NAME, pdb_url)) { + if (!download_url(PDB_NAME, pdb_url)) { eprintf("Failed to download PDB file\n"); goto out_ps; } From patchwork Thu Mar 7 10:20:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1909174 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20230601.gappssmtp.com header.i=@daynix-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=WjaefdxV; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Tr55T1dgRz1yX3 for ; Thu, 7 Mar 2024 21:24:45 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1riAsT-0004XK-1t; Thu, 07 Mar 2024 05:21: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 1riAsM-0004Wn-Gq for qemu-devel@nongnu.org; Thu, 07 Mar 2024 05:21:23 -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 1riAsK-00079x-PM for qemu-devel@nongnu.org; Thu, 07 Mar 2024 05:21:22 -0500 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1dc49b00bdbso5849525ad.3 for ; Thu, 07 Mar 2024 02:21:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709806879; x=1710411679; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=shZdRVaAuTUEJwuhgEsEU4+8uLO5iP81udj39ehMmZA=; b=WjaefdxVHQN+v/I9WYPxKM+HMLO4ZdStUxWPZgPB0SnJSeFDPC/AsktZSdRLV3/ZER i9RpxqI0oZhn3GuDDt5gebR+sGlnn0jSVKUzvIL8c7Uu72MU7WzJOxgJUlOoQUFv2+kf tJEtDsp9bRf8kNjRnNaOdbupdwFJLzM7VsAmrTO1Fif71WDbhOtTHCrnnNcOK3uXvzab WCTVBLky68oPwDtwKrsSne3xUMkKVuWNO+LjRvtRSo3gN98hJPEa40di6k7yZQYz/n0a aMNVXiJFb63ToizOxGuSrPUyMA7En+rIgA6oKfn0eeVnXZYWlBTzRyy3elCz5ohJD2hI 9/tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709806879; x=1710411679; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=shZdRVaAuTUEJwuhgEsEU4+8uLO5iP81udj39ehMmZA=; b=IpEBJxk1CmA7xqQ1rZ0kpZ1xO1I4GkFdRZqmGYBZGpR1m/+P8MKhi1o8pba05riNqO Kbi/CqpCQtE0kXhWwmAzL2my0tOlYhmOwRHDS8kJBVmr3zRYkKRQbi3iLfZyAyUFBsHD Fx6yfpCaHQ73unnGGwHWJ0skNvwkrLk4EbusYPfABwcTu11bD/+mhAU3xzg/bJL1NUM8 6VzyopS/mFaCB5JJV66+nuMtU2J2tHkXrEE9YTVFp3k/HmRwlfXcaNMtSWwJXyzp+Ul5 Ctauu9VeCoh8oi3OYtHCJ4i2r9MuBf/LE+N9H7VmLHAQ09HgVMSj6OXDbn0A+ONryXb9 4isQ== X-Gm-Message-State: AOJu0YyeAcqqMNG2ULYb1GQ8hHOz4Q1RG2ht4462KYpu+0lDfONpwKBk lQV6yygXZC/srumZapvoEXDWFlAwe2qQ9Jqz6mmP0HrGdj98RFuojwNjFc87SjqhDdezaUUzYcw N X-Google-Smtp-Source: AGHT+IFS9E7on7QHqwRFZHe90iMnWgvKsB7MqViW/T92QQMSYdEGIhZPqDUIPtx/xxrlUegYzxNt1Q== X-Received: by 2002:a17:903:2289:b0:1dd:4064:9f2a with SMTP id b9-20020a170903228900b001dd40649f2amr4227472plh.38.1709806879020; Thu, 07 Mar 2024 02:21:19 -0800 (PST) Received: from localhost ([2400:4050:a840:1e00:9ac7:6d57:2b16:6932]) by smtp.gmail.com with UTF8SMTPSA id l4-20020a170902f68400b001dcbffec642sm14137868plg.133.2024.03.07.02.21.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 07 Mar 2024 02:21:18 -0800 (PST) From: Akihiko Odaki Date: Thu, 07 Mar 2024 19:20:50 +0900 Subject: [PATCH v4 07/19] contrib/elf2dmp: Fix error reporting style in pdb.c MIME-Version: 1.0 Message-Id: <20240307-elf2dmp-v4-7-4f324ad4d99d@daynix.com> References: <20240307-elf2dmp-v4-0-4f324ad4d99d@daynix.com> In-Reply-To: <20240307-elf2dmp-v4-0-4f324ad4d99d@daynix.com> To: Viktor Prutyanov , Peter Maydell Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org include/qapi/error.h says: > We recommend > * bool-valued functions return true on success / false on failure, > ... Signed-off-by: Akihiko Odaki Reviewed-by: Peter Maydell --- contrib/elf2dmp/pdb.h | 2 +- contrib/elf2dmp/main.c | 2 +- contrib/elf2dmp/pdb.c | 50 +++++++++++++++++++++++++------------------------- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/contrib/elf2dmp/pdb.h b/contrib/elf2dmp/pdb.h index 2a50da56ac96..feddf1862f08 100644 --- a/contrib/elf2dmp/pdb.h +++ b/contrib/elf2dmp/pdb.h @@ -233,7 +233,7 @@ struct pdb_reader { size_t segs_size; }; -int pdb_init_from_file(const char *name, struct pdb_reader *reader); +bool pdb_init_from_file(const char *name, struct pdb_reader *reader); void pdb_exit(struct pdb_reader *reader); uint64_t pdb_resolve(uint64_t img_base, struct pdb_reader *r, const char *name); uint64_t pdb_find_public_v3_symbol(struct pdb_reader *reader, const char *name); diff --git a/contrib/elf2dmp/main.c b/contrib/elf2dmp/main.c index d295fd92be2f..7a3a7225905e 100644 --- a/contrib/elf2dmp/main.c +++ b/contrib/elf2dmp/main.c @@ -596,7 +596,7 @@ int main(int argc, char *argv[]) goto out_ps; } - if (pdb_init_from_file(PDB_NAME, &pdb)) { + if (!pdb_init_from_file(PDB_NAME, &pdb)) { eprintf("Failed to initialize PDB reader\n"); goto out_pdb_file; } diff --git a/contrib/elf2dmp/pdb.c b/contrib/elf2dmp/pdb.c index abf17c2e7c12..1c5051425185 100644 --- a/contrib/elf2dmp/pdb.c +++ b/contrib/elf2dmp/pdb.c @@ -158,30 +158,30 @@ static void *pdb_ds_read_file(struct pdb_reader* r, uint32_t file_number) return pdb_ds_read(r->ds.header, block_list, file_size[file_number]); } -static int pdb_init_segments(struct pdb_reader *r) +static bool pdb_init_segments(struct pdb_reader *r) { unsigned stream_idx = r->segments; r->segs = pdb_ds_read_file(r, stream_idx); if (!r->segs) { - return 1; + return false; } r->segs_size = pdb_get_file_size(r, stream_idx); if (!r->segs_size) { - return 1; + return false; } - return 0; + return true; } -static int pdb_init_symbols(struct pdb_reader *r) +static bool pdb_init_symbols(struct pdb_reader *r) { PDB_SYMBOLS *symbols; symbols = pdb_ds_read_file(r, 3); if (!symbols) { - return 1; + return false; } r->symbols = symbols; @@ -198,18 +198,18 @@ static int pdb_init_symbols(struct pdb_reader *r) goto out_symbols; } - return 0; + return true; out_symbols: g_free(symbols); - return 1; + return false; } -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 == 0) { - return 1; + return false; } memset(r->file_used, 0, sizeof(r->file_used)); @@ -218,22 +218,22 @@ static int pdb_reader_ds_init(struct pdb_reader *r, PDB_DS_HEADER *hdr) hdr->toc_page * hdr->block_size), hdr->toc_size); if (!r->ds.toc) { - return 1; + return false; } - return 0; + return true; } -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[] = "Microsoft C/C++ MSF 7.00"; if (memcmp(data, pdb7, sizeof(pdb7) - 1)) { - return 1; + return false; } - if (pdb_reader_ds_init(r, data)) { - return 1; + if (!pdb_reader_ds_init(r, data)) { + return false; } r->ds.root = pdb_ds_read_file(r, 1); @@ -241,15 +241,15 @@ static int pdb_reader_init(struct pdb_reader *r, void *data) goto out_ds; } - if (pdb_init_symbols(r)) { + if (!pdb_init_symbols(r)) { goto out_root; } - if (pdb_init_segments(r)) { + if (!pdb_init_segments(r)) { goto out_sym; } - return 0; + return true; out_sym: pdb_exit_symbols(r); @@ -258,7 +258,7 @@ out_root: out_ds: pdb_reader_ds_exit(r); - return 1; + return false; } 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); } -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 = NULL; void *map; @@ -278,21 +278,21 @@ int pdb_init_from_file(const char *name, struct pdb_reader *reader) if (gerr) { eprintf("Failed to map PDB file \'%s\'\n", name); g_error_free(gerr); - return 1; + return false; } reader->file_size = g_mapped_file_get_length(reader->gmf); map = g_mapped_file_get_contents(reader->gmf); - if (pdb_reader_init(reader, map)) { + if (!pdb_reader_init(reader, map)) { goto out_unmap; } - return 0; + return true; out_unmap: g_mapped_file_unref(reader->gmf); - return 1; + return false; } void pdb_exit(struct pdb_reader *reader) From patchwork Thu Mar 7 10:20:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1909170 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20230601.gappssmtp.com header.i=@daynix-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=KkXxzOCa; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Tr5414g3pz1yX3 for ; Thu, 7 Mar 2024 21:23:29 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1riAsU-0004bv-L6; Thu, 07 Mar 2024 05:21:30 -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 1riAsQ-0004X5-Vu for qemu-devel@nongnu.org; Thu, 07 Mar 2024 05:21:27 -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 1riAsN-0007AG-F9 for qemu-devel@nongnu.org; Thu, 07 Mar 2024 05:21:26 -0500 Received: by mail-pg1-x531.google.com with SMTP id 41be03b00d2f7-5ce07cf1e5dso579667a12.2 for ; Thu, 07 Mar 2024 02:21:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709806882; x=1710411682; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=g0+eTNzDAfP/I8pMSpLdPirrAbqQUuAszFkDupkQLY8=; b=KkXxzOCao1yI/9lsyirmPUzpCLGHugzeB3tsh6CnEk6DBT1YI4utnK4U5EOCDa3u+b CvsO5ORDn74uSqbxT+kabhSJqZVqsdfFMusncoomBTtFGO6rcs/xSIEjWSw3u/tFQBHF iX97bX4yCC6BppbkxGGQJkMGhqsfSbwqzUdhZHxS4uZWuEOddtjyqu2LwWCpFT2SXK2Q 9GuK6Lj/CL1bv9bRxxH3REHLZZvCqu/qoUXdgEcXc529FSZh9OT2UuuDrM1BwYrxkqN3 qyPF/vBoBeMi2fTgcMXdTz9HW6joQrLeF0H1bBLenw+P7fDX8o/JLwqobjtWSLGRDMvT He6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709806882; x=1710411682; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=g0+eTNzDAfP/I8pMSpLdPirrAbqQUuAszFkDupkQLY8=; b=Uf61ekR15ZnSO0F96dp09vQaLkXR6HydJMV+fw/utdvdbGEYmQQiC1wLPPWdw3W59q /mejnUdWQ/lUntGZD2touMenFd8wpfKGLCWd4UewcC2sSA03oNXPnQSmHHq+dRpX8+JA EbwSz/1qEiUUUSErSxd0Lx3VB7F36c6Z897QKJR9Auw19yCHXQoxQvFAOk2Cdg/9lUH2 xELsQ+QQ61U5uOvzoJZUWruR86kbomUGFbd3pJQRusR7xucnvdybOR4b5uHYp9op8s0c OjfF0mpKmBKRwrX/o/jSsbWkgdhppxmVaEAVSIN2A16/EOoEjbTR2t2Iu6EY5MudlPQl pOBA== X-Gm-Message-State: AOJu0YzCuHU/lXlYlgcp7z8yzusmzWhQzZfNZd7U8Mfr7gCPeXf2Gsnd BDiSupqxsUdKNwJgdJwruo58VvLbILdkq27yxoRF1FCVIDtmQnYt7S8Cuo7i9I6lDfo70ZH8k0h N X-Google-Smtp-Source: AGHT+IE3oXDscRQyJLlAQugirK0otEyfEtPl8P9vkYqyOcdqznOTxPzT7bSLmqpYB2lzW2I7G9HleA== X-Received: by 2002:a05:6a20:9189:b0:1a1:7513:1f74 with SMTP id v9-20020a056a20918900b001a175131f74mr823641pzd.37.1709806882276; Thu, 07 Mar 2024 02:21:22 -0800 (PST) Received: from localhost ([2400:4050:a840:1e00:9ac7:6d57:2b16:6932]) by smtp.gmail.com with UTF8SMTPSA id 11-20020a63104b000000b005d8e30897e4sm12132972pgq.69.2024.03.07.02.21.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 07 Mar 2024 02:21:21 -0800 (PST) From: Akihiko Odaki Date: Thu, 07 Mar 2024 19:20:51 +0900 Subject: [PATCH v4 08/19] contrib/elf2dmp: Fix error reporting style in qemu_elf.c MIME-Version: 1.0 Message-Id: <20240307-elf2dmp-v4-8-4f324ad4d99d@daynix.com> References: <20240307-elf2dmp-v4-0-4f324ad4d99d@daynix.com> In-Reply-To: <20240307-elf2dmp-v4-0-4f324ad4d99d@daynix.com> To: Viktor Prutyanov , Peter Maydell Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org include/qapi/error.h says: > We recommend > * bool-valued functions return true on success / false on failure, > ... Signed-off-by: Akihiko Odaki Reviewed-by: Peter Maydell --- contrib/elf2dmp/qemu_elf.h | 2 +- contrib/elf2dmp/main.c | 2 +- contrib/elf2dmp/qemu_elf.c | 32 ++++++++++++++++---------------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/contrib/elf2dmp/qemu_elf.h b/contrib/elf2dmp/qemu_elf.h index afa75f10b2d2..adc50238b46b 100644 --- a/contrib/elf2dmp/qemu_elf.h +++ b/contrib/elf2dmp/qemu_elf.h @@ -42,7 +42,7 @@ typedef struct QEMU_Elf { int has_kernel_gs_base; } QEMU_Elf; -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); Elf64_Phdr *elf64_getphdr(void *map); diff --git a/contrib/elf2dmp/main.c b/contrib/elf2dmp/main.c index 7a3a7225905e..cb28971789e4 100644 --- a/contrib/elf2dmp/main.c +++ b/contrib/elf2dmp/main.c @@ -535,7 +535,7 @@ int main(int argc, char *argv[]) return 1; } - if (QEMU_Elf_init(&qemu_elf, argv[1])) { + if (!QEMU_Elf_init(&qemu_elf, argv[1])) { eprintf("Failed to initialize QEMU ELF dump\n"); return 1; } diff --git a/contrib/elf2dmp/qemu_elf.c b/contrib/elf2dmp/qemu_elf.c index 055e6f8792e9..a22c057d3ec3 100644 --- a/contrib/elf2dmp/qemu_elf.c +++ b/contrib/elf2dmp/qemu_elf.c @@ -60,7 +60,7 @@ Elf64_Half elf_getphdrnum(void *map) return ehdr->e_phnum; } -static int init_states(QEMU_Elf *qe) +static bool init_states(QEMU_Elf *qe) { Elf64_Phdr *phdr = elf64_getphdr(qe->map); Elf64_Nhdr *start = (void *)((uint8_t *)qe->map + phdr[0].p_offset); @@ -70,7 +70,7 @@ static int init_states(QEMU_Elf *qe) if (phdr[0].p_type != PT_NOTE) { eprintf("Failed to find PT_NOTE\n"); - return 1; + return false; } qe->has_kernel_gs_base = 1; @@ -107,7 +107,7 @@ static int init_states(QEMU_Elf *qe) qe->state_nr = cpu_nr; - return 0; + return true; } static void exit_states(QEMU_Elf *qe) @@ -162,7 +162,7 @@ static bool check_ehdr(QEMU_Elf *qe) return true; } -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 *filename) fd = open(filename, O_RDONLY, 0); if (fd == -1) { eprintf("Failed to open ELF dump file \'%s\'\n", filename); - return 1; + return false; } if (fstat(fd, &st)) { eprintf("Failed to get size of ELF dump file\n"); close(fd); - return 1; + return false; } qe->size = st.st_size; @@ -188,7 +188,7 @@ static int QEMU_Elf_map(QEMU_Elf *qe, const char *filename) if (qe->map == MAP_FAILED) { eprintf("Failed to map ELF file\n"); close(fd); - return 1; + return false; } close(fd); @@ -201,14 +201,14 @@ static int QEMU_Elf_map(QEMU_Elf *qe, const char *filename) if (gerr) { eprintf("Failed to map ELF dump file \'%s\'\n", filename); g_error_free(gerr); - return 1; + return false; } qe->map = g_mapped_file_get_contents(qe->gmf); qe->size = g_mapped_file_get_length(qe->gmf); #endif - return 0; + return true; } static void QEMU_Elf_unmap(QEMU_Elf *qe) @@ -220,25 +220,25 @@ static void QEMU_Elf_unmap(QEMU_Elf *qe) #endif } -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; } if (!check_ehdr(qe)) { eprintf("Input file has the wrong format\n"); QEMU_Elf_unmap(qe); - return 1; + return false; } - if (init_states(qe)) { + if (!init_states(qe)) { eprintf("Failed to extract QEMU CPU states\n"); QEMU_Elf_unmap(qe); - return 1; + return false; } - return 0; + return true; } void QEMU_Elf_exit(QEMU_Elf *qe) From patchwork Thu Mar 7 10:20:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1909175 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20230601.gappssmtp.com header.i=@daynix-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=Q59FXDae; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Tr55Z5mfmz1yX3 for ; Thu, 7 Mar 2024 21:24:50 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1riAsV-0004e9-Ag; Thu, 07 Mar 2024 05:21:31 -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 1riAsT-0004XM-2J for qemu-devel@nongnu.org; Thu, 07 Mar 2024 05:21:29 -0500 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1riAsQ-0007AS-OO for qemu-devel@nongnu.org; Thu, 07 Mar 2024 05:21:28 -0500 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-6e09143c7bdso556937b3a.3 for ; Thu, 07 Mar 2024 02:21:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709806885; x=1710411685; 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=Qu0/SyjtgjMsZVCuj2aWQAULDW+4uRg6GTgBSV1VdlA=; b=Q59FXDaeG4uWzweQOwAVYxj6veFj589k2Tc2hrPlkadhzHOLfo7IJV8JeFM+4BXE09 7funCeeWlPPGCGjTUdupsD14MecokXD59/DTwd1cm6j9UPvwvA6S07IfY4AzPLbK7alx xXtdno/+MYbvHvsuI9dq5YDZ3UI+z/0tCrzBDrwGqVFwAItM8drQLr7pNXENwRKqv4vQ 0zLOW4wmhvePXELV8M6rKboUJpEql8PdNw7zyJrZoq8DWBKBzp1Cagis6CBACMoXYexp fhNlW6CIskK/YUyaUTWTFZJ8VrbM91mbuPADsFh3s10hKbfpmQr9QFpRFf52hg+fJoCz PkbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709806885; x=1710411685; 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=Qu0/SyjtgjMsZVCuj2aWQAULDW+4uRg6GTgBSV1VdlA=; b=TzwUsMjLiDcZSxrNFiAzlRjPPvFUCHqgY5xzBzVStImfHgo9y/wpGrAouaVZGknqmK YU4JE/EeTLaND6lPjB30JP1AhtVD8+EyrR1K+ib6mYi17R4Y7CJiwLIUXdtEq16lFD8U fdrLL+VRWR/resDfFQEFEN34WSW1A9our67v8/6AO03OaIYBLx/v3D3FVlUkdJASVIN1 XV2wkK1LJGo6PeSZ7zJgMHQeKwVoeITGOj3MlyRt9oUnPwsxZrFKHknvotjd/0JEm/lE mvoMzF4s4VuWVCQMtoS/cDWPdYRl9OQqFVuxmRt6Gqln7EprdJH6RvHOi2B2EF4rbRHD QrJQ== X-Gm-Message-State: AOJu0Yx7Adgmo44YBrI4SpnBfKXp2yQkjOLtgXewTQnMiFB4kRqIgJjZ ZFKcDBtkwXyTM5r3d3AsC78y2LTlAxHlxn8HRg0w3+MVgp9db/eC7vW9vjOTJe4= X-Google-Smtp-Source: AGHT+IEstnLOvrcK9UjgrpKxKaQLUIlooY+EA1yomeMLrX83yGcvlwQcdUPLi+1EU7JHEzlaz2j05A== X-Received: by 2002:aa7:8889:0:b0:6e5:69f8:e2c1 with SMTP id z9-20020aa78889000000b006e569f8e2c1mr18172100pfe.22.1709806885015; Thu, 07 Mar 2024 02:21:25 -0800 (PST) Received: from localhost ([2400:4050:a840:1e00:9ac7:6d57:2b16:6932]) by smtp.gmail.com with UTF8SMTPSA id z12-20020aa785cc000000b006e56e5c09absm12597830pfn.14.2024.03.07.02.21.23 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 07 Mar 2024 02:21:24 -0800 (PST) From: Akihiko Odaki Date: Thu, 07 Mar 2024 19:20:52 +0900 Subject: [PATCH v4 09/19] contrib/elf2dmp: Fix error reporting style in main.c MIME-Version: 1.0 Message-Id: <20240307-elf2dmp-v4-9-4f324ad4d99d@daynix.com> References: <20240307-elf2dmp-v4-0-4f324ad4d99d@daynix.com> In-Reply-To: <20240307-elf2dmp-v4-0-4f324ad4d99d@daynix.com> To: Viktor Prutyanov , Peter Maydell Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 Received-SPF: none client-ip=2607:f8b0:4864:20::433; envelope-from=akihiko.odaki@daynix.com; helo=mail-pf1-x433.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org include/qapi/error.h says: > We recommend > * bool-valued functions return true on success / false on failure, > ... Signed-off-by: Akihiko Odaki Reviewed-by: Peter Maydell --- 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..9347b0cd5a2d 100644 --- a/contrib/elf2dmp/main.c +++ b/contrib/elf2dmp/main.c @@ -186,13 +186,13 @@ static void win_context_init_from_qemu_cpu_state(WinContext64 *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; } /* @@ -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); } } @@ -220,16 +220,16 @@ static int fix_dtb(struct va_space *vs, QEMU_Elf *qe) uint64_t *cr3 = va_space_resolve(vs, Prcb + 0x7000); if (!cr3) { - return 1; + return false; } va_space_set_dtb(vs, *cr3); printf("DirectoryTableBase = 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); } - return 1; + return true; } static void try_merge_runs(struct pa_space *ps, @@ -268,9 +268,10 @@ static void try_merge_runs(struct pa_space *ps, } } -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 = va_space_resolve(vs, SharedUserData + KUSD_OFFSET_SUITE_MASK); @@ -283,12 +284,12 @@ static int fill_header(WinDumpHeader64 *hdr, struct pa_space *ps, QEMU_BUILD_BUG_ON(KUSD_OFFSET_PRODUCT_TYPE >= ELF2DMP_PAGE_SIZE); if (!suite_mask || !product_type) { - return 1; + return false; } if (!va_space_rw(vs, KdVersionBlock, &kvb, sizeof(kvb), 0)) { eprintf("Failed to extract KdVersionBlock\n"); - return 1; + return false; } h = (WinDumpHeader64) { @@ -333,7 +334,7 @@ static int fill_header(WinDumpHeader64 *hdr, struct pa_space *ps, *hdr = h; - return 0; + return true; } /* @@ -379,8 +380,8 @@ static void fill_context(KDDEBUGGER_DATA64 *kdbg, } } -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_space *vs) { const char e_magic[2] = "MZ"; const char Signature[4] = "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) >= ELF2DMP_PAGE_SIZE); if (memcmp(&dos_hdr->e_magic, e_magic, sizeof(e_magic))) { - return 1; + return false; } if (!va_space_rw(vs, base + dos_hdr->e_lfanew, &nt_hdrs, sizeof(nt_hdrs), 0)) { - return 1; + return false; } if (memcmp(&nt_hdrs.Signature, Signature, sizeof(Signature)) || file_hdr->Machine != 0x8664 || opt_hdr->Magic != 0x020b) { - return 1; + return false; } if (!va_space_rw(vs, base + data_dir[idx].VirtualAddress, entry, size, 0)) { - return 1; + return false; } printf("Data directory entry #%d: RVA = 0x%08"PRIx32"\n", idx, (uint32_t)data_dir[idx].VirtualAddress); - return 0; + return true; } -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 = fopen(name, "wb"); size_t i; if (!dmp_file) { eprintf("Failed to open output file \'%s\'\n", name); - return 1; + return false; } 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) != 1) { eprintf("Failed to write dump header\n"); fclose(dmp_file); - return 1; + return false; } for (i = 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) != 1) { eprintf("Failed to write block\n"); fclose(dmp_file); - return 1; + return false; } } - return fclose(dmp_file); + return !fclose(dmp_file); } 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 *start_addr, IMAGE_DEBUG_DIRECTORY debug_dir; char pdb_name[sizeof(PDB_NAME)]; - 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_DIRECTORY, + &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]); 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; } - 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; } fill_context(kdbg, &vs, &qemu_elf); - if (write_dump(&ps, &header, argv[2])) { + if (!write_dump(&ps, &header, argv[2])) { eprintf("Failed to save dump\n"); goto out_kdbg; } From patchwork Thu Mar 7 10:20:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1909177 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20230601.gappssmtp.com header.i=@daynix-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=Yp+HuO8L; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Tr56R0mF0z1yX8 for ; Thu, 7 Mar 2024 21:25:35 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1riAsX-0004pj-OW; Thu, 07 Mar 2024 05:21: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 1riAsU-0004cl-Tb for qemu-devel@nongnu.org; Thu, 07 Mar 2024 05:21:30 -0500 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1riAsT-0007Aq-76 for qemu-devel@nongnu.org; Thu, 07 Mar 2024 05:21:30 -0500 Received: by mail-pj1-x1032.google.com with SMTP id 98e67ed59e1d1-29b70bf6c58so472121a91.0 for ; Thu, 07 Mar 2024 02:21:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709806888; x=1710411688; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=QP7weYtq4QbJF4sIXleLE+UckEHf7lBxF+Hq2Ng452s=; b=Yp+HuO8LKTESgehzaS487PIk+t6s6qt5zK//kqkt7Ri6qvjAc5Gid9YhBl67xPwfNC niACSxA9mut5TqFWuGhNvZeB7XyinKR3BONb923aHrij6e43r+zuhLCYJ8bYWDdnduwC 9xeEYMaNJR4wesg+S2YM7/IT6t2a4aKKpKapt6uhrxC7NRHe0wjpj5/VCMKXwTsw/u0f wWYtFsGlAESM3Btcj7gh9B4vs9T/OJbRBFmTTj99zioeeHEYQIbFWH97WV36zF2wZaPg 44oVgZ+4LOJoH0Gh8xjo37ESj7xsG5I+JyysbGDP2CjZz1q0ck1n0Z51UObHFirmdsd6 F8yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709806888; x=1710411688; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QP7weYtq4QbJF4sIXleLE+UckEHf7lBxF+Hq2Ng452s=; b=ekywgxSp4Ecg4ZuSnwjLQKzWeavjT1OFAXF74ob5VePUb2NTlWoNbuMhcxmaEsR2t5 t0Nb7e0tVj9AZB1TwHj954e459V7wozFVNbUE4ZzvqToLzombs/FxGj4VzwdotFzWn8E K4u3Cdd4YyEMLo/J1AMbCkA7z5q9aMQFQptuRW3FMh+gMDyf7UoA4uCTnf2f+WHXFWul NiHXfCmTE7lg5oMl1EDbba2w0wtwN4rxEWYeZZw5k+z3YeOaZti+chkw/eZx1GKwq4VL Mlmcj4qq6frVx/5yKVSJ7zYvgot4TZOnFgO6djcws1rvNtHr5CfiCXlUYEL/PxK5i6sj Bx2w== X-Gm-Message-State: AOJu0Yw1t6AEypfXsYYKUB6rwy3N0ktGMasIxvWr2LBVc5ogKm49eVQ/ YiNd4SidOPL+X07ayJ1b7Bs8Ud8mJsrZbLXFXf1v7V2wpFuK9vOmeTmDNEI3Ufk= X-Google-Smtp-Source: AGHT+IFbRyi2XeKtdwhnEB8vkbu9dmQMmGE7wE+OuDwZGbpK0VU6TFBybTPUFiK2THAId3fI4cqeyw== X-Received: by 2002:a17:90b:3ccf:b0:299:3ebf:d180 with SMTP id qd15-20020a17090b3ccf00b002993ebfd180mr15706246pjb.6.1709806887843; Thu, 07 Mar 2024 02:21:27 -0800 (PST) Received: from localhost ([2400:4050:a840:1e00:9ac7:6d57:2b16:6932]) by smtp.gmail.com with UTF8SMTPSA id 8-20020a17090a0cc800b0029b5f69830dsm1334553pjt.22.2024.03.07.02.21.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 07 Mar 2024 02:21:27 -0800 (PST) From: Akihiko Odaki Date: Thu, 07 Mar 2024 19:20:53 +0900 Subject: [PATCH v4 10/19] contrib/elf2dmp: Always check for PA resolution failure MIME-Version: 1.0 Message-Id: <20240307-elf2dmp-v4-10-4f324ad4d99d@daynix.com> References: <20240307-elf2dmp-v4-0-4f324ad4d99d@daynix.com> In-Reply-To: <20240307-elf2dmp-v4-0-4f324ad4d99d@daynix.com> To: Viktor Prutyanov , Peter Maydell Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 Received-SPF: none client-ip=2607:f8b0:4864:20::1032; envelope-from=akihiko.odaki@daynix.com; helo=mail-pj1-x1032.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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_space *ps, uint64_t pa) return NULL; } -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 = pa_space_find_block(ps, pa); @@ -33,6 +33,19 @@ static uint8_t *pa_space_resolve(struct pa_space *ps, uint64_t pa) return block->addr + (pa - block->paddr); } +static bool pa_space_read64(struct pa_space *ps, uint64_t pa, uint64_t *value) +{ + uint64_t *resolved = pa_space_resolve(ps, pa); + + if (!resolved) { + return false; + } + + *value = *resolved; + + return true; +} + static void pa_block_align(struct pa_block *b) { uint64_t low_align = ((b->paddr - 1) | ELF2DMP_PAGE_MASK) + 1 - b->paddr; @@ -106,19 +119,20 @@ void va_space_create(struct va_space *vs, struct pa_space *ps, uint64_t dtb) va_space_set_dtb(vs, dtb); } -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 = (vs->dtb & 0xffffffffff000) | ((va & 0xff8000000000) >> 36); - return *(uint64_t *)pa_space_resolve(vs->ps, pa); + return pa_space_read64(vs->ps, pa, value); } -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 = (pml4e & 0xffffffffff000) | ((va & 0x7FC0000000) >> 27); - return *(uint64_t *)pa_space_resolve(vs->ps, pdpte_paddr); + return pa_space_read64(vs->ps, pdpte_paddr, value); } static uint64_t pde_index(uint64_t va) @@ -131,11 +145,12 @@ static uint64_t pdba_base(uint64_t pdpe) return pdpe & 0xFFFFFFFFFF000; } -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 = pdba_base(pdpe) + pde_index(va) * 8; - return *(uint64_t *)pa_space_resolve(vs->ps, pgd_entry); + return pa_space_read64(vs->ps, pgd_entry, value); } static uint64_t pte_index(uint64_t va) @@ -148,11 +163,12 @@ static uint64_t ptba_base(uint64_t pde) return pde & 0xFFFFFFFFFF000; } -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 = ptba_base(pgd) + pte_index(va) * 8; - return *(uint64_t *)pa_space_resolve(vs->ps, pgd_val); + return pa_space_read64(vs->ps, pgd_val, value); } 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, uint64_t va) { uint64_t pml4e, pdpe, pgd, pte; - pml4e = get_pml4e(vs, va); - if (!is_present(pml4e)) { + if (!get_pml4e(vs, va, &pml4e) || !is_present(pml4e)) { return INVALID_PA; } - pdpe = get_pdpi(vs, va, pml4e); - if (!is_present(pdpe)) { + if (!get_pdpi(vs, va, pml4e, &pdpe) || !is_present(pdpe)) { return INVALID_PA; } @@ -198,8 +212,7 @@ static uint64_t va_space_va2pa(struct va_space *vs, uint64_t va) return get_1GB_paddr(va, pdpe); } - pgd = get_pgd(vs, va, pdpe); - if (!is_present(pgd)) { + if (!get_pgd(vs, va, pdpe, &pgd) || !is_present(pgd)) { return INVALID_PA; } @@ -207,8 +220,7 @@ static uint64_t va_space_va2pa(struct va_space *vs, uint64_t va) return get_2MB_paddr(va, pgd); } - pte = get_pte(vs, va, pgd); - if (!is_present(pte)) { + if (!get_pte(vs, va, pgd, &pte) || !is_present(pte)) { return INVALID_PA; } From patchwork Thu Mar 7 10:20:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1909168 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20230601.gappssmtp.com header.i=@daynix-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=edEN9G8a; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Tr53X018Lz1yX3 for ; Thu, 7 Mar 2024 21:23:04 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1riAsY-0004vD-PI; Thu, 07 Mar 2024 05:21: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 1riAsX-0004q2-PL for qemu-devel@nongnu.org; Thu, 07 Mar 2024 05:21:33 -0500 Received: from mail-oi1-x233.google.com ([2607:f8b0:4864:20::233]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1riAsW-0007BZ-9a for qemu-devel@nongnu.org; Thu, 07 Mar 2024 05:21:33 -0500 Received: by mail-oi1-x233.google.com with SMTP id 5614622812f47-3bbbc6b4ed1so376135b6e.2 for ; Thu, 07 Mar 2024 02:21:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709806891; x=1710411691; 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=G+hvr6O3ORvjAgJg+6YyeFVM5M5tHwrDPGaC/yhxpOs=; b=edEN9G8aIFLBqHy1kI+n9Vy4Yxzd0XzU1jwxcbC7Ccn1qOZz7Lbg+tGoEdD9QOWggQ Iw4QxyNv2FrdNnTtbSkQDx/BWS/9TskUtwbIj/WWGeTusxni8bXxCpv7DpqexxbH7VXN BsTk7TMsbtebn+8y0oac8vLybB8FAAPuH57Zdp3YU17xqf9UccxAC7czjEGxos4Q6P8x +mjaGXlI2XpZs6nlSYPa3icBjYc2hhVqs6CzacU2d4uazNhB2YVNwiaNOUkdEjNoAvQs NyigP6nxUr2cu1u3Tu2lETfbS2O9x4hQ8zpXZyZFFssKdx3YsJZTn0gXYKquB+YcQnZa aM0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709806891; x=1710411691; 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=G+hvr6O3ORvjAgJg+6YyeFVM5M5tHwrDPGaC/yhxpOs=; b=KoZbsVMTDqXL8A1mDBydv9WhV34nEi9NKTU95bR1SMd7envQtyHi2fVNZs1Ei6hdLH H76ltEIqxsoTm8txD/O7KbtyZ8lsZFwH3wIuX5wJqB7SjV+HxIW4ZUAouYySVyb5DrM2 g3rAqdRjxTBId+dhGfVoonR4ogS/4+gVhmEL/YoCv5T++5K2V1jZxBLZIDdXJ9Y9fwuF KvKWDciAb06OHbV220ti5phLjajvw2JYzWsM8KbIJbRI/4X4SuDq2fha9EEryUqa0GKp 0R/id0q2bMS/E0ODF7Io/BOWrW5P7LlL/lmRYWW9sshQVVCchfJ6aBdHEW6y6CfjHA04 9rSQ== X-Gm-Message-State: AOJu0Yz9fw8UHKZe8dv6MNo6vkfnGuO1yTIEqMz3dYE1wxXGXjhdDfiI mvh5mnNKVDHWvlMC6T3ihueixXp5Jnu/+6sWqDO3oqKPsuUHe7CS7/1JLmlia3R5SztWU+poBiQ X X-Google-Smtp-Source: AGHT+IE+5K8qNDUXcyBZ8B5kfZtu1smKEb2NTTloy3SIIj84alLgPs4HIz0J7yI2piRYpT2ixl1Kkg== X-Received: by 2002:a05:6808:6297:b0:3c1:e999:467d with SMTP id du23-20020a056808629700b003c1e999467dmr7439216oib.40.1709806890801; Thu, 07 Mar 2024 02:21:30 -0800 (PST) Received: from localhost ([2400:4050:a840:1e00:9ac7:6d57:2b16:6932]) by smtp.gmail.com with UTF8SMTPSA id u23-20020aa78497000000b006e5092fb3efsm12237604pfn.159.2024.03.07.02.21.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 07 Mar 2024 02:21:30 -0800 (PST) From: Akihiko Odaki Date: Thu, 07 Mar 2024 19:20:54 +0900 Subject: [PATCH v4 11/19] contrib/elf2dmp: Always destroy PA space MIME-Version: 1.0 Message-Id: <20240307-elf2dmp-v4-11-4f324ad4d99d@daynix.com> References: <20240307-elf2dmp-v4-0-4f324ad4d99d@daynix.com> In-Reply-To: <20240307-elf2dmp-v4-0-4f324ad4d99d@daynix.com> To: Viktor Prutyanov , Peter Maydell Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 Received-SPF: none client-ip=2607:f8b0:4864:20::233; envelope-from=akihiko.odaki@daynix.com; helo=mail-oi1-x233.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 9347b0cd5a2d..32dc8bac6a30 100644 --- a/contrib/elf2dmp/main.c +++ b/contrib/elf2dmp/main.c @@ -549,7 +549,7 @@ int main(int argc, char *argv[]) va_space_create(&vs, &ps, state->cr[3]); if (!fix_dtb(&vs, &qemu_elf)) { eprintf("Failed to find paging base\n"); - goto out_elf; + goto out_ps; } printf("CPU #0 IDT is at 0x%016"PRIx64"\n", state->idt.base); @@ -634,7 +634,6 @@ out_pdb_file: unlink(PDB_NAME); out_ps: pa_space_destroy(&ps); -out_elf: QEMU_Elf_exit(&qemu_elf); return err; From patchwork Thu Mar 7 10:20:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1909173 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20230601.gappssmtp.com header.i=@daynix-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=XChQ+CU8; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Tr55M1NQFz1yX3 for ; Thu, 7 Mar 2024 21:24:39 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1riAsq-0005Y0-PS; Thu, 07 Mar 2024 05:21:53 -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 1riAso-0005Sz-3x for qemu-devel@nongnu.org; Thu, 07 Mar 2024 05:21:50 -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 1riAsY-0007C9-RJ for qemu-devel@nongnu.org; Thu, 07 Mar 2024 05:21:49 -0500 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1dc5d0162bcso6213555ad.0 for ; Thu, 07 Mar 2024 02:21:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709806893; x=1710411693; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=DgfW3dC2BQFvXbkrpvVsfPqRuCKLeW6kZAejsXMFwME=; b=XChQ+CU8MZcZoAiSyOKgtkVpeutHCHB6S4HM0I0U1uQqs4nqxsnGsY1UyPb8157EuO y5yei1WIHf584LShlEcmEbEEwTFa7Q65CTPljH6L1H1MgTWn6OhMnPOM+QCs3QZ6keEA CSDZ3JyRCTaPhquHfcK/TEFxYvsB61dyc8Vk0gkIEzPRzonXyabBo73nqxVfcZKP8e5C onrlxswus2roa+LgqCx66dvp9OHB/CVFXF1+fPyGGWVE91coVZh/IXB4FnwjHDSsjo8+ JeMzN5i8s9VQxr1kOWtqmoSsaYcFKBe9ViGWMeXT3azr9JKrl8s5OAYBc/xT+ruZD47z KANQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709806893; x=1710411693; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DgfW3dC2BQFvXbkrpvVsfPqRuCKLeW6kZAejsXMFwME=; b=wSxWKQb2pqCFpd96WlfyoPrAW11P886gToIREjaHZ6DjFSQ4l/e00alhOqFLUe9moA GsBGd2DNo0B9BufCCpACIuo3nP+91rn0q8+H3xXVvwy57OHokIgArkSZirOGlfjvOx2/ EpMRHjMqWe26czNFoB8d7Gs8ugcFykllHc97K73INoomhFnReOxMj4tyXL8+DCit2Tnq fapFDjqiysReOTDSErlpqKLVUjcx2Kj0YdJfj7DVjANCk9POJGepA87Dk57SjRbnqdFz 82XkGlVy+QBwQyWeQXoRgudHF7RTwYmSjOzkkbrVecU9RVVIwqKHosq+TZqb50liMwLR 1Wdw== X-Gm-Message-State: AOJu0YxoSr9Gi6Tmb4lbvdyHAPLWJQ37vt0vWetj5G0oD7XZfvmcDAjJ kCLkLC65MvbQnoZfPvQTnJSaYNXiqLdDAtJyxBPjw3YtHWFtsCZE51uDe0jbtNEYTDrA/2vIWo7 T X-Google-Smtp-Source: AGHT+IF68jZdEFj/hfyYQYRzibgDe2IpMF8NgclC81IrSYKhqEqysT+ohre6ZHAMbK0QQozN8FY/Vw== X-Received: by 2002:a17:903:11c6:b0:1dc:a605:5435 with SMTP id q6-20020a17090311c600b001dca6055435mr8705251plh.31.1709806893548; Thu, 07 Mar 2024 02:21:33 -0800 (PST) Received: from localhost ([2400:4050:a840:1e00:9ac7:6d57:2b16:6932]) by smtp.gmail.com with UTF8SMTPSA id f6-20020a170902ce8600b001db45bae92dsm14237079plg.74.2024.03.07.02.21.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 07 Mar 2024 02:21:33 -0800 (PST) From: Akihiko Odaki Date: Thu, 07 Mar 2024 19:20:55 +0900 Subject: [PATCH v4 12/19] contrib/elf2dmp: Ensure segment fits in file MIME-Version: 1.0 Message-Id: <20240307-elf2dmp-v4-12-4f324ad4d99d@daynix.com> References: <20240307-elf2dmp-v4-0-4f324ad4d99d@daynix.com> In-Reply-To: <20240307-elf2dmp-v4-0-4f324ad4d99d@daynix.com> To: Viktor Prutyanov , Peter Maydell Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 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, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 *qemu_elf) ps->block = g_new(struct pa_block, ps->block_nr); for (i = 0; i < phdr_nr; i++) { - if (phdr[i].p_type == PT_LOAD) { + if (phdr[i].p_type == PT_LOAD && phdr[i].p_offset < qemu_elf->size) { ps->block[block_i] = (struct pa_block) { .addr = (uint8_t *)qemu_elf->map + phdr[i].p_offset, .paddr = phdr[i].p_paddr, - .size = phdr[i].p_filesz, + .size = MIN(phdr[i].p_filesz, + qemu_elf->size - phdr[i].p_offset), }; pa_block_align(&ps->block[block_i]); block_i = ps->block[block_i].size ? (block_i + 1) : block_i; From patchwork Thu Mar 7 10:20:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1909166 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20230601.gappssmtp.com header.i=@daynix-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=gih6fdu5; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Tr52x3l8sz1yX3 for ; Thu, 7 Mar 2024 21:22:33 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1riAt9-00068W-HL; Thu, 07 Mar 2024 05:22:12 -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 1riAsv-0005h1-H1 for qemu-devel@nongnu.org; Thu, 07 Mar 2024 05:21:58 -0500 Received: from mail-oi1-x22d.google.com ([2607:f8b0:4864:20::22d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1riAsb-0007CO-Rb for qemu-devel@nongnu.org; Thu, 07 Mar 2024 05:21:56 -0500 Received: by mail-oi1-x22d.google.com with SMTP id 5614622812f47-3c19dd9ade5so290687b6e.3 for ; Thu, 07 Mar 2024 02:21:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709806897; x=1710411697; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Zd2GK/LwiDy+x5sdYIECrLQP++QUZzK/GPm/IzIIz+I=; b=gih6fdu5X+7Em/564vrF3AxKXg64Duvx7MJj4tK8+K5VpoJ5IX6HVa03Kng1m5asLu 1/yGdwUSJ3sZ5Wj6nL+ECgGk10y6sNUzL5jfSCzblQ/W49spHkOgMFF96Kro+U4UrvCe AsmbqJAmO6jN7kwDvXv9IuxBSGMT6fvpZopzz5MVuw0BtQvShCL2Sle4P0l3jKo5b7j7 KHlLzIAkMG3Jud9Qb51JLPx1/3CqxIjxYgzWMSOxvZvk3haBE/ZDiv5Ik+EDQX9kjEeX K5Itriyt8AoTwf6tPF5eBb+rYRy2darcxJFGQ69gQ0EOGW6JbpVUA901pKjIuv6xTu/Y b6xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709806897; x=1710411697; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Zd2GK/LwiDy+x5sdYIECrLQP++QUZzK/GPm/IzIIz+I=; b=CC6d9eZRBVBILpN8FmzzIZU2ylTkdPRgIUmQv2t7K7PsVoqWScJbeV5+0te7xD0YQ+ USSvq9XGYeDEGPKno/uvo1+tG0i63Fq1ctfB107HDecZVatPSKxIzU8KDd3YOl7q7Yg+ 53sYxJpIBPYWdNA3ooEoeLDzx84RvuceQ2Z34vRYmWs91HqNVo4LqoV10IkHjzhyvUew UdU55Ax1UgxKH0K+Jy3M1+SU+zwsJrIAKahetM32FE0L19MQLh7GS5BHSAvq2UtbPR5+ mgWX7xKQsekUdPM1F0QZ4x37hFWQ/WqpTOelt5BZouzEYcmQszRrgKZcF1UehpI+DiCL p9+A== X-Gm-Message-State: AOJu0YweGBgz8osKe3oPOCChQuQHFoGz+2234fttg6Ark0Z0ht0EaqLj CobvOtxnofK4kxKGDBXObOUNYmJh5NHihn2CcDQGkxRwhOXqchdEKdRfPZUPRW8= X-Google-Smtp-Source: AGHT+IFh5+E/eS9NGlCYAwHg8bnfDHzD7Fy96mwn11F+dikQhF/w1TkxsAwgDW7xXP9BrOeuh3nv3g== X-Received: by 2002:a05:6808:313:b0:3c1:f2fd:78c3 with SMTP id i19-20020a056808031300b003c1f2fd78c3mr7646919oie.15.1709806896863; Thu, 07 Mar 2024 02:21:36 -0800 (PST) Received: from localhost ([2400:4050:a840:1e00:9ac7:6d57:2b16:6932]) by smtp.gmail.com with UTF8SMTPSA id d19-20020a630e13000000b005dcc8a3b26esm12042345pgl.16.2024.03.07.02.21.35 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 07 Mar 2024 02:21:36 -0800 (PST) From: Akihiko Odaki Date: Thu, 07 Mar 2024 19:20:56 +0900 Subject: [PATCH v4 13/19] contrib/elf2dmp: Use lduw_le_p() to read PDB MIME-Version: 1.0 Message-Id: <20240307-elf2dmp-v4-13-4f324ad4d99d@daynix.com> References: <20240307-elf2dmp-v4-0-4f324ad4d99d@daynix.com> In-Reply-To: <20240307-elf2dmp-v4-0-4f324ad4d99d@daynix.com> To: Viktor Prutyanov , Peter Maydell Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 Received-SPF: none client-ip=2607:f8b0:4864:20::22d; envelope-from=akihiko.odaki@daynix.com; helo=mail-oi1-x22d.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The relevant value may be unaligned and is little-endian. Signed-off-by: Akihiko Odaki Reviewed-by: Philippe Mathieu-Daudé --- 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 @@ */ #include "qemu/osdep.h" +#include "qemu/bswap.h" #include "pdb.h" #include "err.h" @@ -186,7 +187,7 @@ static bool pdb_init_symbols(struct pdb_reader *r) r->symbols = symbols; - r->segments = *(uint16_t *)((const char *)symbols + sizeof(PDB_SYMBOLS) + + r->segments = 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 + From patchwork Thu Mar 7 10:20:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1909161 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20230601.gappssmtp.com header.i=@daynix-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=eXBavnfl; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Tr52K6f6hz1yX3 for ; Thu, 7 Mar 2024 21:22:01 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1riAso-0005PZ-DP; Thu, 07 Mar 2024 05:21:50 -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 1riAsi-0005Ow-Na for qemu-devel@nongnu.org; Thu, 07 Mar 2024 05:21:44 -0500 Received: from mail-ot1-x32a.google.com ([2607:f8b0:4864:20::32a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1riAsf-0007CU-Cg for qemu-devel@nongnu.org; Thu, 07 Mar 2024 05:21:44 -0500 Received: by mail-ot1-x32a.google.com with SMTP id 46e09a7af769-6e4a0e80d14so554215a34.1 for ; Thu, 07 Mar 2024 02:21:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709806899; x=1710411699; 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/84n3G740Rm4hmj3TunpldInJlo341Vetn+9WdD47E=; b=eXBavnflLvZ3nKviTKvbDLXC35tYgkUqajS8Ahtw26qTj/AJ21da0I1FQ6ShSXdo6s Hm+M8WsQnQSdCs+r1YtqtgQpH9og8JZVqnaPki0E+euu7Y3OKkKy6IXNLB0N1Lv7VgHn uHb2LH5heyUW0ps6aEiNpFSEUy60+VUgxtozsOe+6acp4ayymJMWZfeHnyc3p2JDViaT rNh7GExz+AQzasW57qvtRYEjrLqCtznWCp6zjrZf3OcqBbqKECTu0UVX+n9F2PEfgN6g dqGr8mA5Q8AFbEBPNfOhYulR6+1xENIz3irEdC4j2wY0t4PsVQ6vcaRtHpzW6y0ND7Ml hdcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709806899; x=1710411699; 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/84n3G740Rm4hmj3TunpldInJlo341Vetn+9WdD47E=; b=vxfSHuFbGnRKCdPJ3yklTKUlp/16+qrtdittpjl7u79UNOEuoMW9MwNJcOJIYcTj8b G2YpqDemNxLyn3fBugjnVtUpcxkcNld9Avpg6VbRUcQPOFRliYyolIW7+kssMLfUbUz1 p55Sr9lw3mmSgasCeugNByn63s1unzGyNQl0KREzavfV5F/D/KS2NslQH0MiJJCsUW4r bxE0wJVDhr2ZeV2Da8kXxpl83X4hcU3Y7sdY6I8jmCQwZ3KJRemoIk0AzYblbLewUFoj 2P3HCK+LTGVdkpOGlmL/kgLb6cwMK6iruWLCCZfVMhaLeL466aTzaJbIpHZiF4V9t6uh KrsA== X-Gm-Message-State: AOJu0Yzn5Xsa7d2J8k3ORcFlUxYrirsW+x5Q+asXyVWvCnIMZJoxG2Qz pG2QaWGrGAVmSzZ6S1cklrfxjU36CHB5lX3EA5wIJKxXc6xhMyoBQYIyIY4wUuo= X-Google-Smtp-Source: AGHT+IFh3G/9ZepsXtxbhdUpXFx3vDivziBUBOZ/ZDpSEbsqw9dGzIm9WId/UrIg3ew0NhlmcfOz3w== X-Received: by 2002:a9d:75cc:0:b0:6e4:e7c5:d4c7 with SMTP id c12-20020a9d75cc000000b006e4e7c5d4c7mr8127384otl.19.1709806899615; Thu, 07 Mar 2024 02:21:39 -0800 (PST) Received: from localhost ([2400:4050:a840:1e00:9ac7:6d57:2b16:6932]) by smtp.gmail.com with UTF8SMTPSA id b16-20020a630c10000000b005dbed0ffb10sm12353454pgl.83.2024.03.07.02.21.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 07 Mar 2024 02:21:39 -0800 (PST) From: Akihiko Odaki Date: Thu, 07 Mar 2024 19:20:57 +0900 Subject: [PATCH v4 14/19] contrib/elf2dmp: Use rol64() to decode MIME-Version: 1.0 Message-Id: <20240307-elf2dmp-v4-14-4f324ad4d99d@daynix.com> References: <20240307-elf2dmp-v4-0-4f324ad4d99d@daynix.com> In-Reply-To: <20240307-elf2dmp-v4-0-4f324ad4d99d@daynix.com> To: Viktor Prutyanov , Peter Maydell Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 Received-SPF: none client-ip=2607:f8b0:4864:20::32a; envelope-from=akihiko.odaki@daynix.com; helo=mail-ot1-x32a.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org rol64() is roubust against too large shift values and fixes UBSan warnings. Signed-off-by: Akihiko Odaki Reviewed-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé --- 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 32dc8bac6a30..d046a72ae67f 100644 --- a/contrib/elf2dmp/main.c +++ b/contrib/elf2dmp/main.c @@ -6,6 +6,7 @@ */ #include "qemu/osdep.h" +#include "qemu/bitops.h" #include "err.h" #include "addrspace.h" @@ -47,11 +48,6 @@ static const uint64_t SharedUserData = 0xfffff78000000000; s ? printf(#s" = 0x%016"PRIx64"\n", s) :\ eprintf("Failed to resolve "#s"\n"), s) -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, size_t size, uint64_t block; block = src[i]; - block = rol(block ^ kwn, (uint8_t)kwn); + block = rol64(block ^ kwn, kwn); block = __builtin_bswap64(block ^ kdbe) ^ kwa; dst[i] = block; } From patchwork Thu Mar 7 10:20:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1909164 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20230601.gappssmtp.com header.i=@daynix-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=I68rP7CT; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Tr52t0trRz1yX3 for ; Thu, 7 Mar 2024 21:22:30 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1riAso-0005Pc-Dx; Thu, 07 Mar 2024 05:21:50 -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 1riAsk-0005PL-Rh for qemu-devel@nongnu.org; Thu, 07 Mar 2024 05:21:46 -0500 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1riAsi-0007E2-3j for qemu-devel@nongnu.org; Thu, 07 Mar 2024 05:21:45 -0500 Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1dc49b00bdbso5851835ad.3 for ; Thu, 07 Mar 2024 02:21:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709806902; x=1710411702; 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=I68rP7CTVuDzdr6/nK3QXKNzvVmtB4U/KZXVXJulE9ZERAL+HhO2y84rrIvr6T/4fj 3rdSfd7Mj4pSkLcfPVB3aTRVU+ic63GS4pNHqGnr+a1gjmY9Kt2VDzTehlWdOQ+Es/wU aJTvIyMkIPpJtuapQag7o46qqFlz56+Putc8ODdcMEfAOPrrP/eXdNcpxYMxeJPMaFlc kg3AcSXGS7Wr54xPbIW5wgGiHb8jgFM7CSWhP5mK7HfCWsRGjib6JejWerAPqnySrMhA WyEh+Z4oTwqSIBJTV3H4NhCZ6ek4nyvKqNAP7BQtd4MxBlLnRU5VD1cwyWtqEP52afvT WZWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709806902; x=1710411702; 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=HSS31Pt9/QWoMt0W4Tv113/mNn02jDhh1ENC4v1WMLof3Jzh5EsVak8aoX5PLNEzie noi7cFDgH7U4/FEYaFVOIEPUnupAGyICfEFdR5O54Z/ANsDzTzRg+6GaMHfUXuQNoWWa inXLp3vdhuqvFaFAzIVlijmayV7yrH6FAY9qc9ZOe5uw0J2bRUpT5Hrns55cb/1bZ1KT MXf+yPy1c7h6cW0vOUGqPnumjqX31r/jGcGj48c900wCP+64OgvOUGl260aEEx+xuHRy H9o3DFNDjAFWRswlEHfuRjOS/TVHPN+ogyJ5VI/AMhDJykK4RSlgurQ7hr/KNx9dAdxk TTTQ== X-Gm-Message-State: AOJu0Yy3ETY4y3ALFxI9ViJK47G5J9jCFPvd8OoKK9dw45jqFPvmWI+N Mi+I8IgNTSulc/mBqhiOyEjecm+iNDTi+glezx0rUrBjgcGDTbbrbA/U5uy7oSk= X-Google-Smtp-Source: AGHT+IHEYROO8JPIUI0EFZv06Q0m+0BcIE5xz/NFQNC6OSq/XBAOUnCiH6OImAU/5yaQzOLvy/tQIg== X-Received: by 2002:a17:903:1104:b0:1dc:a40c:31c6 with SMTP id n4-20020a170903110400b001dca40c31c6mr8261517plh.25.1709806902441; Thu, 07 Mar 2024 02:21:42 -0800 (PST) Received: from localhost ([2400:4050:a840:1e00:9ac7:6d57:2b16:6932]) by smtp.gmail.com with UTF8SMTPSA id s13-20020a170902988d00b001db499c5c12sm746733plp.143.2024.03.07.02.21.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 07 Mar 2024 02:21:42 -0800 (PST) From: Akihiko Odaki Date: Thu, 07 Mar 2024 19:20:58 +0900 Subject: [PATCH v4 15/19] MAINTAINERS: Add Akihiko Odaki as a elf2dmp reviewer MIME-Version: 1.0 Message-Id: <20240307-elf2dmp-v4-15-4f324ad4d99d@daynix.com> References: <20240307-elf2dmp-v4-0-4f324ad4d99d@daynix.com> In-Reply-To: <20240307-elf2dmp-v4-0-4f324ad4d99d@daynix.com> To: Viktor Prutyanov , Peter Maydell Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 Received-SPF: none client-ip=2607:f8b0:4864:20::62a; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x62a.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Akihiko Odaki Reviewed-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Viktor Prutyanov --- 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 elf2dmp M: Viktor Prutyanov +R: Akihiko Odaki S: Maintained F: contrib/elf2dmp/ From patchwork Thu Mar 7 10:20:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1909176 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20230601.gappssmtp.com header.i=@daynix-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=VdMW3Byi; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Tr55s5MRNz1yX8 for ; Thu, 7 Mar 2024 21:25:05 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1riAss-0005ZL-9v; Thu, 07 Mar 2024 05:21:54 -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 1riAso-0005VJ-Ln for qemu-devel@nongnu.org; Thu, 07 Mar 2024 05:21:52 -0500 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1riAsl-0007Eo-B9 for qemu-devel@nongnu.org; Thu, 07 Mar 2024 05:21:50 -0500 Received: by mail-pj1-x1035.google.com with SMTP id 98e67ed59e1d1-299b818d63aso557752a91.0 for ; Thu, 07 Mar 2024 02:21:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709806906; x=1710411706; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=5x59V7N2Snccc4Fu7ozWsaURAyB+hFzG8uxYs6vkbiI=; b=VdMW3ByiUeegC21ya5aXAGk1Sv2cimBUk2l8IX9RsBi/k7wlielcNMFHAX+ElZ5P3e Jb69qdy3zXKLU65BeIpXwQLgnoF4ogIRpt5YfYEOTaa+aP0w7jCBwKnSqOY/KJvxl/Y8 4zyXfn2DiZqdkS8Rtsaa7soKvercO8+ZZBic5AO53vMMZel4uo+R+HxSoI/dQwvjVvY/ r/T91dgnoVYRFArj5CnuEnThDaEc4qzkj0EzY6Qj1FHG7CWx8JOB88FBBGLT0FXForB5 i7HivU71P3tEaGG4c+lJfhE7/UZRJ9vmYmLpAuw+ezqnIkCFOWOYNLVfxnGMgQVxbhVT uxHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709806906; x=1710411706; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5x59V7N2Snccc4Fu7ozWsaURAyB+hFzG8uxYs6vkbiI=; b=RPMNNQVidkvzBJg5Sj2DFpP5UKt+VLx8WZXs7bOqedSFDbs6q9MFBOU5V2GYPBuyqX j7R+/tR67SNrKatIxy53iLgxPbUsrC6ivO7VIwV+up0j0s2Hr6sI45ew9rSfFc+CtGn2 YcsZ5w8qgznzYKn/Da1WX+QCS80qqa0jJH4hjezVCauqInG1E2cjalfuTALGaGEjF6RA GYlGDlu83kQ+ZvDC24JMyZ7AuGKsAvMsYCXM1miPsGcBZkCVnh2n8zr7xbpX1y9NuEM6 TmCYtq+7vFG2OY+eqFSOuXSDn2pX7B8Bg9soEWcOe2y0eZ43P6s0SWaTC7+xDsyonPPU Xd0Q== X-Gm-Message-State: AOJu0YwfTLznps3LXkL4v03t8QQr1lO+RhbNzJ+9bcxCzFkwuPilLnhe oz5NMHp9cWX9pJtCka+As94bMrnqtdxdQU5gcF79JRJTZ/5iUlp67QODubuDHqE= X-Google-Smtp-Source: AGHT+IGM+22Aww+KQMPaqiVvSGwfBGsH2hsx8DDihAHHo9PMU1xwhHj+AFMIeS2g0gNjCq48HNpYRA== X-Received: by 2002:a17:90b:128b:b0:29b:931:37f1 with SMTP id fw11-20020a17090b128b00b0029b093137f1mr1612067pjb.19.1709806905891; Thu, 07 Mar 2024 02:21:45 -0800 (PST) Received: from localhost ([2400:4050:a840:1e00:9ac7:6d57:2b16:6932]) by smtp.gmail.com with UTF8SMTPSA id oc11-20020a17090b1c0b00b0029aea375586sm2123245pjb.1.2024.03.07.02.21.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 07 Mar 2024 02:21:45 -0800 (PST) From: Akihiko Odaki Date: Thu, 07 Mar 2024 19:20:59 +0900 Subject: [PATCH v4 16/19] contrib/elf2dmp: Build only for little endian host MIME-Version: 1.0 Message-Id: <20240307-elf2dmp-v4-16-4f324ad4d99d@daynix.com> References: <20240307-elf2dmp-v4-0-4f324ad4d99d@daynix.com> In-Reply-To: <20240307-elf2dmp-v4-0-4f324ad4d99d@daynix.com> To: Viktor Prutyanov , Peter Maydell Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 Received-SPF: none client-ip=2607:f8b0:4864:20::1035; envelope-from=akihiko.odaki@daynix.com; helo=mail-pj1-x1035.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org elf2dmp assumes little endian host in many places. Build it only for little endian hosts until they are fixed. Signed-off-by: Akihiko Odaki --- contrib/elf2dmp/meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/elf2dmp/meson.build b/contrib/elf2dmp/meson.build index 6707d43c4fa5..046569861f7a 100644 --- a/contrib/elf2dmp/meson.build +++ b/contrib/elf2dmp/meson.build @@ -1,4 +1,4 @@ -if curl.found() +if curl.found() and host_machine.endian() == 'little' executable('elf2dmp', files('main.c', 'addrspace.c', 'download.c', 'pdb.c', 'qemu_elf.c'), genh, dependencies: [glib, curl], install: true) From patchwork Thu Mar 7 10:21:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1909162 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20230601.gappssmtp.com header.i=@daynix-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=1/Qkl/BS; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Tr52S67Y0z1yX3 for ; Thu, 7 Mar 2024 21:22:08 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1riAsw-0005dJ-A9; Thu, 07 Mar 2024 05:21:58 -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 1riAsp-0005WB-Vb for qemu-devel@nongnu.org; Thu, 07 Mar 2024 05:21:52 -0500 Received: from mail-oi1-x22a.google.com ([2607:f8b0:4864:20::22a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1riAso-0007F5-Dp for qemu-devel@nongnu.org; Thu, 07 Mar 2024 05:21:51 -0500 Received: by mail-oi1-x22a.google.com with SMTP id 5614622812f47-3bd72353d9fso307265b6e.3 for ; Thu, 07 Mar 2024 02:21:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709806909; x=1710411709; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=SWv/n6ZKj2r4AuXL4UqGI23kMpuzOnRejuu9Q3uLHrw=; b=1/Qkl/BSvuZ6Pe3LVvtuswGUfBtm7SsFOUeu8q4a2/hmrZyqrPf83Yce+6tiziCs1Z MX8QreJRjSHCheIMIUNYPZOQ7YRSpKRIGccBfUOqcT4SFUvCgGQA7849dFjKqPszT2vQ nKcPShyWvF+XwJpN1zgTn7FhDKTGb5YK/mbca3luGdM2maRvYmAWvZtitT0Mzod8e+bG CZ1BUiphKfr5R5ltj0Sbc12Zv9j3wOr45Bb9g4xCzJbsUywxIIKcbvXYjpR0MoXfQJxi V9B1eVJjQkHKPByE8uWjMt4ObMRdTLuMSgZuF7NJZxMf4z6bLNuPPsprXNbBEIPrPG8n +L5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709806909; x=1710411709; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SWv/n6ZKj2r4AuXL4UqGI23kMpuzOnRejuu9Q3uLHrw=; b=WWE6mut/BExNniJ2LHmQHuW4CBZB9aXyhO95NEyLiVrSWaYtxBHt6UNZUOIoG35hnY 5VNmDL+VXLkPOJOJ0Ux+QsNBmPwaMd7yZPXK3w1Fbt2bUbZzs7TIqx9aeWVJmF7OF/hT zGTAdNe7+z1uhX7yY0G3vfAqvxOtF0445oVvWW4x08iLGif76SDauJChqdo5ZppbeG9b oIqOdaNDgP4js0CbRWQH7+9dPDxfqLOFWHHEOLLGlAIOKbcPFLjMH/+PTyRxMmpJxfZ0 tdsT0UMvb1QSI103nGCVOeBfsQJNSMHp/M2XrXLeF321wyqg6qavOwzbs93GqPxg7/XJ pcPg== X-Gm-Message-State: AOJu0YyaA8CwGnWgnhB2frDql62ufe4ScBUILiBMtwJuBQ3QaZZCABL5 /DkDTooMwofGC8otzHaqvm3VIwj4xS1XWlZM3Sr11ro7HJd5HSZBkQ9JbrtfCnJQBVokuDQg33M K X-Google-Smtp-Source: AGHT+IGwXSPAhhT9Q4vOFxyGynKFUYnnavYEGXAQmIVBHM/YfXvH1OF/25PjupTjV2WjuH/DqXkvgQ== X-Received: by 2002:a05:6870:a70a:b0:21e:5a2b:58ac with SMTP id g10-20020a056870a70a00b0021e5a2b58acmr7672016oam.15.1709806909126; Thu, 07 Mar 2024 02:21:49 -0800 (PST) Received: from localhost ([2400:4050:a840:1e00:9ac7:6d57:2b16:6932]) by smtp.gmail.com with UTF8SMTPSA id r11-20020a63ec4b000000b005d880b41598sm12186644pgj.94.2024.03.07.02.21.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 07 Mar 2024 02:21:48 -0800 (PST) From: Akihiko Odaki Date: Thu, 07 Mar 2024 19:21:00 +0900 Subject: [PATCH v4 17/19] contrib/elf2dmp: Use GPtrArray MIME-Version: 1.0 Message-Id: <20240307-elf2dmp-v4-17-4f324ad4d99d@daynix.com> References: <20240307-elf2dmp-v4-0-4f324ad4d99d@daynix.com> In-Reply-To: <20240307-elf2dmp-v4-0-4f324ad4d99d@daynix.com> To: Viktor Prutyanov , Peter Maydell Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 Received-SPF: none client-ip=2607:f8b0:4864:20::22a; envelope-from=akihiko.odaki@daynix.com; helo=mail-oi1-x22a.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 = (void *)((uint8_t *)qe->map + phdr[0].p_offset); Elf64_Nhdr *end = (void *)((uint8_t *)start + phdr[0].p_memsz); Elf64_Nhdr *nhdr; - size_t cpu_nr = 0; + GPtrArray *states; if (phdr[0].p_type != PT_NOTE) { eprintf("Failed to find PT_NOTE\n"); @@ -74,38 +74,29 @@ static bool init_states(QEMU_Elf *qe) } qe->has_kernel_gs_base = 1; + states = g_ptr_array_new(); for (nhdr = start; nhdr < end; nhdr = nhdr_get_next(nhdr)) { if (!strcmp(nhdr_get_name(nhdr), QEMU_NOTE_NAME)) { QEMUCPUState *state = nhdr_get_desc(nhdr); 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_BASE or * no one has. */ qe->has_kernel_gs_base = 0; } - cpu_nr++; + g_ptr_array_add(states, state); } } - printf("%zu CPU states has been found\n", cpu_nr); + printf("%u CPU states has been found\n", states->len); - qe->state = g_new(QEMUCPUState*, cpu_nr); - - cpu_nr = 0; - - for (nhdr = start; nhdr < end; nhdr = nhdr_get_next(nhdr)) { - if (!strcmp(nhdr_get_name(nhdr), QEMU_NOTE_NAME)) { - qe->state[cpu_nr] = nhdr_get_desc(nhdr); - cpu_nr++; - } - } - - qe->state_nr = cpu_nr; + qe->state_nr = states->len; + qe->state = (void *)g_ptr_array_free(states, FALSE); return true; } From patchwork Thu Mar 7 10:21:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1909172 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20230601.gappssmtp.com header.i=@daynix-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=dcXDxpwZ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Tr5463t2fz23hR for ; Thu, 7 Mar 2024 21:23:34 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1riAt5-0005yt-OV; Thu, 07 Mar 2024 05:22:07 -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 1riAst-0005af-2M for qemu-devel@nongnu.org; Thu, 07 Mar 2024 05:21:55 -0500 Received: from mail-oi1-x230.google.com ([2607:f8b0:4864:20::230]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1riAsr-0007FU-9i for qemu-devel@nongnu.org; Thu, 07 Mar 2024 05:21:54 -0500 Received: by mail-oi1-x230.google.com with SMTP id 5614622812f47-3c1ea425a0fso269108b6e.3 for ; Thu, 07 Mar 2024 02:21:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709806912; x=1710411712; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=CotLFv3JVXm6i3Wu/BAcc+rvRVqdPlzG06TuPB40/EU=; b=dcXDxpwZ8sdP9roQ6GExJHSgODK2bFHSmN9sm6P2DvnaLIKTn72yBeTai02WXivKoH iw6oF8Oftf9BAi6QvU7QX9k6IuuvGpNwD5VkQO8WZ2VkMjSUBbiSDyR8/GoDseTuMdfh 6rM19mgjknvH487tRSPQNpFeHpq3a4mKA1l4sfNvwWhFdFjmAaW2X/9QgIGQibszUi4y I92M/28CI5qAJUmf3bgugMlsNOytlgQM9tJwX26lzBFzWVapuY2yZZEfrZ3Jk3RRiJgN Dng06oTE4Yv/Ejoxyp6mvdTzU7nhlgIaG5ioWdxjkAARClu4MSfx1I97xL5sFtvyERMV lEAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709806912; x=1710411712; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CotLFv3JVXm6i3Wu/BAcc+rvRVqdPlzG06TuPB40/EU=; b=F4Qxt9hLH4qIa1iH++uN/E6SW/jqNCc7DDaJSre1lSNiqd+cUj/ud7+e1gJRHwAGXh 4s/zDjlal7avD/1vbZMsjt6Ak1388NqOg5uJe6au3+Rju7ILfHpRyf1U+kL48JkZ7G0q eWu4ORQRjd8J8du2Mt8kfSyccG40RhhXr03VwFb6VuDwzIe/SA3Or4z+UFtkm+afBnMr hSMNlhEZYb6vPpmg4ZqJxr/JSjnwZYMdGXGzzK8UoIlpXJQVX2l9MKZN7KTxkV4F5GGd gDFA3OoBbkMbeHOwzV6AXJ7/RTCyrWhVGfBdqWd7WvZpuQuyLLa4MjaWER9i669vhYpB VWzw== X-Gm-Message-State: AOJu0YzVra74DaU062e0bgqjV/y1aDnlmiXSeKN87bLlKRlVAdUdq/RY Cff8WZLA1blVOzU2yJsWor+bGKfkONbRjC20F0lP7r/zA5L57cThp7BJewQQxAY= X-Google-Smtp-Source: AGHT+IGtJKL80c09SGBnAxxBqv+OCOF4NcVIHEXz2vfqvUZJBiWWkOvD4GEcxOZD0oYjjjrLVel26g== X-Received: by 2002:a05:6808:6297:b0:3c2:154f:7716 with SMTP id du23-20020a056808629700b003c2154f7716mr5593304oib.43.1709806911935; Thu, 07 Mar 2024 02:21:51 -0800 (PST) Received: from localhost ([2400:4050:a840:1e00:9ac7:6d57:2b16:6932]) by smtp.gmail.com with UTF8SMTPSA id z4-20020a626504000000b006e621fd613fsm7032514pfb.80.2024.03.07.02.21.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 07 Mar 2024 02:21:51 -0800 (PST) From: Akihiko Odaki Date: Thu, 07 Mar 2024 19:21:01 +0900 Subject: [PATCH v4 18/19] contrib/elf2dmp: Clamp QEMU note to file size MIME-Version: 1.0 Message-Id: <20240307-elf2dmp-v4-18-4f324ad4d99d@daynix.com> References: <20240307-elf2dmp-v4-0-4f324ad4d99d@daynix.com> In-Reply-To: <20240307-elf2dmp-v4-0-4f324ad4d99d@daynix.com> To: Viktor Prutyanov , Peter Maydell Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 Received-SPF: none client-ip=2607:f8b0:4864:20::230; envelope-from=akihiko.odaki@daynix.com; helo=mail-oi1-x230.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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This fixes crashes with truncated dumps. Signed-off-by: Akihiko Odaki Reviewed-by: Peter Maydell --- contrib/elf2dmp/qemu_elf.c | 87 +++++++++++++++++++++++++++++----------------- 1 file changed, 55 insertions(+), 32 deletions(-) diff --git a/contrib/elf2dmp/qemu_elf.c b/contrib/elf2dmp/qemu_elf.c index 7d896cac5b15..8d750adf904a 100644 --- a/contrib/elf2dmp/qemu_elf.c +++ b/contrib/elf2dmp/qemu_elf.c @@ -6,6 +6,7 @@ */ #include "qemu/osdep.h" +#include "qemu/host-utils.h" #include "err.h" #include "qemu_elf.h" @@ -15,36 +16,11 @@ #define ROUND_UP(n, d) (((n) + (d) - 1) & -(0 ? (n) : (d))) #endif -#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; } -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 = map; @@ -60,13 +36,35 @@ Elf64_Half elf_getphdrnum(void *map) return ehdr->e_phnum; } +static bool advance_note_offset(uint64_t *offsetp, uint64_t size, uint64_t end) +{ + uint64_t offset = *offsetp; + + if (uadd64_overflow(offset, size, &offset) || offset > UINT64_MAX - 3) { + return false; + } + + offset = ROUND_UP(offset, 4); + + if (offset > end) { + return false; + } + + *offsetp = offset; + + return true; +} + static bool init_states(QEMU_Elf *qe) { Elf64_Phdr *phdr = elf64_getphdr(qe->map); - Elf64_Nhdr *start = (void *)((uint8_t *)qe->map + phdr[0].p_offset); - Elf64_Nhdr *end = (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; if (phdr[0].p_type != PT_NOTE) { eprintf("Failed to find PT_NOTE\n"); @@ -74,15 +72,40 @@ static bool init_states(QEMU_Elf *qe) } qe->has_kernel_gs_base = 1; + offset = phdr[0].p_offset; states = g_ptr_array_new(); - for (nhdr = start; nhdr < end; nhdr = nhdr_get_next(nhdr)) { - if (!strcmp(nhdr_get_name(nhdr), QEMU_NOTE_NAME)) { - QEMUCPUState *state = nhdr_get_desc(nhdr); + if (uadd64_overflow(offset, phdr[0].p_memsz, &end_offset) || + end_offset > qe->size) { + end_offset = qe->size; + } + + while (offset < end_offset) { + nhdr = (void *)((uint8_t *)qe->map + offset); + + if (!advance_note_offset(&offset, sizeof(*nhdr), end_offset)) { + break; + } + + name = (char *)qe->map + offset; + + if (!advance_note_offset(&offset, nhdr->n_namesz, end_offset)) { + break; + } + + state = (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 >= offsetof(QEMUCPUState, kernel_gs_base)) { + state_size = MIN(state->size, nhdr->n_descsz); - 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_BASE or * no one has. From patchwork Thu Mar 7 10:21:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akihiko Odaki X-Patchwork-Id: 1909163 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=daynix-com.20230601.gappssmtp.com header.i=@daynix-com.20230601.gappssmtp.com header.a=rsa-sha256 header.s=20230601 header.b=PbGIfVCe; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Tr52m31zJz1yX3 for ; Thu, 7 Mar 2024 21:22:24 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1riAt9-00068V-HN; Thu, 07 Mar 2024 05:22:12 -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 1riAsz-0005lS-0X for qemu-devel@nongnu.org; Thu, 07 Mar 2024 05:22:02 -0500 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1riAsu-0007GH-3N for qemu-devel@nongnu.org; Thu, 07 Mar 2024 05:21:59 -0500 Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1dcad814986so5879215ad.0 for ; Thu, 07 Mar 2024 02:21:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1709806915; x=1710411715; darn=nongnu.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=vWeSXxnvukh1qTIQXUJcznaqlBnX6VJYT1GjqHDMtek=; b=PbGIfVCeCfzPdQgGreLjHsucCnWtlVZBBsVqRXg/HUBiF9n4O43UsyXL7Zjn3icMgG PlJ5lHGg4fnhwNtzIwW9lLaiVprIpOZbohIoBiVH8eXfogXVt+KsnTXr7eKyTd7LoIuh 9rq+6YJZHojt2tEFerfvHuayVJFpqnYEsAtioSv+6akFN5I6Axf4x1LqB+FeylYulsxT M5aWWA+FZVw9O9zmP6V1R2OP4wNxphwVdriVP9jvyoyoSgTihuAbCCtIdQ2hPFkPKs2D u4GCP7MCjscQsnGHMTBvp5whr2RvAGdPHFOxouCLSR43aWxhJV9QbaHYGlD6DxM9M7lt SG2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709806915; x=1710411715; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=vWeSXxnvukh1qTIQXUJcznaqlBnX6VJYT1GjqHDMtek=; b=i1FvLDIC+4ErBs2yn5zO9y3RZc5G9Mq5gLkpm5pdao/lfZKZxT4eLUSQJsD8JYFSWJ cTAhx3wo5JjCymFgqmnIKvmHIG+IWSL7FFcTtws/SVXTFmOpX078TwbNmbmBPHZrmJuA EAo3FZKyt46o516LFo7/1qzc2Fky3er+JWIRMSHfHCwo7AIQDs91j3V5dcbE/4owU1kS A/QqbVUaC6qeYiJrCXn6hsEWrBCgQ+9QJ3nWLSG+gSp8BqK6krWFTqeUI9lebEuQATQ7 amw+N8SxfLMNgyDv5aHj64ZNGTNj7FtN3Mnw75Bol8gyNW9ez1xF9+ZQ/yjNX6b8VoSU ETbQ== X-Gm-Message-State: AOJu0YyRAetHFO2cxSL02sjGIKInMnM4KLbyEnBOoYgCEBjBF7x/prrw YZDm9OkB6iwLG7csWCckU7V7T64RuFq5ri4dkkUnq9f5/v8mWJeFwMHT8nW3i6M= X-Google-Smtp-Source: AGHT+IGcyD8Lye81gYG8MZAUVsbPTvmgN9XANVoQ+SxJafkoSETTxGYx7rySuiXeNOO/FyoNVPaU8g== X-Received: by 2002:a17:902:f684:b0:1dc:b6bf:fae8 with SMTP id l4-20020a170902f68400b001dcb6bffae8mr10002174plg.59.1709806914784; Thu, 07 Mar 2024 02:21:54 -0800 (PST) Received: from localhost ([2400:4050:a840:1e00:9ac7:6d57:2b16:6932]) by smtp.gmail.com with UTF8SMTPSA id kz12-20020a170902f9cc00b001db8f7720e2sm14228261plb.288.2024.03.07.02.21.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 07 Mar 2024 02:21:54 -0800 (PST) From: Akihiko Odaki Date: Thu, 07 Mar 2024 19:21:02 +0900 Subject: [PATCH v4 19/19] contrib/elf2dmp: Ensure phdrs fit in file MIME-Version: 1.0 Message-Id: <20240307-elf2dmp-v4-19-4f324ad4d99d@daynix.com> References: <20240307-elf2dmp-v4-0-4f324ad4d99d@daynix.com> In-Reply-To: <20240307-elf2dmp-v4-0-4f324ad4d99d@daynix.com> To: Viktor Prutyanov , Peter Maydell Cc: qemu-devel@nongnu.org, Akihiko Odaki X-Mailer: b4 0.12.3 Received-SPF: none client-ip=2607:f8b0:4864:20::62e; envelope-from=akihiko.odaki@daynix.com; helo=mail-pl1-x62e.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Callers of elf64_getphdr() and elf_getphdrnum() assume phdrs are accessible. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2202 Signed-off-by: Akihiko Odaki Reviewed-by: Peter Maydell --- contrib/elf2dmp/qemu_elf.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/contrib/elf2dmp/qemu_elf.c b/contrib/elf2dmp/qemu_elf.c index 8d750adf904a..c9bad6e82cf3 100644 --- a/contrib/elf2dmp/qemu_elf.c +++ b/contrib/elf2dmp/qemu_elf.c @@ -132,6 +132,7 @@ static void exit_states(QEMU_Elf *qe) static bool check_ehdr(QEMU_Elf *qe) { Elf64_Ehdr *ehdr = qe->map; + uint64_t phendoff; if (sizeof(Elf64_Ehdr) > qe->size) { eprintf("Invalid input dump file size\n"); @@ -173,6 +174,13 @@ static bool check_ehdr(QEMU_Elf *qe) return false; } + if (umul64_overflow(ehdr->e_phnum, sizeof(Elf64_Phdr), &phendoff) || + uadd64_overflow(phendoff, ehdr->e_phoff, &phendoff) || + phendoff > qe->size) { + eprintf("phdrs do not fit in file\n"); + return false; + } + return true; }