xref: /minix/sys/sys/ksyms.h (revision 84d9c625)
1 /*	$NetBSD: ksyms.h,v 1.28 2012/11/18 00:06:56 chs Exp $	*/
2 
3 /*
4  * Copyright (c) 2001, 2003 Anders Magnusson (ragge@ludd.luth.se).
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. The name of the author may not be used to endorse or promote products
16  *    derived from this software without specific prior written permission
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #ifndef _SYS_KSYMS_H_
31 #define _SYS_KSYMS_H_
32 
33 #ifdef _KSYMS_PRIVATE
34 
35 #define	ELFSIZE	ARCH_ELFSIZE
36 #include <sys/exec_elf.h>
37 #include <sys/queue.h>
38 
39 struct ksyms_symtab {
40 	TAILQ_ENTRY(ksyms_symtab) sd_queue; /* All active tables */
41 	const char *sd_name;	/* Name of this table */
42 	Elf_Sym *sd_symstart;	/* Address of symbol table */
43 	uintptr_t sd_minsym;	/* symbol with minimum value */
44 	uintptr_t sd_maxsym;	/* symbol with maximum value */
45 	char *sd_strstart;	/* Address of corresponding string table */
46 	int sd_usroffset;	/* Real address for userspace */
47 	int sd_symsize;		/* Size in bytes of symbol table */
48 	int sd_strsize;		/* Size of string table */
49 	int sd_nglob;		/* Number of global symbols */
50 	bool sd_gone;		/* dead but around for open() */
51 	void *sd_ctfstart;	/* Address of CTF contents */
52 	int sd_ctfsize;		/* Size in bytes of CTF contents */
53 	uint32_t *sd_nmap;	/* Name map for sorted symbols */
54 	int sd_nmapsize;	/* Total span of map */
55 };
56 
57 /*
58  * Static allocated ELF header.
59  * Basic info is filled in at attach, sizes at open.
60  */
61 #define	SYMTAB		1
62 #define	STRTAB		2
63 #define	SHSTRTAB	3
64 #define	SHBSS		4
65 #define	SHCTF		5
66 #define NSECHDR		6
67 
68 #define	NPRGHDR		1
69 #define	SHSTRSIZ	42
70 
71 struct ksyms_hdr {
72 	Elf_Ehdr	kh_ehdr;
73 	Elf_Phdr	kh_phdr[NPRGHDR];
74 	Elf_Shdr	kh_shdr[NSECHDR];
75 	char 		kh_strtab[SHSTRSIZ];
76 };
77 #endif	/* _KSYMS_PRIVATE */
78 
79 /*
80  * Do a lookup of a symbol using the in-kernel lookup algorithm.
81  */
82 struct ksyms_gsymbol {
83 	const char *kg_name;
84 	union {
85 		void *ku_sym;		 /* Normally Elf_Sym */
86 		unsigned long *ku_value;
87 	} _un;
88 #define	kg_sym _un.ku_sym
89 #define	kg_value _un.ku_value
90 };
91 
92 #define	KIOCGSYMBOL	_IOW('l', 1, struct ksyms_gsymbol)
93 #define	KIOCGVALUE	_IOW('l', 2, struct ksyms_gsymbol)
94 #define	KIOCGSIZE	_IOR('l', 3, int)
95 
96 
97 #if defined(_KERNEL) || defined(_KMEMUSER)
98 /*
99  * Definitions used in ksyms_getname() and ksyms_getval().
100  */
101 #define	KSYMS_CLOSEST	0001	/* Nearest lower match */
102 #define	KSYMS_EXACT	0002	/* Only exact match allowed */
103 #define KSYMS_EXTERN	0000	/* Only external symbols (pseudo) */
104 #define KSYMS_PROC	0100	/* Procedures only */
105 #define KSYMS_ANY	0200	/* Also local symbols (DDB use only) */
106 
107 typedef int (*ksyms_callback_t)(const char *, int, void *,
108 	uint32_t, int, void *);
109 
110 /*
111  * Prototypes
112  */
113 
114 int ksyms_getname(const char **, const char **, vaddr_t, int);
115 int ksyms_getval(const char *, const char *, unsigned long *, int);
116 int ksyms_getval_unlocked(const char *, const char *, unsigned long *, int);
117 struct ksyms_symtab *ksyms_get_mod(const char *);
118 int ksyms_mod_foreach(const char *mod, ksyms_callback_t, void *);
119 int ksyms_addsymtab(const char *, void *, vsize_t, char *, vsize_t);
120 int ksyms_delsymtab(const char *);
121 void ksyms_init(void);
122 void ksyms_addsyms_elf(int, void *, void *);
123 void ksyms_addsyms_explicit(void *, void *, size_t, void *, size_t);
124 int ksyms_sift(char *, char *, int);
125 void ksyms_modload(const char *, void *, vsize_t, char *, vsize_t);
126 void ksyms_modunload(const char *);
127 
128 #endif /* _KERNEL */
129 #endif /* _SYS_KSYMS_H_ */
130