From nobody Sat Jul 12 05:45:24 2025 Delivered-To: importer2@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer2=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1650628642227970.2612364523567; Fri, 22 Apr 2022 04:57:22 -0700 (PDT) Received: from localhost ([::1]:60724 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nhrub-0007Z3-0m for importer2@patchew.org; Fri, 22 Apr 2022 07:57:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:32904) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nhqKK-0000Bf-7b for qemu-devel@nongnu.org; Fri, 22 Apr 2022 06:15:48 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:32319) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nhqKI-0004my-FU for qemu-devel@nongnu.org; Fri, 22 Apr 2022 06:15:47 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-154-ZHoZj5BnPYauWlXy4x3_Sg-1; Fri, 22 Apr 2022 06:15:43 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3878738149B1; Fri, 22 Apr 2022 10:15:43 +0000 (UTC) Received: from localhost (unknown [10.39.208.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id D7C3A40E80F5; Fri, 22 Apr 2022 10:15:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650622544; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2UUAiq0z2rzGHnE26rtABqpfZSZSn8iucEsR8c2fwcE=; b=DwDcYppH9rt/BsVMuTaFOiYPBogUuQQgp7tCioOLOL8kdhSoMjKtJ/IAaFdY7+zIbdxKfj +spmBf9jImhe1c1ApSQLsG4I+Wla9sur1QDlErHHNRG9gIwyiRUJS7rSxlNdaKVRbUNaVF kVMJKoD7duQTcqasDFGnhk1l84nfKfc= X-MC-Unique: ZHoZj5BnPYauWlXy4x3_Sg-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Subject: [PULL v2 03/13] dump: Introduce shdr_num to decrease complexity Date: Fri, 22 Apr 2022 14:15:15 +0400 Message-Id: <20220422101525.3260741-4-marcandre.lureau@redhat.com> In-Reply-To: <20220422101525.3260741-1-marcandre.lureau@redhat.com> References: <20220422101525.3260741-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , viktor.prutyanov@redhat.com, richard.henderson@linaro.org, frankja@linux.ibm.com Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1650628643620100001 From: Janosch Frank Let's move from a boolean to a int variable which will later enable us to store the number of sections that are in the dump file. Signed-off-by: Janosch Frank Reviewed-by: Richard Henderson Reviewed-by: Marc-Andr=C3=A9 Lureau Message-Id: <20220330123603.107120-4-frankja@linux.ibm.com> --- include/sysemu/dump.h | 2 +- dump/dump.c | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/include/sysemu/dump.h b/include/sysemu/dump.h index b463fc9c0226..19458bffbd1d 100644 --- a/include/sysemu/dump.h +++ b/include/sysemu/dump.h @@ -155,7 +155,7 @@ typedef struct DumpState { ArchDumpInfo dump_info; MemoryMappingList list; uint32_t phdr_num; - bool have_section; + uint32_t shdr_num; bool resume; bool detached; ssize_t note_size; diff --git a/dump/dump.c b/dump/dump.c index 010b272da038..285ed4475b0d 100644 --- a/dump/dump.c +++ b/dump/dump.c @@ -144,12 +144,12 @@ static void write_elf64_header(DumpState *s, Error **= errp) elf_header.e_phoff =3D cpu_to_dump64(s, sizeof(Elf64_Ehdr)); elf_header.e_phentsize =3D cpu_to_dump16(s, sizeof(Elf64_Phdr)); elf_header.e_phnum =3D cpu_to_dump16(s, phnum); - if (s->have_section) { + if (s->shdr_num) { uint64_t shoff =3D sizeof(Elf64_Ehdr) + sizeof(Elf64_Phdr) * s->ph= dr_num; =20 elf_header.e_shoff =3D cpu_to_dump64(s, shoff); elf_header.e_shentsize =3D cpu_to_dump16(s, sizeof(Elf64_Shdr)); - elf_header.e_shnum =3D cpu_to_dump16(s, 1); + elf_header.e_shnum =3D cpu_to_dump16(s, s->shdr_num); } =20 ret =3D fd_write_vmcore(&elf_header, sizeof(elf_header), s); @@ -181,12 +181,12 @@ static void write_elf32_header(DumpState *s, Error **= errp) elf_header.e_phoff =3D cpu_to_dump32(s, sizeof(Elf32_Ehdr)); elf_header.e_phentsize =3D cpu_to_dump16(s, sizeof(Elf32_Phdr)); elf_header.e_phnum =3D cpu_to_dump16(s, phnum); - if (s->have_section) { + if (s->shdr_num) { uint32_t shoff =3D sizeof(Elf32_Ehdr) + sizeof(Elf32_Phdr) * s->ph= dr_num; =20 elf_header.e_shoff =3D cpu_to_dump32(s, shoff); elf_header.e_shentsize =3D cpu_to_dump16(s, sizeof(Elf32_Shdr)); - elf_header.e_shnum =3D cpu_to_dump16(s, 1); + elf_header.e_shnum =3D cpu_to_dump16(s, s->shdr_num); } =20 ret =3D fd_write_vmcore(&elf_header, sizeof(elf_header), s); @@ -565,7 +565,7 @@ static void dump_begin(DumpState *s, Error **errp) } =20 /* write section to vmcore */ - if (s->have_section) { + if (s->shdr_num) { write_elf_section(s, 1, errp); if (*errp) { return; @@ -591,7 +591,7 @@ static void dump_begin(DumpState *s, Error **errp) } =20 /* write section to vmcore */ - if (s->have_section) { + if (s->shdr_num) { write_elf_section(s, 0, errp); if (*errp) { return; @@ -1802,11 +1802,11 @@ static void dump_init(DumpState *s, int fd, bool ha= s_format, */ s->phdr_num =3D 1; /* PT_NOTE */ if (s->list.num < UINT16_MAX - 2) { + s->shdr_num =3D 0; s->phdr_num +=3D s->list.num; - s->have_section =3D false; } else { /* sh_info of section 0 holds the real number of phdrs */ - s->have_section =3D true; + s->shdr_num =3D 1; =20 /* the type of shdr->sh_info is uint32_t, so we should avoid overf= low */ if (s->list.num <=3D UINT32_MAX - 1) { @@ -1817,19 +1817,19 @@ static void dump_init(DumpState *s, int fd, bool ha= s_format, } =20 if (s->dump_info.d_class =3D=3D ELFCLASS64) { - if (s->have_section) { + if (s->shdr_num) { s->memory_offset =3D sizeof(Elf64_Ehdr) + sizeof(Elf64_Phdr) * s->phdr_num + - sizeof(Elf64_Shdr) + s->note_size; + sizeof(Elf64_Shdr) * s->shdr_num + s->note_= size; } else { s->memory_offset =3D sizeof(Elf64_Ehdr) + sizeof(Elf64_Phdr) * s->phdr_num + s->note_= size; } } else { - if (s->have_section) { + if (s->shdr_num) { s->memory_offset =3D sizeof(Elf32_Ehdr) + sizeof(Elf32_Phdr) * s->phdr_num + - sizeof(Elf32_Shdr) + s->note_size; + sizeof(Elf32_Shdr) * s->shdr_num + s->note_= size; } else { s->memory_offset =3D sizeof(Elf32_Ehdr) + sizeof(Elf32_Phdr) * s->phdr_num + s->note_= size; --=20 2.36.0