[Crash-utility] [PATCH v3 8/9] shift ramdump_def.end_paddr calculation from alloc_program_headers() to is_ramdump()

Oleg Nesterov oleg at redhat.com
Tue May 3 17:36:15 UTC 2016


Preparation. This way "ramdump" array is ready for use right after
is_ramdump(), and this also simplifies the code a little bit.

Signed-off-by: Oleg Nesterov <oleg at redhat.com>
---
 ramdump.c | 24 +++++++++---------------
 1 file changed, 9 insertions(+), 15 deletions(-)

diff --git a/ramdump.c b/ramdump.c
index ab93767..1922c1b 100644
--- a/ramdump.c
+++ b/ramdump.c
@@ -59,29 +59,19 @@ static void alloc_elf_header(Elf64_Ehdr *ehdr, ushort e_machine)
 	ehdr->e_shstrndx = 0;
 }
 
-static int alloc_program_headers(Elf64_Phdr *phdr)
+static void alloc_program_headers(Elf64_Phdr *phdr)
 {
 	unsigned int i;
-	struct stat64 st;
 
 	for (i = 0; i < nodes; i++) {
 		phdr[i].p_type = PT_LOAD;
-
-		if (0 > stat64(ramdump[i].path, &st)) {
-			error(INFO, "ramdump stat failed\n");
-			return -1;
-		}
-
-		phdr[i].p_filesz = st.st_size;
+		phdr[i].p_filesz = ramdump[i].end_paddr + 1 - ramdump[i].start_paddr;
 		phdr[i].p_memsz = phdr[i].p_filesz;
 		phdr[i].p_vaddr = 0;
 		phdr[i].p_paddr = ramdump[i].start_paddr;
-		ramdump[i].end_paddr = ramdump[i].start_paddr + st.st_size - 1;
 		phdr[i].p_flags = PF_R | PF_W | PF_X;
 		phdr[i].p_align = 0;
 	}
-
-	return 0;
 }
 
 static char *write_elf(Elf64_Phdr *load, Elf64_Ehdr *e_head, size_t data_offset)
@@ -219,8 +209,7 @@ char *ramdump_to_elf(void)
 
 	load = (Elf64_Phdr *)ptr;
 
-	if (alloc_program_headers(load))
-		goto end;
+	alloc_program_headers(load);
 
 	offset += sizeof(Elf64_Phdr) * nodes;
 	ptr += sizeof(Elf64_Phdr) * nodes;
@@ -238,7 +227,7 @@ char *ramdump_to_elf(void)
 	}
 
 	e_file = write_elf(load, e_head, data_offset);
-end:
+
 	free(e_head);
 	return e_file;
 }
@@ -248,6 +237,7 @@ int is_ramdump(char *p)
 	char *x = NULL, *y = NULL, *pat;
 	size_t len;
 	char *pattern;
+	struct stat64 st;
 	int err = 0;
 
 	if (nodes || !strchr(p, '@'))
@@ -277,6 +267,10 @@ int is_ramdump(char *p)
 						"ramdump %s open failed:%s\n",
 						ramdump[nodes - 1].path,
 						strerror(errno));
+			if (fstat64(ramdump[nodes - 1].rfd, &st) < 0)
+				error(FATAL, "ramdump stat failed\n");
+			ramdump[nodes - 1].end_paddr =
+				ramdump[nodes - 1].start_paddr + st.st_size - 1;
 		}
 
 		pat = NULL;
-- 
2.5.0




More information about the Crash-utility mailing list