@@ -71,25 +71,34 @@ static unsigned long long get_kernel_stext_sym(void)
char sym[128];
char line[128];
FILE *fp;
- unsigned long long vaddr;
+ unsigned long long vaddr = 0;
char type;
- fp = fopen(kallsyms, "r"); if (!fp) {
+ fp = fopen(kallsyms, "r");
+ if (!fp) {
fprintf(stderr, "Cannot open %s\n", kallsyms);
return 0;
}
while(fgets(line, sizeof(line), fp) != NULL) {
- if (sscanf(line, "%Lx %c %s", &vaddr, &type, sym) != 3)
+ unsigned long long addr;
+
+ if (sscanf(line, "%Lx %c %s", &addr, &type, sym) != 3)
continue;
+
if (strcmp(sym, stext) == 0) {
- dbgprintf("kernel symbol %s vaddr = %16llx\n", stext, vaddr);
- return vaddr;
+ dbgprintf("kernel symbol %s vaddr = %#llx\n", stext, addr);
+ vaddr = addr;
+ break;
}
}
- fprintf(stderr, "Cannot get kernel %s symbol address\n", stext);
- return 0;
+ fclose(fp);
+
+ if (vaddr == 0)
+ fprintf(stderr, "Cannot get kernel %s symbol address\n", stext);
+
+ return vaddr;
}
static int get_kernel_page_offset(struct kexec_info *info,