File: symbols.c

package info (click to toggle)
kexec-tools 1%3A2.0.29-2
  • links: PTS
  • area: main
  • in suites: trixie
  • size: 3,040 kB
  • sloc: ansic: 29,720; sh: 3,553; asm: 2,625; cpp: 1,753; makefile: 964
file content (36 lines) | stat: -rw-r--r-- 765 bytes parent folder | download | duplicates (4)
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
35
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;
}