summaryrefslogtreecommitdiffstats
path: root/mdk-stage1/insmod-modutils/include/kallsyms.h
blob: 9748873cfaea0deff670adf8560f029c880b1fb0 (plain)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/* kallsyms headers
   Copyright 2000 Keith Owens <kaos@ocs.com.au>

   This file is part of the Linux modutils.  It is exported to kernel
   space so debuggers can access the kallsyms data.

   The kallsyms data contains all the non-stack symbols from a kernel
   or a module.  The kernel symbols are held between __start___kallsyms
   and __stop___kallsyms.  The symbols for a module are accessed via
   the struct module chain which is based at module_list.

   This program is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by the
   Free Software Foundation; either version 2 of the License, or (at your
   option) any later version.

   This program is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software Foundation,
   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#ident "$Id$"

#ifndef MODUTILS_KALLSYMS_H
#define MODUTILS_KALLSYMS_H 1

/* Have to (re)define these ElfW entries here because external kallsyms
 * code does not have access to modutils/include/obj.h.  This code is
 * included from user spaces tools (modutils) and kernel, they need
 * different includes.
 */

#ifndef ELFCLASS32
#ifdef __KERNEL__
#include <linux/elf.h>
#else	/* __KERNEL__ */
#include <elf.h>
#endif	/* __KERNEL__ */
#endif	/* ELFCLASS32 */

#ifndef ELFCLASSM
#define ELFCLASSM ELF_CLASS
#endif

#ifndef ElfW
# if ELFCLASSM == ELFCLASS32
#  define ElfW(x)  Elf32_ ## x
#  define ELFW(x)  ELF32_ ## x
# else
#  define ElfW(x)  Elf64_ ## x
#  define ELFW(x)  ELF64_ ## x
# endif
#endif

/* Format of data in the kallsyms section.
 * Most of the fields are small numbers but the total size and all
 * offsets can be large so use the 32/64 bit types for these fields.
 *
 * Do not use sizeof() on these structures, modutils may be using extra
 * fields.  Instead use the size fields in the header to access the
 * other bits of data.
 */  

struct kallsyms_header {
	int		size;		/* Size of this header */
	ElfW(Word)	total_size;	/* Total size of kallsyms data */
	int		sections;	/* Number of section entries */
	ElfW(Off)	section_off;	/* Offset to first section entry */
	int		section_size;	/* Size of one section entry */
	int		symbols;	/* Number of symbol entries */
	ElfW(Off)	symbol_off;	/* Offset to first symbol entry */
	int		symbol_size;	/* Size of one symbol entry */
	ElfW(Off)	string_off;	/* Offset to first string */
	ElfW(Addr)	start;		/* Start address of first section */
	ElfW(Addr)	end;		/* End address of last section */
};

struct kallsyms_section {
	ElfW(Addr)	start;		/* Start address of section */
	ElfW(Word)	size;		/* Size of this section */
	ElfW(Off)	name_off;	/* Offset to section name */
	ElfW(Word)	flags;		/* Flags from section */
};

struct kallsyms_symbol {
	ElfW(Off)	section_off;	/* Offset to section that owns this symbol */
	ElfW(Addr)	symbol_addr;	/* Address of symbol */
	ElfW(Off)	name_off;	/* Offset to symbol name */
};

#define KALLSYMS_SEC_NAME "__kallsyms"
#define KALLSYMS_IDX 2			/* obj_kallsyms creates kallsyms as section 2 */

#define kallsyms_next_sec(h,s) \
	((s) = (struct kallsyms_section *)((char *)(s) + (h)->section_size))
#define kallsyms_next_sym(h,s) \
	((s) = (struct kallsyms_symbol *)((char *)(s) + (h)->symbol_size))

int kallsyms_symbol_to_address(
	const char       *name,			/* Name to lookup */
	unsigned long    *token,		/* Which module to start with */
	const char      **mod_name,		/* Set to module name or "kernel" */
	unsigned long    *mod_start,		/* Set to start address of module */
	unsigned long    *mod_end,		/* Set to end address of module */
	const char      **sec_name,		/* Set to section name */
	unsigned long    *sec_start,		/* Set to start address of section */
	unsigned long    *sec_end,		/* Set to end address of section */
	const char      **sym_name,		/* Set to full symbol name */
	unsigned long    *sym_start,		/* Set to start address of symbol */
	unsigned long    *sym_end		/* Set to end address of symbol */
	);

int kallsyms_address_to_symbol(
	unsigned long     address,		/* Address to lookup */
	const char      **mod_name,		/* Set to module name */
	unsigned long    *mod_start,		/* Set to start address of module */
	unsigned long    *mod_end,		/* Set to end address of module */
	const char      **sec_name,		/* Set to section name */
	unsigned long    *sec_start,		/* Set to start address of section */
	unsigned long    *sec_end,		/* Set to end address of section */
	const char      **sym_name,		/* Set to full symbol name */
	unsigned long    *sym_start,		/* Set to start address of symbol */
	unsigned long    *sym_end		/* Set to end address of symbol */
	);

#endif /* kallsyms.h */