summaryrefslogtreecommitdiff
path: root/scripts/kallsyms.h
blob: 4b2801ba628593ee2fcf5995adef6a33a8aeae0a (plain) (blame)
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
37
38
39
40
41
42
43
44
/* SPDX-License-Identifier: GPL-2.0 */
#ifndef KALLSYMS_H
#define KALLSYMS_H

#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>

#include <array_size.h>
#include "elf-parse.h"

static inline bool string_starts_with(const char *s, const char *prefix)
{
	return strncmp(s, prefix, strlen(prefix)) == 0;
}

static inline bool string_ends_with(const char *s, const char *suffix)
{
	size_t len = strlen(s), suffix_len = strlen(suffix);

	return len >= suffix_len && strcmp(s + len - suffix_len, suffix) == 0;
}

/* A symbol as nm lists it. */
struct sysmap_symbol {
	unsigned long long addr;
	const char *name;
	char type;
};

/* The symbols of an ELF file that System.map lists, in its order. */
struct sysmap {
	struct sysmap_symbol *syms;
	size_t nr_syms;
	int addr_width;		/* hex digits of an address */
	struct elf_file elf;	/* the mapping the names point into */
};

struct sysmap *sysmap_read(const char *path);
void sysmap_write(const struct sysmap *map, FILE *out);
void sysmap_free(struct sysmap *map);

#endif /* KALLSYMS_H */