kern_ksyms.c revision 1.44 1 1.44 ad /* $NetBSD: kern_ksyms.c,v 1.44 2008/11/16 15:28:15 ad Exp $ */
2 1.38 skrll
3 1.39 ad /*-
4 1.39 ad * Copyright (c) 2008 The NetBSD Foundation, Inc.
5 1.39 ad * All rights reserved.
6 1.39 ad *
7 1.39 ad * This code is derived from software developed for The NetBSD Foundation
8 1.39 ad * by Andrew Doran.
9 1.39 ad *
10 1.39 ad * Redistribution and use in source and binary forms, with or without
11 1.39 ad * modification, are permitted provided that the following conditions
12 1.39 ad * are met:
13 1.39 ad * 1. Redistributions of source code must retain the above copyright
14 1.39 ad * notice, this list of conditions and the following disclaimer.
15 1.39 ad * 2. Redistributions in binary form must reproduce the above copyright
16 1.39 ad * notice, this list of conditions and the following disclaimer in the
17 1.39 ad * documentation and/or other materials provided with the distribution.
18 1.39 ad *
19 1.39 ad * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.39 ad * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.39 ad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.39 ad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.39 ad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.39 ad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.39 ad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.39 ad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.39 ad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.39 ad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.39 ad * POSSIBILITY OF SUCH DAMAGE.
30 1.39 ad */
31 1.39 ad
32 1.1 ragge /*
33 1.1 ragge * Copyright (c) 2001, 2003 Anders Magnusson (ragge (at) ludd.luth.se).
34 1.1 ragge * All rights reserved.
35 1.1 ragge *
36 1.1 ragge * Redistribution and use in source and binary forms, with or without
37 1.1 ragge * modification, are permitted provided that the following conditions
38 1.1 ragge * are met:
39 1.1 ragge * 1. Redistributions of source code must retain the above copyright
40 1.1 ragge * notice, this list of conditions and the following disclaimer.
41 1.1 ragge * 2. Redistributions in binary form must reproduce the above copyright
42 1.1 ragge * notice, this list of conditions and the following disclaimer in the
43 1.1 ragge * documentation and/or other materials provided with the distribution.
44 1.1 ragge * 3. The name of the author may not be used to endorse or promote products
45 1.1 ragge * derived from this software without specific prior written permission
46 1.1 ragge *
47 1.1 ragge * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
48 1.1 ragge * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
49 1.1 ragge * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
50 1.1 ragge * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
51 1.1 ragge * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
52 1.1 ragge * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
53 1.1 ragge * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
54 1.1 ragge * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
55 1.1 ragge * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
56 1.1 ragge * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
57 1.1 ragge */
58 1.1 ragge
59 1.1 ragge /*
60 1.1 ragge * Code to deal with in-kernel symbol table management + /dev/ksyms.
61 1.1 ragge *
62 1.1 ragge * For each loaded module the symbol table info is kept track of by a
63 1.1 ragge * struct, placed in a circular list. The first entry is the kernel
64 1.1 ragge * symbol table.
65 1.1 ragge */
66 1.1 ragge
67 1.1 ragge /*
68 1.1 ragge * TODO:
69 1.1 ragge *
70 1.39 ad * Add support for mmap, poll.
71 1.1 ragge */
72 1.11 jdolecek
73 1.11 jdolecek #include <sys/cdefs.h>
74 1.44 ad __KERNEL_RCSID(0, "$NetBSD: kern_ksyms.c,v 1.44 2008/11/16 15:28:15 ad Exp $");
75 1.1 ragge
76 1.1 ragge #ifdef _KERNEL
77 1.1 ragge #include "opt_ddb.h"
78 1.3 ragge #include "opt_ddbparam.h" /* for SYMTAB_SPACE */
79 1.1 ragge #endif
80 1.1 ragge
81 1.39 ad #define _KSYMS_PRIVATE
82 1.39 ad
83 1.1 ragge #include <sys/param.h>
84 1.1 ragge #include <sys/errno.h>
85 1.1 ragge #include <sys/queue.h>
86 1.1 ragge #include <sys/exec.h>
87 1.1 ragge #include <sys/systm.h>
88 1.1 ragge #include <sys/conf.h>
89 1.1 ragge #include <sys/malloc.h>
90 1.39 ad #include <sys/kmem.h>
91 1.1 ragge #include <sys/proc.h>
92 1.39 ad #include <sys/module.h>
93 1.39 ad #include <sys/atomic.h>
94 1.1 ragge #include <sys/ksyms.h>
95 1.1 ragge
96 1.1 ragge #include <lib/libkern/libkern.h>
97 1.1 ragge
98 1.1 ragge #ifdef DDB
99 1.1 ragge #include <ddb/db_output.h>
100 1.1 ragge #endif
101 1.1 ragge
102 1.1 ragge #include "ksyms.h"
103 1.1 ragge
104 1.39 ad static int ksyms_maxlen;
105 1.39 ad static bool ksyms_isopen;
106 1.39 ad static bool ksyms_initted;
107 1.39 ad static struct ksyms_hdr ksyms_hdr;
108 1.40 christos static kmutex_t ksyms_lock;
109 1.1 ragge
110 1.39 ad void ksymsattach(int);
111 1.40 christos static void ksyms_hdr_init(void *);
112 1.1 ragge static void ksyms_sizes_calc(void);
113 1.1 ragge
114 1.1 ragge #ifdef KSYMS_DEBUG
115 1.1 ragge #define FOLLOW_CALLS 1
116 1.1 ragge #define FOLLOW_MORE_CALLS 2
117 1.1 ragge #define FOLLOW_DEVKSYMS 4
118 1.1 ragge static int ksyms_debug;
119 1.1 ragge #endif
120 1.1 ragge
121 1.3 ragge #ifdef SYMTAB_SPACE
122 1.3 ragge #define SYMTAB_FILLER "|This is the symbol table!"
123 1.3 ragge
124 1.3 ragge char db_symtab[SYMTAB_SPACE] = SYMTAB_FILLER;
125 1.3 ragge int db_symtabsize = SYMTAB_SPACE;
126 1.3 ragge #endif
127 1.1 ragge
128 1.39 ad int ksyms_symsz;
129 1.39 ad int ksyms_strsz;
130 1.39 ad TAILQ_HEAD(, ksyms_symtab) ksyms_symtabs =
131 1.39 ad TAILQ_HEAD_INITIALIZER(ksyms_symtabs);
132 1.39 ad static struct ksyms_symtab kernel_symtab;
133 1.1 ragge
134 1.33 christos static int
135 1.33 christos ksyms_verify(void *symstart, void *strstart)
136 1.33 christos {
137 1.33 christos #if defined(DIAGNOSTIC) || defined(DEBUG)
138 1.33 christos if (symstart == NULL)
139 1.33 christos printf("ksyms: Symbol table not found\n");
140 1.33 christos if (strstart == NULL)
141 1.33 christos printf("ksyms: String table not found\n");
142 1.33 christos if (symstart == NULL || strstart == NULL)
143 1.33 christos printf("ksyms: Perhaps the kernel is stripped?\n");
144 1.33 christos #endif
145 1.33 christos if (symstart == NULL || strstart == NULL)
146 1.33 christos return 0;
147 1.33 christos KASSERT(symstart <= strstart);
148 1.33 christos return 1;
149 1.33 christos }
150 1.33 christos
151 1.8 ragge /*
152 1.43 ad * Finds a certain symbol name in a certain symbol table.
153 1.8 ragge */
154 1.43 ad static Elf_Sym *
155 1.43 ad findsym(const char *name, struct ksyms_symtab *table, int type)
156 1.8 ragge {
157 1.43 ad Elf_Sym *sym, *maxsym;
158 1.43 ad int low, mid, high, nglob;
159 1.43 ad char *str, *cmp;
160 1.43 ad
161 1.43 ad sym = table->sd_symstart;
162 1.43 ad str = table->sd_strstart - table->sd_usroffset;
163 1.43 ad nglob = table->sd_nglob;
164 1.43 ad low = 0;
165 1.43 ad high = nglob;
166 1.8 ragge
167 1.43 ad /*
168 1.43 ad * Start with a binary search of all global symbols in this table.
169 1.43 ad * Global symbols must have unique names.
170 1.43 ad */
171 1.43 ad while (low < high) {
172 1.43 ad mid = (low + high) >> 1;
173 1.43 ad cmp = sym[mid].st_name + str;
174 1.43 ad if (cmp[0] < name[0] || strcmp(cmp, name) < 0) {
175 1.43 ad low = mid + 1;
176 1.43 ad } else {
177 1.43 ad high = mid;
178 1.43 ad }
179 1.8 ragge }
180 1.43 ad KASSERT(low == high);
181 1.43 ad if (__predict_true(low < nglob &&
182 1.43 ad strcmp(sym[low].st_name + str, name) == 0)) {
183 1.43 ad KASSERT(ELF_ST_BIND(sym[low].st_info) == STB_GLOBAL);
184 1.43 ad return &sym[low];
185 1.8 ragge }
186 1.8 ragge
187 1.43 ad /*
188 1.43 ad * Perform a linear search of local symbols (rare). Many local
189 1.43 ad * symbols with the same name can exist so are not included in
190 1.43 ad * the binary search.
191 1.43 ad */
192 1.43 ad if (type != KSYMS_EXTERN) {
193 1.43 ad maxsym = sym + table->sd_symsize / sizeof(Elf_Sym);
194 1.43 ad for (sym += nglob; sym < maxsym; sym++) {
195 1.43 ad if (strcmp(name, sym->st_name + str) == 0) {
196 1.43 ad return sym;
197 1.43 ad }
198 1.43 ad }
199 1.1 ragge }
200 1.1 ragge return NULL;
201 1.1 ragge }
202 1.1 ragge
203 1.1 ragge /*
204 1.1 ragge * The "attach" is in reality done in ksyms_init().
205 1.1 ragge */
206 1.1 ragge void
207 1.30 yamt ksymsattach(int arg)
208 1.1 ragge {
209 1.42 ad
210 1.1 ragge }
211 1.1 ragge
212 1.1 ragge /*
213 1.29 jmmv * Add a symbol table.
214 1.29 jmmv * This is intended for use when the symbol table and its corresponding
215 1.29 jmmv * string table are easily available. If they are embedded in an ELF
216 1.29 jmmv * image, use addsymtab_elf() instead.
217 1.29 jmmv *
218 1.29 jmmv * name - Symbol's table name.
219 1.29 jmmv * symstart, symsize - Address and size of the symbol table.
220 1.29 jmmv * strstart, strsize - Address and size of the string table.
221 1.29 jmmv * tab - Symbol table to be updated with this information.
222 1.29 jmmv * newstart - Address to which the symbol table has to be copied during
223 1.29 jmmv * shrinking. If NULL, it is not moved.
224 1.1 ragge */
225 1.43 ad static const char *addsymtab_strstart;
226 1.43 ad
227 1.43 ad static int
228 1.43 ad addsymtab_compar(const void *a, const void *b)
229 1.43 ad {
230 1.43 ad const Elf_Sym *sa, *sb;
231 1.43 ad
232 1.43 ad sa = a;
233 1.43 ad sb = b;
234 1.43 ad
235 1.43 ad /*
236 1.43 ad * Split the symbol table into two, with globals at the start
237 1.43 ad * and locals at the end.
238 1.43 ad */
239 1.43 ad if (ELF_ST_BIND(sa->st_info) != ELF_ST_BIND(sb->st_info)) {
240 1.43 ad if (ELF_ST_BIND(sa->st_info) == STB_GLOBAL) {
241 1.43 ad return -1;
242 1.43 ad }
243 1.43 ad if (ELF_ST_BIND(sb->st_info) == STB_GLOBAL) {
244 1.43 ad return 1;
245 1.43 ad }
246 1.43 ad }
247 1.43 ad
248 1.43 ad /* Within each band, sort by name. */
249 1.43 ad return strcmp(sa->st_name + addsymtab_strstart,
250 1.43 ad sb->st_name + addsymtab_strstart);
251 1.43 ad }
252 1.43 ad
253 1.1 ragge static void
254 1.39 ad addsymtab(const char *name, void *symstart, size_t symsize,
255 1.39 ad void *strstart, size_t strsize, struct ksyms_symtab *tab,
256 1.39 ad void *newstart)
257 1.1 ragge {
258 1.8 ragge Elf_Sym *sym, *nsym;
259 1.43 ad int i, j, n, nglob;
260 1.8 ragge char *str;
261 1.1 ragge
262 1.39 ad tab->sd_symstart = symstart;
263 1.29 jmmv tab->sd_symsize = symsize;
264 1.29 jmmv tab->sd_strstart = strstart;
265 1.29 jmmv tab->sd_strsize = strsize;
266 1.1 ragge tab->sd_name = name;
267 1.44 ad tab->sd_minsym = UINTPTR_MAX;
268 1.44 ad tab->sd_maxsym = 0;
269 1.39 ad tab->sd_usroffset = 0;
270 1.39 ad tab->sd_gone = false;
271 1.8 ragge #ifdef KSYMS_DEBUG
272 1.39 ad printf("newstart %p sym %p ksyms_symsz %d str %p strsz %d send %p\n",
273 1.39 ad newstart, symstart, symsize, strstart, strsize,
274 1.39 ad tab->sd_strstart + tab->sd_strsize);
275 1.8 ragge #endif
276 1.1 ragge
277 1.39 ad /* Pack symbol table by removing all file name references. */
278 1.8 ragge sym = tab->sd_symstart;
279 1.29 jmmv nsym = (Elf_Sym *)newstart;
280 1.8 ragge str = tab->sd_strstart;
281 1.43 ad nglob = 0;
282 1.39 ad for (i = n = 0; i < tab->sd_symsize/sizeof(Elf_Sym); i++) {
283 1.8 ragge /*
284 1.8 ragge * Remove useless symbols.
285 1.8 ragge * Should actually remove all typeless symbols.
286 1.8 ragge */
287 1.5 ragge if (sym[i].st_name == 0)
288 1.8 ragge continue; /* Skip nameless entries */
289 1.34 ad if (sym[i].st_shndx == SHN_UNDEF)
290 1.34 ad continue; /* Skip external references */
291 1.8 ragge if (ELF_ST_TYPE(sym[i].st_info) == STT_FILE)
292 1.8 ragge continue; /* Skip filenames */
293 1.8 ragge if (ELF_ST_TYPE(sym[i].st_info) == STT_NOTYPE &&
294 1.8 ragge sym[i].st_value == 0 &&
295 1.8 ragge strcmp(str + sym[i].st_name, "*ABS*") == 0)
296 1.8 ragge continue; /* XXX */
297 1.8 ragge if (ELF_ST_TYPE(sym[i].st_info) == STT_NOTYPE &&
298 1.8 ragge strcmp(str + sym[i].st_name, "gcc2_compiled.") == 0)
299 1.8 ragge continue; /* XXX */
300 1.8 ragge
301 1.8 ragge /* Save symbol. Set it as an absolute offset */
302 1.8 ragge nsym[n] = sym[i];
303 1.8 ragge nsym[n].st_shndx = SHN_ABS;
304 1.43 ad j = strlen(nsym[n].st_name + str) + 1;
305 1.39 ad if (j > ksyms_maxlen)
306 1.39 ad ksyms_maxlen = j;
307 1.43 ad nglob += (ELF_ST_BIND(nsym[n].st_info) == STB_GLOBAL);
308 1.43 ad
309 1.43 ad /* Compute min and max symbols. */
310 1.44 ad if (nsym[n].st_value < tab->sd_minsym) {
311 1.44 ad tab->sd_minsym = nsym[n].st_value;
312 1.44 ad }
313 1.44 ad if (nsym[n].st_value > tab->sd_maxsym) {
314 1.44 ad tab->sd_maxsym = nsym[n].st_value;
315 1.43 ad }
316 1.8 ragge n++;
317 1.43 ad }
318 1.8 ragge
319 1.43 ad /* Fill the rest of the record, and sort the symbols. */
320 1.8 ragge tab->sd_symstart = nsym;
321 1.8 ragge tab->sd_symsize = n * sizeof(Elf_Sym);
322 1.43 ad tab->sd_nglob = nglob;
323 1.43 ad addsymtab_strstart = str;
324 1.43 ad qsort(nsym, n, sizeof(Elf_Sym), addsymtab_compar);
325 1.43 ad
326 1.39 ad /* ksymsread() is unlocked, so membar. */
327 1.39 ad membar_producer();
328 1.39 ad TAILQ_INSERT_TAIL(&ksyms_symtabs, tab, sd_queue);
329 1.39 ad ksyms_sizes_calc();
330 1.39 ad ksyms_initted = true;
331 1.1 ragge }
332 1.1 ragge
333 1.1 ragge /*
334 1.39 ad * Setup the kernel symbol table stuff.
335 1.29 jmmv */
336 1.39 ad void
337 1.39 ad ksyms_init(int symsize, void *start, void *end)
338 1.29 jmmv {
339 1.29 jmmv int i, j;
340 1.29 jmmv Elf_Shdr *shdr;
341 1.32 christos char *symstart = NULL, *strstart = NULL;
342 1.39 ad size_t strsize = 0;
343 1.3 ragge Elf_Ehdr *ehdr;
344 1.3 ragge
345 1.40 christos mutex_init(&ksyms_lock, MUTEX_DEFAULT, IPL_NONE);
346 1.3 ragge #ifdef SYMTAB_SPACE
347 1.3 ragge if (symsize <= 0 &&
348 1.3 ragge strncmp(db_symtab, SYMTAB_FILLER, sizeof(SYMTAB_FILLER))) {
349 1.3 ragge symsize = db_symtabsize;
350 1.3 ragge start = db_symtab;
351 1.3 ragge end = db_symtab + db_symtabsize;
352 1.3 ragge }
353 1.3 ragge #endif
354 1.3 ragge if (symsize <= 0) {
355 1.3 ragge printf("[ Kernel symbol table missing! ]\n");
356 1.3 ragge return;
357 1.3 ragge }
358 1.3 ragge
359 1.3 ragge /* Sanity check */
360 1.3 ragge if (ALIGNED_POINTER(start, long) == 0) {
361 1.3 ragge printf("[ Kernel symbol table has bad start address %p ]\n",
362 1.3 ragge start);
363 1.3 ragge return;
364 1.3 ragge }
365 1.3 ragge
366 1.3 ragge ehdr = (Elf_Ehdr *)start;
367 1.1 ragge
368 1.1 ragge /* check if this is a valid ELF header */
369 1.1 ragge /* No reason to verify arch type, the kernel is actually running! */
370 1.1 ragge if (memcmp(ehdr->e_ident, ELFMAG, SELFMAG) ||
371 1.1 ragge ehdr->e_ident[EI_CLASS] != ELFCLASS ||
372 1.1 ragge ehdr->e_version > 1) {
373 1.3 ragge printf("[ Kernel symbol table invalid! ]\n");
374 1.1 ragge return; /* nothing to do */
375 1.1 ragge }
376 1.1 ragge
377 1.8 ragge /* Loaded header will be scratched in addsymtab */
378 1.8 ragge ksyms_hdr_init(start);
379 1.8 ragge
380 1.39 ad /* Find the symbol table and the corresponding string table. */
381 1.39 ad shdr = (Elf_Shdr *)((uint8_t *)start + ehdr->e_shoff);
382 1.39 ad for (i = 1; i < ehdr->e_shnum; i++) {
383 1.39 ad if (shdr[i].sh_type != SHT_SYMTAB)
384 1.39 ad continue;
385 1.39 ad if (shdr[i].sh_offset == 0)
386 1.39 ad continue;
387 1.39 ad symstart = (uint8_t *)start + shdr[i].sh_offset;
388 1.39 ad symsize = shdr[i].sh_size;
389 1.39 ad j = shdr[i].sh_link;
390 1.39 ad if (shdr[j].sh_offset == 0)
391 1.39 ad continue; /* Can this happen? */
392 1.39 ad strstart = (uint8_t *)start + shdr[j].sh_offset;
393 1.39 ad strsize = shdr[j].sh_size;
394 1.39 ad break;
395 1.39 ad }
396 1.8 ragge
397 1.39 ad if (!ksyms_verify(symstart, strstart))
398 1.39 ad return;
399 1.39 ad addsymtab("netbsd", symstart, symsize, strstart, strsize,
400 1.39 ad &kernel_symtab, start);
401 1.8 ragge
402 1.1 ragge #ifdef DEBUG
403 1.1 ragge printf("Loaded initial symtab at %p, strtab at %p, # entries %ld\n",
404 1.1 ragge kernel_symtab.sd_symstart, kernel_symtab.sd_strstart,
405 1.2 ragge (long)kernel_symtab.sd_symsize/sizeof(Elf_Sym));
406 1.1 ragge #endif
407 1.1 ragge }
408 1.1 ragge
409 1.1 ragge /*
410 1.29 jmmv * Setup the kernel symbol table stuff.
411 1.29 jmmv * Use this when the address of the symbol and string tables are known;
412 1.29 jmmv * otherwise use ksyms_init with an ELF image.
413 1.31 jmmv * We need to pass a minimal ELF header which will later be completed by
414 1.31 jmmv * ksyms_hdr_init and handed off to userland through /dev/ksyms. We use
415 1.32 christos * a void *rather than a pointer to avoid exposing the Elf_Ehdr type.
416 1.29 jmmv */
417 1.29 jmmv void
418 1.32 christos ksyms_init_explicit(void *ehdr, void *symstart, size_t symsize,
419 1.39 ad void *strstart, size_t strsize)
420 1.29 jmmv {
421 1.29 jmmv
422 1.42 ad mutex_init(&ksyms_lock, MUTEX_DEFAULT, IPL_NONE);
423 1.42 ad
424 1.33 christos if (!ksyms_verify(symstart, strstart))
425 1.33 christos return;
426 1.29 jmmv
427 1.31 jmmv ksyms_hdr_init(ehdr);
428 1.29 jmmv addsymtab("netbsd", symstart, symsize, strstart, strsize,
429 1.39 ad &kernel_symtab, symstart);
430 1.29 jmmv }
431 1.29 jmmv
432 1.29 jmmv /*
433 1.1 ragge * Get the value associated with a symbol.
434 1.23 perry * "mod" is the module name, or null if any module.
435 1.1 ragge * "sym" is the symbol name.
436 1.1 ragge * "val" is a pointer to the corresponding value, if call succeeded.
437 1.1 ragge * Returns 0 if success or ENOENT if no such entry.
438 1.39 ad *
439 1.39 ad * Call with ksyms_lock, unless known that the symbol table can't change.
440 1.1 ragge */
441 1.41 christos int
442 1.40 christos ksyms_getval_unlocked(const char *mod, const char *sym, unsigned long *val,
443 1.42 ad int type)
444 1.1 ragge {
445 1.39 ad struct ksyms_symtab *st;
446 1.1 ragge Elf_Sym *es;
447 1.1 ragge
448 1.1 ragge #ifdef KSYMS_DEBUG
449 1.1 ragge if (ksyms_debug & FOLLOW_CALLS)
450 1.40 christos printf("ksyms_getval_unlocked: mod %s sym %s valp %p\n",
451 1.40 christos mod, sym, val);
452 1.1 ragge #endif
453 1.1 ragge
454 1.39 ad TAILQ_FOREACH(st, &ksyms_symtabs, sd_queue) {
455 1.43 ad if (__predict_false(st->sd_gone))
456 1.1 ragge continue;
457 1.43 ad if (mod != NULL && strcmp(st->sd_name, mod))
458 1.1 ragge continue;
459 1.43 ad if ((es = findsym(sym, st, type)) != NULL) {
460 1.1 ragge *val = es->st_value;
461 1.43 ad return 0;
462 1.43 ad }
463 1.1 ragge }
464 1.1 ragge return ENOENT;
465 1.1 ragge }
466 1.1 ragge
467 1.40 christos int
468 1.40 christos ksyms_getval(const char *mod, const char *sym, unsigned long *val, int type)
469 1.40 christos {
470 1.40 christos int rc;
471 1.40 christos
472 1.43 ad if (!ksyms_initted)
473 1.43 ad return ENOENT;
474 1.43 ad
475 1.40 christos mutex_enter(&ksyms_lock);
476 1.40 christos rc = ksyms_getval_unlocked(mod, sym, val, type);
477 1.40 christos mutex_exit(&ksyms_lock);
478 1.40 christos return rc;
479 1.40 christos }
480 1.40 christos
481 1.1 ragge /*
482 1.1 ragge * Get "mod" and "symbol" associated with an address.
483 1.1 ragge * Returns 0 if success or ENOENT if no such entry.
484 1.39 ad *
485 1.39 ad * Call with ksyms_lock, unless known that the symbol table can't change.
486 1.1 ragge */
487 1.1 ragge int
488 1.24 christos ksyms_getname(const char **mod, const char **sym, vaddr_t v, int f)
489 1.1 ragge {
490 1.39 ad struct ksyms_symtab *st;
491 1.1 ragge Elf_Sym *les, *es = NULL;
492 1.1 ragge vaddr_t laddr = 0;
493 1.15 christos const char *lmod = NULL;
494 1.15 christos char *stable = NULL;
495 1.1 ragge int type, i, sz;
496 1.1 ragge
497 1.39 ad if (!ksyms_initted)
498 1.1 ragge return ENOENT;
499 1.1 ragge
500 1.39 ad TAILQ_FOREACH(st, &ksyms_symtabs, sd_queue) {
501 1.39 ad if (st->sd_gone)
502 1.39 ad continue;
503 1.44 ad if (v < st->sd_minsym || v > st->sd_maxsym)
504 1.35 matt continue;
505 1.1 ragge sz = st->sd_symsize/sizeof(Elf_Sym);
506 1.1 ragge for (i = 0; i < sz; i++) {
507 1.1 ragge les = st->sd_symstart + i;
508 1.1 ragge type = ELF_ST_TYPE(les->st_info);
509 1.1 ragge
510 1.1 ragge if ((f & KSYMS_PROC) && (type != STT_FUNC))
511 1.1 ragge continue;
512 1.1 ragge
513 1.1 ragge if (type == STT_NOTYPE)
514 1.1 ragge continue;
515 1.1 ragge
516 1.1 ragge if (((f & KSYMS_ANY) == 0) &&
517 1.1 ragge (type != STT_FUNC) && (type != STT_OBJECT))
518 1.1 ragge continue;
519 1.1 ragge
520 1.1 ragge if ((les->st_value <= v) && (les->st_value > laddr)) {
521 1.1 ragge laddr = les->st_value;
522 1.1 ragge es = les;
523 1.1 ragge lmod = st->sd_name;
524 1.17 cube stable = st->sd_strstart - st->sd_usroffset;
525 1.1 ragge }
526 1.1 ragge }
527 1.1 ragge }
528 1.1 ragge if (es == NULL)
529 1.1 ragge return ENOENT;
530 1.1 ragge if ((f & KSYMS_EXACT) && (v != es->st_value))
531 1.1 ragge return ENOENT;
532 1.1 ragge if (mod)
533 1.1 ragge *mod = lmod;
534 1.1 ragge if (sym)
535 1.1 ragge *sym = stable + es->st_name;
536 1.1 ragge return 0;
537 1.1 ragge }
538 1.1 ragge
539 1.22 cube /*
540 1.39 ad * Add a symbol table from a loadable module.
541 1.39 ad */
542 1.39 ad void
543 1.39 ad ksyms_modload(const char *name, void *symstart, vsize_t symsize,
544 1.39 ad char *strstart, vsize_t strsize)
545 1.17 cube {
546 1.39 ad struct ksyms_symtab *st;
547 1.39 ad
548 1.39 ad st = kmem_zalloc(sizeof(*st), KM_SLEEP);
549 1.39 ad mutex_enter(&ksyms_lock);
550 1.39 ad addsymtab(name, symstart, symsize, strstart, strsize, st, symstart);
551 1.39 ad mutex_exit(&ksyms_lock);
552 1.39 ad }
553 1.17 cube
554 1.39 ad /*
555 1.39 ad * Remove a symbol table from a loadable module.
556 1.39 ad */
557 1.39 ad void
558 1.39 ad ksyms_modunload(const char *name)
559 1.39 ad {
560 1.39 ad struct ksyms_symtab *st;
561 1.17 cube
562 1.39 ad mutex_enter(&ksyms_lock);
563 1.39 ad TAILQ_FOREACH(st, &ksyms_symtabs, sd_queue) {
564 1.39 ad if (st->sd_gone)
565 1.39 ad continue;
566 1.39 ad if (strcmp(name, st->sd_name) != 0)
567 1.39 ad continue;
568 1.39 ad st->sd_gone = true;
569 1.39 ad if (!ksyms_isopen) {
570 1.39 ad TAILQ_REMOVE(&ksyms_symtabs, st, sd_queue);
571 1.39 ad ksyms_sizes_calc();
572 1.39 ad kmem_free(st, sizeof(*st));
573 1.39 ad }
574 1.39 ad break;
575 1.39 ad }
576 1.39 ad mutex_exit(&ksyms_lock);
577 1.39 ad KASSERT(st != NULL);
578 1.17 cube }
579 1.17 cube
580 1.1 ragge #ifdef DDB
581 1.1 ragge /*
582 1.1 ragge * Keep sifting stuff here, to avoid export of ksyms internals.
583 1.39 ad *
584 1.39 ad * Systems is expected to be quiescent, so no locking done.
585 1.1 ragge */
586 1.1 ragge int
587 1.1 ragge ksyms_sift(char *mod, char *sym, int mode)
588 1.1 ragge {
589 1.39 ad struct ksyms_symtab *st;
590 1.1 ragge char *sb;
591 1.1 ragge int i, sz;
592 1.1 ragge
593 1.39 ad if (!ksyms_initted)
594 1.1 ragge return ENOENT;
595 1.1 ragge
596 1.39 ad TAILQ_FOREACH(st, &ksyms_symtabs, sd_queue) {
597 1.39 ad if (st->sd_gone)
598 1.39 ad continue;
599 1.1 ragge if (mod && strcmp(mod, st->sd_name))
600 1.1 ragge continue;
601 1.39 ad sb = st->sd_strstart - st->sd_usroffset;
602 1.1 ragge
603 1.1 ragge sz = st->sd_symsize/sizeof(Elf_Sym);
604 1.1 ragge for (i = 0; i < sz; i++) {
605 1.1 ragge Elf_Sym *les = st->sd_symstart + i;
606 1.1 ragge char c;
607 1.1 ragge
608 1.39 ad if (strstr(sb + les->st_name, sym) == NULL)
609 1.1 ragge continue;
610 1.1 ragge
611 1.1 ragge if (mode == 'F') {
612 1.1 ragge switch (ELF_ST_TYPE(les->st_info)) {
613 1.1 ragge case STT_OBJECT:
614 1.1 ragge c = '+';
615 1.1 ragge break;
616 1.1 ragge case STT_FUNC:
617 1.1 ragge c = '*';
618 1.1 ragge break;
619 1.1 ragge case STT_SECTION:
620 1.1 ragge c = '&';
621 1.1 ragge break;
622 1.1 ragge case STT_FILE:
623 1.1 ragge c = '/';
624 1.1 ragge break;
625 1.1 ragge default:
626 1.1 ragge c = ' ';
627 1.1 ragge break;
628 1.1 ragge }
629 1.39 ad db_printf("%s%c ", sb + les->st_name, c);
630 1.1 ragge } else
631 1.39 ad db_printf("%s ", sb + les->st_name);
632 1.1 ragge }
633 1.1 ragge }
634 1.1 ragge return ENOENT;
635 1.1 ragge }
636 1.25 thorpej #endif /* DDB */
637 1.1 ragge
638 1.1 ragge /*
639 1.39 ad * In case we exposing the symbol table to the userland using the pseudo-
640 1.39 ad * device /dev/ksyms, it is easier to provide all the tables as one.
641 1.39 ad * However, it means we have to change all the st_name fields for the
642 1.39 ad * symbols so they match the ELF image that the userland will read
643 1.39 ad * through the device.
644 1.39 ad *
645 1.39 ad * The actual (correct) value of st_name is preserved through a global
646 1.39 ad * offset stored in the symbol table structure.
647 1.39 ad *
648 1.39 ad * Call with ksyms_lock held.
649 1.1 ragge */
650 1.39 ad static void
651 1.39 ad ksyms_sizes_calc(void)
652 1.39 ad {
653 1.39 ad struct ksyms_symtab *st;
654 1.39 ad int i, delta;
655 1.1 ragge
656 1.39 ad ksyms_symsz = ksyms_strsz = 0;
657 1.39 ad TAILQ_FOREACH(st, &ksyms_symtabs, sd_queue) {
658 1.39 ad delta = ksyms_strsz - st->sd_usroffset;
659 1.39 ad if (delta != 0) {
660 1.39 ad for (i = 0; i < st->sd_symsize/sizeof(Elf_Sym); i++)
661 1.39 ad st->sd_symstart[i].st_name += delta;
662 1.39 ad st->sd_usroffset = ksyms_strsz;
663 1.39 ad }
664 1.39 ad ksyms_symsz += st->sd_symsize;
665 1.39 ad ksyms_strsz += st->sd_strsize;
666 1.39 ad }
667 1.39 ad }
668 1.1 ragge
669 1.25 thorpej static void
670 1.32 christos ksyms_hdr_init(void *hdraddr)
671 1.1 ragge {
672 1.1 ragge
673 1.1 ragge /* Copy the loaded elf exec header */
674 1.1 ragge memcpy(&ksyms_hdr.kh_ehdr, hdraddr, sizeof(Elf_Ehdr));
675 1.1 ragge
676 1.1 ragge /* Set correct program/section header sizes, offsets and numbers */
677 1.1 ragge ksyms_hdr.kh_ehdr.e_phoff = offsetof(struct ksyms_hdr, kh_phdr[0]);
678 1.1 ragge ksyms_hdr.kh_ehdr.e_phentsize = sizeof(Elf_Phdr);
679 1.1 ragge ksyms_hdr.kh_ehdr.e_phnum = NPRGHDR;
680 1.1 ragge ksyms_hdr.kh_ehdr.e_shoff = offsetof(struct ksyms_hdr, kh_shdr[0]);
681 1.1 ragge ksyms_hdr.kh_ehdr.e_shentsize = sizeof(Elf_Shdr);
682 1.1 ragge ksyms_hdr.kh_ehdr.e_shnum = NSECHDR;
683 1.1 ragge ksyms_hdr.kh_ehdr.e_shstrndx = NSECHDR - 1; /* Last section */
684 1.1 ragge
685 1.39 ad /* Text */
686 1.39 ad ksyms_hdr.kh_phdr[0].p_type = PT_LOAD;
687 1.39 ad ksyms_hdr.kh_phdr[0].p_memsz = (unsigned long)-1L;
688 1.39 ad ksyms_hdr.kh_phdr[0].p_flags = PF_R | PF_X;
689 1.39 ad
690 1.39 ad /* Data */
691 1.39 ad ksyms_hdr.kh_phdr[1].p_type = PT_LOAD;
692 1.39 ad ksyms_hdr.kh_phdr[1].p_memsz = (unsigned long)-1L;
693 1.39 ad ksyms_hdr.kh_phdr[1].p_flags = PF_R | PF_W | PF_X;
694 1.39 ad
695 1.39 ad /* First section is null */
696 1.1 ragge
697 1.1 ragge /* Second section header; ".symtab" */
698 1.1 ragge ksyms_hdr.kh_shdr[SYMTAB].sh_name = 1; /* Section 3 offset */
699 1.1 ragge ksyms_hdr.kh_shdr[SYMTAB].sh_type = SHT_SYMTAB;
700 1.1 ragge ksyms_hdr.kh_shdr[SYMTAB].sh_offset = sizeof(struct ksyms_hdr);
701 1.1 ragge /* ksyms_hdr.kh_shdr[SYMTAB].sh_size = filled in at open */
702 1.1 ragge ksyms_hdr.kh_shdr[SYMTAB].sh_link = 2; /* Corresponding strtab */
703 1.1 ragge ksyms_hdr.kh_shdr[SYMTAB].sh_addralign = sizeof(long);
704 1.1 ragge ksyms_hdr.kh_shdr[SYMTAB].sh_entsize = sizeof(Elf_Sym);
705 1.1 ragge
706 1.1 ragge /* Third section header; ".strtab" */
707 1.1 ragge ksyms_hdr.kh_shdr[STRTAB].sh_name = 9; /* Section 3 offset */
708 1.1 ragge ksyms_hdr.kh_shdr[STRTAB].sh_type = SHT_STRTAB;
709 1.1 ragge /* ksyms_hdr.kh_shdr[STRTAB].sh_offset = filled in at open */
710 1.1 ragge /* ksyms_hdr.kh_shdr[STRTAB].sh_size = filled in at open */
711 1.1 ragge ksyms_hdr.kh_shdr[STRTAB].sh_addralign = sizeof(char);
712 1.1 ragge
713 1.1 ragge /* Fourth section, ".shstrtab" */
714 1.1 ragge ksyms_hdr.kh_shdr[SHSTRTAB].sh_name = 17; /* This section name offset */
715 1.1 ragge ksyms_hdr.kh_shdr[SHSTRTAB].sh_type = SHT_STRTAB;
716 1.1 ragge ksyms_hdr.kh_shdr[SHSTRTAB].sh_offset =
717 1.1 ragge offsetof(struct ksyms_hdr, kh_strtab);
718 1.1 ragge ksyms_hdr.kh_shdr[SHSTRTAB].sh_size = SHSTRSIZ;
719 1.1 ragge ksyms_hdr.kh_shdr[SHSTRTAB].sh_addralign = sizeof(char);
720 1.1 ragge
721 1.1 ragge /* Set section names */
722 1.10 itojun strlcpy(&ksyms_hdr.kh_strtab[1], ".symtab",
723 1.10 itojun sizeof(ksyms_hdr.kh_strtab) - 1);
724 1.10 itojun strlcpy(&ksyms_hdr.kh_strtab[9], ".strtab",
725 1.10 itojun sizeof(ksyms_hdr.kh_strtab) - 9);
726 1.10 itojun strlcpy(&ksyms_hdr.kh_strtab[17], ".shstrtab",
727 1.10 itojun sizeof(ksyms_hdr.kh_strtab) - 17);
728 1.39 ad }
729 1.1 ragge
730 1.25 thorpej static int
731 1.30 yamt ksymsopen(dev_t dev, int oflags, int devtype, struct lwp *l)
732 1.1 ragge {
733 1.1 ragge
734 1.39 ad if (minor(dev) != 0 || !ksyms_initted)
735 1.18 cube return ENXIO;
736 1.1 ragge
737 1.39 ad /*
738 1.39 ad * Create a "snapshot" of the kernel symbol table. Setting
739 1.39 ad * ksyms_isopen will prevent symbol tables from being freed.
740 1.39 ad */
741 1.39 ad mutex_enter(&ksyms_lock);
742 1.39 ad ksyms_hdr.kh_shdr[SYMTAB].sh_size = ksyms_symsz;
743 1.39 ad ksyms_hdr.kh_shdr[SYMTAB].sh_info = ksyms_symsz / sizeof(Elf_Sym);
744 1.39 ad ksyms_hdr.kh_shdr[STRTAB].sh_offset = ksyms_symsz +
745 1.1 ragge ksyms_hdr.kh_shdr[SYMTAB].sh_offset;
746 1.39 ad ksyms_hdr.kh_shdr[STRTAB].sh_size = ksyms_strsz;
747 1.39 ad ksyms_isopen = true;
748 1.39 ad mutex_exit(&ksyms_lock);
749 1.1 ragge
750 1.1 ragge return 0;
751 1.1 ragge }
752 1.1 ragge
753 1.25 thorpej static int
754 1.30 yamt ksymsclose(dev_t dev, int oflags, int devtype, struct lwp *l)
755 1.1 ragge {
756 1.39 ad struct ksyms_symtab *st, *next;
757 1.39 ad bool resize;
758 1.1 ragge
759 1.39 ad /* Discard refernces to symbol tables. */
760 1.39 ad mutex_enter(&ksyms_lock);
761 1.39 ad ksyms_isopen = false;
762 1.39 ad resize = false;
763 1.39 ad for (st = TAILQ_FIRST(&ksyms_symtabs); st != NULL; st = next) {
764 1.39 ad next = TAILQ_NEXT(st, sd_queue);
765 1.39 ad if (st->sd_gone) {
766 1.39 ad TAILQ_REMOVE(&ksyms_symtabs, st, sd_queue);
767 1.39 ad kmem_free(st, sizeof(*st));
768 1.39 ad resize = true;
769 1.39 ad }
770 1.39 ad }
771 1.39 ad if (resize)
772 1.39 ad ksyms_sizes_calc();
773 1.39 ad mutex_exit(&ksyms_lock);
774 1.1 ragge
775 1.1 ragge return 0;
776 1.1 ragge }
777 1.1 ragge
778 1.25 thorpej static int
779 1.30 yamt ksymsread(dev_t dev, struct uio *uio, int ioflag)
780 1.1 ragge {
781 1.39 ad struct ksyms_symtab *st;
782 1.1 ragge size_t filepos, inpos, off;
783 1.39 ad int error;
784 1.1 ragge
785 1.1 ragge /*
786 1.39 ad * First: Copy out the ELF header. XXX Lose if ksymsopen()
787 1.39 ad * occurs during read of the header.
788 1.1 ragge */
789 1.39 ad off = uio->uio_offset;
790 1.39 ad if (off < sizeof(struct ksyms_hdr)) {
791 1.39 ad error = uiomove((char *)&ksyms_hdr + off,
792 1.39 ad sizeof(struct ksyms_hdr) - off, uio);
793 1.39 ad if (error != 0)
794 1.39 ad return error;
795 1.39 ad }
796 1.1 ragge
797 1.1 ragge /*
798 1.1 ragge * Copy out the symbol table.
799 1.1 ragge */
800 1.39 ad filepos = sizeof(struct ksyms_hdr);
801 1.39 ad TAILQ_FOREACH(st, &ksyms_symtabs, sd_queue) {
802 1.1 ragge if (uio->uio_resid == 0)
803 1.1 ragge return 0;
804 1.1 ragge if (uio->uio_offset <= st->sd_symsize + filepos) {
805 1.1 ragge inpos = uio->uio_offset - filepos;
806 1.39 ad error = uiomove((char *)st->sd_symstart + inpos,
807 1.1 ragge st->sd_symsize - inpos, uio);
808 1.39 ad if (error != 0)
809 1.39 ad return error;
810 1.1 ragge }
811 1.1 ragge filepos += st->sd_symsize;
812 1.1 ragge }
813 1.1 ragge
814 1.1 ragge /*
815 1.1 ragge * Copy out the string table
816 1.1 ragge */
817 1.39 ad KASSERT(filepos == sizeof(struct ksyms_hdr) +
818 1.39 ad ksyms_hdr.kh_shdr[SYMTAB].sh_size);
819 1.39 ad TAILQ_FOREACH(st, &ksyms_symtabs, sd_queue) {
820 1.1 ragge if (uio->uio_resid == 0)
821 1.1 ragge return 0;
822 1.1 ragge if (uio->uio_offset <= st->sd_strsize + filepos) {
823 1.1 ragge inpos = uio->uio_offset - filepos;
824 1.39 ad error = uiomove((char *)st->sd_strstart + inpos,
825 1.1 ragge st->sd_strsize - inpos, uio);
826 1.39 ad if (error != 0)
827 1.39 ad return error;
828 1.1 ragge }
829 1.1 ragge filepos += st->sd_strsize;
830 1.1 ragge }
831 1.39 ad
832 1.1 ragge return 0;
833 1.1 ragge }
834 1.1 ragge
835 1.25 thorpej static int
836 1.30 yamt ksymswrite(dev_t dev, struct uio *uio, int ioflag)
837 1.1 ragge {
838 1.30 yamt
839 1.1 ragge return EROFS;
840 1.1 ragge }
841 1.1 ragge
842 1.25 thorpej static int
843 1.32 christos ksymsioctl(dev_t dev, u_long cmd, void *data, int fflag, struct lwp *l)
844 1.1 ragge {
845 1.1 ragge struct ksyms_gsymbol *kg = (struct ksyms_gsymbol *)data;
846 1.39 ad struct ksyms_symtab *st;
847 1.39 ad Elf_Sym *sym = NULL, copy;
848 1.1 ragge unsigned long val;
849 1.1 ragge int error = 0;
850 1.15 christos char *str = NULL;
851 1.39 ad int len;
852 1.39 ad
853 1.39 ad /* Read ksyms_maxlen only once while not holding the lock. */
854 1.39 ad len = ksyms_maxlen;
855 1.5 ragge
856 1.39 ad if (cmd == KIOCGVALUE || cmd == KIOCGSYMBOL) {
857 1.39 ad str = kmem_alloc(len, KM_SLEEP);
858 1.39 ad if ((error = copyinstr(kg->kg_name, str, len, NULL)) != 0) {
859 1.39 ad kmem_free(str, len);
860 1.39 ad return error;
861 1.39 ad }
862 1.39 ad }
863 1.1 ragge
864 1.1 ragge switch (cmd) {
865 1.1 ragge case KIOCGVALUE:
866 1.1 ragge /*
867 1.1 ragge * Use the in-kernel symbol lookup code for fast
868 1.1 ragge * retreival of a value.
869 1.1 ragge */
870 1.39 ad error = ksyms_getval(NULL, str, &val, KSYMS_EXTERN);
871 1.39 ad if (error == 0)
872 1.39 ad error = copyout(&val, kg->kg_value, sizeof(long));
873 1.39 ad kmem_free(str, len);
874 1.1 ragge break;
875 1.1 ragge
876 1.1 ragge case KIOCGSYMBOL:
877 1.1 ragge /*
878 1.1 ragge * Use the in-kernel symbol lookup code for fast
879 1.1 ragge * retreival of a symbol.
880 1.1 ragge */
881 1.39 ad mutex_enter(&ksyms_lock);
882 1.39 ad TAILQ_FOREACH(st, &ksyms_symtabs, sd_queue) {
883 1.39 ad if (st->sd_gone)
884 1.39 ad continue;
885 1.43 ad if ((sym = findsym(str, st, KSYMS_ANY)) == NULL)
886 1.1 ragge continue;
887 1.36 christos #ifdef notdef
888 1.1 ragge /* Skip if bad binding */
889 1.1 ragge if (ELF_ST_BIND(sym->st_info) != STB_GLOBAL) {
890 1.1 ragge sym = NULL;
891 1.1 ragge continue;
892 1.1 ragge }
893 1.36 christos #endif
894 1.1 ragge break;
895 1.1 ragge }
896 1.39 ad if (sym != NULL) {
897 1.39 ad memcpy(©, sym, sizeof(copy));
898 1.39 ad mutex_exit(&ksyms_lock);
899 1.39 ad error = copyout(©, kg->kg_sym, sizeof(Elf_Sym));
900 1.39 ad } else {
901 1.39 ad mutex_exit(&ksyms_lock);
902 1.1 ragge error = ENOENT;
903 1.39 ad }
904 1.39 ad kmem_free(str, len);
905 1.1 ragge break;
906 1.1 ragge
907 1.1 ragge case KIOCGSIZE:
908 1.1 ragge /*
909 1.1 ragge * Get total size of symbol table.
910 1.1 ragge */
911 1.39 ad mutex_enter(&ksyms_lock);
912 1.39 ad *(int *)data = ksyms_strsz + ksyms_symsz +
913 1.39 ad sizeof(struct ksyms_hdr);
914 1.39 ad mutex_exit(&ksyms_lock);
915 1.1 ragge break;
916 1.1 ragge
917 1.1 ragge default:
918 1.1 ragge error = ENOTTY;
919 1.1 ragge break;
920 1.1 ragge }
921 1.5 ragge
922 1.5 ragge return error;
923 1.1 ragge }
924 1.25 thorpej
925 1.25 thorpej const struct cdevsw ksyms_cdevsw = {
926 1.25 thorpej ksymsopen, ksymsclose, ksymsread, ksymswrite, ksymsioctl,
927 1.39 ad nullstop, notty, nopoll, nommap, nullkqfilter, D_OTHER | D_MPSAFE
928 1.25 thorpej };
929