|
|
62547e |
From 255722667a4fa4d522bb0b7e0825cbbe635abb8d Mon Sep 17 00:00:00 2001
|
|
|
62547e |
From: Janosch Frank <frankja@linux.ibm.com>
|
|
|
62547e |
Date: Wed, 30 Mar 2022 12:35:57 +0000
|
|
|
62547e |
Subject: [PATCH 15/42] dump: Introduce shdr_num to decrease complexity
|
|
|
62547e |
MIME-Version: 1.0
|
|
|
62547e |
Content-Type: text/plain; charset=UTF-8
|
|
|
62547e |
Content-Transfer-Encoding: 8bit
|
|
|
62547e |
|
|
|
62547e |
RH-Author: Cédric Le Goater <clg@redhat.com>
|
|
|
62547e |
RH-MergeRequest: 226: s390: Enhanced Interpretation for PCI Functions and Secure Execution guest dump
|
|
|
62547e |
RH-Bugzilla: 1664378 2043909
|
|
|
62547e |
RH-Acked-by: Thomas Huth <thuth@redhat.com>
|
|
|
62547e |
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
|
|
|
62547e |
RH-Acked-by: Jon Maloy <jmaloy@redhat.com>
|
|
|
62547e |
RH-Commit: [15/41] b0215ea5d381ef7f6abfe3f3bafea51ce933da56
|
|
|
62547e |
|
|
|
62547e |
Let's move from a boolean to a int variable which will later enable us
|
|
|
62547e |
to store the number of sections that are in the dump file.
|
|
|
62547e |
|
|
|
62547e |
Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
|
|
|
62547e |
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
|
|
|
62547e |
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
|
|
|
62547e |
Message-Id: <20220330123603.107120-4-frankja@linux.ibm.com>
|
|
|
62547e |
(cherry picked from commit 862a395858e5a302ed5921487777acdc95a3a31b)
|
|
|
62547e |
Signed-off-by: Cédric Le Goater <clg@redhat.com>
|
|
|
62547e |
---
|
|
|
62547e |
dump/dump.c | 24 ++++++++++++------------
|
|
|
62547e |
include/sysemu/dump.h | 2 +-
|
|
|
62547e |
2 files changed, 13 insertions(+), 13 deletions(-)
|
|
|
62547e |
|
|
|
62547e |
diff --git a/dump/dump.c b/dump/dump.c
|
|
|
62547e |
index 7236b167cc..972e28b089 100644
|
|
|
62547e |
--- a/dump/dump.c
|
|
|
62547e |
+++ b/dump/dump.c
|
|
|
62547e |
@@ -145,12 +145,12 @@ static void write_elf64_header(DumpState *s, Error **errp)
|
|
|
62547e |
elf_header.e_phoff = cpu_to_dump64(s, sizeof(Elf64_Ehdr));
|
|
|
62547e |
elf_header.e_phentsize = cpu_to_dump16(s, sizeof(Elf64_Phdr));
|
|
|
62547e |
elf_header.e_phnum = cpu_to_dump16(s, phnum);
|
|
|
62547e |
- if (s->have_section) {
|
|
|
62547e |
+ if (s->shdr_num) {
|
|
|
62547e |
uint64_t shoff = sizeof(Elf64_Ehdr) + sizeof(Elf64_Phdr) * s->phdr_num;
|
|
|
62547e |
|
|
|
62547e |
elf_header.e_shoff = cpu_to_dump64(s, shoff);
|
|
|
62547e |
elf_header.e_shentsize = cpu_to_dump16(s, sizeof(Elf64_Shdr));
|
|
|
62547e |
- elf_header.e_shnum = cpu_to_dump16(s, 1);
|
|
|
62547e |
+ elf_header.e_shnum = cpu_to_dump16(s, s->shdr_num);
|
|
|
62547e |
}
|
|
|
62547e |
|
|
|
62547e |
ret = fd_write_vmcore(&elf_header, sizeof(elf_header), s);
|
|
|
62547e |
@@ -182,12 +182,12 @@ static void write_elf32_header(DumpState *s, Error **errp)
|
|
|
62547e |
elf_header.e_phoff = cpu_to_dump32(s, sizeof(Elf32_Ehdr));
|
|
|
62547e |
elf_header.e_phentsize = cpu_to_dump16(s, sizeof(Elf32_Phdr));
|
|
|
62547e |
elf_header.e_phnum = cpu_to_dump16(s, phnum);
|
|
|
62547e |
- if (s->have_section) {
|
|
|
62547e |
+ if (s->shdr_num) {
|
|
|
62547e |
uint32_t shoff = sizeof(Elf32_Ehdr) + sizeof(Elf32_Phdr) * s->phdr_num;
|
|
|
62547e |
|
|
|
62547e |
elf_header.e_shoff = cpu_to_dump32(s, shoff);
|
|
|
62547e |
elf_header.e_shentsize = cpu_to_dump16(s, sizeof(Elf32_Shdr));
|
|
|
62547e |
- elf_header.e_shnum = cpu_to_dump16(s, 1);
|
|
|
62547e |
+ elf_header.e_shnum = cpu_to_dump16(s, s->shdr_num);
|
|
|
62547e |
}
|
|
|
62547e |
|
|
|
62547e |
ret = fd_write_vmcore(&elf_header, sizeof(elf_header), s);
|
|
|
62547e |
@@ -566,7 +566,7 @@ static void dump_begin(DumpState *s, Error **errp)
|
|
|
62547e |
}
|
|
|
62547e |
|
|
|
62547e |
/* write section to vmcore */
|
|
|
62547e |
- if (s->have_section) {
|
|
|
62547e |
+ if (s->shdr_num) {
|
|
|
62547e |
write_elf_section(s, 1, errp);
|
|
|
62547e |
if (*errp) {
|
|
|
62547e |
return;
|
|
|
62547e |
@@ -592,7 +592,7 @@ static void dump_begin(DumpState *s, Error **errp)
|
|
|
62547e |
}
|
|
|
62547e |
|
|
|
62547e |
/* write section to vmcore */
|
|
|
62547e |
- if (s->have_section) {
|
|
|
62547e |
+ if (s->shdr_num) {
|
|
|
62547e |
write_elf_section(s, 0, errp);
|
|
|
62547e |
if (*errp) {
|
|
|
62547e |
return;
|
|
|
62547e |
@@ -1811,11 +1811,11 @@ static void dump_init(DumpState *s, int fd, bool has_format,
|
|
|
62547e |
*/
|
|
|
62547e |
s->phdr_num = 1; /* PT_NOTE */
|
|
|
62547e |
if (s->list.num < UINT16_MAX - 2) {
|
|
|
62547e |
+ s->shdr_num = 0;
|
|
|
62547e |
s->phdr_num += s->list.num;
|
|
|
62547e |
- s->have_section = false;
|
|
|
62547e |
} else {
|
|
|
62547e |
/* sh_info of section 0 holds the real number of phdrs */
|
|
|
62547e |
- s->have_section = true;
|
|
|
62547e |
+ s->shdr_num = 1;
|
|
|
62547e |
|
|
|
62547e |
/* the type of shdr->sh_info is uint32_t, so we should avoid overflow */
|
|
|
62547e |
if (s->list.num <= UINT32_MAX - 1) {
|
|
|
62547e |
@@ -1826,19 +1826,19 @@ static void dump_init(DumpState *s, int fd, bool has_format,
|
|
|
62547e |
}
|
|
|
62547e |
|
|
|
62547e |
if (s->dump_info.d_class == ELFCLASS64) {
|
|
|
62547e |
- if (s->have_section) {
|
|
|
62547e |
+ if (s->shdr_num) {
|
|
|
62547e |
s->memory_offset = sizeof(Elf64_Ehdr) +
|
|
|
62547e |
sizeof(Elf64_Phdr) * s->phdr_num +
|
|
|
62547e |
- sizeof(Elf64_Shdr) + s->note_size;
|
|
|
62547e |
+ sizeof(Elf64_Shdr) * s->shdr_num + s->note_size;
|
|
|
62547e |
} else {
|
|
|
62547e |
s->memory_offset = sizeof(Elf64_Ehdr) +
|
|
|
62547e |
sizeof(Elf64_Phdr) * s->phdr_num + s->note_size;
|
|
|
62547e |
}
|
|
|
62547e |
} else {
|
|
|
62547e |
- if (s->have_section) {
|
|
|
62547e |
+ if (s->shdr_num) {
|
|
|
62547e |
s->memory_offset = sizeof(Elf32_Ehdr) +
|
|
|
62547e |
sizeof(Elf32_Phdr) * s->phdr_num +
|
|
|
62547e |
- sizeof(Elf32_Shdr) + s->note_size;
|
|
|
62547e |
+ sizeof(Elf32_Shdr) * s->shdr_num + s->note_size;
|
|
|
62547e |
} else {
|
|
|
62547e |
s->memory_offset = sizeof(Elf32_Ehdr) +
|
|
|
62547e |
sizeof(Elf32_Phdr) * s->phdr_num + s->note_size;
|
|
|
62547e |
diff --git a/include/sysemu/dump.h b/include/sysemu/dump.h
|
|
|
62547e |
index b463fc9c02..19458bffbd 100644
|
|
|
62547e |
--- a/include/sysemu/dump.h
|
|
|
62547e |
+++ b/include/sysemu/dump.h
|
|
|
62547e |
@@ -155,7 +155,7 @@ typedef struct DumpState {
|
|
|
62547e |
ArchDumpInfo dump_info;
|
|
|
62547e |
MemoryMappingList list;
|
|
|
62547e |
uint32_t phdr_num;
|
|
|
62547e |
- bool have_section;
|
|
|
62547e |
+ uint32_t shdr_num;
|
|
|
62547e |
bool resume;
|
|
|
62547e |
bool detached;
|
|
|
62547e |
ssize_t note_size;
|
|
|
62547e |
--
|
|
|
62547e |
2.37.3
|
|
|
62547e |
|