|
|
97168e |
From d1e147a3133d4d31d4b0c02c05916366fadd9c30 Mon Sep 17 00:00:00 2001
|
|
|
97168e |
From: Janosch Frank <frankja@linux.ibm.com>
|
|
|
97168e |
Date: Thu, 11 Aug 2022 12:11:00 +0000
|
|
|
97168e |
Subject: [PATCH 28/42] dump: Split elf header functions into prepare and write
|
|
|
97168e |
MIME-Version: 1.0
|
|
|
97168e |
Content-Type: text/plain; charset=UTF-8
|
|
|
97168e |
Content-Transfer-Encoding: 8bit
|
|
|
97168e |
|
|
|
97168e |
RH-Author: Cédric Le Goater <clg@redhat.com>
|
|
|
97168e |
RH-MergeRequest: 226: s390: Enhanced Interpretation for PCI Functions and Secure Execution guest dump
|
|
|
97168e |
RH-Bugzilla: 1664378 2043909
|
|
|
97168e |
RH-Acked-by: Thomas Huth <thuth@redhat.com>
|
|
|
97168e |
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
|
|
|
97168e |
RH-Acked-by: Jon Maloy <jmaloy@redhat.com>
|
|
|
97168e |
RH-Commit: [28/41] f70a13ad443835e7f46b7c5e176e372d370ac797
|
|
|
97168e |
|
|
|
97168e |
Let's split the write from the modification of the elf header so we
|
|
|
97168e |
can consolidate the write of the data in one function.
|
|
|
97168e |
|
|
|
97168e |
Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
|
|
|
97168e |
Reviewed-by: Janis Schoetterl-Glausch <scgl@linux.ibm.com>
|
|
|
97168e |
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
|
|
|
97168e |
Message-Id: <20220811121111.9878-8-frankja@linux.ibm.com>
|
|
|
97168e |
(cherry picked from commit 670e76998a61ca171200fcded3865b294a2d1243)
|
|
|
97168e |
Signed-off-by: Cédric Le Goater <clg@redhat.com>
|
|
|
97168e |
---
|
|
|
97168e |
dump/dump.c | 100 ++++++++++++++++++++++++++++------------------------
|
|
|
97168e |
1 file changed, 53 insertions(+), 47 deletions(-)
|
|
|
97168e |
|
|
|
97168e |
diff --git a/dump/dump.c b/dump/dump.c
|
|
|
97168e |
index 902a85ef8e..8d5226f861 100644
|
|
|
97168e |
--- a/dump/dump.c
|
|
|
97168e |
+++ b/dump/dump.c
|
|
|
97168e |
@@ -132,7 +132,7 @@ static int fd_write_vmcore(const void *buf, size_t size, void *opaque)
|
|
|
97168e |
return 0;
|
|
|
97168e |
}
|
|
|
97168e |
|
|
|
97168e |
-static void write_elf64_header(DumpState *s, Error **errp)
|
|
|
97168e |
+static void prepare_elf64_header(DumpState *s, Elf64_Ehdr *elf_header)
|
|
|
97168e |
{
|
|
|
97168e |
/*
|
|
|
97168e |
* phnum in the elf header is 16 bit, if we have more segments we
|
|
|
97168e |
@@ -140,34 +140,27 @@ static void write_elf64_header(DumpState *s, Error **errp)
|
|
|
97168e |
* special section.
|
|
|
97168e |
*/
|
|
|
97168e |
uint16_t phnum = MIN(s->phdr_num, PN_XNUM);
|
|
|
97168e |
- Elf64_Ehdr elf_header;
|
|
|
97168e |
- int ret;
|
|
|
97168e |
|
|
|
97168e |
- memset(&elf_header, 0, sizeof(Elf64_Ehdr));
|
|
|
97168e |
- memcpy(&elf_header, ELFMAG, SELFMAG);
|
|
|
97168e |
- elf_header.e_ident[EI_CLASS] = ELFCLASS64;
|
|
|
97168e |
- elf_header.e_ident[EI_DATA] = s->dump_info.d_endian;
|
|
|
97168e |
- elf_header.e_ident[EI_VERSION] = EV_CURRENT;
|
|
|
97168e |
- elf_header.e_type = cpu_to_dump16(s, ET_CORE);
|
|
|
97168e |
- elf_header.e_machine = cpu_to_dump16(s, s->dump_info.d_machine);
|
|
|
97168e |
- elf_header.e_version = cpu_to_dump32(s, EV_CURRENT);
|
|
|
97168e |
- elf_header.e_ehsize = cpu_to_dump16(s, sizeof(elf_header));
|
|
|
97168e |
- elf_header.e_phoff = cpu_to_dump64(s, s->phdr_offset);
|
|
|
97168e |
- elf_header.e_phentsize = cpu_to_dump16(s, sizeof(Elf64_Phdr));
|
|
|
97168e |
- elf_header.e_phnum = cpu_to_dump16(s, phnum);
|
|
|
97168e |
+ memset(elf_header, 0, sizeof(Elf64_Ehdr));
|
|
|
97168e |
+ memcpy(elf_header, ELFMAG, SELFMAG);
|
|
|
97168e |
+ elf_header->e_ident[EI_CLASS] = ELFCLASS64;
|
|
|
97168e |
+ elf_header->e_ident[EI_DATA] = s->dump_info.d_endian;
|
|
|
97168e |
+ elf_header->e_ident[EI_VERSION] = EV_CURRENT;
|
|
|
97168e |
+ elf_header->e_type = cpu_to_dump16(s, ET_CORE);
|
|
|
97168e |
+ elf_header->e_machine = cpu_to_dump16(s, s->dump_info.d_machine);
|
|
|
97168e |
+ elf_header->e_version = cpu_to_dump32(s, EV_CURRENT);
|
|
|
97168e |
+ elf_header->e_ehsize = cpu_to_dump16(s, sizeof(elf_header));
|
|
|
97168e |
+ elf_header->e_phoff = cpu_to_dump64(s, s->phdr_offset);
|
|
|
97168e |
+ elf_header->e_phentsize = cpu_to_dump16(s, sizeof(Elf64_Phdr));
|
|
|
97168e |
+ elf_header->e_phnum = cpu_to_dump16(s, phnum);
|
|
|
97168e |
if (s->shdr_num) {
|
|
|
97168e |
- elf_header.e_shoff = cpu_to_dump64(s, s->shdr_offset);
|
|
|
97168e |
- elf_header.e_shentsize = cpu_to_dump16(s, sizeof(Elf64_Shdr));
|
|
|
97168e |
- elf_header.e_shnum = cpu_to_dump16(s, s->shdr_num);
|
|
|
97168e |
- }
|
|
|
97168e |
-
|
|
|
97168e |
- ret = fd_write_vmcore(&elf_header, sizeof(elf_header), s);
|
|
|
97168e |
- if (ret < 0) {
|
|
|
97168e |
- error_setg_errno(errp, -ret, "dump: failed to write elf header");
|
|
|
97168e |
+ elf_header->e_shoff = cpu_to_dump64(s, s->shdr_offset);
|
|
|
97168e |
+ elf_header->e_shentsize = cpu_to_dump16(s, sizeof(Elf64_Shdr));
|
|
|
97168e |
+ elf_header->e_shnum = cpu_to_dump16(s, s->shdr_num);
|
|
|
97168e |
}
|
|
|
97168e |
}
|
|
|
97168e |
|
|
|
97168e |
-static void write_elf32_header(DumpState *s, Error **errp)
|
|
|
97168e |
+static void prepare_elf32_header(DumpState *s, Elf32_Ehdr *elf_header)
|
|
|
97168e |
{
|
|
|
97168e |
/*
|
|
|
97168e |
* phnum in the elf header is 16 bit, if we have more segments we
|
|
|
97168e |
@@ -175,28 +168,45 @@ static void write_elf32_header(DumpState *s, Error **errp)
|
|
|
97168e |
* special section.
|
|
|
97168e |
*/
|
|
|
97168e |
uint16_t phnum = MIN(s->phdr_num, PN_XNUM);
|
|
|
97168e |
- Elf32_Ehdr elf_header;
|
|
|
97168e |
- int ret;
|
|
|
97168e |
|
|
|
97168e |
- memset(&elf_header, 0, sizeof(Elf32_Ehdr));
|
|
|
97168e |
- memcpy(&elf_header, ELFMAG, SELFMAG);
|
|
|
97168e |
- elf_header.e_ident[EI_CLASS] = ELFCLASS32;
|
|
|
97168e |
- elf_header.e_ident[EI_DATA] = s->dump_info.d_endian;
|
|
|
97168e |
- elf_header.e_ident[EI_VERSION] = EV_CURRENT;
|
|
|
97168e |
- elf_header.e_type = cpu_to_dump16(s, ET_CORE);
|
|
|
97168e |
- elf_header.e_machine = cpu_to_dump16(s, s->dump_info.d_machine);
|
|
|
97168e |
- elf_header.e_version = cpu_to_dump32(s, EV_CURRENT);
|
|
|
97168e |
- elf_header.e_ehsize = cpu_to_dump16(s, sizeof(elf_header));
|
|
|
97168e |
- elf_header.e_phoff = cpu_to_dump32(s, s->phdr_offset);
|
|
|
97168e |
- elf_header.e_phentsize = cpu_to_dump16(s, sizeof(Elf32_Phdr));
|
|
|
97168e |
- elf_header.e_phnum = cpu_to_dump16(s, phnum);
|
|
|
97168e |
+ memset(elf_header, 0, sizeof(Elf32_Ehdr));
|
|
|
97168e |
+ memcpy(elf_header, ELFMAG, SELFMAG);
|
|
|
97168e |
+ elf_header->e_ident[EI_CLASS] = ELFCLASS32;
|
|
|
97168e |
+ elf_header->e_ident[EI_DATA] = s->dump_info.d_endian;
|
|
|
97168e |
+ elf_header->e_ident[EI_VERSION] = EV_CURRENT;
|
|
|
97168e |
+ elf_header->e_type = cpu_to_dump16(s, ET_CORE);
|
|
|
97168e |
+ elf_header->e_machine = cpu_to_dump16(s, s->dump_info.d_machine);
|
|
|
97168e |
+ elf_header->e_version = cpu_to_dump32(s, EV_CURRENT);
|
|
|
97168e |
+ elf_header->e_ehsize = cpu_to_dump16(s, sizeof(elf_header));
|
|
|
97168e |
+ elf_header->e_phoff = cpu_to_dump32(s, s->phdr_offset);
|
|
|
97168e |
+ elf_header->e_phentsize = cpu_to_dump16(s, sizeof(Elf32_Phdr));
|
|
|
97168e |
+ elf_header->e_phnum = cpu_to_dump16(s, phnum);
|
|
|
97168e |
if (s->shdr_num) {
|
|
|
97168e |
- elf_header.e_shoff = cpu_to_dump32(s, s->shdr_offset);
|
|
|
97168e |
- elf_header.e_shentsize = cpu_to_dump16(s, sizeof(Elf32_Shdr));
|
|
|
97168e |
- elf_header.e_shnum = cpu_to_dump16(s, s->shdr_num);
|
|
|
97168e |
+ elf_header->e_shoff = cpu_to_dump32(s, s->shdr_offset);
|
|
|
97168e |
+ elf_header->e_shentsize = cpu_to_dump16(s, sizeof(Elf32_Shdr));
|
|
|
97168e |
+ elf_header->e_shnum = cpu_to_dump16(s, s->shdr_num);
|
|
|
97168e |
}
|
|
|
97168e |
+}
|
|
|
97168e |
|
|
|
97168e |
- ret = fd_write_vmcore(&elf_header, sizeof(elf_header), s);
|
|
|
97168e |
+static void write_elf_header(DumpState *s, Error **errp)
|
|
|
97168e |
+{
|
|
|
97168e |
+ Elf32_Ehdr elf32_header;
|
|
|
97168e |
+ Elf64_Ehdr elf64_header;
|
|
|
97168e |
+ size_t header_size;
|
|
|
97168e |
+ void *header_ptr;
|
|
|
97168e |
+ int ret;
|
|
|
97168e |
+
|
|
|
97168e |
+ if (dump_is_64bit(s)) {
|
|
|
97168e |
+ prepare_elf64_header(s, &elf64_header);
|
|
|
97168e |
+ header_size = sizeof(elf64_header);
|
|
|
97168e |
+ header_ptr = &elf64_header;
|
|
|
97168e |
+ } else {
|
|
|
97168e |
+ prepare_elf32_header(s, &elf32_header);
|
|
|
97168e |
+ header_size = sizeof(elf32_header);
|
|
|
97168e |
+ header_ptr = &elf32_header;
|
|
|
97168e |
+ }
|
|
|
97168e |
+
|
|
|
97168e |
+ ret = fd_write_vmcore(header_ptr, header_size, s);
|
|
|
97168e |
if (ret < 0) {
|
|
|
97168e |
error_setg_errno(errp, -ret, "dump: failed to write elf header");
|
|
|
97168e |
}
|
|
|
97168e |
@@ -565,11 +575,7 @@ static void dump_begin(DumpState *s, Error **errp)
|
|
|
97168e |
*/
|
|
|
97168e |
|
|
|
97168e |
/* write elf header to vmcore */
|
|
|
97168e |
- if (dump_is_64bit(s)) {
|
|
|
97168e |
- write_elf64_header(s, errp);
|
|
|
97168e |
- } else {
|
|
|
97168e |
- write_elf32_header(s, errp);
|
|
|
97168e |
- }
|
|
|
97168e |
+ write_elf_header(s, errp);
|
|
|
97168e |
if (*errp) {
|
|
|
97168e |
return;
|
|
|
97168e |
}
|
|
|
97168e |
--
|
|
|
97168e |
2.37.3
|
|
|
97168e |
|