Rearranges the x86_process_elf_notes() to make it more reusable,
by making it more generic. Splits the code for handling Elf32 and
Elf64 PT_NOTE headers to separate functions.
This may be reused by other architectures, e.g, ppc32.
Signed-off-by: Suzuki K. Poulose <suzuki(a)in.ibm.com>
---
diskdump.c | 73 ++++++++++++++++++++++++++++++++++++++++--------------------
1 files changed, 49 insertions(+), 24 deletions(-)
diff --git a/diskdump.c b/diskdump.c
index 5519af7..9f4b228 100644
--- a/diskdump.c
+++ b/diskdump.c
@@ -85,6 +85,9 @@ static struct diskdump_data **dd_list = NULL;
static int num_dd = 0;
static int num_dumpfiles = 0;
+void process_elf32_notes(void *, ulong);
+void process_elf64_notes(void *, ulong);
+
int dumpfile_is_split(void)
{
return KDUMP_SPLIT();
@@ -232,44 +235,66 @@ open_dump_file(char *file)
return TRUE;
}
-void
-x86_process_elf_notes(void *note_ptr, unsigned long size_note)
+void
+process_elf32_notes(void *note_buf, unsigned long size_note)
{
- Elf32_Nhdr *note32 = NULL;
- Elf64_Nhdr *note64 = NULL;
- size_t tot, len = 0;
+ Elf32_Nhdr *nt;
+ size_t index, len = 0;
int num = 0;
- for (tot = 0; tot < size_note; tot += len) {
- if (machine_type("X86_64")) {
- note64 = note_ptr + tot;
- if (note64->n_type == NT_PRSTATUS) {
- dd->nt_prstatus_percpu[num] = note64;
- num++;
- }
+ for (index = 0; index < size_note; index += len) {
+ nt = note_buf + index;
- len = sizeof(Elf64_Nhdr);
- len = roundup(len + note64->n_namesz, 4);
- len = roundup(len + note64->n_descsz, 4);
- } else if (machine_type("X86")) {
- note32 = note_ptr + tot;
+ if(nt->n_type == NT_PRSTATUS) {
+ dd->nt_prstatus_percpu[num] = nt;
+ num++;
+ }
+ len = sizeof(Elf32_Nhdr);
+ len = roundup(len + nt->n_namesz, 4);
+ len = roundup(len + nt->n_descsz, 4);
+ }
- if (note32->n_type == NT_PRSTATUS) {
- dd->nt_prstatus_percpu[num] = note32;
- num++;
- }
+ if (num > 0) {
+ pc->flags2 |= ELF_NOTES;
+ dd->num_prstatus_notes = num;
+ }
+ return;
+}
+
+void
+process_elf64_notes(void *note_buf, unsigned long size_note)
+{
+ Elf64_Nhdr *nt;
+ size_t index, len = 0;
+ int num = 0;
- len = sizeof(Elf32_Nhdr);
- len = roundup(len + note32->n_namesz, 4);
- len = roundup(len + note32->n_descsz, 4);
+ for (index = 0; index < size_note; index += len) {
+ nt = note_buf + index;
+
+ if(nt->n_type == NT_PRSTATUS) {
+ dd->nt_prstatus_percpu[num] = nt;
+ num++;
}
+ len = sizeof(Elf64_Nhdr);
+ len = roundup(len + nt->n_namesz, 4);
+ len = roundup(len + nt->n_descsz, 4);
}
if (num > 0) {
pc->flags2 |= ELF_NOTES;
dd->num_prstatus_notes = num;
}
+ return;
+}
+
+void
+x86_process_elf_notes(void *note_ptr, unsigned long size_note)
+{
+ if (machine_type("X86_64"))
+ process_elf64_notes(note_ptr, size_note);
+ else if (machine_type("X86"))
+ process_elf32_notes(note_ptr, size_note);
}
static int