mirror of
https://github.com/ibm-s390-linux/s390-tools.git
synced 2026-08-05 02:14:52 +00:00
zdump: df_elf: read_elf_hdr: return Elf64_Ehdr struct
This makes the API of `read_elf_hdr` consistent with `read_elf_phdrs`. Signed-off-by: Marc Hartmayer <mhartmay@linux.ibm.com> Reviewed-by: Alexander Egorenkov <egorenar@linux.ibm.com> Reviewed-by: Steffen Eiden <seiden@linux.ibm.com> Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
committed by
Jan Höppner
parent
4e6d43e2ac
commit
f93f437f8b
@@ -52,15 +52,17 @@ bool ehdr_is_s390x(const Elf64_Ehdr *ehdr)
|
||||
ehdr->e_ident[EI_CLASS] == ELFCLASS64;
|
||||
}
|
||||
|
||||
int read_elf_hdr(const struct zg_fh *fh, Elf64_Ehdr *ehdr)
|
||||
Elf64_Ehdr *read_elf_hdr(const struct zg_fh *fh)
|
||||
{
|
||||
Elf64_Ehdr *ehdr;
|
||||
const size_t ehdr_size = sizeof(*ehdr);
|
||||
|
||||
if (zg_size(fh) < ehdr_size)
|
||||
return -1;
|
||||
return NULL;
|
||||
|
||||
ehdr = util_malloc(ehdr_size);
|
||||
zg_read(fh, ehdr, ehdr_size, ZG_CHECK);
|
||||
return 0;
|
||||
return ehdr;
|
||||
}
|
||||
|
||||
Elf64_Phdr *read_elf_phdrs(const struct zg_fh *fh, const Elf64_Ehdr *ehdr, unsigned int *phdr_count)
|
||||
|
||||
@@ -146,7 +146,7 @@ bool ehdr_is_s390x(const Elf64_Ehdr *ehdr);
|
||||
/*
|
||||
* Read ELF header at current offset
|
||||
*/
|
||||
int read_elf_hdr(const struct zg_fh *fh, Elf64_Ehdr *ehdr);
|
||||
Elf64_Ehdr *read_elf_hdr(const struct zg_fh *fh);
|
||||
|
||||
/*
|
||||
* Read ELF program headers
|
||||
|
||||
@@ -267,21 +267,23 @@ static int dfi_elf_init(void)
|
||||
{
|
||||
unsigned int phnum, i;
|
||||
Elf64_Phdr *phdrs;
|
||||
Elf64_Ehdr ehdr;
|
||||
Elf64_Ehdr *ehdr;
|
||||
int rc = -ENODEV;
|
||||
|
||||
util_log_print(UTIL_LOG_DEBUG, "DFI ELF initialization\n");
|
||||
|
||||
if (read_elf_hdr(g.fh, &ehdr) != 0)
|
||||
ehdr = read_elf_hdr(g.fh);
|
||||
if (!ehdr)
|
||||
return -ENODEV;
|
||||
|
||||
if (check_elf_hdr(&ehdr) < 0)
|
||||
return -ENODEV;
|
||||
if (check_elf_hdr(ehdr) < 0)
|
||||
goto free_ehdr;
|
||||
|
||||
df_elf_ensure_s390x();
|
||||
dfi_arch_set(DFI_ARCH_64);
|
||||
dfi_cpu_info_init(DFI_CPU_CONTENT_ALL);
|
||||
|
||||
phdrs = read_elf_phdrs(g.fh, &ehdr, &phnum);
|
||||
phdrs = read_elf_phdrs(g.fh, ehdr, &phnum);
|
||||
util_log_print(UTIL_LOG_DEBUG, "DFI ELF e_phnum %u\n", phnum);
|
||||
for (i = 0; i < phnum; i++) {
|
||||
const Elf64_Phdr *phdr = &phdrs[i];
|
||||
@@ -290,24 +292,29 @@ static int dfi_elf_init(void)
|
||||
switch (phdr->p_type) {
|
||||
case PT_LOAD:
|
||||
if (pt_load_add(phdr)) {
|
||||
free(phdrs);
|
||||
return -EINVAL;
|
||||
rc = -EINVAL;
|
||||
goto free_phdrs;
|
||||
}
|
||||
break;
|
||||
case PT_NOTE:
|
||||
if (pt_notes_add(phdr)) {
|
||||
free(phdrs);
|
||||
return -EINVAL;
|
||||
rc = -EINVAL;
|
||||
goto free_phdrs;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
free(phdrs);
|
||||
|
||||
dfi_attr_version_set(ehdr.e_ident[EI_VERSION]);
|
||||
return 0;
|
||||
dfi_attr_version_set(ehdr->e_ident[EI_VERSION]);
|
||||
rc = 0;
|
||||
|
||||
free_phdrs:
|
||||
free(phdrs);
|
||||
free_ehdr:
|
||||
free(ehdr);
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user