From 61765090769c1c95d94bdd2ddc9933df1c0a0bad Mon Sep 17 00:00:00 2001 From: Marc Hartmayer Date: Fri, 23 Sep 2022 13:58:43 +0000 Subject: [PATCH] zdump: df_elf: refactor `check_elf_hdr` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The function will be reused by upcoming patches. Signed-off-by: Marc Hartmayer Reviewed-by: Steffen Eiden Signed-off-by: Jan Höppner --- zdump/df_elf.c | 9 +++++++++ zdump/df_elf.h | 5 +++++ zdump/dfi_elf.c | 11 +---------- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/zdump/df_elf.c b/zdump/df_elf.c index a1780e21..602080f7 100644 --- a/zdump/df_elf.c +++ b/zdump/df_elf.c @@ -52,6 +52,15 @@ bool ehdr_is_s390x(const Elf64_Ehdr *ehdr) ehdr->e_ident[EI_CLASS] == ELFCLASS64; } +int ehdr_check_s390x(const Elf64_Ehdr *ehdr) +{ + if (!ehdr_is_elf_object(ehdr) || !ehdr_is_vmcore(ehdr)) + return -ENODEV; + if (!ehdr_is_s390x(ehdr)) + ERR_EXIT("Only s390x (64 bit) core dump files are supported"); + return 0; +} + Elf64_Ehdr *read_elf_hdr(const struct zg_fh *fh) { Elf64_Ehdr *ehdr; diff --git a/zdump/df_elf.h b/zdump/df_elf.h index 583217fa..11441f0b 100644 --- a/zdump/df_elf.h +++ b/zdump/df_elf.h @@ -147,6 +147,11 @@ bool ehdr_is_vmcore(const Elf64_Ehdr *ehdr); */ bool ehdr_is_s390x(const Elf64_Ehdr *ehdr); +/* + * Verify that given header is a s390x ELF header + */ +int ehdr_check_s390x(const Elf64_Ehdr *ehdr); + /* * Read ELF header at current offset */ diff --git a/zdump/dfi_elf.c b/zdump/dfi_elf.c index 102a4a4d..605904bc 100644 --- a/zdump/dfi_elf.c +++ b/zdump/dfi_elf.c @@ -251,15 +251,6 @@ static int pt_notes_add(const Elf64_Phdr *phdr) return 0; } -static int check_elf_hdr(const Elf64_Ehdr *ehdr) -{ - if (!ehdr_is_elf_object(ehdr) || !ehdr_is_vmcore(ehdr)) - return -ENODEV; - if (!ehdr_is_s390x(ehdr)) - ERR_EXIT("Only s390x (64 bit) core dump files are supported"); - return 0; -} - /* * Initialize ELF input dump format */ @@ -276,7 +267,7 @@ static int dfi_elf_init(void) if (!ehdr) return -ENODEV; - if (check_elf_hdr(ehdr) < 0) + if (ehdr_check_s390x(ehdr) < 0) goto free_ehdr; df_elf_ensure_s390x();