Index: sys/kern/kern_ksyms.c =================================================================== RCS file: /cvsroot/src/sys/kern/kern_ksyms.c,v retrieving revision 1.87 diff -p -u -r1.87 kern_ksyms.c --- sys/kern/kern_ksyms.c 4 Nov 2017 22:17:55 -0000 1.87 +++ sys/kern/kern_ksyms.c 9 Dec 2017 14:10:20 -0000 @@ -93,6 +93,10 @@ __KERNEL_RCSID(0, "$NetBSD: kern_ksyms.c #include #include +#ifdef KDTRACE_HOOKS +#include +#endif + #ifdef DDB #include #endif @@ -102,11 +106,11 @@ __KERNEL_RCSID(0, "$NetBSD: kern_ksyms.c #include "ioconf.h" #endif -#define KSYMS_MAX_ID 98304 #ifdef KDTRACE_HOOKS -static uint32_t ksyms_nmap[KSYMS_MAX_ID]; /* sorted symbol table map */ +static uint32_t *ksyms_nmap = NULL; /* sorted symbol table map */ +static uint32_t **const ksyms_nmapp = &ksyms_nmap; #else -static uint32_t *ksyms_nmap = NULL; +static uint32_t **const ksyms_nmapp = NULL; #endif static int ksyms_maxlen; @@ -290,21 +294,29 @@ addsymtab_compar(const void *a, const vo static void addsymtab(const char *name, void *symstart, size_t symsize, void *strstart, size_t strsize, struct ksyms_symtab *tab, - void *newstart, void *ctfstart, size_t ctfsize, uint32_t *nmap) + void *newstart, void *ctfstart, size_t ctfsize, uint32_t **nmapp) { Elf_Sym *sym, *nsym, ts; int i, j, n, nglob; char *str; int nsyms = symsize / sizeof(Elf_Sym); + uint32_t *nmap = *nmapp; - /* Sanity check for pre-allocated map table used during startup. */ - if ((nmap == ksyms_nmap) && (nsyms >= KSYMS_MAX_ID)) { - printf("kern_ksyms: ERROR %d > %d, increase KSYMS_MAX_ID\n", - nsyms, KSYMS_MAX_ID); - - /* truncate for now */ - nsyms = KSYMS_MAX_ID - 1; +#ifdef KDTRACE_HOOKS + /* Bootstrap kernel symbol table. */ + if (nmapp == ksyms_nmapp) { + const size_t nmapsz = nsyms * sizeof((*nmapp)[0]); + vaddr_t va; + + KASSERT(nmapp != NULL); + KASSERT(*nmapp == NULL); + va = uvm_km_alloc(kernel_map, round_page(nmapsz), 0, + UVM_KMF_WIRED|UVM_KMF_ZERO|UVM_KMF_WAITVA); + KASSERT(va != 0); + nmap = *nmapp = (void *)va; + KASSERT(nmap != NULL); } +#endif tab->sd_symstart = symstart; tab->sd_symsize = symsize; @@ -527,7 +539,7 @@ ksyms_addsyms_elf(int symsize, void *sta return; addsymtab("netbsd", symstart, symsize, strstart, strsize, - &kernel_symtab, symstart, ctfstart, ctfsize, ksyms_nmap); + &kernel_symtab, symstart, ctfstart, ctfsize, ksyms_nmapp); #ifdef DEBUG aprint_normal("Loaded initial symtab at %p, strtab at %p, # entries %ld\n", @@ -553,7 +565,7 @@ ksyms_addsyms_explicit(void *ehdr, void ksyms_hdr_init(ehdr); addsymtab("netbsd", symstart, symsize, strstart, strsize, - &kernel_symtab, symstart, NULL, 0, ksyms_nmap); + &kernel_symtab, symstart, NULL, 0, ksyms_nmapp); } /* @@ -739,14 +751,14 @@ ksyms_modload(const char *name, void *sy char *strstart, vsize_t strsize) { struct ksyms_symtab *st; - void *nmap; + uint32_t *nmap; st = kmem_zalloc(sizeof(*st), KM_SLEEP); nmap = kmem_zalloc(symsize / sizeof(Elf_Sym) * sizeof (uint32_t), KM_SLEEP); mutex_enter(&ksyms_lock); addsymtab(name, symstart, symsize, strstart, strsize, st, symstart, - NULL, 0, nmap); + NULL, 0, &nmap); mutex_exit(&ksyms_lock); }