From nobody Thu Apr 25 22:20:58 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=phystech.edu ARC-Seal: i=1; a=rsa-sha256; t=1642035408; cv=none; d=zohomail.com; s=zohoarc; b=K325XD7vZF/R6iFyHsPgyGXpA5fCnHFUyVXUftA4leKII32GJ8p7ZPC9qzAc6YbDfjyaKL+ZLDJjr9Qk82zFjLiu5QnnyvkhIg76nyghKdNiRGi1BEiKMAZgFY4f9solJScmFkA053p/Imq4UElv3pahy4acfFIVletlQq4HfPo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642035408; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=IDjRtlfdJm8ybSCVHOvFOaC8nUHRGEycooXc8kxeUnM=; b=n5+ceOoUv4uxN3ye5L22QaoUbgPXpypVmIvyXW7Eq9078C+024yVgwZr7+Oic9WlU8M3R/iH4Nqp/1WhPZVGcbhjlMhR7fuvh5o1ZL5/a61C4HMCqm82hN/UtOWnDgFlQvu23qQxJeRCtTzyr9N6zH79vCuZqmXqmvdbOuRWvE0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1642035408095406.17776868182557; Wed, 12 Jan 2022 16:56:48 -0800 (PST) Received: from localhost ([::1]:34740 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n7oQ2-0002Nh-H5 for importer@patchew.org; Wed, 12 Jan 2022 19:56:46 -0500 Received: from eggs.gnu.org ([209.51.188.92]:36800) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n7oMw-0008V0-LV for qemu-devel@nongnu.org; Wed, 12 Jan 2022 19:53:34 -0500 Received: from [2a00:1450:4864:20::130] (port=41929 helo=mail-lf1-x130.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n7oMt-0000Wu-9s for qemu-devel@nongnu.org; Wed, 12 Jan 2022 19:53:33 -0500 Received: by mail-lf1-x130.google.com with SMTP id x7so14033212lfu.8 for ; Wed, 12 Jan 2022 16:53:30 -0800 (PST) Received: from vp-pc.. ([2a00:1370:8174:b458:9ba9:b90b:f25a:ca4d]) by smtp.gmail.com with ESMTPSA id d2sm107688ljj.118.2022.01.12.16.53.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jan 2022 16:53:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=phystech-edu.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=IDjRtlfdJm8ybSCVHOvFOaC8nUHRGEycooXc8kxeUnM=; b=jqgW4AG58oOCZ77L3Enr5YrHnhr2hg/kGub7L+zUNoBBbFT4JgXGHCxckNGGt/rxCZ 3gnJNVyb2bqbfDyUpSvUtRYHoELK7wEKLGPHJuwDVIJyWVD/nIYlPgHFlc00bu9NN2ry wAfw3m+RycYWthxIS8bi3fECZkQedyX0PnemMhiI53NOtBRXo802u/wX5NHNOs+yrIXq 98eXBPVVv7toIYtDBVpD2M4hW+R5xxkAVydJs7m1+DtAjHGjsTNR5IVQ0tjIs1i+eVVY mqIxrtJT/ZL26FCbP6JgOGUb/aJN85DIpvVeaG54L7mMlbl69iTFUwJTnXC3aABLjbgj fGuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=IDjRtlfdJm8ybSCVHOvFOaC8nUHRGEycooXc8kxeUnM=; b=f5Ll0v13uMp8aesP1RAcXIFvaNRHSkPUuJmKGEmYLztgqVFTraJ+IsnrOw26e6FleM QZHyBVK+11bn3l/ox3GQaP4ljlAbeVjpuB2A1gCnL97qKZ0NxnaHnoZyT3S4zWxTiAyx D/jC8r6lSZzm+NPyFuK2b6E5eXCuZL0Vi5RrS5yGUvLqXY3iYBsQw8HuFfVaCM9PgAcw 5jn+oUshHm9Op1onLIWMyjfecrNc2MM3M9QaPgpyIe/pjRW+lGxLC3y9h0CbSefRMwea jk+GCRmpI8goo6tclNAbH3O49jYKPl4SiQT1X7KMfejMH3iV0E/xBbG9BnjCL9/0t+W1 OfjA== X-Gm-Message-State: AOAM531phU/o6vf1GvJl02G1O1Iv5Oq6+RkPmncpwSRxRQRXgzjhu58/ 6mgq996KRqQRzuo0ngQlV3J8AQ== X-Google-Smtp-Source: ABdhPJwxV6ZRNF2vX+4pqQiVtk9MUWl/bSdssaCmhmQw55rUIABR0f8j1PgxhXcNhP0fL4+2QNxMaw== X-Received: by 2002:a05:6512:2506:: with SMTP id be6mr1675952lfb.113.1642035208938; Wed, 12 Jan 2022 16:53:28 -0800 (PST) From: Viktor Prutyanov To: marcandre.lureau@redhat.com, dgilbert@redhat.com, yuri.benditovich@daynix.com, yan@daynix.com, philmd@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v2 1/4] include/qemu: rename Windows context definitions to expose bitness Date: Thu, 13 Jan 2022 03:52:45 +0300 Message-Id: <20220113005248.172522-2-viktor.prutyanov@phystech.edu> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220113005248.172522-1-viktor.prutyanov@phystech.edu> References: <20220113005248.172522-1-viktor.prutyanov@phystech.edu> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::130 (failed) Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::130; envelope-from=viktor.prutyanov@phystech.edu; helo=mail-lf1-x130.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: , Cc: Viktor Prutyanov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @phystech-edu.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1642035410644100002 Content-Type: text/plain; charset="utf-8" Context structure in 64-bit Windows differs from 32-bit one and it should be reflected in its name. Signed-off-by: Viktor Prutyanov Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- contrib/elf2dmp/main.c | 6 +++--- dump/win_dump.c | 14 +++++++------- include/qemu/win_dump_defs.h | 8 ++++---- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/contrib/elf2dmp/main.c b/contrib/elf2dmp/main.c index 20b477d582..b9fc6d230c 100644 --- a/contrib/elf2dmp/main.c +++ b/contrib/elf2dmp/main.c @@ -141,10 +141,10 @@ static KDDEBUGGER_DATA64 *get_kdbg(uint64_t KernBase,= struct pdb_reader *pdb, return kdbg; } =20 -static void win_context_init_from_qemu_cpu_state(WinContext *ctx, +static void win_context_init_from_qemu_cpu_state(WinContext64 *ctx, QEMUCPUState *s) { - WinContext win_ctx =3D (WinContext){ + WinContext64 win_ctx =3D (WinContext64){ .ContextFlags =3D WIN_CTX_X64 | WIN_CTX_INT | WIN_CTX_SEG | WIN_CT= X_CTL, .MxCsr =3D INITIAL_MXCSR, =20 @@ -302,7 +302,7 @@ static int fill_context(KDDEBUGGER_DATA64 *kdbg, for (i =3D 0; i < qe->state_nr; i++) { uint64_t Prcb; uint64_t Context; - WinContext ctx; + WinContext64 ctx; QEMUCPUState *s =3D qe->state[i]; =20 if (va_space_rw(vs, kdbg->KiProcessorBlock + sizeof(Prcb) * i, diff --git a/dump/win_dump.c b/dump/win_dump.c index c5eb5a9aac..29b6e4f670 100644 --- a/dump/win_dump.c +++ b/dump/win_dump.c @@ -189,7 +189,7 @@ try_again: } =20 struct saved_context { - WinContext ctx; + WinContext64 ctx; uint64_t addr; }; =20 @@ -221,7 +221,7 @@ static void patch_and_save_context(WinDumpHeader64 *h, CPUX86State *env =3D &x86_cpu->env; uint64_t Prcb; uint64_t Context; - WinContext ctx; + WinContext64 ctx; =20 if (cpu_memory_rw_debug(first_cpu, KiProcessorBlock + i * sizeof(uint64_t), @@ -241,8 +241,8 @@ static void patch_and_save_context(WinDumpHeader64 *h, =20 saved_ctx[i].addr =3D Context; =20 - ctx =3D (WinContext){ - .ContextFlags =3D WIN_CTX_ALL, + ctx =3D (WinContext64){ + .ContextFlags =3D WIN_CTX64_ALL, .MxCsr =3D env->mxcsr, =20 .SegEs =3D env->segs[0].selector, @@ -284,13 +284,13 @@ static void patch_and_save_context(WinDumpHeader64 *h, }; =20 if (cpu_memory_rw_debug(first_cpu, Context, - (uint8_t *)&saved_ctx[i].ctx, sizeof(WinContext), 0)) { + (uint8_t *)&saved_ctx[i].ctx, sizeof(WinContext64), 0)) { error_setg(errp, "win-dump: failed to save CPU #%d context", i= ); return; } =20 if (cpu_memory_rw_debug(first_cpu, Context, - (uint8_t *)&ctx, sizeof(WinContext), 1)) { + (uint8_t *)&ctx, sizeof(WinContext64), 1)) { error_setg(errp, "win-dump: failed to write CPU #%d context", = i); return; } @@ -306,7 +306,7 @@ static void restore_context(WinDumpHeader64 *h, =20 for (i =3D 0; i < h->NumberProcessors; i++) { if (cpu_memory_rw_debug(first_cpu, saved_ctx[i].addr, - (uint8_t *)&saved_ctx[i].ctx, sizeof(WinContext), 1)) { + (uint8_t *)&saved_ctx[i].ctx, sizeof(WinContext64), 1)) { warn_report("win-dump: failed to restore CPU #%d context", i); } } diff --git a/include/qemu/win_dump_defs.h b/include/qemu/win_dump_defs.h index 145096e8ee..5a5e5a5e09 100644 --- a/include/qemu/win_dump_defs.h +++ b/include/qemu/win_dump_defs.h @@ -97,8 +97,8 @@ typedef struct WinDumpHeader64 { #define WIN_CTX_FP 0x00000008L #define WIN_CTX_DBG 0x00000010L =20 -#define WIN_CTX_FULL (WIN_CTX_X64 | WIN_CTX_CTL | WIN_CTX_INT | WIN_CTX= _FP) -#define WIN_CTX_ALL (WIN_CTX_FULL | WIN_CTX_SEG | WIN_CTX_DBG) +#define WIN_CTX64_FULL (WIN_CTX_X64 | WIN_CTX_CTL | WIN_CTX_INT | WIN_CTX= _FP) +#define WIN_CTX64_ALL (WIN_CTX64_FULL | WIN_CTX_SEG | WIN_CTX_DBG) =20 #define LIVE_SYSTEM_DUMP 0x00000161 =20 @@ -107,7 +107,7 @@ typedef struct WinM128A { int64_t high; } QEMU_ALIGNED(16) WinM128A; =20 -typedef struct WinContext { +typedef struct WinContext64 { uint64_t PHome[6]; =20 uint32_t ContextFlags; @@ -174,6 +174,6 @@ typedef struct WinContext { uint64_t LastBranchFromRip; uint64_t LastExceptionToRip; uint64_t LastExceptionFromRip; -} QEMU_ALIGNED(16) WinContext; +} QEMU_ALIGNED(16) WinContext64; =20 #endif /* QEMU_WIN_DUMP_DEFS_H */ --=20 2.31.1 From nobody Thu Apr 25 22:20:58 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=phystech.edu ARC-Seal: i=1; a=rsa-sha256; t=1642035454; cv=none; d=zohomail.com; s=zohoarc; b=AliKLjXl+yXqRVODl/Lm5xrXJa5MquN1NIaf2rwLapC6J01JNWviUmKxYRgD4JnXz2UcTYB6RrwKitT+Kpx8U69kEs2xKEiosBZjdfyQRwMEXj3U12NUqQ9bC+DhTyWGikTFA213KMKYeoDBmT/0ixaKVld9e59WINZKVEWSBz4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642035454; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=WQaRJsaTTS3PbM0RSVFFC7TxkmLvya3coDXUZRZqHSQ=; b=MGZXM5qNOLDYGv2y+jhP6AP/ETmtGI6sl+UtgeFH6YK8jICn2LmVlAHlXKIgh7jWrANIY+S0c1EXezywesrmaV6QMR5RY0fmOObUtPlUC+vp4u3eG1Px3jqd8xVQRzt5x69e8kzz+tVyfkS2k3MuRsofx0zJt8IfphszwWeL6m8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1642035454617253.49869983632993; Wed, 12 Jan 2022 16:57:34 -0800 (PST) Received: from localhost ([::1]:35398 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n7oQm-0002pT-CW for importer@patchew.org; Wed, 12 Jan 2022 19:57:32 -0500 Received: from eggs.gnu.org ([209.51.188.92]:36822) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n7oMx-0008Vu-H8 for qemu-devel@nongnu.org; Wed, 12 Jan 2022 19:53:35 -0500 Received: from [2a00:1450:4864:20::143] (port=44589 helo=mail-lf1-x143.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n7oMt-0000X0-NO for qemu-devel@nongnu.org; Wed, 12 Jan 2022 19:53:35 -0500 Received: by mail-lf1-x143.google.com with SMTP id o15so13979121lfo.11 for ; Wed, 12 Jan 2022 16:53:31 -0800 (PST) Received: from vp-pc.. ([2a00:1370:8174:b458:9ba9:b90b:f25a:ca4d]) by smtp.gmail.com with ESMTPSA id d2sm107688ljj.118.2022.01.12.16.53.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jan 2022 16:53:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=phystech-edu.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WQaRJsaTTS3PbM0RSVFFC7TxkmLvya3coDXUZRZqHSQ=; b=vnLcv9LlOUAmvlbbMiVziWFSw4Zl0WkwoMziX2lZrF+sp8Q2gKd7WeVN8jQUDwKUqh qGT0LojJFlSnMRUIAdaatbsbp8PwhZ7Yaoz3afKt47OEtSw/PQdQP8W/W7cNjANzO+a0 D/8Uu49n2BP+YkIpXZX7eqtu02UWOarDzJn/MjiV/5oKM9SZIuUsn00RyKAgi7tfPzNV u5KEjvmJXShL6z4XP/U9FoIBt2hE83HgJyLyKXxs5sCKiqDTBgwPHE+k425oqozsvZUf hlFh5C+X3lRI451xPelzMp57aFgXRl6vm75o7l6deZIP/xSAxG7Y4qYqmpFZn9L/N99I KkWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WQaRJsaTTS3PbM0RSVFFC7TxkmLvya3coDXUZRZqHSQ=; b=q3LgGi+L/RA4mSfKGeTXoF+INGMBCaxnaY8ShVr3ue0K6QiVGWEkfUJTFH708hIlkj 9IloGD5QgTt5FxTtqkoegIa3us1viO7fcQEuVJMffsfnL7D5RSKU7/uTho4NQbXkaMoH 9uBHCIpwBPg3bv2zHb2GhVZPWwWyfbMlAuQoe/ux9UgFSFijqM0ANbztafbeNmfAk1Hn Vi2A8mWFQ6Qiff1UIn/lgQUSS3/tpDJOuQVqYj41er5Yxg8kihGjvVofMsddFfYMQ5kM iC453JVjeHLUAZ3cvnzT2GmavZCtBQ4GgjDzPmYoj9lU1QT4jzIteyFwDVDuFgXx2ryf IleA== X-Gm-Message-State: AOAM531LT83BE8C5P9Mg33TWgfdNG93HOKhz4Ty+js0etgxmuihcr51j 7kV5SYeT7gcNwvaGmyo6H3Rd6w== X-Google-Smtp-Source: ABdhPJyPwaKsFm3osm6p08XDbXtlu/6NC+AeNge3Sl3vHEoG9EBQWtWOckCK0dk5xQpcHDQ3ic0glA== X-Received: by 2002:ac2:41c3:: with SMTP id d3mr1626258lfi.397.1642035209965; Wed, 12 Jan 2022 16:53:29 -0800 (PST) From: Viktor Prutyanov To: marcandre.lureau@redhat.com, dgilbert@redhat.com, yuri.benditovich@daynix.com, yan@daynix.com, philmd@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v2 2/4] dump/win_dump: add helper macros for Windows dump header access Date: Thu, 13 Jan 2022 03:52:46 +0300 Message-Id: <20220113005248.172522-3-viktor.prutyanov@phystech.edu> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220113005248.172522-1-viktor.prutyanov@phystech.edu> References: <20220113005248.172522-1-viktor.prutyanov@phystech.edu> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::143 (failed) Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::143; envelope-from=viktor.prutyanov@phystech.edu; helo=mail-lf1-x143.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: , Cc: Viktor Prutyanov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @phystech-edu.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1642035455807100001 Content-Type: text/plain; charset="utf-8" Perform read access to Windows dump header fields via helper macros. This is preparation for the next 32-bit guest Windows dump support. Signed-off-by: Viktor Prutyanov --- dump/win_dump.c | 100 +++++++++++++++++++++++++++++++----------------- 1 file changed, 65 insertions(+), 35 deletions(-) diff --git a/dump/win_dump.c b/dump/win_dump.c index 29b6e4f670..df3b432ca5 100644 --- a/dump/win_dump.c +++ b/dump/win_dump.c @@ -24,11 +24,25 @@ #include "hw/misc/vmcoreinfo.h" #include "win_dump.h" =20 -static size_t write_run(WinDumpPhyMemRun64 *run, int fd, Error **errp) +#define WIN_DUMP_PTR_SIZE sizeof(uint64_t) + +#define _WIN_DUMP_FIELD(f) (h->f) +#define WIN_DUMP_FIELD(field) _WIN_DUMP_FIELD(field) + +#define _WIN_DUMP_FIELD_PTR(f) ((void *)&h->f) +#define WIN_DUMP_FIELD_PTR(field) _WIN_DUMP_FIELD_PTR(field) + +#define _WIN_DUMP_FIELD_SIZE(f) sizeof(h->f) +#define WIN_DUMP_FIELD_SIZE(field) _WIN_DUMP_FIELD_SIZE(field) + +#define WIN_DUMP_CTX_SIZE sizeof(WinContext64) + +static size_t write_run(uint64_t base_page, uint64_t page_count, + int fd, Error **errp) { void *buf; - uint64_t addr =3D run->BasePage << TARGET_PAGE_BITS; - uint64_t size =3D run->PageCount << TARGET_PAGE_BITS; + uint64_t addr =3D base_page << TARGET_PAGE_BITS; + uint64_t size =3D page_count << TARGET_PAGE_BITS; uint64_t len, l; size_t total =3D 0; =20 @@ -59,13 +73,14 @@ static size_t write_run(WinDumpPhyMemRun64 *run, int fd= , Error **errp) =20 static void write_runs(DumpState *s, WinDumpHeader64 *h, Error **errp) { - WinDumpPhyMemDesc64 *desc =3D &h->PhysicalMemoryBlock; - WinDumpPhyMemRun64 *run =3D desc->Run; + uint64_t BasePage, PageCount; Error *local_err =3D NULL; int i; =20 - for (i =3D 0; i < desc->NumberOfRuns; i++) { - s->written_size +=3D write_run(run + i, s->fd, &local_err); + for (i =3D 0; i < WIN_DUMP_FIELD(PhysicalMemoryBlock.NumberOfRuns); i+= +) { + BasePage =3D WIN_DUMP_FIELD(PhysicalMemoryBlock.Run[i].BasePage); + PageCount =3D WIN_DUMP_FIELD(PhysicalMemoryBlock.Run[i].PageCount); + s->written_size +=3D write_run(BasePage, PageCount, s->fd, &local_= err); if (local_err) { error_propagate(errp, local_err); return; @@ -73,11 +88,24 @@ static void write_runs(DumpState *s, WinDumpHeader64 *h= , Error **errp) } } =20 +static int cpu_read_ptr(CPUState *cpu, uint64_t addr, uint64_t *ptr) +{ + int ret; + uint64_t ptr64; + + ret =3D cpu_memory_rw_debug(cpu, addr, &ptr64, WIN_DUMP_PTR_SIZE, 0); + + *ptr =3D ptr64; + + return ret; +} + static void patch_mm_pfn_database(WinDumpHeader64 *h, Error **errp) { if (cpu_memory_rw_debug(first_cpu, - h->KdDebuggerDataBlock + KDBG_MM_PFN_DATABASE_OFFSET64, - (uint8_t *)&h->PfnDatabase, sizeof(h->PfnDatabase), 0)) { + WIN_DUMP_FIELD(KdDebuggerDataBlock) + KDBG_MM_PFN_DATABASE_OFF= SET64, + WIN_DUMP_FIELD_PTR(PfnDatabase), + WIN_DUMP_FIELD_SIZE(PfnDatabase), 0)) { error_setg(errp, "win-dump: failed to read MmPfnDatabase"); return; } @@ -87,16 +115,17 @@ static void patch_bugcheck_data(WinDumpHeader64 *h, Er= ror **errp) { uint64_t KiBugcheckData; =20 - if (cpu_memory_rw_debug(first_cpu, - h->KdDebuggerDataBlock + KDBG_KI_BUGCHECK_DATA_OFFSET64, - (uint8_t *)&KiBugcheckData, sizeof(KiBugcheckData), 0)) { + if (cpu_read_ptr(first_cpu, + WIN_DUMP_FIELD(KdDebuggerDataBlock) + + KDBG_KI_BUGCHECK_DATA_OFFSET64, + &KiBugcheckData)) { error_setg(errp, "win-dump: failed to read KiBugcheckData"); return; } =20 - if (cpu_memory_rw_debug(first_cpu, - KiBugcheckData, - h->BugcheckData, sizeof(h->BugcheckData), 0)) { + if (cpu_memory_rw_debug(first_cpu, KiBugcheckData, + WIN_DUMP_FIELD(BugcheckData), + WIN_DUMP_FIELD_SIZE(BugcheckData), 0)) { error_setg(errp, "win-dump: failed to read bugcheck data"); return; } @@ -105,8 +134,8 @@ static void patch_bugcheck_data(WinDumpHeader64 *h, Err= or **errp) * If BugcheckCode wasn't saved, we consider guest OS as alive. */ =20 - if (!h->BugcheckCode) { - h->BugcheckCode =3D LIVE_SYSTEM_DUMP; + if (!WIN_DUMP_FIELD(BugcheckCode)) { + *(uint32_t *)WIN_DUMP_FIELD_PTR(BugcheckCode) =3D LIVE_SYSTEM_DUMP; } } =20 @@ -155,7 +184,7 @@ static void check_kdbg(WinDumpHeader64 *h, Error **errp) { const char OwnerTag[] =3D "KDBG"; char read_OwnerTag[4]; - uint64_t KdDebuggerDataBlock =3D h->KdDebuggerDataBlock; + uint64_t KdDebuggerDataBlock =3D WIN_DUMP_FIELD(KdDebuggerDataBlock); bool try_fallback =3D true; =20 try_again: @@ -174,7 +203,7 @@ try_again: * we try to use KDBG obtained by guest driver. */ =20 - KdDebuggerDataBlock =3D h->BugcheckParameter1; + KdDebuggerDataBlock =3D WIN_DUMP_FIELD(BugcheckParameter1); try_fallback =3D false; goto try_again; } else { @@ -197,20 +226,21 @@ static void patch_and_save_context(WinDumpHeader64 *h, struct saved_context *saved_ctx, Error **errp) { + uint64_t KdDebuggerDataBlock =3D WIN_DUMP_FIELD(KdDebuggerDataBlock); uint64_t KiProcessorBlock; uint16_t OffsetPrcbContext; CPUState *cpu; int i =3D 0; =20 - if (cpu_memory_rw_debug(first_cpu, - h->KdDebuggerDataBlock + KDBG_KI_PROCESSOR_BLOCK_OFFSET64, - (uint8_t *)&KiProcessorBlock, sizeof(KiProcessorBlock), 0)) { + if (cpu_read_ptr(first_cpu, + KdDebuggerDataBlock + KDBG_KI_PROCESSOR_BLOCK_OFFSET64, + &KiProcessorBlock)) { error_setg(errp, "win-dump: failed to read KiProcessorBlock"); return; } =20 if (cpu_memory_rw_debug(first_cpu, - h->KdDebuggerDataBlock + KDBG_OFFSET_PRCB_CONTEXT_OFFSET64, + KdDebuggerDataBlock + KDBG_OFFSET_PRCB_CONTEXT_OFFSET64, (uint8_t *)&OffsetPrcbContext, sizeof(OffsetPrcbContext), 0)) { error_setg(errp, "win-dump: failed to read OffsetPrcbContext"); return; @@ -223,17 +253,17 @@ static void patch_and_save_context(WinDumpHeader64 *h, uint64_t Context; WinContext64 ctx; =20 - if (cpu_memory_rw_debug(first_cpu, - KiProcessorBlock + i * sizeof(uint64_t), - (uint8_t *)&Prcb, sizeof(Prcb), 0)) { + if (cpu_read_ptr(first_cpu, + KiProcessorBlock + i * WIN_DUMP_PTR_SIZE, + &Prcb)) { error_setg(errp, "win-dump: failed to read" " CPU #%d PRCB location", i); return; } =20 - if (cpu_memory_rw_debug(first_cpu, + if (cpu_read_ptr(first_cpu, Prcb + OffsetPrcbContext, - (uint8_t *)&Context, sizeof(Context), 0)) { + &Context)) { error_setg(errp, "win-dump: failed to read" " CPU #%d ContextFrame location", i); return; @@ -284,13 +314,13 @@ static void patch_and_save_context(WinDumpHeader64 *h, }; =20 if (cpu_memory_rw_debug(first_cpu, Context, - (uint8_t *)&saved_ctx[i].ctx, sizeof(WinContext64), 0)) { + &saved_ctx[i].ctx, WIN_DUMP_CTX_SIZE, 0)) { error_setg(errp, "win-dump: failed to save CPU #%d context", i= ); return; } =20 if (cpu_memory_rw_debug(first_cpu, Context, - (uint8_t *)&ctx, sizeof(WinContext64), 1)) { + &ctx, WIN_DUMP_CTX_SIZE, 1)) { error_setg(errp, "win-dump: failed to write CPU #%d context", = i); return; } @@ -304,9 +334,9 @@ static void restore_context(WinDumpHeader64 *h, { int i; =20 - for (i =3D 0; i < h->NumberProcessors; i++) { + for (i =3D 0; i < WIN_DUMP_FIELD(NumberProcessors); i++) { if (cpu_memory_rw_debug(first_cpu, saved_ctx[i].addr, - (uint8_t *)&saved_ctx[i].ctx, sizeof(WinContext64), 1)) { + &saved_ctx[i].ctx, WIN_DUMP_CTX_SIZE, 1)) { warn_report("win-dump: failed to restore CPU #%d context", i); } } @@ -338,7 +368,7 @@ void create_win_dump(DumpState *s, Error **errp) * should be made from system context. */ =20 - first_x86_cpu->env.cr[3] =3D h->DirectoryTableBase; + first_x86_cpu->env.cr[3] =3D WIN_DUMP_FIELD(DirectoryTableBase); =20 check_kdbg(h, &local_err); if (local_err) { @@ -348,7 +378,7 @@ void create_win_dump(DumpState *s, Error **errp) =20 patch_header(h); =20 - saved_ctx =3D g_new(struct saved_context, h->NumberProcessors); + saved_ctx =3D g_new(struct saved_context, WIN_DUMP_FIELD(NumberProcess= ors)); =20 /* * Always patch context because there is no way @@ -361,7 +391,7 @@ void create_win_dump(DumpState *s, Error **errp) goto out_free; } =20 - s->total_size =3D h->RequiredDumpSpace; + s->total_size =3D WIN_DUMP_FIELD(RequiredDumpSpace); =20 s->written_size =3D qemu_write_full(s->fd, h, sizeof(*h)); if (s->written_size !=3D sizeof(*h)) { --=20 2.31.1 From nobody Thu Apr 25 22:20:58 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=phystech.edu ARC-Seal: i=1; a=rsa-sha256; t=1642035579; cv=none; d=zohomail.com; s=zohoarc; b=oHtwm031JQ2iRUD6sn+NBsIyGvV3o1uXuJUcyeHD2P/31gwaolKZi7l3zLmXpu/7LbIy5mUDNaLfeKZzcFloJuljEfail3RKlPKpowzFEKFnviKZbbEcEAI4iAbvaKIQOEYhKlQwGWfRQjTnXs2XBCtWDsOyJr08ujIA2kA6xek= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642035579; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/LJdqGaYOx2UrTajnO9wXZ7cQQh/SPwEo+RieODvDxs=; b=ZYkGfYjZsoIyWwPdTA8Uy4YlS4XqYQ4f3jQTn2h7719jZJu+hjKWO1X8wXWp5ASZLxtNgapRfiLgHSSw09BTQ0wtbVv5rPM+TwbZm2J6Gdvjq9gXMtFPcyHlWVXsD3vgVEbTzzRisNAY7Vu+1XNblM9rfWmUi2QX2WVbnnoxnXc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1642035579039734.440213715794; Wed, 12 Jan 2022 16:59:39 -0800 (PST) Received: from localhost ([::1]:41344 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n7oSo-0006z2-0q for importer@patchew.org; Wed, 12 Jan 2022 19:59:38 -0500 Received: from eggs.gnu.org ([209.51.188.92]:36856) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n7oN7-00009F-Q9 for qemu-devel@nongnu.org; Wed, 12 Jan 2022 19:53:45 -0500 Received: from [2a00:1450:4864:20::133] (port=36401 helo=mail-lf1-x133.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n7oMw-0000YG-NI for qemu-devel@nongnu.org; Wed, 12 Jan 2022 19:53:37 -0500 Received: by mail-lf1-x133.google.com with SMTP id j11so14111628lfg.3 for ; Wed, 12 Jan 2022 16:53:33 -0800 (PST) Received: from vp-pc.. ([2a00:1370:8174:b458:9ba9:b90b:f25a:ca4d]) by smtp.gmail.com with ESMTPSA id d2sm107688ljj.118.2022.01.12.16.53.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jan 2022 16:53:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=phystech-edu.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/LJdqGaYOx2UrTajnO9wXZ7cQQh/SPwEo+RieODvDxs=; b=e01KiqlSup7/JnROgDxoZp7f9idZ6VZNxrK/OK5bErtN8/Mo3e3wzlonFpUXydVC/u tx3gBEdEoLz3k0BUqOg0osEazUnFV4ApAT0zO74s/F7JkQTQ38WbbV4qVge2dx+YI6Wf fPdjH8VeulR8I1dA92l9u7basWGkS/HqcG0NkEDMCvqmE8wfbLGyf9GxT2vk2PLiohwn ZVfn5AcRZ4d3dRg4Uy8ZFz9TOeeDWXT84Rxiwbmiy8VJ9hfu2qUF2nUpwCCTDyFnhyfe gQmWtEOQWMVR/O2+4HgyYLx/CWVQphgtk+IYxFsu3NoeJquFwjS+66sxNhJJkF2sJh6t /Qmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/LJdqGaYOx2UrTajnO9wXZ7cQQh/SPwEo+RieODvDxs=; b=jH+kU+zYnLWmvTKM7WN7YI+ivQgZfbQOhr07ipGe3KJFJiwes2LsCqtUef29yh+LIs NBbcS5DM2ggmtnVOm5OpYi+3XqKtJAkXjCnfxpisJIal+0XW4KF3sFJap+1OAHTJ1eX5 RPHi689UXq4djpKPuXE8kCMHjVZrxpwoT+t0dwb5u5J3w5k1SPslofLcZJIp9tmVvOYP kC4E0k0gJKOiEXX/TcFFflYSV/3Ci43zEj4InlfsCWnvUkAQcPT5lIXqvoiE98teIBdD 5AzEh0MgVhOypJvtE5EaHyNCsDAbC1Vlawp3MbT7hLrsJ7J16Zp+zw4ydi8Z02AzlULy QCNQ== X-Gm-Message-State: AOAM530OpF9x4OcVCG8wxBvuGNJvV20aHEszWEczCB4krPBk6L1aYfcj EuPr2ykRXSbMu8DA2IYgt/55Tw== X-Google-Smtp-Source: ABdhPJw7Jb+US/t9kgvNt2j6bMN5MSVqGEKDLO79siw67Kxftfo20VgMZs5FgLDdfnNSfh/oXnT/ZQ== X-Received: by 2002:a05:6512:374f:: with SMTP id a15mr1540646lfs.571.1642035211137; Wed, 12 Jan 2022 16:53:31 -0800 (PST) From: Viktor Prutyanov To: marcandre.lureau@redhat.com, dgilbert@redhat.com, yuri.benditovich@daynix.com, yan@daynix.com, philmd@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v2 3/4] include/qemu: add 32-bit Windows dump structures Date: Thu, 13 Jan 2022 03:52:47 +0300 Message-Id: <20220113005248.172522-4-viktor.prutyanov@phystech.edu> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220113005248.172522-1-viktor.prutyanov@phystech.edu> References: <20220113005248.172522-1-viktor.prutyanov@phystech.edu> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::133 (failed) Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::133; envelope-from=viktor.prutyanov@phystech.edu; helo=mail-lf1-x133.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: , Cc: Viktor Prutyanov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @phystech-edu.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1642035580886100001 Content-Type: text/plain; charset="utf-8" These structures are required to produce 32-bit guest Windows Complete Memory Dump. Add 32-bit Windows dump header, CPU context and physical memory descriptor structures along with corresponding definitions. Signed-off-by: Viktor Prutyanov Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- include/qemu/win_dump_defs.h | 107 +++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) diff --git a/include/qemu/win_dump_defs.h b/include/qemu/win_dump_defs.h index 5a5e5a5e09..73a44e2408 100644 --- a/include/qemu/win_dump_defs.h +++ b/include/qemu/win_dump_defs.h @@ -11,11 +11,22 @@ #ifndef QEMU_WIN_DUMP_DEFS_H #define QEMU_WIN_DUMP_DEFS_H =20 +typedef struct WinDumpPhyMemRun32 { + uint32_t BasePage; + uint32_t PageCount; +} QEMU_PACKED WinDumpPhyMemRun32; + typedef struct WinDumpPhyMemRun64 { uint64_t BasePage; uint64_t PageCount; } QEMU_PACKED WinDumpPhyMemRun64; =20 +typedef struct WinDumpPhyMemDesc32 { + uint32_t NumberOfRuns; + uint32_t NumberOfPages; + WinDumpPhyMemRun32 Run[86]; +} QEMU_PACKED WinDumpPhyMemDesc32; + typedef struct WinDumpPhyMemDesc64 { uint32_t NumberOfRuns; uint32_t unused; @@ -33,6 +44,39 @@ typedef struct WinDumpExceptionRecord { uint64_t ExceptionInformation[15]; } QEMU_PACKED WinDumpExceptionRecord; =20 +typedef struct WinDumpHeader32 { + char Signature[4]; + char ValidDump[4]; + uint32_t MajorVersion; + uint32_t MinorVersion; + uint32_t DirectoryTableBase; + uint32_t PfnDatabase; + uint32_t PsLoadedModuleList; + uint32_t PsActiveProcessHead; + uint32_t MachineImageType; + uint32_t NumberProcessors; + union { + struct { + uint32_t BugcheckCode; + uint32_t BugcheckParameter1; + uint32_t BugcheckParameter2; + uint32_t BugcheckParameter3; + uint32_t BugcheckParameter4; + }; + uint8_t BugcheckData[20]; + }; + uint8_t VersionUser[32]; + uint32_t reserved0; + uint32_t KdDebuggerDataBlock; + union { + WinDumpPhyMemDesc32 PhysicalMemoryBlock; + uint8_t PhysicalMemoryBlockBuffer[700]; + }; + uint8_t reserved1[3200]; + uint32_t RequiredDumpSpace; + uint8_t reserved2[92]; +} QEMU_PACKED WinDumpHeader32; + typedef struct WinDumpHeader64 { char Signature[4]; char ValidDump[4]; @@ -81,25 +125,49 @@ typedef struct WinDumpHeader64 { uint8_t reserved[4018]; } QEMU_PACKED WinDumpHeader64; =20 +typedef union WinDumpHeader { + struct { + char Signature[4]; + char ValidDump[4]; + }; + WinDumpHeader32 x32; + WinDumpHeader64 x64; +} WinDumpHeader; + #define KDBG_OWNER_TAG_OFFSET64 0x10 #define KDBG_MM_PFN_DATABASE_OFFSET64 0xC0 #define KDBG_KI_BUGCHECK_DATA_OFFSET64 0x88 #define KDBG_KI_PROCESSOR_BLOCK_OFFSET64 0x218 #define KDBG_OFFSET_PRCB_CONTEXT_OFFSET64 0x338 =20 +#define KDBG_OWNER_TAG_OFFSET KDBG_OWNER_TAG_OFFSET64 +#define KDBG_MM_PFN_DATABASE_OFFSET KDBG_MM_PFN_DATABASE_OFFSET64 +#define KDBG_KI_BUGCHECK_DATA_OFFSET KDBG_KI_BUGCHECK_DATA_OFFSET64 +#define KDBG_KI_PROCESSOR_BLOCK_OFFSET KDBG_KI_PROCESSOR_BLOCK_OFFSET64 +#define KDBG_OFFSET_PRCB_CONTEXT_OFFSET KDBG_OFFSET_PRCB_CONTEXT_OFFSET64 + #define VMCOREINFO_ELF_NOTE_HDR_SIZE 24 +#define VMCOREINFO_WIN_DUMP_NOTE_SIZE64 (sizeof(WinDumpHeader64) + \ + VMCOREINFO_ELF_NOTE_HDR_SIZE) +#define VMCOREINFO_WIN_DUMP_NOTE_SIZE32 (sizeof(WinDumpHeader32) + \ + VMCOREINFO_ELF_NOTE_HDR_SIZE) =20 #define WIN_CTX_X64 0x00100000L +#define WIN_CTX_X86 0x00010000L =20 #define WIN_CTX_CTL 0x00000001L #define WIN_CTX_INT 0x00000002L #define WIN_CTX_SEG 0x00000004L #define WIN_CTX_FP 0x00000008L #define WIN_CTX_DBG 0x00000010L +#define WIN_CTX_EXT 0x00000020L =20 #define WIN_CTX64_FULL (WIN_CTX_X64 | WIN_CTX_CTL | WIN_CTX_INT | WIN_CTX= _FP) #define WIN_CTX64_ALL (WIN_CTX64_FULL | WIN_CTX_SEG | WIN_CTX_DBG) =20 +#define WIN_CTX32_FULL (WIN_CTX_X86 | WIN_CTX_CTL | WIN_CTX_INT | WIN_CTX_= SEG) +#define WIN_CTX32_ALL (WIN_CTX32_FULL | WIN_CTX_FP | WIN_CTX_DBG | WIN_CTX= _EXT) + #define LIVE_SYSTEM_DUMP 0x00000161 =20 typedef struct WinM128A { @@ -107,6 +175,40 @@ typedef struct WinM128A { int64_t high; } QEMU_ALIGNED(16) WinM128A; =20 +typedef struct WinContext32 { + uint32_t ContextFlags; + + uint32_t Dr0; + uint32_t Dr1; + uint32_t Dr2; + uint32_t Dr3; + uint32_t Dr6; + uint32_t Dr7; + + uint8_t FloatSave[112]; + + uint32_t SegGs; + uint32_t SegFs; + uint32_t SegEs; + uint32_t SegDs; + + uint32_t Edi; + uint32_t Esi; + uint32_t Ebx; + uint32_t Edx; + uint32_t Ecx; + uint32_t Eax; + + uint32_t Ebp; + uint32_t Eip; + uint32_t SegCs; + uint32_t EFlags; + uint32_t Esp; + uint32_t SegSs; + + uint8_t ExtendedRegisters[512]; +} QEMU_ALIGNED(16) WinContext32; + typedef struct WinContext64 { uint64_t PHome[6]; =20 @@ -176,4 +278,9 @@ typedef struct WinContext64 { uint64_t LastExceptionFromRip; } QEMU_ALIGNED(16) WinContext64; =20 +typedef union WinContext { + WinContext32 x32; + WinContext64 x64; +} WinContext; + #endif /* QEMU_WIN_DUMP_DEFS_H */ --=20 2.31.1 From nobody Thu Apr 25 22:20:58 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=phystech.edu ARC-Seal: i=1; a=rsa-sha256; t=1642035598; cv=none; d=zohomail.com; s=zohoarc; b=CA1ANCcQuIxt3o/lbG19iepdPzWl0U5QwZe0ccNLH8sXxQzHWhZ+mSYRU9arAV00NHVTxH2pxL0DpvfD/4fh6dsP39RWKiWgSEct7CiK+dbpCBC4Fq7rN7G7OwW+9Uiax0sJTS6kU/CxpPXIulT8CgqTIa1g3F3AfTsnqz8UrTg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642035598; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Auxh+lgZ+uRp/+VUohEf91tHdfU5iJFTNGOhiE2MXRM=; b=c2+NtnWkyDfl0AYwi4+sqcO/JPZoDuKbYY33DT/Fru1jvlipq2Lv7LVPtJ1dc14aampytEnaChsgfHgs6UdDaDINUxwNX5BOUQZDJiDhzL9yf6lAbMkp0pdVl8H0a4DSoqa6J1V9LxllInwTqcyQ7Wa5Nb0oZI1f2xUJPCuLaQY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1642035598047248.3891367360959; Wed, 12 Jan 2022 16:59:58 -0800 (PST) Received: from localhost ([::1]:41900 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1n7oT7-0007N8-1p for importer@patchew.org; Wed, 12 Jan 2022 19:59:57 -0500 Received: from eggs.gnu.org ([209.51.188.92]:36858) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n7oN7-00009J-Ph for qemu-devel@nongnu.org; Wed, 12 Jan 2022 19:53:45 -0500 Received: from [2a00:1450:4864:20::142] (port=38703 helo=mail-lf1-x142.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1n7oMw-0000YK-F5 for qemu-devel@nongnu.org; Wed, 12 Jan 2022 19:53:37 -0500 Received: by mail-lf1-x142.google.com with SMTP id x6so14085869lfa.5 for ; Wed, 12 Jan 2022 16:53:33 -0800 (PST) Received: from vp-pc.. ([2a00:1370:8174:b458:9ba9:b90b:f25a:ca4d]) by smtp.gmail.com with ESMTPSA id d2sm107688ljj.118.2022.01.12.16.53.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jan 2022 16:53:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=phystech-edu.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Auxh+lgZ+uRp/+VUohEf91tHdfU5iJFTNGOhiE2MXRM=; b=LrhdmanGEHCkiTXi1UxVDoLmQbYbsZikXR4Cpp499G6Zma6u2Zb3ikxuswjDizlBHF ZZtDX1HeeTkiMFzfUdb4Vg93YsJaMDwUIsxc3i577e9rPlMIkJoc/BSXWTb+GZpVu1QR v7o1gFiV/01zPjfbGcmgcNulYnwrsEw+bV1kKYfF707PERfBNuj0o+wC8LKOo2dlYqur TGAsyxIuYvlbJm6Zgza2vYWuvGh7I0wNN8JndHD1lp8oYBwRIhYKdJi7bSLyOGfLpsVS YRRchAeCX+6BzFPbiAyWD4+WGQNuqyhlBTww7tmEUV1euRMzIY5u1QrZng0l3hRUgQG8 W+XA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Auxh+lgZ+uRp/+VUohEf91tHdfU5iJFTNGOhiE2MXRM=; b=xXhhykH8JvLhIHoBH7+JZEt5qu6U361o4EBhAIqnT0Ox4a7DAdHhXtsAcKw6zvUJO3 //QVxJdi1QQhvUu7a4m+F7twVW8ogZlT3P2F1YVgSZEZFdFejqXt0fgoX4vUBFcjQcvs 8bxWpLKVTeUnk3M+I6ypLaV+vRZ52mKpJQMgFawKb1kc5w4JOjzZYoeNgdmBCwvHJaNl XMA/ldmanaG2pl8qdCa9DoH4NQ2GR3X8jCi3FwVTupOX1JRo6eETuW+w3AG7AivbQhdh qh4bTH/sO63PD0Iym9+EtdiIhiXQXia+MwsjiLzTBt+x+me9OK/R1hRmwKNDWVQdToy5 Dn/g== X-Gm-Message-State: AOAM531G63tCHTPt0fT71XabJma/BbUS4rxLmiqg6zGZdhOTOPLP4Uu2 PWO3476xIS6Te4HvshuYrfLBoA== X-Google-Smtp-Source: ABdhPJyiojrQDTgvTREDyr1i4hg8TO0cr1TzFGVpxKAygzKNuW+nB6jU7KPuNFjB2GEMEuoE1fnd8g== X-Received: by 2002:a2e:bc17:: with SMTP id b23mr1386323ljf.365.1642035212181; Wed, 12 Jan 2022 16:53:32 -0800 (PST) From: Viktor Prutyanov To: marcandre.lureau@redhat.com, dgilbert@redhat.com, yuri.benditovich@daynix.com, yan@daynix.com, philmd@redhat.com, qemu-devel@nongnu.org Subject: [PATCH v2 4/4] dump/win_dump: add 32-bit guest Windows support Date: Thu, 13 Jan 2022 03:52:48 +0300 Message-Id: <20220113005248.172522-5-viktor.prutyanov@phystech.edu> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220113005248.172522-1-viktor.prutyanov@phystech.edu> References: <20220113005248.172522-1-viktor.prutyanov@phystech.edu> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::142 (failed) Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::142; envelope-from=viktor.prutyanov@phystech.edu; helo=mail-lf1-x142.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: , Cc: Viktor Prutyanov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @phystech-edu.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1642035599190100001 Content-Type: text/plain; charset="utf-8" Before this patch, 'dump-guest-memory -w' was accepting only 64-bit dump header provided by guest through vmcoreinfo and thus was unable to produce 32-bit guest Windows dump. So, add 32-bit guest Windows dumping support. Signed-off-by: Viktor Prutyanov Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- dump/win_dump.c | 231 +++++++++++++++++++++++++++++------------------- 1 file changed, 139 insertions(+), 92 deletions(-) diff --git a/dump/win_dump.c b/dump/win_dump.c index df3b432ca5..d751cd6d36 100644 --- a/dump/win_dump.c +++ b/dump/win_dump.c @@ -24,18 +24,18 @@ #include "hw/misc/vmcoreinfo.h" #include "win_dump.h" =20 -#define WIN_DUMP_PTR_SIZE sizeof(uint64_t) +#define WIN_DUMP_PTR_SIZE (x64 ? sizeof(uint64_t) : sizeof(uint32_t)) =20 -#define _WIN_DUMP_FIELD(f) (h->f) +#define _WIN_DUMP_FIELD(f) (x64 ? h->x64.f : h->x32.f) #define WIN_DUMP_FIELD(field) _WIN_DUMP_FIELD(field) =20 -#define _WIN_DUMP_FIELD_PTR(f) ((void *)&h->f) +#define _WIN_DUMP_FIELD_PTR(f) (x64 ? (void *)&h->x64.f : (void *)&h->x32.= f) #define WIN_DUMP_FIELD_PTR(field) _WIN_DUMP_FIELD_PTR(field) =20 -#define _WIN_DUMP_FIELD_SIZE(f) sizeof(h->f) +#define _WIN_DUMP_FIELD_SIZE(f) (x64 ? sizeof(h->x64.f) : sizeof(h->x32.f)) #define WIN_DUMP_FIELD_SIZE(field) _WIN_DUMP_FIELD_SIZE(field) =20 -#define WIN_DUMP_CTX_SIZE sizeof(WinContext64) +#define WIN_DUMP_CTX_SIZE (x64 ? sizeof(WinContext64) : sizeof(WinContext3= 2)) =20 static size_t write_run(uint64_t base_page, uint64_t page_count, int fd, Error **errp) @@ -71,7 +71,7 @@ static size_t write_run(uint64_t base_page, uint64_t page= _count, return total; } =20 -static void write_runs(DumpState *s, WinDumpHeader64 *h, Error **errp) +static void write_runs(DumpState *s, WinDumpHeader *h, bool x64, Error **e= rrp) { uint64_t BasePage, PageCount; Error *local_err =3D NULL; @@ -88,22 +88,24 @@ static void write_runs(DumpState *s, WinDumpHeader64 *h= , Error **errp) } } =20 -static int cpu_read_ptr(CPUState *cpu, uint64_t addr, uint64_t *ptr) +static int cpu_read_ptr(bool x64, CPUState *cpu, uint64_t addr, uint64_t *= ptr) { int ret; + uint32_t ptr32; uint64_t ptr64; =20 - ret =3D cpu_memory_rw_debug(cpu, addr, &ptr64, WIN_DUMP_PTR_SIZE, 0); + ret =3D cpu_memory_rw_debug(cpu, addr, x64 ? (void *)&ptr64 : (void *)= &ptr32, + WIN_DUMP_PTR_SIZE, 0); =20 - *ptr =3D ptr64; + *ptr =3D x64 ? ptr64 : ptr32; =20 return ret; } =20 -static void patch_mm_pfn_database(WinDumpHeader64 *h, Error **errp) +static void patch_mm_pfn_database(WinDumpHeader *h, bool x64, Error **errp) { if (cpu_memory_rw_debug(first_cpu, - WIN_DUMP_FIELD(KdDebuggerDataBlock) + KDBG_MM_PFN_DATABASE_OFF= SET64, + WIN_DUMP_FIELD(KdDebuggerDataBlock) + KDBG_MM_PFN_DATABASE_OFF= SET, WIN_DUMP_FIELD_PTR(PfnDatabase), WIN_DUMP_FIELD_SIZE(PfnDatabase), 0)) { error_setg(errp, "win-dump: failed to read MmPfnDatabase"); @@ -111,13 +113,12 @@ static void patch_mm_pfn_database(WinDumpHeader64 *h,= Error **errp) } } =20 -static void patch_bugcheck_data(WinDumpHeader64 *h, Error **errp) +static void patch_bugcheck_data(WinDumpHeader *h, bool x64, Error **errp) { uint64_t KiBugcheckData; =20 - if (cpu_read_ptr(first_cpu, - WIN_DUMP_FIELD(KdDebuggerDataBlock) + - KDBG_KI_BUGCHECK_DATA_OFFSET64, + if (cpu_read_ptr(x64, first_cpu, + WIN_DUMP_FIELD(KdDebuggerDataBlock) + KDBG_KI_BUGCHECK_DATA_OF= FSET, &KiBugcheckData)) { error_setg(errp, "win-dump: failed to read KiBugcheckData"); return; @@ -142,30 +143,34 @@ static void patch_bugcheck_data(WinDumpHeader64 *h, E= rror **errp) /* * This routine tries to correct mistakes in crashdump header. */ -static void patch_header(WinDumpHeader64 *h) +static void patch_header(WinDumpHeader *h, bool x64) { Error *local_err =3D NULL; =20 - h->RequiredDumpSpace =3D sizeof(WinDumpHeader64) + - (h->PhysicalMemoryBlock.NumberOfPages << TARGET_PAGE_BITS); - h->PhysicalMemoryBlock.unused =3D 0; - h->unused1 =3D 0; + if (x64) { + h->x64.RequiredDumpSpace =3D sizeof(WinDumpHeader64) + + (h->x64.PhysicalMemoryBlock.NumberOfPages << TARGET_PAGE_BITS); + h->x64.PhysicalMemoryBlock.unused =3D 0; + h->x64.unused1 =3D 0; + } else { + h->x32.RequiredDumpSpace =3D sizeof(WinDumpHeader32) + + (h->x32.PhysicalMemoryBlock.NumberOfPages << TARGET_PAGE_BITS); + } =20 - patch_mm_pfn_database(h, &local_err); + patch_mm_pfn_database(h, x64, &local_err); if (local_err) { warn_report_err(local_err); local_err =3D NULL; } - patch_bugcheck_data(h, &local_err); + patch_bugcheck_data(h, x64, &local_err); if (local_err) { warn_report_err(local_err); } } =20 -static void check_header(WinDumpHeader64 *h, Error **errp) +static void check_header(WinDumpHeader *h, bool *x64, Error **errp) { const char Signature[] =3D "PAGE"; - const char ValidDump[] =3D "DU64"; =20 if (memcmp(h->Signature, Signature, sizeof(h->Signature))) { error_setg(errp, "win-dump: invalid header, expected '%.4s'," @@ -173,14 +178,17 @@ static void check_header(WinDumpHeader64 *h, Error **= errp) return; } =20 - if (memcmp(h->ValidDump, ValidDump, sizeof(h->ValidDump))) { - error_setg(errp, "win-dump: invalid header, expected '%.4s'," - " got '%.4s'", ValidDump, h->ValidDump); - return; + if (!memcmp(h->ValidDump, "DUMP", sizeof(h->ValidDump))) { + *x64 =3D false; + } else if (!memcmp(h->ValidDump, "DU64", sizeof(h->ValidDump))) { + *x64 =3D true; + } else { + error_setg(errp, "win-dump: invalid header, expected 'DUMP' or 'DU= 64'," + " got '%.4s'", h->ValidDump); } } =20 -static void check_kdbg(WinDumpHeader64 *h, Error **errp) +static void check_kdbg(WinDumpHeader *h, bool x64, Error **errp) { const char OwnerTag[] =3D "KDBG"; char read_OwnerTag[4]; @@ -189,7 +197,7 @@ static void check_kdbg(WinDumpHeader64 *h, Error **errp) =20 try_again: if (cpu_memory_rw_debug(first_cpu, - KdDebuggerDataBlock + KDBG_OWNER_TAG_OFFSET64, + KdDebuggerDataBlock + KDBG_OWNER_TAG_OFFSET, (uint8_t *)&read_OwnerTag, sizeof(read_OwnerTag), 0)) { error_setg(errp, "win-dump: failed to read OwnerTag"); return; @@ -214,15 +222,19 @@ try_again: } } =20 - h->KdDebuggerDataBlock =3D KdDebuggerDataBlock; + if (x64) { + h->x64.KdDebuggerDataBlock =3D KdDebuggerDataBlock; + } else { + h->x32.KdDebuggerDataBlock =3D KdDebuggerDataBlock; + } } =20 struct saved_context { - WinContext64 ctx; + WinContext ctx; uint64_t addr; }; =20 -static void patch_and_save_context(WinDumpHeader64 *h, +static void patch_and_save_context(WinDumpHeader *h, bool x64, struct saved_context *saved_ctx, Error **errp) { @@ -232,15 +244,15 @@ static void patch_and_save_context(WinDumpHeader64 *h, CPUState *cpu; int i =3D 0; =20 - if (cpu_read_ptr(first_cpu, - KdDebuggerDataBlock + KDBG_KI_PROCESSOR_BLOCK_OFFSET64, + if (cpu_read_ptr(x64, first_cpu, + KdDebuggerDataBlock + KDBG_KI_PROCESSOR_BLOCK_OFFSET, &KiProcessorBlock)) { error_setg(errp, "win-dump: failed to read KiProcessorBlock"); return; } =20 if (cpu_memory_rw_debug(first_cpu, - KdDebuggerDataBlock + KDBG_OFFSET_PRCB_CONTEXT_OFFSET64, + KdDebuggerDataBlock + KDBG_OFFSET_PRCB_CONTEXT_OFFSET, (uint8_t *)&OffsetPrcbContext, sizeof(OffsetPrcbContext), 0)) { error_setg(errp, "win-dump: failed to read OffsetPrcbContext"); return; @@ -251,9 +263,9 @@ static void patch_and_save_context(WinDumpHeader64 *h, CPUX86State *env =3D &x86_cpu->env; uint64_t Prcb; uint64_t Context; - WinContext64 ctx; + WinContext ctx; =20 - if (cpu_read_ptr(first_cpu, + if (cpu_read_ptr(x64, first_cpu, KiProcessorBlock + i * WIN_DUMP_PTR_SIZE, &Prcb)) { error_setg(errp, "win-dump: failed to read" @@ -261,7 +273,7 @@ static void patch_and_save_context(WinDumpHeader64 *h, return; } =20 - if (cpu_read_ptr(first_cpu, + if (cpu_read_ptr(x64, first_cpu, Prcb + OffsetPrcbContext, &Context)) { error_setg(errp, "win-dump: failed to read" @@ -271,47 +283,79 @@ static void patch_and_save_context(WinDumpHeader64 *h, =20 saved_ctx[i].addr =3D Context; =20 - ctx =3D (WinContext64){ - .ContextFlags =3D WIN_CTX64_ALL, - .MxCsr =3D env->mxcsr, - - .SegEs =3D env->segs[0].selector, - .SegCs =3D env->segs[1].selector, - .SegSs =3D env->segs[2].selector, - .SegDs =3D env->segs[3].selector, - .SegFs =3D env->segs[4].selector, - .SegGs =3D env->segs[5].selector, - .EFlags =3D cpu_compute_eflags(env), - - .Dr0 =3D env->dr[0], - .Dr1 =3D env->dr[1], - .Dr2 =3D env->dr[2], - .Dr3 =3D env->dr[3], - .Dr6 =3D env->dr[6], - .Dr7 =3D env->dr[7], - - .Rax =3D env->regs[R_EAX], - .Rbx =3D env->regs[R_EBX], - .Rcx =3D env->regs[R_ECX], - .Rdx =3D env->regs[R_EDX], - .Rsp =3D env->regs[R_ESP], - .Rbp =3D env->regs[R_EBP], - .Rsi =3D env->regs[R_ESI], - .Rdi =3D env->regs[R_EDI], - .R8 =3D env->regs[8], - .R9 =3D env->regs[9], - .R10 =3D env->regs[10], - .R11 =3D env->regs[11], - .R12 =3D env->regs[12], - .R13 =3D env->regs[13], - .R14 =3D env->regs[14], - .R15 =3D env->regs[15], - - .Rip =3D env->eip, - .FltSave =3D { + if (x64) { + ctx.x64 =3D (WinContext64){ + .ContextFlags =3D WIN_CTX64_ALL, .MxCsr =3D env->mxcsr, - }, - }; + + .SegEs =3D env->segs[0].selector, + .SegCs =3D env->segs[1].selector, + .SegSs =3D env->segs[2].selector, + .SegDs =3D env->segs[3].selector, + .SegFs =3D env->segs[4].selector, + .SegGs =3D env->segs[5].selector, + .EFlags =3D cpu_compute_eflags(env), + + .Dr0 =3D env->dr[0], + .Dr1 =3D env->dr[1], + .Dr2 =3D env->dr[2], + .Dr3 =3D env->dr[3], + .Dr6 =3D env->dr[6], + .Dr7 =3D env->dr[7], + + .Rax =3D env->regs[R_EAX], + .Rbx =3D env->regs[R_EBX], + .Rcx =3D env->regs[R_ECX], + .Rdx =3D env->regs[R_EDX], + .Rsp =3D env->regs[R_ESP], + .Rbp =3D env->regs[R_EBP], + .Rsi =3D env->regs[R_ESI], + .Rdi =3D env->regs[R_EDI], + .R8 =3D env->regs[8], + .R9 =3D env->regs[9], + .R10 =3D env->regs[10], + .R11 =3D env->regs[11], + .R12 =3D env->regs[12], + .R13 =3D env->regs[13], + .R14 =3D env->regs[14], + .R15 =3D env->regs[15], + + .Rip =3D env->eip, + .FltSave =3D { + .MxCsr =3D env->mxcsr, + }, + }; + } else { + ctx.x32 =3D (WinContext32){ + .ContextFlags =3D WIN_CTX32_FULL | WIN_CTX_DBG, + + .SegEs =3D env->segs[0].selector, + .SegCs =3D env->segs[1].selector, + .SegSs =3D env->segs[2].selector, + .SegDs =3D env->segs[3].selector, + .SegFs =3D env->segs[4].selector, + .SegGs =3D env->segs[5].selector, + .EFlags =3D cpu_compute_eflags(env), + + .Dr0 =3D env->dr[0], + .Dr1 =3D env->dr[1], + .Dr2 =3D env->dr[2], + .Dr3 =3D env->dr[3], + .Dr6 =3D env->dr[6], + .Dr7 =3D env->dr[7], + + .Eax =3D env->regs[R_EAX], + .Ebx =3D env->regs[R_EBX], + .Ecx =3D env->regs[R_ECX], + .Edx =3D env->regs[R_EDX], + .Esp =3D env->regs[R_ESP], + .Ebp =3D env->regs[R_EBP], + .Esi =3D env->regs[R_ESI], + .Edi =3D env->regs[R_EDI], + + .Eip =3D env->eip, + }; + } =20 if (cpu_memory_rw_debug(first_cpu, Context, &saved_ctx[i].ctx, WIN_DUMP_CTX_SIZE, 0)) { @@ -329,7 +373,7 @@ static void patch_and_save_context(WinDumpHeader64 *h, } } =20 -static void restore_context(WinDumpHeader64 *h, +static void restore_context(WinDumpHeader *h, bool x64, struct saved_context *saved_ctx) { int i; @@ -344,25 +388,28 @@ static void restore_context(WinDumpHeader64 *h, =20 void create_win_dump(DumpState *s, Error **errp) { - WinDumpHeader64 *h =3D (WinDumpHeader64 *)(s->guest_note + - VMCOREINFO_ELF_NOTE_HDR_SIZE); + WinDumpHeader *h =3D (void *)(s->guest_note + VMCOREINFO_ELF_NOTE_HDR_= SIZE); X86CPU *first_x86_cpu =3D X86_CPU(first_cpu); uint64_t saved_cr3 =3D first_x86_cpu->env.cr[3]; struct saved_context *saved_ctx =3D NULL; Error *local_err =3D NULL; + bool x64; + size_t hdr_size; =20 - if (s->guest_note_size !=3D sizeof(WinDumpHeader64) + - VMCOREINFO_ELF_NOTE_HDR_SIZE) { + if (s->guest_note_size !=3D VMCOREINFO_WIN_DUMP_NOTE_SIZE32 && + s->guest_note_size !=3D VMCOREINFO_WIN_DUMP_NOTE_SIZE64) { error_setg(errp, "win-dump: invalid vmcoreinfo note size"); return; } =20 - check_header(h, &local_err); + check_header(h, &x64, &local_err); if (local_err) { error_propagate(errp, local_err); return; } =20 + hdr_size =3D x64 ? sizeof(WinDumpHeader64) : sizeof(WinDumpHeader32); + /* * Further access to kernel structures by virtual addresses * should be made from system context. @@ -370,13 +417,13 @@ void create_win_dump(DumpState *s, Error **errp) =20 first_x86_cpu->env.cr[3] =3D WIN_DUMP_FIELD(DirectoryTableBase); =20 - check_kdbg(h, &local_err); + check_kdbg(h, x64, &local_err); if (local_err) { error_propagate(errp, local_err); goto out_cr3; } =20 - patch_header(h); + patch_header(h, x64); =20 saved_ctx =3D g_new(struct saved_context, WIN_DUMP_FIELD(NumberProcess= ors)); =20 @@ -385,7 +432,7 @@ void create_win_dump(DumpState *s, Error **errp) * to determine if the system-saved context is valid */ =20 - patch_and_save_context(h, saved_ctx, &local_err); + patch_and_save_context(h, x64, saved_ctx, &local_err); if (local_err) { error_propagate(errp, local_err); goto out_free; @@ -393,20 +440,20 @@ void create_win_dump(DumpState *s, Error **errp) =20 s->total_size =3D WIN_DUMP_FIELD(RequiredDumpSpace); =20 - s->written_size =3D qemu_write_full(s->fd, h, sizeof(*h)); - if (s->written_size !=3D sizeof(*h)) { + s->written_size =3D qemu_write_full(s->fd, h, hdr_size); + if (s->written_size !=3D hdr_size) { error_setg(errp, QERR_IO_ERROR); goto out_restore; } =20 - write_runs(s, h, &local_err); + write_runs(s, h, x64, &local_err); if (local_err) { error_propagate(errp, local_err); goto out_restore; } =20 out_restore: - restore_context(h, saved_ctx); + restore_context(h, x64, saved_ctx); out_free: g_free(saved_ctx); out_cr3: --=20 2.31.1