Blame SOURCES/0001-x86-Fix-failure-of-collecting-vsyscall-mapping-due-t.patch

a5fab1
From 03f9360715731f18e4fdae7b30aa34b30dddcd57 Mon Sep 17 00:00:00 2001
a5fab1
From: HATAYAMA Daisuke <d.hatayama@fujitsu.com>
a5fab1
Date: Sat, 26 Mar 2022 21:42:02 +0900
a5fab1
Subject: [PATCH 1/5] x86: Fix failure of collecting vsyscall mapping due to
a5fab1
 change of enum type of vsyscall_mode
a5fab1
a5fab1
vsyscall mapping fails to get collected because the commit
a5fab1
bd49e16e3339 (x86/vsyscall: Add a new vsyscall=xonly mode) merged at
a5fab1
kernel v5.2-rc7 added constant XONLY to the anonymous enumeration type
a5fab1
of variable vsyscall_mode, which made the value of constant NONE
a5fab1
change from 1 to 2.
a5fab1
a5fab1
This commit fixes the issue by checking the value of constant NONE
a5fab1
using gdb's print command and typeof operator since there's no utility
a5fab1
function to handle such anonymous enumeration type currently in crash
a5fab1
utility.
a5fab1
a5fab1
Signed-off-by: HATAYAMA Daisuke <d.hatayama@fujitsu.com>
a5fab1
Signed-off-by: Lianbo Jiang <lijiang@redhat.com>
a5fab1
---
a5fab1
 src/libgcore/gcore_x86.c | 56 ++++++++++++++++++++++++++++++++++++++--
a5fab1
 1 file changed, 54 insertions(+), 2 deletions(-)
a5fab1
a5fab1
diff --git a/src/libgcore/gcore_x86.c b/src/libgcore/gcore_x86.c
a5fab1
index 08e573c741f6..f334a85d4240 100644
a5fab1
--- a/src/libgcore/gcore_x86.c
a5fab1
+++ b/src/libgcore/gcore_x86.c
a5fab1
@@ -41,6 +41,9 @@ struct gcore_x86_table
a5fab1
 static struct gcore_x86_table gcore_x86_table;
a5fab1
 struct gcore_x86_table *gxt = &gcore_x86_table;
a5fab1
 
a5fab1
+static void gdb_run_command(char *cmd, char *buf, size_t size);
a5fab1
+static int get_vsyscall_mode_none(void);
a5fab1
+
a5fab1
 #ifdef X86_64
a5fab1
 static ulong gcore_x86_64_get_old_rsp(int cpu);
a5fab1
 static ulong gcore_x86_64_get_per_cpu__old_rsp(int cpu);
a5fab1
@@ -2367,6 +2370,54 @@ int gcore_is_arch_32bit_emulation(struct task_context *tc)
a5fab1
 	return FALSE;
a5fab1
 }
a5fab1
 
a5fab1
+static void gdb_run_command(char *cmd, char *buf, size_t size)
a5fab1
+{
a5fab1
+	open_tmpfile();
a5fab1
+	if (!gdb_pass_through(cmd,
a5fab1
+			      pc->tmpfile,
a5fab1
+			      GNU_RETURN_ON_ERROR)) {
a5fab1
+		close_tmpfile();
a5fab1
+		error(FATAL, "gdb command failed: %s", cmd);
a5fab1
+	}
a5fab1
+	rewind(pc->tmpfile);
a5fab1
+	fgets(buf, size, pc->tmpfile);
a5fab1
+	close_tmpfile();
a5fab1
+}
a5fab1
+
a5fab1
+static int get_vsyscall_mode_none(void)
a5fab1
+{
a5fab1
+	static int none = -1;
a5fab1
+	char cmd[32], buf[BUFSIZE];
a5fab1
+	int i;
a5fab1
+
a5fab1
+	if (none != -1)
a5fab1
+		return none;
a5fab1
+
a5fab1
+	/*
a5fab1
+	 * Variable vsyscall_mode is of anonymous enumeration
a5fab1
+	 * type. Because there's no utility function in crash utility
a5fab1
+	 * to get value of each constant in specified anonymous
a5fab1
+	 * enumeration type, we have no choice but rely on gdb's print
a5fab1
+	 * command in combination with typeof operator.
a5fab1
+	 */
a5fab1
+	for (i = 0; i < 10; ++i) {
a5fab1
+		snprintf(cmd, sizeof(cmd), "p (typeof(vsyscall_mode))%d", i);
a5fab1
+		gdb_run_command(cmd, buf, sizeof(buf));
a5fab1
+		if (strstr(buf, "NONE"))
a5fab1
+			return none = i;
a5fab1
+	}
a5fab1
+
a5fab1
+	/*
a5fab1
+	 * When the above logic doesn't work as expected, use 2, which
a5fab1
+	 * is the value on the definition where vsyscall_mode was
a5fab1
+	 * first introduced at the commit 3ae36655b97a (x86-64: Rework
a5fab1
+	 * vsyscall emulation and add vsyscall= parameter).
a5fab1
+	 */
a5fab1
+	none = 2;
a5fab1
+
a5fab1
+	return none;
a5fab1
+}
a5fab1
+
a5fab1
 /**
a5fab1
  * Return an address to gate_vma.
a5fab1
  */
a5fab1
@@ -2377,7 +2428,8 @@ ulong gcore_arch_get_gate_vma(void)
a5fab1
 		return 0UL;
a5fab1
 
a5fab1
 	if (symbol_exists("vsyscall_mode")) {
a5fab1
-		enum { ENUMERATE, NONE } vsyscall_mode;
a5fab1
+		int vsyscall_mode;
a5fab1
+		int none = get_vsyscall_mode_none();
a5fab1
 
a5fab1
 		readmem(symbol_value("vsyscall_mode"),
a5fab1
 			KVADDR,
a5fab1
@@ -2386,7 +2438,7 @@ ulong gcore_arch_get_gate_vma(void)
a5fab1
 			"gcore_arch_get_gate_vma: vsyscall_mode",
a5fab1
 			gcore_verbose_error_handle());
a5fab1
 
a5fab1
-		if (vsyscall_mode == NONE)
a5fab1
+		if (vsyscall_mode == none)
a5fab1
 			return 0UL;
a5fab1
 	}
a5fab1
 
a5fab1
-- 
a5fab1
2.37.1
a5fab1