Blame SOURCES/github_a6cd8408_mach-m.patch

01fc30
commit a6cd8408d1d214a67ed0c4b09343fec77a8e2ae7
01fc30
Author: Dave Anderson <anderson@redhat.com>
01fc30
Date:   Thu May 31 11:43:14 2018 -0400
01fc30
01fc30
    Fix for the x86 and x86_64 "mach -m" option on Linux 4.12 and later
01fc30
    kernels to account for the structure name changes "e820map" to
01fc30
    "e820_table", and "e820entry" to "e820_entry", and for the symbol
01fc30
    name change from "e820" to "e820_table".  Also updated the display
01fc30
    output to properly translate E820_PRAM and E820_RESERVED_KERN entries.
01fc30
    Without the patch on all kernels, E820_PRAM and E820_RESERVED_KERN
01fc30
    entries show "type 12" and "type 128" respectively.  Without the
01fc30
    patch on Linux 4.12 and later kernels, the command fails with the
01fc30
    error message "mach: cannot resolve e820".
01fc30
    (anderson@redhat.com)
01fc30
01fc30
diff --git a/x86.c b/x86.c
01fc30
index 47767b6..88562b6 100644
01fc30
--- a/x86.c
01fc30
+++ b/x86.c
01fc30
@@ -1,8 +1,8 @@
01fc30
 /* x86.c - core analysis suite
01fc30
  *
01fc30
  * Portions Copyright (C) 1999, 2000, 2001, 2002 Mission Critical Linux, Inc.
01fc30
- * Copyright (C) 2002-2014,2017 David Anderson
01fc30
- * Copyright (C) 2002-2014,2017 Red Hat, Inc. All rights reserved.
01fc30
+ * Copyright (C) 2002-2014,2017-2018 David Anderson
01fc30
+ * Copyright (C) 2002-2014,2017-2018 Red Hat, Inc. All rights reserved.
01fc30
  *
01fc30
  * This program is free software; you can redistribute it and/or modify
01fc30
  * it under the terms of the GNU General Public License as published by
01fc30
@@ -1967,15 +1967,27 @@ x86_init(int when)
01fc30
 		}
01fc30
 		MEMBER_OFFSET_INIT(thread_struct_cr3, "thread_struct", "cr3");
01fc30
 		STRUCT_SIZE_INIT(cpuinfo_x86, "cpuinfo_x86");
01fc30
-		STRUCT_SIZE_INIT(e820map, "e820map");
01fc30
-		STRUCT_SIZE_INIT(e820entry, "e820entry");
01fc30
 		STRUCT_SIZE_INIT(irq_ctx, "irq_ctx");
01fc30
+		if (STRUCT_EXISTS("e820map")) {
01fc30
+			STRUCT_SIZE_INIT(e820map, "e820map");
01fc30
+			MEMBER_OFFSET_INIT(e820map_nr_map, "e820map", "nr_map");
01fc30
+		} else {
01fc30
+			STRUCT_SIZE_INIT(e820map, "e820_table");
01fc30
+			MEMBER_OFFSET_INIT(e820map_nr_map, "e820_table", "nr_entries");
01fc30
+		}
01fc30
+		if (STRUCT_EXISTS("e820entry")) {
01fc30
+			STRUCT_SIZE_INIT(e820entry, "e820entry");
01fc30
+			MEMBER_OFFSET_INIT(e820entry_addr, "e820entry", "addr");
01fc30
+			MEMBER_OFFSET_INIT(e820entry_size, "e820entry", "size");
01fc30
+			MEMBER_OFFSET_INIT(e820entry_type, "e820entry", "type");
01fc30
+		} else {
01fc30
+			STRUCT_SIZE_INIT(e820entry, "e820_entry");
01fc30
+			MEMBER_OFFSET_INIT(e820entry_addr, "e820_entry", "addr");
01fc30
+			MEMBER_OFFSET_INIT(e820entry_size, "e820_entry", "size");
01fc30
+			MEMBER_OFFSET_INIT(e820entry_type, "e820_entry", "type");
01fc30
+		}
01fc30
 		if (!VALID_STRUCT(irq_ctx))
01fc30
 			STRUCT_SIZE_INIT(irq_ctx, "irq_stack");
01fc30
-		MEMBER_OFFSET_INIT(e820map_nr_map, "e820map", "nr_map");
01fc30
-		MEMBER_OFFSET_INIT(e820entry_addr, "e820entry", "addr");
01fc30
-		MEMBER_OFFSET_INIT(e820entry_size, "e820entry", "size");
01fc30
-		MEMBER_OFFSET_INIT(e820entry_type, "e820entry", "type");
01fc30
 		if (KVMDUMP_DUMPFILE())
01fc30
 			set_kvm_iohole(NULL);
01fc30
 		if (symbol_exists("irq_desc"))
01fc30
@@ -4415,33 +4427,54 @@ static char *e820type[] = {
01fc30
 static void
01fc30
 x86_display_memmap(void)
01fc30
 {
01fc30
-	ulong e820;
01fc30
-	int nr_map, i;
01fc30
-	char *buf, *e820entry_ptr;
01fc30
-	ulonglong addr, size;
01fc30
-	ulong type;
01fc30
+        ulong e820;
01fc30
+        int nr_map, i;
01fc30
+        char *buf, *e820entry_ptr;
01fc30
+        ulonglong addr, size;
01fc30
+        uint type;
01fc30
+
01fc30
+	if (kernel_symbol_exists("e820")) {
01fc30
+		if (get_symbol_type("e820", NULL, NULL) == TYPE_CODE_PTR)
01fc30
+			get_symbol_data("e820", sizeof(void *), &e820);
01fc30
+		else
01fc30
+			e820 = symbol_value("e820");
01fc30
+
01fc30
+	} else if (kernel_symbol_exists("e820_table"))
01fc30
+		get_symbol_data("e820_table", sizeof(void *), &e820);
01fc30
+	else
01fc30
+		error(FATAL, "neither e820 or e820_table symbols exist\n");
01fc30
 
01fc30
-	e820 = symbol_value("e820");
01fc30
-	buf = (char *)GETBUF(SIZE(e820map));
01fc30
+	if (CRASHDEBUG(1)) {
01fc30
+		if (STRUCT_EXISTS("e820map"))
01fc30
+			dump_struct("e820map", e820, RADIX(16));
01fc30
+		else if (STRUCT_EXISTS("e820_table"))
01fc30
+			dump_struct("e820_table", e820, RADIX(16));
01fc30
+	}
01fc30
+        buf = (char *)GETBUF(SIZE(e820map));
01fc30
 
01fc30
-        readmem(e820, KVADDR, &buf[0], SIZE(e820map), 
01fc30
-		"e820map", FAULT_ON_ERROR);
01fc30
+        readmem(e820, KVADDR, &buf[0], SIZE(e820map),
01fc30
+                "e820map", FAULT_ON_ERROR);
01fc30
 
01fc30
-	nr_map = INT(buf + OFFSET(e820map_nr_map));
01fc30
+        nr_map = INT(buf + OFFSET(e820map_nr_map));
01fc30
 
01fc30
-	fprintf(fp, "      PHYSICAL ADDRESS RANGE         TYPE\n");
01fc30
+        fprintf(fp, "      PHYSICAL ADDRESS RANGE         TYPE\n");
01fc30
 
01fc30
-	for (i = 0; i < nr_map; i++) {
01fc30
-		e820entry_ptr = buf + sizeof(int) + (SIZE(e820entry) * i);
01fc30
-		addr = ULONGLONG(e820entry_ptr + OFFSET(e820entry_addr));
01fc30
-		size = ULONGLONG(e820entry_ptr + OFFSET(e820entry_size));
01fc30
-		type = ULONG(e820entry_ptr + OFFSET(e820entry_type));
01fc30
+        for (i = 0; i < nr_map; i++) {
01fc30
+                e820entry_ptr = buf + sizeof(int) + (SIZE(e820entry) * i);
01fc30
+                addr = ULONGLONG(e820entry_ptr + OFFSET(e820entry_addr));
01fc30
+                size = ULONGLONG(e820entry_ptr + OFFSET(e820entry_size));
01fc30
+                type = UINT(e820entry_ptr + OFFSET(e820entry_type));
01fc30
 		fprintf(fp, "%016llx - %016llx  ", addr, addr+size);
01fc30
-		if (type >= (sizeof(e820type)/sizeof(char *)))
01fc30
-			fprintf(fp, "type %ld\n", type);
01fc30
-		else
01fc30
+		if (type >= (sizeof(e820type)/sizeof(char *))) {
01fc30
+			if (type == 12)
01fc30
+				fprintf(fp, "E820_PRAM\n");
01fc30
+			else if (type == 128)
01fc30
+				fprintf(fp, "E820_RESERVED_KERN\n");
01fc30
+			else
01fc30
+				fprintf(fp, "type %d\n", type);
01fc30
+		} else
01fc30
 			fprintf(fp, "%s\n", e820type[type]);
01fc30
-	}
01fc30
+        }
01fc30
 }
01fc30
 
01fc30
 /*
01fc30
diff --git a/x86_64.c b/x86_64.c
01fc30
index 921552b..1d5e155 100644
01fc30
--- a/x86_64.c
01fc30
+++ b/x86_64.c
01fc30
@@ -415,12 +415,26 @@ x86_64_init(int when)
01fc30
 			STRUCT_SIZE_INIT(gate_struct, "gate_desc");
01fc30
 		else
01fc30
 			STRUCT_SIZE_INIT(gate_struct, "gate_struct");
01fc30
-                STRUCT_SIZE_INIT(e820map, "e820map");
01fc30
-                STRUCT_SIZE_INIT(e820entry, "e820entry");
01fc30
-                MEMBER_OFFSET_INIT(e820map_nr_map, "e820map", "nr_map");
01fc30
-                MEMBER_OFFSET_INIT(e820entry_addr, "e820entry", "addr");
01fc30
-                MEMBER_OFFSET_INIT(e820entry_size, "e820entry", "size");
01fc30
-                MEMBER_OFFSET_INIT(e820entry_type, "e820entry", "type");
01fc30
+
01fc30
+		if (STRUCT_EXISTS("e820map")) {
01fc30
+			STRUCT_SIZE_INIT(e820map, "e820map");
01fc30
+			MEMBER_OFFSET_INIT(e820map_nr_map, "e820map", "nr_map");
01fc30
+		} else {
01fc30
+			STRUCT_SIZE_INIT(e820map, "e820_table");
01fc30
+			MEMBER_OFFSET_INIT(e820map_nr_map, "e820_table", "nr_entries");
01fc30
+		}
01fc30
+		if (STRUCT_EXISTS("e820entry")) {
01fc30
+			STRUCT_SIZE_INIT(e820entry, "e820entry");
01fc30
+			MEMBER_OFFSET_INIT(e820entry_addr, "e820entry", "addr");
01fc30
+			MEMBER_OFFSET_INIT(e820entry_size, "e820entry", "size");
01fc30
+			MEMBER_OFFSET_INIT(e820entry_type, "e820entry", "type");
01fc30
+		} else {
01fc30
+			STRUCT_SIZE_INIT(e820entry, "e820_entry");
01fc30
+			MEMBER_OFFSET_INIT(e820entry_addr, "e820_entry", "addr");
01fc30
+			MEMBER_OFFSET_INIT(e820entry_size, "e820_entry", "size");
01fc30
+			MEMBER_OFFSET_INIT(e820entry_type, "e820_entry", "type");
01fc30
+		}
01fc30
+
01fc30
 		if (KVMDUMP_DUMPFILE())
01fc30
 			set_kvm_iohole(NULL);
01fc30
 		MEMBER_OFFSET_INIT(thread_struct_rip, "thread_struct", "rip");
01fc30
@@ -5643,12 +5657,23 @@ x86_64_display_memmap(void)
01fc30
         ulonglong addr, size;
01fc30
         uint type;
01fc30
 
01fc30
-	if (get_symbol_type("e820", NULL, NULL) == TYPE_CODE_PTR)
01fc30
-		get_symbol_data("e820", sizeof(void *), &e820);
01fc30
+	if (kernel_symbol_exists("e820")) {
01fc30
+		if (get_symbol_type("e820", NULL, NULL) == TYPE_CODE_PTR)
01fc30
+			get_symbol_data("e820", sizeof(void *), &e820);
01fc30
+		else
01fc30
+			e820 = symbol_value("e820");
01fc30
+
01fc30
+	} else if (kernel_symbol_exists("e820_table"))
01fc30
+		get_symbol_data("e820_table", sizeof(void *), &e820);
01fc30
 	else
01fc30
-		e820 = symbol_value("e820");
01fc30
-	if (CRASHDEBUG(1))
01fc30
-		dump_struct("e820map", e820, RADIX(16));
01fc30
+		error(FATAL, "neither e820 or e820_table symbols exist\n");
01fc30
+
01fc30
+	if (CRASHDEBUG(1)) {
01fc30
+		if (STRUCT_EXISTS("e820map"))
01fc30
+			dump_struct("e820map", e820, RADIX(16));
01fc30
+		else if (STRUCT_EXISTS("e820_table"))
01fc30
+			dump_struct("e820_table", e820, RADIX(16));
01fc30
+	}
01fc30
         buf = (char *)GETBUF(SIZE(e820map));
01fc30
 
01fc30
         readmem(e820, KVADDR, &buf[0], SIZE(e820map),
01fc30
@@ -5664,9 +5689,14 @@ x86_64_display_memmap(void)
01fc30
                 size = ULONGLONG(e820entry_ptr + OFFSET(e820entry_size));
01fc30
                 type = UINT(e820entry_ptr + OFFSET(e820entry_type));
01fc30
 		fprintf(fp, "%016llx - %016llx  ", addr, addr+size);
01fc30
-		if (type >= (sizeof(e820type)/sizeof(char *)))
01fc30
-			fprintf(fp, "type %d\n", type);
01fc30
-		else
01fc30
+		if (type >= (sizeof(e820type)/sizeof(char *))) {
01fc30
+			if (type == 12)
01fc30
+				fprintf(fp, "E820_PRAM\n");
01fc30
+			else if (type == 128)
01fc30
+				fprintf(fp, "E820_RESERVED_KERN\n");
01fc30
+			else
01fc30
+				fprintf(fp, "type %d\n", type);
01fc30
+		} else
01fc30
 			fprintf(fp, "%s\n", e820type[type]);
01fc30
         }
01fc30
 }