[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 4/7] dump: Introduce dump_is_64bit() helper function
From: |
Janosch Frank |
Subject: |
[PATCH 4/7] dump: Introduce dump_is_64bit() helper function |
Date: |
Tue, 1 Mar 2022 14:22:10 +0000 |
Checking d_class in dump_info leads to lengthy conditionals so let's
shorten things a bit by introducing a helper function.
Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
---
dump/dump.c | 14 +++++++-------
include/sysemu/dump.h | 6 ++++++
2 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/dump/dump.c b/dump/dump.c
index 242f83db95..bb152bddff 100644
--- a/dump/dump.c
+++ b/dump/dump.c
@@ -481,7 +481,7 @@ static void write_elf_loads(DumpState *s, Error **errp)
get_offset_range(memory_mapping->phys_addr,
memory_mapping->length,
s, &offset, &filesz);
- if (s->dump_info.d_class == ELFCLASS64) {
+ if (dump_is_64bit(s)) {
write_elf64_load(s, memory_mapping, phdr_index++, offset,
filesz, &local_err);
} else {
@@ -530,7 +530,7 @@ static void dump_begin(DumpState *s, Error **errp)
*/
/* write elf header to vmcore */
- if (s->dump_info.d_class == ELFCLASS64) {
+ if (dump_is_64bit(s)) {
write_elf64_header(s, &local_err);
} else {
write_elf32_header(s, &local_err);
@@ -540,7 +540,7 @@ static void dump_begin(DumpState *s, Error **errp)
return;
}
- if (s->dump_info.d_class == ELFCLASS64) {
+ if (dump_is_64bit(s)) {
/* write PT_NOTE to vmcore */
write_elf64_note(s, &local_err);
if (local_err) {
@@ -761,7 +761,7 @@ static void get_note_sizes(DumpState *s, const void *note,
uint64_t name_sz;
uint64_t desc_sz;
- if (s->dump_info.d_class == ELFCLASS64) {
+ if (dump_is_64bit(s)) {
const Elf64_Nhdr *hdr = note;
note_head_sz = sizeof(Elf64_Nhdr);
name_sz = tswap64(hdr->n_namesz);
@@ -1023,7 +1023,7 @@ out:
static void write_dump_header(DumpState *s, Error **errp)
{
- if (s->dump_info.d_class == ELFCLASS32) {
+ if (!dump_is_64bit(s)) {
create_header32(s, errp);
} else {
create_header64(s, errp);
@@ -1716,7 +1716,7 @@ static void dump_init(DumpState *s, int fd, bool
has_format,
uint32_t size;
uint16_t format;
- note_head_size = s->dump_info.d_class == ELFCLASS32 ?
+ note_head_size = !dump_is_64bit(s) ?
sizeof(Elf32_Nhdr) : sizeof(Elf64_Nhdr);
format = le16_to_cpu(vmci->vmcoreinfo.guest_format);
@@ -1821,7 +1821,7 @@ static void dump_init(DumpState *s, int fd, bool
has_format,
}
}
- if (s->dump_info.d_class == ELFCLASS64) {
+ if (dump_is_64bit(s)) {
s->phdr_offset = sizeof(Elf64_Ehdr);
s->shdr_offset = s->phdr_offset + sizeof(Elf64_Phdr) * s->phdr_num;
s->note_offset = s->shdr_offset + sizeof(Elf64_Shdr) * s->shdr_num;
diff --git a/include/sysemu/dump.h b/include/sysemu/dump.h
index ffc2ea1072..078b3d57a1 100644
--- a/include/sysemu/dump.h
+++ b/include/sysemu/dump.h
@@ -203,4 +203,10 @@ typedef struct DumpState {
uint16_t cpu_to_dump16(DumpState *s, uint16_t val);
uint32_t cpu_to_dump32(DumpState *s, uint32_t val);
uint64_t cpu_to_dump64(DumpState *s, uint64_t val);
+
+static inline bool dump_is_64bit(DumpState *s)
+{
+ return s->dump_info.d_class == ELFCLASS64;
+}
+
#endif
--
2.32.0
- [PATCH 0/7] dump: Cleanup and consolidation, Janosch Frank, 2022/03/01
- [PATCH 3/7] dump: Add more offset variables, Janosch Frank, 2022/03/01
- [PATCH 6/7] dump: Cleanup dump_begin write functions, Janosch Frank, 2022/03/01
- [PATCH 2/7] dump: Remove the sh_info variable, Janosch Frank, 2022/03/01
- [PATCH 5/7] dump: Consolidate phdr note writes, Janosch Frank, 2022/03/01