File: symbols.c

package info (click to toggle)
kexec-tools 1%3A2.0.20-2.1
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 2,828 kB
  • sloc: ansic: 27,201; sh: 3,486; asm: 2,625; cpp: 1,752; makefile: 930
file content (34 lines) | stat: -rw-r--r-- 737 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#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);
			return vaddr;
		}
	}

	dbgprintf("Cannot get kernel %s symbol address\n", symbol);

	return 0;
}