dump: Introduce dump_is_64bit() helper function
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> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <20220330123603.107120-7-frankja@linux.ibm.com>
This commit is contained in:
parent
e71d353360
commit
05bbaa5040
25
dump/dump.c
25
dump/dump.c
@ -54,6 +54,11 @@ static Error *dump_migration_blocker;
|
||||
DIV_ROUND_UP((name_size), 4) + \
|
||||
DIV_ROUND_UP((desc_size), 4)) * 4)
|
||||
|
||||
static inline bool dump_is_64bit(DumpState *s)
|
||||
{
|
||||
return s->dump_info.d_class == ELFCLASS64;
|
||||
}
|
||||
|
||||
uint16_t cpu_to_dump16(DumpState *s, uint16_t val)
|
||||
{
|
||||
if (s->dump_info.d_endian == ELFDATA2LSB) {
|
||||
@ -488,7 +493,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, errp);
|
||||
} else {
|
||||
@ -536,7 +541,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, errp);
|
||||
} else {
|
||||
write_elf32_header(s, errp);
|
||||
@ -545,7 +550,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, errp);
|
||||
if (*errp) {
|
||||
@ -756,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);
|
||||
@ -1016,10 +1021,10 @@ out:
|
||||
|
||||
static void write_dump_header(DumpState *s, Error **errp)
|
||||
{
|
||||
if (s->dump_info.d_class == ELFCLASS32) {
|
||||
create_header32(s, errp);
|
||||
} else {
|
||||
if (dump_is_64bit(s)) {
|
||||
create_header64(s, errp);
|
||||
} else {
|
||||
create_header32(s, errp);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1706,8 +1711,8 @@ 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 ?
|
||||
sizeof(Elf32_Nhdr) : sizeof(Elf64_Nhdr);
|
||||
note_head_size = dump_is_64bit(s) ?
|
||||
sizeof(Elf64_Nhdr) : sizeof(Elf32_Nhdr);
|
||||
|
||||
format = le16_to_cpu(vmci->vmcoreinfo.guest_format);
|
||||
size = le32_to_cpu(vmci->vmcoreinfo.size);
|
||||
@ -1810,7 +1815,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;
|
||||
|
Loading…
Reference in New Issue
Block a user