From patchwork Wed Sep 13 22:46:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viktor Prutyanov X-Patchwork-Id: 13383883 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8B453EE0212 for ; Wed, 13 Sep 2023 22:48:40 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgYdh-0007BX-Sp; Wed, 13 Sep 2023 18:47:17 -0400 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 1qgYdf-0007AP-8W for qemu-devel@nongnu.org; Wed, 13 Sep 2023 18:47:15 -0400 Received: from mail-lf1-x130.google.com ([2a00:1450:4864:20::130]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qgYdb-0007k4-JV for qemu-devel@nongnu.org; Wed, 13 Sep 2023 18:47:15 -0400 Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-500cfb168c6so479825e87.2 for ; Wed, 13 Sep 2023 15:47:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1694645228; x=1695250028; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8ftC+g7kcyTDI9qRSERzH52xT8C77XKKARe67AM6V0M=; b=2hrfAZkY81ST1HEYQoI4yXQf38nf/Jc4IlTwVpk6TgSDwOWTRkLtotIjjVTJRzAf+m ncN0VLSQm36V1JMtto9TFiGKcYI9fx7cGQV0CNd+1oGv/4Qk8tU6ANxGmbsayPg8bp1e C1z1x9mM0sJs5CAqv0OM/0B+Xtr/A2U95ClkiQKIL1Wfs8TE3CzyueMB0tQGYxT0J7TU mwFz5wWqfDQazlata6OtHd9LR6hSjjWLRBmxGLvv/M8JtXFOovsLhD5JzzzTkv++SnH7 Wl1t/NIeI45CGi+fofO9Knvu1ln3wwiHuAEG03AxQ+mjFuM1Ryj7efPWteavG42Qq3sV 0GTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694645228; x=1695250028; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8ftC+g7kcyTDI9qRSERzH52xT8C77XKKARe67AM6V0M=; b=TVRb/jLiMtbJ5ZWCkoKtiZEQ2xwrjQatnc20EXQ/GM3sboJjlYGuotLeRDXTNDdQuv WN02EyyJiQt2mk8FuD5OejCdAxJuisWNe26rZosSHKd9Y0VENVi3ZsB1MeL0LdJ7Xk// 5jWXqHCZadnWtYLKF7hkdwOXYjcXeotL48mZEddfOdKq6zGKeVEw+TkqKuLuoSHeeomf cryXg4wZJDQrZy26yYEQtrV/yWwF94l8VgJRIax02XzJ2tWAJBsDhajoFQuta3uP6hw1 pbw5ZRAB5MnSwhyPtsexElzfAmnGBbTUCh2BOgIQVHFm1eg+ZIVV50mGeatO5xEqI/EV ZIfA== X-Gm-Message-State: AOJu0YxJ5Ey86B/v8O4S9vqGMXwKOcWvqvhN4oDfSzzqiPHKUx83JAPJ tEe6OvPtfGtYErRxp5NsNvl7tQ== X-Google-Smtp-Source: AGHT+IFCRl54tctilNmt1gchhHZn9VlIwPyh6ZiBb6I1+wU68U4VBpWijfq2HS09lKUNO9VFojvhew== X-Received: by 2002:a19:7914:0:b0:4fe:19ef:8791 with SMTP id u20-20020a197914000000b004fe19ef8791mr2308356lfc.38.1694645228523; Wed, 13 Sep 2023 15:47:08 -0700 (PDT) Received: from localhost.localdomain ([109.252.90.8]) by smtp.gmail.com with ESMTPSA id u28-20020a056512041c00b004fdba93b92asm25020lfk.252.2023.09.13.15.47.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 15:47:08 -0700 (PDT) From: Viktor Prutyanov To: annie.li@oracle.com, akihiko.odaki@daynix.com, kkostiuk@redhat.com Cc: qemu-devel@nongnu.org, peter.maydell@linaro.org, yan@daynix.com, viktor@daynix.com, viktor.prutyanov@phystech.edu Subject: [PATCH 1/5] elf2dmp: replace PE export name check with PDB name check Date: Thu, 14 Sep 2023 01:46:53 +0300 Message-Id: <20230913224657.11606-2-viktor@daynix.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20230913224657.11606-1-viktor@daynix.com> References: <20230913224657.11606-1-viktor@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2a00:1450:4864:20::130; envelope-from=viktor@daynix.com; helo=mail-lf1-x130.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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org PE export name check introduced in d399d6b179 isn't reliable enough, because a page with the export directory may be not present for some reason. On the other hand, elf2dmp retrieves the PDB name in any case. It can be also used to check that a PE image is the kernel image. So, check PDB name when searching for Windows kernel image. Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=2165917 Signed-off-by: Viktor Prutyanov --- contrib/elf2dmp/main.c | 93 +++++++++++++++--------------------------- 1 file changed, 33 insertions(+), 60 deletions(-) diff --git a/contrib/elf2dmp/main.c b/contrib/elf2dmp/main.c index 6d4d18501a..bb6744c0cd 100644 --- a/contrib/elf2dmp/main.c +++ b/contrib/elf2dmp/main.c @@ -411,89 +411,64 @@ static int write_dump(struct pa_space *ps, return fclose(dmp_file); } -static bool pe_check_export_name(uint64_t base, void *start_addr, - struct va_space *vs) -{ - IMAGE_EXPORT_DIRECTORY export_dir; - const char *pe_name; - - if (pe_get_data_dir_entry(base, start_addr, IMAGE_FILE_EXPORT_DIRECTORY, - &export_dir, sizeof(export_dir), vs)) { - return false; - } - - pe_name = va_space_resolve(vs, base + export_dir.Name); - if (!pe_name) { - return false; - } - - return !strcmp(pe_name, PE_NAME); -} - -static int pe_get_pdb_symstore_hash(uint64_t base, void *start_addr, - char *hash, struct va_space *vs) +static bool pe_check_pdb_name(uint64_t base, void *start_addr, + struct va_space *vs, OMFSignatureRSDS *rsds) { const char sign_rsds[4] = "RSDS"; IMAGE_DEBUG_DIRECTORY debug_dir; - OMFSignatureRSDS rsds; - char *pdb_name; - size_t pdb_name_sz; - size_t i; + 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)) { eprintf("Failed to get Debug Directory\n"); - return 1; + return false; } if (debug_dir.Type != IMAGE_DEBUG_TYPE_CODEVIEW) { - return 1; + eprintf("Debug Directory type is not CodeView\n"); + return false; } if (va_space_rw(vs, base + debug_dir.AddressOfRawData, - &rsds, sizeof(rsds), 0)) { - return 1; + rsds, sizeof(*rsds), 0)) { + eprintf("Failed to resolve OMFSignatureRSDS\n"); + return false; } - printf("CodeView signature is \'%.4s\'\n", rsds.Signature); - - if (memcmp(&rsds.Signature, sign_rsds, sizeof(sign_rsds))) { - return 1; + if (memcmp(&rsds->Signature, sign_rsds, sizeof(sign_rsds))) { + eprintf("CodeView signature is \'%.4s\', \'%s\' expected\n", + rsds->Signature, sign_rsds); + return false; } - pdb_name_sz = debug_dir.SizeOfData - sizeof(rsds); - pdb_name = malloc(pdb_name_sz); - if (!pdb_name) { - return 1; + if (debug_dir.SizeOfData - sizeof(*rsds) != sizeof(PDB_NAME)) { + eprintf("PDB name size doesn't match\n"); + return false; } if (va_space_rw(vs, base + debug_dir.AddressOfRawData + - offsetof(OMFSignatureRSDS, name), pdb_name, pdb_name_sz, 0)) { - free(pdb_name); - return 1; + offsetof(OMFSignatureRSDS, name), pdb_name, sizeof(PDB_NAME), + 0)) { + eprintf("Failed to resolve PDB name\n"); + return false; } printf("PDB name is \'%s\', \'%s\' expected\n", pdb_name, PDB_NAME); - if (strcmp(pdb_name, PDB_NAME)) { - eprintf("Unexpected PDB name, it seems the kernel isn't found\n"); - free(pdb_name); - return 1; - } - - free(pdb_name); + return !strcmp(pdb_name, PDB_NAME); +} - sprintf(hash, "%.08x%.04x%.04x%.02x%.02x", rsds.guid.a, rsds.guid.b, - rsds.guid.c, rsds.guid.d[0], rsds.guid.d[1]); +static void pe_get_pdb_symstore_hash(OMFSignatureRSDS *rsds, char *hash) +{ + sprintf(hash, "%.08x%.04x%.04x%.02x%.02x", rsds->guid.a, rsds->guid.b, + rsds->guid.c, rsds->guid.d[0], rsds->guid.d[1]); hash += 20; - for (i = 0; i < 6; i++, hash += 2) { - sprintf(hash, "%.02x", rsds.guid.e[i]); + for (unsigned int i = 0; i < 6; i++, hash += 2) { + sprintf(hash, "%.02x", rsds->guid.e[i]); } - sprintf(hash, "%.01x", rsds.age); - - return 0; + sprintf(hash, "%.01x", rsds->age); } int main(int argc, char *argv[]) @@ -515,6 +490,7 @@ int main(int argc, char *argv[]) KDDEBUGGER_DATA64 *kdbg; uint64_t KdVersionBlock; bool kernel_found = false; + OMFSignatureRSDS rsds; if (argc != 3) { eprintf("usage:\n\t%s elf_file dmp_file\n", argv[0]); @@ -562,7 +538,8 @@ int main(int argc, char *argv[]) } if (*(uint16_t *)nt_start_addr == 0x5a4d) { /* MZ */ - if (pe_check_export_name(KernBase, nt_start_addr, &vs)) { + printf("Checking candidate KernBase = 0x%016"PRIx64"\n", KernBase); + if (pe_check_pdb_name(KernBase, nt_start_addr, &vs, &rsds)) { kernel_found = true; break; } @@ -578,11 +555,7 @@ int main(int argc, char *argv[]) printf("KernBase = 0x%016"PRIx64", signature is \'%.2s\'\n", KernBase, (char *)nt_start_addr); - if (pe_get_pdb_symstore_hash(KernBase, nt_start_addr, pdb_hash, &vs)) { - eprintf("Failed to get PDB symbol store hash\n"); - err = 1; - goto out_ps; - } + pe_get_pdb_symstore_hash(&rsds, pdb_hash); sprintf(pdb_url, "%s%s/%s/%s", SYM_URL_BASE, PDB_NAME, pdb_hash, PDB_NAME); printf("PDB URL is %s\n", pdb_url); From patchwork Wed Sep 13 22:46:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viktor Prutyanov X-Patchwork-Id: 13383880 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7D5B1EE0215 for ; Wed, 13 Sep 2023 22:48:25 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgYdh-0007B5-2l; Wed, 13 Sep 2023 18:47:17 -0400 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 1qgYdd-00079j-LL for qemu-devel@nongnu.org; Wed, 13 Sep 2023 18:47:13 -0400 Received: from mail-lf1-x12b.google.com ([2a00:1450: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 1qgYdb-0007le-JZ for qemu-devel@nongnu.org; Wed, 13 Sep 2023 18:47:13 -0400 Received: by mail-lf1-x12b.google.com with SMTP id 2adb3069b0e04-501bd7711e8so491941e87.1 for ; Wed, 13 Sep 2023 15:47:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1694645229; x=1695250029; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=sRDq0Frl7ofiI6ZyF6ZdAHnr6ekU2KaX/hYSpVHMAzM=; b=CYpoCttaSyqfiaPunfJ8Vb6IHO4BX9tQidsFdsMwLyAXGR3NKf0NRpBPS9xkJ1FTMO /Zq+eBnhiXqCQfyk78WiqLTECQCU5K4n2R+JdkUNlf2FbnUXz9u3PzqG2tlZ5MH0DULV 41mmdA8iivGHmrc6nmyL54HvzRDEFQlBN594tXq1lqH0Oys4kw6upC/GtMp+DRsnvCQc ziQp1/DOUw3D63/fo9584KPNWNBkOlr8AOGQutwmVqLQe9uWz32U43PbZv9/cWuPWUSc 4loGxrQkI7LiuT+jyaTZqhKrywXrQUJbZywlsdVw46kgvrTkVrRlcl0RcmJcgjtJuvxg CXNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694645229; x=1695250029; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sRDq0Frl7ofiI6ZyF6ZdAHnr6ekU2KaX/hYSpVHMAzM=; b=NdtVJrO0cFMB4KExjRzRNoXFQ4k5H99B+eve0sWvz5PFdLX6bzFAJ7yNQilsSCWj9J z4wqyrpmhhtliojRMEvq6IuYp+tkOr0U3nyDLJKvAw+xReP2JBmRNGtYXutOPBlebVs3 vRgklBY0h0IX41+i3CGHsDCxgkqqP6OQftMZsvGzvcU3ifk1XpC2JUiGv3Pam9jbbV9O 9WXhq5udu7NUkRnC/dUBYIK9jD5JvEQ/wVoiN6LzqrGiPLvZ9oVZZB1g/PSzVsigQnmM u/z4DG4cJoD6OYCzb7zB7vvqqKD0yCD13JvjCIo17Q6+gZ+bSvgnZHwRy9W4HEzyd27G inEw== X-Gm-Message-State: AOJu0Yw29zdmSOI0SBHK5ovnjC7YmSkePwS7sun2BpgMkMGA2h7f0rmO cNo3OTTBBMudOit1n8CZHcazig== X-Google-Smtp-Source: AGHT+IHeGZeu4O4rqmqgDdRwOXV1TSrWDJK165TCXD87XWN++I1t03lerrNVm4DvXdFUt5pdM7IOtA== X-Received: by 2002:a19:6412:0:b0:4ff:87f6:6ee5 with SMTP id y18-20020a196412000000b004ff87f66ee5mr2728194lfb.10.1694645229346; Wed, 13 Sep 2023 15:47:09 -0700 (PDT) Received: from localhost.localdomain ([109.252.90.8]) by smtp.gmail.com with ESMTPSA id u28-20020a056512041c00b004fdba93b92asm25020lfk.252.2023.09.13.15.47.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 15:47:09 -0700 (PDT) From: Viktor Prutyanov To: annie.li@oracle.com, akihiko.odaki@daynix.com, kkostiuk@redhat.com Cc: qemu-devel@nongnu.org, peter.maydell@linaro.org, yan@daynix.com, viktor@daynix.com, viktor.prutyanov@phystech.edu Subject: [PATCH 2/5] elf2dmp: introduce physical block alignment Date: Thu, 14 Sep 2023 01:46:54 +0300 Message-Id: <20230913224657.11606-3-viktor@daynix.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20230913224657.11606-1-viktor@daynix.com> References: <20230913224657.11606-1-viktor@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2a00:1450:4864:20::12b; envelope-from=viktor@daynix.com; helo=mail-lf1-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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Physical memory ranges may not be aligned to page size in QEMU ELF, but DMP can only contain page-aligned runs. So, align them. Signed-off-by: Viktor Prutyanov --- contrib/elf2dmp/addrspace.c | 31 +++++++++++++++++++++++++++++-- contrib/elf2dmp/addrspace.h | 1 + contrib/elf2dmp/main.c | 5 +++-- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/contrib/elf2dmp/addrspace.c b/contrib/elf2dmp/addrspace.c index 0b04cba00e..64b5d680ad 100644 --- a/contrib/elf2dmp/addrspace.c +++ b/contrib/elf2dmp/addrspace.c @@ -14,7 +14,7 @@ static struct pa_block *pa_space_find_block(struct pa_space *ps, uint64_t pa) for (i = 0; i < ps->block_nr; i++) { if (ps->block[i].paddr <= pa && - pa <= ps->block[i].paddr + ps->block[i].size) { + pa < ps->block[i].paddr + ps->block[i].size) { return ps->block + i; } } @@ -33,6 +33,30 @@ static uint8_t *pa_space_resolve(struct pa_space *ps, uint64_t pa) return block->addr + (pa - block->paddr); } +static void pa_block_align(struct pa_block *b) +{ + uint64_t low_align = ((b->paddr - 1) | ELF2DMP_PAGE_MASK) + 1 - b->paddr; + uint64_t high_align = (b->paddr + b->size) & ELF2DMP_PAGE_MASK; + + if (low_align == 0 && high_align == 0) { + return; + } + + if (low_align + high_align < b->size) { + printf("Block 0x%"PRIx64"+:0x%"PRIx64" will be aligned to " + "0x%"PRIx64"+:0x%"PRIx64"\n", b->paddr, b->size, + b->paddr + low_align, b->size - low_align - high_align); + b->size -= low_align + high_align; + } else { + printf("Block 0x%"PRIx64"+:0x%"PRIx64" is too small to align\n", + b->paddr, b->size); + b->size = 0; + } + + b->addr += low_align; + b->paddr += low_align; +} + int pa_space_create(struct pa_space *ps, QEMU_Elf *qemu_elf) { Elf64_Half phdr_nr = elf_getphdrnum(qemu_elf->map); @@ -60,10 +84,13 @@ int pa_space_create(struct pa_space *ps, QEMU_Elf *qemu_elf) .paddr = phdr[i].p_paddr, .size = phdr[i].p_filesz, }; - block_i++; + pa_block_align(&ps->block[block_i]); + block_i = ps->block[block_i].size ? (block_i + 1) : block_i; } } + ps->block_nr = block_i; + return 0; } diff --git a/contrib/elf2dmp/addrspace.h b/contrib/elf2dmp/addrspace.h index 00b44c1218..039c70c5b0 100644 --- a/contrib/elf2dmp/addrspace.h +++ b/contrib/elf2dmp/addrspace.h @@ -12,6 +12,7 @@ #define ELF2DMP_PAGE_BITS 12 #define ELF2DMP_PAGE_SIZE (1ULL << ELF2DMP_PAGE_BITS) +#define ELF2DMP_PAGE_MASK (ELF2DMP_PAGE_SIZE - 1) #define ELF2DMP_PFN_MASK (~(ELF2DMP_PAGE_SIZE - 1)) #define INVALID_PA UINT64_MAX diff --git a/contrib/elf2dmp/main.c b/contrib/elf2dmp/main.c index bb6744c0cd..b7e3930164 100644 --- a/contrib/elf2dmp/main.c +++ b/contrib/elf2dmp/main.c @@ -400,9 +400,10 @@ static int write_dump(struct pa_space *ps, for (i = 0; i < ps->block_nr; i++) { struct pa_block *b = &ps->block[i]; - printf("Writing block #%zu/%zu to file...\n", i, ps->block_nr); + printf("Writing block #%zu/%zu of %"PRIu64" bytes to file...\n", i, + ps->block_nr, b->size); if (fwrite(b->addr, b->size, 1, dmp_file) != 1) { - eprintf("Failed to write dump header\n"); + eprintf("Failed to write block\n"); fclose(dmp_file); return 1; } From patchwork Wed Sep 13 22:46:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viktor Prutyanov X-Patchwork-Id: 13383878 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D0EDDEE0214 for ; Wed, 13 Sep 2023 22:48:23 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgYdh-0007BN-Jw; Wed, 13 Sep 2023 18:47:17 -0400 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 1qgYdf-0007A1-1c for qemu-devel@nongnu.org; Wed, 13 Sep 2023 18:47:15 -0400 Received: from mail-lf1-x130.google.com ([2a00:1450:4864:20::130]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qgYdb-0007nj-Nx for qemu-devel@nongnu.org; Wed, 13 Sep 2023 18:47:14 -0400 Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-501eec0a373so485795e87.3 for ; Wed, 13 Sep 2023 15:47:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1694645230; x=1695250030; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Z3tMwAfRExD0uT8VCFW97ojoDnYEYZidkv6sT6LS0Hg=; b=pz+Y7t0vr1/kOka8fChL97KkaRBEsa2YexkGBWsSYkct4hhOb+332YZIsSTRhE9HPh Wd/Xw+vQ2woo9lLDYbGqoz4stZIH7xfhB8K9gUWK4pPSKIIhnGrlrK+902rB5AQAq2QX bSc9RHJDjf0MeXhkM0zVguDUQNNhlcx9f9VLSEKli5l3VaKAiGUb7qJpDNvSaH71OWiv qztoCr90KUsSmZjUke8spFvvur6WzXOD+b2humusx9ZEHGGnZzA23XyBPdiqad8mE8BK jm/KRZAU39zEbbGVpNDYqYXA/m03hQTUTu7iJlQA7AjQ1BW7Ax5HvmEPYB6gzV1FKx/Y 9qTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694645230; x=1695250030; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Z3tMwAfRExD0uT8VCFW97ojoDnYEYZidkv6sT6LS0Hg=; b=QF577DZ00l8EV464LNYCxjKofhd4L/qhZHJpGZ24loGaACJeOtvl8SVklW+rjQtBVa GRbfpeAlRdfzYqJ17wBCv3wr1KDyAQOb52dY3LRQJkfC09E+0ShDdMls385j6gw0IQE0 nliCOTIuOnfh+PVGPNgJAk0U+lxGYrjf5TScjOnuFGlxKFszTse+da2j/0kF+8oFXgVi NMrmxEvWy9ZeT5Pfmscrq57EX3nhyUfZOGi7UMyAFJ0xYOLHHsinVDff9xQ7HHHalWiw EU+7tyrlK/bG4iKtdxYgUIp3qSwy+gfdnAjGmDfqJhpNvp5UnPNvFoGFXUVUY5E9/7Wd D1tw== X-Gm-Message-State: AOJu0YyN4IKh1fc3zow3AjO328a8VccG4G4gWztxEwNaeo7pOIeX6anC 7UhUgShAfTyeHasvg8AW75ZL4sFLJLssXxhFwO8= X-Google-Smtp-Source: AGHT+IHvq4FkgLpMFan4wj1Zp0sMmS1IhixSclOMzcYGmA5zHJmJWah//iA9dV5mIEmcgMyKoa8nRw== X-Received: by 2002:a05:6512:1151:b0:500:ac71:f26a with SMTP id m17-20020a056512115100b00500ac71f26amr3899311lfg.57.1694645230171; Wed, 13 Sep 2023 15:47:10 -0700 (PDT) Received: from localhost.localdomain ([109.252.90.8]) by smtp.gmail.com with ESMTPSA id u28-20020a056512041c00b004fdba93b92asm25020lfk.252.2023.09.13.15.47.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 15:47:09 -0700 (PDT) From: Viktor Prutyanov To: annie.li@oracle.com, akihiko.odaki@daynix.com, kkostiuk@redhat.com Cc: qemu-devel@nongnu.org, peter.maydell@linaro.org, yan@daynix.com, viktor@daynix.com, viktor.prutyanov@phystech.edu Subject: [PATCH 3/5] elf2dmp: introduce merging of physical memory runs Date: Thu, 14 Sep 2023 01:46:55 +0300 Message-Id: <20230913224657.11606-4-viktor@daynix.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20230913224657.11606-1-viktor@daynix.com> References: <20230913224657.11606-1-viktor@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2a00:1450:4864:20::130; envelope-from=viktor@daynix.com; helo=mail-lf1-x130.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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org DMP supports 42 physical memory runs at most. So, merge adjacent physical memory ranges from QEMU ELF when possible to minimize total number of runs. Signed-off-by: Viktor Prutyanov --- contrib/elf2dmp/main.c | 56 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 8 deletions(-) diff --git a/contrib/elf2dmp/main.c b/contrib/elf2dmp/main.c index b7e3930164..9ef5cfcd23 100644 --- a/contrib/elf2dmp/main.c +++ b/contrib/elf2dmp/main.c @@ -20,6 +20,7 @@ #define PE_NAME "ntoskrnl.exe" #define INITIAL_MXCSR 0x1f80 +#define MAX_NUMBER_OF_RUNS 42 typedef struct idt_desc { uint16_t offset1; /* offset bits 0..15 */ @@ -234,6 +235,42 @@ static int fix_dtb(struct va_space *vs, QEMU_Elf *qe) return 1; } +static void try_merge_runs(struct pa_space *ps, + WinDumpPhyMemDesc64 *PhysicalMemoryBlock) +{ + unsigned int merge_cnt = 0, run_idx = 0; + + PhysicalMemoryBlock->NumberOfRuns = 0; + + for (unsigned int idx = 0; idx < ps->block_nr; idx++) { + struct pa_block *blk = ps->block + idx; + struct pa_block *next = blk + 1; + + PhysicalMemoryBlock->NumberOfPages += blk->size / ELF2DMP_PAGE_SIZE; + + if (idx + 1 != ps->block_nr && blk->paddr + blk->size == next->paddr) { + printf("Block #%u 0x%"PRIx64"+:0x%"PRIx64" and %u previous will be " + "merged\n", idx, blk->paddr, blk->size, merge_cnt); + merge_cnt++; + } else { + struct pa_block *first_merged = blk - merge_cnt; + + printf("Block #%u 0x%"PRIx64"+:0x%"PRIx64" and %u previous will be " + "merged to 0x%"PRIx64"+:0x%"PRIx64" and saved as run #%u\n", + idx, blk->paddr, blk->size, merge_cnt, first_merged->paddr, + blk->paddr + blk->size - first_merged->paddr, run_idx); + PhysicalMemoryBlock->Run[run_idx] = (WinDumpPhyMemRun64) { + .BasePage = first_merged->paddr / ELF2DMP_PAGE_SIZE, + .PageCount = (blk->paddr + blk->size - first_merged->paddr) / + ELF2DMP_PAGE_SIZE, + }; + PhysicalMemoryBlock->NumberOfRuns++; + run_idx++; + merge_cnt = 0; + } + } +} + 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) @@ -244,7 +281,6 @@ static int fill_header(WinDumpHeader64 *hdr, struct pa_space *ps, KUSD_OFFSET_PRODUCT_TYPE); DBGKD_GET_VERSION64 kvb; WinDumpHeader64 h; - size_t i; QEMU_BUILD_BUG_ON(KUSD_OFFSET_SUITE_MASK >= ELF2DMP_PAGE_SIZE); QEMU_BUILD_BUG_ON(KUSD_OFFSET_PRODUCT_TYPE >= ELF2DMP_PAGE_SIZE); @@ -282,13 +318,17 @@ static int fill_header(WinDumpHeader64 *hdr, struct pa_space *ps, .RequiredDumpSpace = sizeof(h), }; - for (i = 0; i < ps->block_nr; i++) { - h.PhysicalMemoryBlock.NumberOfPages += - ps->block[i].size / ELF2DMP_PAGE_SIZE; - h.PhysicalMemoryBlock.Run[i] = (WinDumpPhyMemRun64) { - .BasePage = ps->block[i].paddr / ELF2DMP_PAGE_SIZE, - .PageCount = ps->block[i].size / ELF2DMP_PAGE_SIZE, - }; + if (h.PhysicalMemoryBlock.NumberOfRuns <= MAX_NUMBER_OF_RUNS) { + for (unsigned int idx = 0; idx < ps->block_nr; idx++) { + h.PhysicalMemoryBlock.NumberOfPages += + ps->block[idx].size / ELF2DMP_PAGE_SIZE; + h.PhysicalMemoryBlock.Run[idx] = (WinDumpPhyMemRun64) { + .BasePage = ps->block[idx].paddr / ELF2DMP_PAGE_SIZE, + .PageCount = ps->block[idx].size / ELF2DMP_PAGE_SIZE, + }; + } + } else { + try_merge_runs(ps, &h.PhysicalMemoryBlock); } h.RequiredDumpSpace += From patchwork Wed Sep 13 22:46:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viktor Prutyanov X-Patchwork-Id: 13383882 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C50E4EE0211 for ; Wed, 13 Sep 2023 22:48:38 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgYdh-0007B6-AY; Wed, 13 Sep 2023 18:47:17 -0400 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 1qgYdf-0007A0-1O for qemu-devel@nongnu.org; Wed, 13 Sep 2023 18:47:15 -0400 Received: from mail-lf1-x131.google.com ([2a00:1450:4864:20::131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qgYdc-0007nt-Fi for qemu-devel@nongnu.org; Wed, 13 Sep 2023 18:47:14 -0400 Received: by mail-lf1-x131.google.com with SMTP id 2adb3069b0e04-502e7d66c1eso57156e87.1 for ; Wed, 13 Sep 2023 15:47:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1694645231; x=1695250031; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yH8HMC5hbSt9eozfwF10NL6pa0YQ8wwIF2lIAW9O7bA=; b=eO6tR7h84/bcvSYA18abBDPoc4gee8trU5WBCUhbe+a+VTNyqB3VOeTgDTYk07WF8P 3emOrXcbaQCrh6/yERJqlbZib49BlVfANCT76zJgWVRFXjWSjg9O4++FF6WdWHamTDDD LUYI2bO5yNQS6dOBy1sSylE3qlb0h6jk1bEcCGOwo8DvGV45Qig10fFFY1H2DyMzpng+ Mz8U0M0LvfeL+OpY6+i5p7sltgcr0VlPq+R5yMA3RcKdVn6olMBV5A8ks4Vkg6B+pJCq Ko0qO/2NP9sCG4UX007Itr7+1vE+z3oHE+JHTIbGzNjGfr/6oAmXVMG8Pj+vbqJwC7KB TE2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694645231; x=1695250031; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yH8HMC5hbSt9eozfwF10NL6pa0YQ8wwIF2lIAW9O7bA=; b=WRRFrh5oHNfOp09W5g5i4V+8B/i5LXydTt70Z73vhNCDa6ca2GZgH9sKV9u1N4lcfu TyHawu9YVlCIZNvmFBY6J4n6U+ur3rTv/3hf8mSnJ94biPqddOjen9Pgp4fGyY3ZrsUp raveRwlIvqV1VnA1TslcmJGvdeYHlY2+Lx/5wys6PrhzMRprxaQpZchdObKTZYsCNcIA dK+DCGDrSVUAaYYYdkbHhafIdydwRplRXDPhbHOUUYdTH75Sl3GMLMQUe4gHHXMwByGI f1gBbO6f4SUVP8v5oyVoaHVcMZ8t+Pvz+fPTUx/x8UXjS2KrUUSqfkYK6I3CFxFGLegH WF7w== X-Gm-Message-State: AOJu0YyV4yJ01o5BfwyB6BxAUWVo6aAD99YV+ZzDYyd2I763Eq5hLlbu cYkf1jEEf9QZwdR2YabdTjOUfw== X-Google-Smtp-Source: AGHT+IHHm94EggcNepjD2EuTcwonqUw1WpG9K3oK+0iE3emVeIP2aH4LVQCN1Jm+vPDmqrQTiRSYJQ== X-Received: by 2002:a19:5002:0:b0:500:a008:a4c5 with SMTP id e2-20020a195002000000b00500a008a4c5mr2812005lfb.59.1694645230969; Wed, 13 Sep 2023 15:47:10 -0700 (PDT) Received: from localhost.localdomain ([109.252.90.8]) by smtp.gmail.com with ESMTPSA id u28-20020a056512041c00b004fdba93b92asm25020lfk.252.2023.09.13.15.47.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 15:47:10 -0700 (PDT) From: Viktor Prutyanov To: annie.li@oracle.com, akihiko.odaki@daynix.com, kkostiuk@redhat.com Cc: qemu-devel@nongnu.org, peter.maydell@linaro.org, yan@daynix.com, viktor@daynix.com, viktor.prutyanov@phystech.edu Subject: [PATCH 4/5] elf2dmp: use Linux mmap with MAP_NORESERVE when possible Date: Thu, 14 Sep 2023 01:46:56 +0300 Message-Id: <20230913224657.11606-5-viktor@daynix.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20230913224657.11606-1-viktor@daynix.com> References: <20230913224657.11606-1-viktor@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2a00:1450:4864:20::131; envelope-from=viktor@daynix.com; helo=mail-lf1-x131.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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Glib's g_mapped_file_new maps file with PROT_READ|PROT_WRITE and MAP_PRIVATE. This leads to premature physical memory allocation of dump file size on Linux hosts and may fail. On Linux, mapping the file with MAP_NORESERVE limits the allocation by available memory. Signed-off-by: Viktor Prutyanov --- contrib/elf2dmp/qemu_elf.c | 66 +++++++++++++++++++++++++++++++------- contrib/elf2dmp/qemu_elf.h | 4 +++ 2 files changed, 58 insertions(+), 12 deletions(-) diff --git a/contrib/elf2dmp/qemu_elf.c b/contrib/elf2dmp/qemu_elf.c index ebda60dcb8..94a8c3ad15 100644 --- a/contrib/elf2dmp/qemu_elf.c +++ b/contrib/elf2dmp/qemu_elf.c @@ -165,10 +165,37 @@ static bool check_ehdr(QEMU_Elf *qe) return true; } -int QEMU_Elf_init(QEMU_Elf *qe, const char *filename) +static int QEMU_Elf_map(QEMU_Elf *qe, const char *filename) { +#ifdef CONFIG_LINUX + struct stat st; + + printf("Using Linux's mmap\n"); + + qe->fd = open(filename, O_RDONLY, 0); + if (qe->fd == -1) { + eprintf("Failed to open ELF dump file \'%s\'\n", filename); + return 1; + } + + if (fstat(qe->fd, &st)) { + eprintf("Failed to get size of ELF dump file\n"); + close(qe->fd); + return 1; + } + qe->size = st.st_size; + + qe->map = mmap(NULL, qe->size, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_NORESERVE, qe->fd, 0); + if (qe->map == MAP_FAILED) { + eprintf("Failed to map ELF file\n"); + close(qe->fd); + return 1; + } +#else GError *gerr = NULL; - int err = 0; + + printf("Using GLib's mmap\n"); qe->gmf = g_mapped_file_new(filename, TRUE, &gerr); if (gerr) { @@ -179,29 +206,44 @@ int QEMU_Elf_init(QEMU_Elf *qe, const char *filename) qe->map = g_mapped_file_get_contents(qe->gmf); qe->size = g_mapped_file_get_length(qe->gmf); +#endif + + return 0; +} + +static void QEMU_Elf_unmap(QEMU_Elf *qe) +{ +#ifdef CONFIG_LINUX + munmap(qe->map, qe->size); + close(qe->fd); +#else + g_mapped_file_unref(qe->gmf); +#endif +} + +int QEMU_Elf_init(QEMU_Elf *qe, const char *filename) +{ + if (QEMU_Elf_map(qe, filename)) { + return 1; + } if (!check_ehdr(qe)) { eprintf("Input file has the wrong format\n"); - err = 1; - goto out_unmap; + QEMU_Elf_unmap(qe); + return 1; } if (init_states(qe)) { eprintf("Failed to extract QEMU CPU states\n"); - err = 1; - goto out_unmap; + QEMU_Elf_unmap(qe); + return 1; } return 0; - -out_unmap: - g_mapped_file_unref(qe->gmf); - - return err; } void QEMU_Elf_exit(QEMU_Elf *qe) { exit_states(qe); - g_mapped_file_unref(qe->gmf); + QEMU_Elf_unmap(qe); } diff --git a/contrib/elf2dmp/qemu_elf.h b/contrib/elf2dmp/qemu_elf.h index b2f0d9cbc9..2a71beca8e 100644 --- a/contrib/elf2dmp/qemu_elf.h +++ b/contrib/elf2dmp/qemu_elf.h @@ -32,7 +32,11 @@ typedef struct QEMUCPUState { int is_system(QEMUCPUState *s); typedef struct QEMU_Elf { +#ifdef CONFIG_POSIX + int fd; +#else GMappedFile *gmf; +#endif size_t size; void *map; QEMUCPUState **state; From patchwork Wed Sep 13 22:46:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viktor Prutyanov X-Patchwork-Id: 13383881 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BFC54EE0212 for ; Wed, 13 Sep 2023 22:48:23 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qgYdg-0007B3-QG; Wed, 13 Sep 2023 18:47:16 -0400 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 1qgYde-00079y-UA for qemu-devel@nongnu.org; Wed, 13 Sep 2023 18:47:14 -0400 Received: from mail-lf1-x134.google.com ([2a00:1450:4864:20::134]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qgYdd-0007nz-7z for qemu-devel@nongnu.org; Wed, 13 Sep 2023 18:47:14 -0400 Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-502a4f33440so497091e87.1 for ; Wed, 13 Sep 2023 15:47:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20230601.gappssmtp.com; s=20230601; t=1694645231; x=1695250031; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=uN8akFDSSf8W02hilGYllT6O5qN0jjlxmrGbHu502bU=; b=SNbECwfwHKsvUx0n61RtyvAz9oNIax9XmwGZs6jxXOwVXOMdoiaBkWGW2c4vptKhtl m/yMaUbCeVdFrJeO3yl1ROjD1DV52gqQ9r8/kZnrkU/MBXmmaeYdy1k4w55pL8HwuUXX SWOowGzNs+XUq7/cJCxCxiET9N4dwqJKkYjtGvV+UOgK1s7/N9SnHj1DNwDqU9enPa/x eidbcXR9N7/IJpNrLOp6QI37uU4fhi7b8tDC1mfQ6ejhq5k2cS9V0b0OS/qpf6vjn90h UFCnY7GGafDBFR4AAXAHQ+DEpOdGhaWegqlYOngrJ8Oin01vv1ipGoGAGbHsBbNNq9+1 i/lA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694645231; x=1695250031; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uN8akFDSSf8W02hilGYllT6O5qN0jjlxmrGbHu502bU=; b=rA6+yODYoKa4jjljs3/KHVgLPxIEQYwSQTp9DTPOiGFnM36vcbEcj/bIBEHpzK5hdv Qk+p0V4Gw3G5bCKrI5g23BEVtcBSXib9paxgqMvDTVPLT50s05ajLe2sUarxgbvjjCe6 I/XivKOzqB8HIOYpSQHc5V1vVIUg8LTjbI2j+uxb4p5nqErwWxIXpjyvEBvGDJVzbnVX //W/IbR9Mfg1GGPbg6h9YOTiM3sYlUnpHhh46XKhsSuAxrWHcsBK2hUc5rokMXDlLWRA /DW6sbiXS0BdFDbCeG4P33Btl2nTPkT9WEROgED1+WQLN63pc3hV+Hs4818HOHdyaKgr B1lA== X-Gm-Message-State: AOJu0Yys4b4HpX6nHMEnKjix+vq9fMT4/e8eE/QDAJvHPkFtUKl8qLuF t4lcTUtftHqL9FcGyWjuY+FrVg== X-Google-Smtp-Source: AGHT+IEXpZYJWXLkxpqVtQgCwhEOl6t6fSB+5E8YNJH8niOH2KifeubyR/i6xiPVIgf1k+UTY0Gmlg== X-Received: by 2002:a05:6512:b92:b0:4fd:fabf:b6ee with SMTP id b18-20020a0565120b9200b004fdfabfb6eemr4003966lfv.9.1694645231565; Wed, 13 Sep 2023 15:47:11 -0700 (PDT) Received: from localhost.localdomain ([109.252.90.8]) by smtp.gmail.com with ESMTPSA id u28-20020a056512041c00b004fdba93b92asm25020lfk.252.2023.09.13.15.47.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 15:47:11 -0700 (PDT) From: Viktor Prutyanov To: annie.li@oracle.com, akihiko.odaki@daynix.com, kkostiuk@redhat.com Cc: qemu-devel@nongnu.org, peter.maydell@linaro.org, yan@daynix.com, viktor@daynix.com, viktor.prutyanov@phystech.edu Subject: [PATCH 5/5] elf2dmp: rework PDB_STREAM_INDEXES::segments obtaining Date: Thu, 14 Sep 2023 01:46:57 +0300 Message-Id: <20230913224657.11606-6-viktor@daynix.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20230913224657.11606-1-viktor@daynix.com> References: <20230913224657.11606-1-viktor@daynix.com> MIME-Version: 1.0 Received-SPF: none client-ip=2a00:1450:4864:20::134; envelope-from=viktor@daynix.com; helo=mail-lf1-x134.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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org PDB for Windows 11 kernel has slightly different structure compared to previous versions. Since elf2dmp don't use the other fields, copy only 'segments' field from PDB_STREAM_INDEXES. Signed-off-by: Viktor Prutyanov --- contrib/elf2dmp/pdb.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/contrib/elf2dmp/pdb.c b/contrib/elf2dmp/pdb.c index adcfa7e154..2ef873b13e 100644 --- a/contrib/elf2dmp/pdb.c +++ b/contrib/elf2dmp/pdb.c @@ -188,15 +188,11 @@ static int pdb_init_symbols(struct pdb_reader *r) r->symbols = symbols; - if (symbols->stream_index_size != sizeof(PDB_STREAM_INDEXES)) { - err = 1; - goto out_symbols; - } - - memcpy(sidx, (const char *)symbols + sizeof(PDB_SYMBOLS) + + sidx->segments = *(uint16_t *)((const char *)symbols + sizeof(PDB_SYMBOLS) + symbols->module_size + symbols->offset_size + symbols->hash_size + symbols->srcmodule_size + - symbols->pdbimport_size + symbols->unknown2_size, sizeof(*sidx)); + symbols->pdbimport_size + symbols->unknown2_size + + offsetof(PDB_STREAM_INDEXES, segments)); /* Read global symbol table */ r->modimage = pdb_ds_read_file(r, symbols->gsym_file);