summaryrefslogtreecommitdiffstats
path: root/kexec/symbols.c
diff options
context:
space:
mode:
Diffstat (limited to 'kexec/symbols.c')
-rw-r--r--kexec/symbols.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/kexec/symbols.c b/kexec/symbols.c
new file mode 100644
index 0000000..04377ca
--- /dev/null
+++ b/kexec/symbols.c
@@ -0,0 +1,36 @@
+#include <stdio.h>
+#include <string.h>
+#include "kexec.h"
+
+/* Retrieve kernel symbol virtual address from /proc/kallsyms */
+unsigned long long get_kernel_sym(const char *symbol)
+{
+ const char *kallsyms = "/proc/kallsyms";
+ char sym[128];
+ char line[128];
+ FILE *fp;
+ unsigned long long vaddr;
+ char type;
+
+ 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, "%llx %c %s", &vaddr, &type, sym) != 3)
+ continue;
+ if (strcmp(sym, symbol) == 0) {
+ dbgprintf("kernel symbol %s vaddr = %16llx\n",
+ symbol, vaddr);
+ fclose(fp);
+ return vaddr;
+ }
+ }
+
+ dbgprintf("Cannot get kernel %s symbol address\n", symbol);
+
+ fclose(fp);
+ return 0;
+}