|
|
bf143f |
From f87abe1ef14e80731249ebe9fe1bea569a68e9b4 Mon Sep 17 00:00:00 2001
|
|
|
bf143f |
From: Janosch Frank <frankja@linux.ibm.com>
|
|
|
bf143f |
Date: Wed, 30 Mar 2022 12:36:01 +0000
|
|
|
bf143f |
Subject: [PATCH 19/42] dump: Consolidate phdr note writes
|
|
|
bf143f |
MIME-Version: 1.0
|
|
|
bf143f |
Content-Type: text/plain; charset=UTF-8
|
|
|
bf143f |
Content-Transfer-Encoding: 8bit
|
|
|
bf143f |
|
|
|
bf143f |
RH-Author: Cédric Le Goater <clg@redhat.com>
|
|
|
bf143f |
RH-MergeRequest: 226: s390: Enhanced Interpretation for PCI Functions and Secure Execution guest dump
|
|
|
bf143f |
RH-Bugzilla: 1664378 2043909
|
|
|
bf143f |
RH-Acked-by: Thomas Huth <thuth@redhat.com>
|
|
|
bf143f |
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
|
|
|
bf143f |
RH-Acked-by: Jon Maloy <jmaloy@redhat.com>
|
|
|
bf143f |
RH-Commit: [19/41] 180c4c0ab4941a0bf366dc7f32ee035e03daa6c0
|
|
|
bf143f |
|
|
|
bf143f |
There's no need to have two write functions. Let's rather have two
|
|
|
bf143f |
functions that set the data for elf 32/64 and then write it in a
|
|
|
bf143f |
common function.
|
|
|
bf143f |
|
|
|
bf143f |
Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
|
|
|
bf143f |
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
|
|
|
bf143f |
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
|
|
|
bf143f |
Message-Id: <20220330123603.107120-8-frankja@linux.ibm.com>
|
|
|
bf143f |
(cherry picked from commit bc7d558017e6700f9a05c61b0b638a8994945f0d)
|
|
|
bf143f |
Signed-off-by: Cédric Le Goater <clg@redhat.com>
|
|
|
bf143f |
---
|
|
|
bf143f |
dump/dump.c | 94 +++++++++++++++++++++++++++--------------------------
|
|
|
bf143f |
1 file changed, 48 insertions(+), 46 deletions(-)
|
|
|
bf143f |
|
|
|
bf143f |
diff --git a/dump/dump.c b/dump/dump.c
|
|
|
bf143f |
index 6394e94023..823ca32883 100644
|
|
|
bf143f |
--- a/dump/dump.c
|
|
|
bf143f |
+++ b/dump/dump.c
|
|
|
bf143f |
@@ -246,24 +246,15 @@ static void write_elf32_load(DumpState *s, MemoryMapping *memory_mapping,
|
|
|
bf143f |
}
|
|
|
bf143f |
}
|
|
|
bf143f |
|
|
|
bf143f |
-static void write_elf64_note(DumpState *s, Error **errp)
|
|
|
bf143f |
+static void write_elf64_phdr_note(DumpState *s, Elf64_Phdr *phdr)
|
|
|
bf143f |
{
|
|
|
bf143f |
- Elf64_Phdr phdr;
|
|
|
bf143f |
- int ret;
|
|
|
bf143f |
-
|
|
|
bf143f |
- memset(&phdr, 0, sizeof(Elf64_Phdr));
|
|
|
bf143f |
- phdr.p_type = cpu_to_dump32(s, PT_NOTE);
|
|
|
bf143f |
- phdr.p_offset = cpu_to_dump64(s, s->note_offset);
|
|
|
bf143f |
- phdr.p_paddr = 0;
|
|
|
bf143f |
- phdr.p_filesz = cpu_to_dump64(s, s->note_size);
|
|
|
bf143f |
- phdr.p_memsz = cpu_to_dump64(s, s->note_size);
|
|
|
bf143f |
- phdr.p_vaddr = 0;
|
|
|
bf143f |
-
|
|
|
bf143f |
- ret = fd_write_vmcore(&phdr, sizeof(Elf64_Phdr), s);
|
|
|
bf143f |
- if (ret < 0) {
|
|
|
bf143f |
- error_setg_errno(errp, -ret,
|
|
|
bf143f |
- "dump: failed to write program header table");
|
|
|
bf143f |
- }
|
|
|
bf143f |
+ memset(phdr, 0, sizeof(*phdr));
|
|
|
bf143f |
+ phdr->p_type = cpu_to_dump32(s, PT_NOTE);
|
|
|
bf143f |
+ phdr->p_offset = cpu_to_dump64(s, s->note_offset);
|
|
|
bf143f |
+ phdr->p_paddr = 0;
|
|
|
bf143f |
+ phdr->p_filesz = cpu_to_dump64(s, s->note_size);
|
|
|
bf143f |
+ phdr->p_memsz = cpu_to_dump64(s, s->note_size);
|
|
|
bf143f |
+ phdr->p_vaddr = 0;
|
|
|
bf143f |
}
|
|
|
bf143f |
|
|
|
bf143f |
static inline int cpu_index(CPUState *cpu)
|
|
|
bf143f |
@@ -311,24 +302,15 @@ static void write_elf64_notes(WriteCoreDumpFunction f, DumpState *s,
|
|
|
bf143f |
write_guest_note(f, s, errp);
|
|
|
bf143f |
}
|
|
|
bf143f |
|
|
|
bf143f |
-static void write_elf32_note(DumpState *s, Error **errp)
|
|
|
bf143f |
+static void write_elf32_phdr_note(DumpState *s, Elf32_Phdr *phdr)
|
|
|
bf143f |
{
|
|
|
bf143f |
- Elf32_Phdr phdr;
|
|
|
bf143f |
- int ret;
|
|
|
bf143f |
-
|
|
|
bf143f |
- memset(&phdr, 0, sizeof(Elf32_Phdr));
|
|
|
bf143f |
- phdr.p_type = cpu_to_dump32(s, PT_NOTE);
|
|
|
bf143f |
- phdr.p_offset = cpu_to_dump32(s, s->note_offset);
|
|
|
bf143f |
- phdr.p_paddr = 0;
|
|
|
bf143f |
- phdr.p_filesz = cpu_to_dump32(s, s->note_size);
|
|
|
bf143f |
- phdr.p_memsz = cpu_to_dump32(s, s->note_size);
|
|
|
bf143f |
- phdr.p_vaddr = 0;
|
|
|
bf143f |
-
|
|
|
bf143f |
- ret = fd_write_vmcore(&phdr, sizeof(Elf32_Phdr), s);
|
|
|
bf143f |
- if (ret < 0) {
|
|
|
bf143f |
- error_setg_errno(errp, -ret,
|
|
|
bf143f |
- "dump: failed to write program header table");
|
|
|
bf143f |
- }
|
|
|
bf143f |
+ memset(phdr, 0, sizeof(*phdr));
|
|
|
bf143f |
+ phdr->p_type = cpu_to_dump32(s, PT_NOTE);
|
|
|
bf143f |
+ phdr->p_offset = cpu_to_dump32(s, s->note_offset);
|
|
|
bf143f |
+ phdr->p_paddr = 0;
|
|
|
bf143f |
+ phdr->p_filesz = cpu_to_dump32(s, s->note_size);
|
|
|
bf143f |
+ phdr->p_memsz = cpu_to_dump32(s, s->note_size);
|
|
|
bf143f |
+ phdr->p_vaddr = 0;
|
|
|
bf143f |
}
|
|
|
bf143f |
|
|
|
bf143f |
static void write_elf32_notes(WriteCoreDumpFunction f, DumpState *s,
|
|
|
bf143f |
@@ -358,6 +340,32 @@ static void write_elf32_notes(WriteCoreDumpFunction f, DumpState *s,
|
|
|
bf143f |
write_guest_note(f, s, errp);
|
|
|
bf143f |
}
|
|
|
bf143f |
|
|
|
bf143f |
+static void write_elf_phdr_note(DumpState *s, Error **errp)
|
|
|
bf143f |
+{
|
|
|
bf143f |
+ ERRP_GUARD();
|
|
|
bf143f |
+ Elf32_Phdr phdr32;
|
|
|
bf143f |
+ Elf64_Phdr phdr64;
|
|
|
bf143f |
+ void *phdr;
|
|
|
bf143f |
+ size_t size;
|
|
|
bf143f |
+ int ret;
|
|
|
bf143f |
+
|
|
|
bf143f |
+ if (dump_is_64bit(s)) {
|
|
|
bf143f |
+ write_elf64_phdr_note(s, &phdr64);
|
|
|
bf143f |
+ size = sizeof(phdr64);
|
|
|
bf143f |
+ phdr = &phdr64;
|
|
|
bf143f |
+ } else {
|
|
|
bf143f |
+ write_elf32_phdr_note(s, &phdr32);
|
|
|
bf143f |
+ size = sizeof(phdr32);
|
|
|
bf143f |
+ phdr = &phdr32;
|
|
|
bf143f |
+ }
|
|
|
bf143f |
+
|
|
|
bf143f |
+ ret = fd_write_vmcore(phdr, size, s);
|
|
|
bf143f |
+ if (ret < 0) {
|
|
|
bf143f |
+ error_setg_errno(errp, -ret,
|
|
|
bf143f |
+ "dump: failed to write program header table");
|
|
|
bf143f |
+ }
|
|
|
bf143f |
+}
|
|
|
bf143f |
+
|
|
|
bf143f |
static void write_elf_section(DumpState *s, int type, Error **errp)
|
|
|
bf143f |
{
|
|
|
bf143f |
Elf32_Shdr shdr32;
|
|
|
bf143f |
@@ -551,13 +559,13 @@ static void dump_begin(DumpState *s, Error **errp)
|
|
|
bf143f |
return;
|
|
|
bf143f |
}
|
|
|
bf143f |
|
|
|
bf143f |
- if (dump_is_64bit(s)) {
|
|
|
bf143f |
- /* write PT_NOTE to vmcore */
|
|
|
bf143f |
- write_elf64_note(s, errp);
|
|
|
bf143f |
- if (*errp) {
|
|
|
bf143f |
- return;
|
|
|
bf143f |
- }
|
|
|
bf143f |
+ /* write PT_NOTE to vmcore */
|
|
|
bf143f |
+ write_elf_phdr_note(s, errp);
|
|
|
bf143f |
+ if (*errp) {
|
|
|
bf143f |
+ return;
|
|
|
bf143f |
+ }
|
|
|
bf143f |
|
|
|
bf143f |
+ if (dump_is_64bit(s)) {
|
|
|
bf143f |
/* write all PT_LOAD to vmcore */
|
|
|
bf143f |
write_elf_loads(s, errp);
|
|
|
bf143f |
if (*errp) {
|
|
|
bf143f |
@@ -578,12 +586,6 @@ static void dump_begin(DumpState *s, Error **errp)
|
|
|
bf143f |
return;
|
|
|
bf143f |
}
|
|
|
bf143f |
} else {
|
|
|
bf143f |
- /* write PT_NOTE to vmcore */
|
|
|
bf143f |
- write_elf32_note(s, errp);
|
|
|
bf143f |
- if (*errp) {
|
|
|
bf143f |
- return;
|
|
|
bf143f |
- }
|
|
|
bf143f |
-
|
|
|
bf143f |
/* write all PT_LOAD to vmcore */
|
|
|
bf143f |
write_elf_loads(s, errp);
|
|
|
bf143f |
if (*errp) {
|
|
|
bf143f |
--
|
|
|
bf143f |
2.37.3
|
|
|
bf143f |
|