From nobody Sun Nov 24 18:37:25 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=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1720445062; cv=none; d=zohomail.com; s=zohoarc; b=AwgQQ8oOUge6d1g8iR2MA/n8AwJsdYJDBErwTcuKciN0wMBWVBerDPVlUWBYAIRKj6tzf/JhKdmz2jJCyQPP60DCpUD5bw5p0cBEJgk2AdvgR8JxODOUjoZPAYPauYSmpkDAE4y0xvcOFChMTf3TvucTpO0Qp0JRjhdxnWdwSCs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720445062; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=nCGoD0xBJw98jcj6O8YNShoey7vZZpF+2IbEsXyWDKk=; b=XC8so4ra3pn3d277zApahxXv5SW2OiXqR8+c1zCBzKi4C76b0RaMd4Uc7h7I+U7OAqd1JWPgAlRFOqDPsFNIqjn5dXIFOe3N/OBGxBEs64ojSaZ0hWJlK8jsw8VN5uotBh0Fy0+Y9ytudPed+gtxmZlfs/34D4bSNUksDQhu/JA= 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=pass 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 17204450628781021.0925825670937; Mon, 8 Jul 2024 06:24:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sQoLl-00024E-TW; Mon, 08 Jul 2024 09:24:13 -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 1sQmUq-0000ZJ-NP for qemu-devel@nongnu.org; Mon, 08 Jul 2024 07:25:28 -0400 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sQmUp-0005R5-3W for qemu-devel@nongnu.org; Mon, 08 Jul 2024 07:25:28 -0400 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-70b0bc1ef81so1617147b3a.1 for ; Mon, 08 Jul 2024 04:25:26 -0700 (PDT) Received: from VM-0-25-fedora.. ([119.28.53.59]) by smtp.googlemail.com with ESMTPSA id d9443c01a7336-1fb1a075616sm94462495ad.15.2024.07.08.04.25.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jul 2024 04:25:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720437924; x=1721042724; darn=nongnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=nCGoD0xBJw98jcj6O8YNShoey7vZZpF+2IbEsXyWDKk=; b=U7Rmt7UTub6b1WtUyIW3NIbv7rXYkz0t9+IbeKVJAJMB2ZMx+cRF7BANEuQPmylfmh vu7s+0k/RwpmgI37vi/MoqslGzC3iypcXYFqUUMwWIDDt2yhHwd8znFwT/pKppqjw/Xw ESbtDsaFzphsPHwzN20xkIuEdxeI8LTdypbMsdiXK5QYiN1k2fuq0rAcDETI3R+k0g4E JixYZOa3g5Nh6V8lU3mEVndL73e7kbF2XLJkzowa5U/Qqth5QbTALglRlVk1vjSXFDhu fhJ3pGhmInICelqG+d4dPuw6my+AvvsmueUhU/jaIJVQHmoEZCah+gbQuaeBaeIxVDu6 Cupw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720437924; x=1721042724; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=nCGoD0xBJw98jcj6O8YNShoey7vZZpF+2IbEsXyWDKk=; b=gLfLYcd2v3xuQIur0IRLs3z4/TIEnMdPFR3o0kP5XRrIvLNfxlbZhQt+gmrZMGzwdx yHRkrMF6baORXvFRqmuptovRc+rcvHX6y5TKoBJTSG6I5OW42mzD7kHVRre1N73ZJbCk 55fjrxzK9CLitltKLM2iIxMMjx7SsiZmLW5vcgcLOQkV17NQWfsLsCCyEMPPgQ4bHwr0 eS1S747UG8YMak8nV8fMth7sNwtcu4C8xv9hCARnOHtmJUUM3Kfp617DKx29RM0+g1cN dg8y39sJUhk7fr6L05R5NDg4+dbzRXzxarLDH6szUmZjOXTP0DlZwzv5KCnTLz4LATcv 8cvg== X-Gm-Message-State: AOJu0YytVc2HysZNOZ6TRW8NommTWX0vEKRoVPm59aM7bo2DBRdmQigk 8qn6oTFXVAm21PWcH6zbkJ62DzGujZDuF34XAxfOUEwlsWX+wQfPlr5H1/lSBVc= X-Google-Smtp-Source: AGHT+IGnF+17yFBxgPVis7cdLBwxrh20nJu5+QF2M3YIJ2qzfwAMcnw55tgQhrq9+VvYjJkpK8zlxw== X-Received: by 2002:a05:6a20:2586:b0:1c0:f23b:cad3 with SMTP id adf61e73a8af0-1c0f23bcbd2mr2265437637.22.1720437923574; Mon, 08 Jul 2024 04:25:23 -0700 (PDT) From: junjiehua X-Google-Original-From: junjiehua To: qemu-devel@nongnu.org Cc: Akihiko Odaki , Viktor Prutyanov , junjiehua Subject: [PATCH] contrib/elf2dmp: a workaround for the buggy msvcrt.dll!fwrite Date: Mon, 8 Jul 2024 19:25:20 +0800 Message-ID: <20240708112520.106127-1-junjiehua@tencent.com> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2607:f8b0:4864:20::42a; envelope-from=halouworls@gmail.com; helo=mail-pf1-x42a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Mon, 08 Jul 2024 09:24:12 -0400 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1720445064717100003 Content-Type: text/plain; charset="utf-8" when building elf2dump with x86_64-w64-mingw32-gcc, fwrite is imported from msvcrt.dll. However, the implementation of msvcrt.dll!fwrite is buggy: it enters an infinite loop when the size of a single write exceeds 4GB. This patch addresses the issue by splitting large physical memory blocks into smaller chunks. Signed-off-by: junjiehua --- contrib/elf2dmp/main.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/contrib/elf2dmp/main.c b/contrib/elf2dmp/main.c index d046a72ae6..1994553d95 100644 --- a/contrib/elf2dmp/main.c +++ b/contrib/elf2dmp/main.c @@ -23,6 +23,8 @@ #define INITIAL_MXCSR 0x1f80 #define MAX_NUMBER_OF_RUNS 42 =20 +#define MAX_CHUNK_SIZE (128 * 1024 * 1024) + typedef struct idt_desc { uint16_t offset1; /* offset bits 0..15 */ uint16_t selector; @@ -434,13 +436,22 @@ static bool write_dump(struct pa_space *ps, =20 for (i =3D 0; i < ps->block_nr; i++) { struct pa_block *b =3D &ps->block[i]; + size_t offset =3D 0; + size_t chunk_size; =20 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) !=3D 1) { - eprintf("Failed to write block\n"); - fclose(dmp_file); - return false; + + while (offset < b->size) { + chunk_size =3D (b->size - offset > MAX_CHUNK_SIZE) + ? MAX_CHUNK_SIZE + : (b->size - offset); + if (fwrite(b->addr + offset, chunk_size, 1, dmp_file) !=3D 1) { + eprintf("Failed to write block\n"); + fclose(dmp_file); + return false; + } + offset +=3D chunk_size; } } =20 --=20 2.45.2