2 * Copyright (c) 1997-2000 Doug Rabson
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
31 #include "opt_hwpmc_hooks.h"
34 #include <sys/param.h>
35 #include <sys/kernel.h>
36 #include <sys/systm.h>
37 #include <sys/malloc.h>
38 #include <sys/sysproto.h>
39 #include <sys/sysent.h>
43 #include <sys/mutex.h>
45 #include <sys/module.h>
46 #include <sys/mount.h>
47 #include <sys/linker.h>
48 #include <sys/fcntl.h>
49 #include <sys/libkern.h>
50 #include <sys/namei.h>
51 #include <sys/vnode.h>
52 #include <sys/syscallsubr.h>
53 #include <sys/sysctl.h>
55 #include <security/mac/mac_framework.h>
57 #include "linker_if.h"
60 #include <sys/pmckern.h>
67 #define KLD_LOCK() sx_xlock(&kld_sx)
68 #define KLD_UNLOCK() sx_xunlock(&kld_sx)
69 #define KLD_LOCKED() sx_xlocked(&kld_sx)
70 #define KLD_LOCK_ASSERT() do { \
72 sx_assert(&kld_sx, SX_XLOCKED); \
76 * static char *linker_search_path(const char *name, struct mod_depend
79 static const char *linker_basename(const char *path);
82 * Find a currently loaded file given its filename.
84 static linker_file_t linker_find_file_by_name(const char* _filename);
87 * Find a currently loaded file given its file id.
89 static linker_file_t linker_find_file_by_id(int _fileid);
91 /* Metadata from the static kernel */
92 SET_DECLARE(modmetadata_set, struct mod_metadata);
94 MALLOC_DEFINE(M_LINKER, "linker", "kernel linker");
96 linker_file_t linker_kernel_file;
98 static struct sx kld_sx; /* kernel linker lock */
101 * Load counter used by clients to determine if a linker file has been
102 * re-loaded. This counter is incremented for each file load.
106 static linker_class_list_t classes;
107 static linker_file_list_t linker_files;
108 static int next_file_id = 1;
109 static int linker_no_more_classes = 0;
111 #define LINKER_GET_NEXT_FILE_ID(a) do { \
112 linker_file_t lftmp; \
116 TAILQ_FOREACH(lftmp, &linker_files, link) { \
117 if (next_file_id == lftmp->id) { \
122 (a) = next_file_id; \
126 /* XXX wrong name; we're looking at version provision tags here, not modules */
127 typedef TAILQ_HEAD(, modlist) modlisthead_t;
129 TAILQ_ENTRY(modlist) link; /* chain together all modules */
130 linker_file_t container;
134 typedef struct modlist *modlist_t;
135 static modlisthead_t found_modules;
137 static int linker_file_add_dependency(linker_file_t file,
139 static caddr_t linker_file_lookup_symbol_internal(linker_file_t file,
140 const char* name, int deps);
141 static int linker_load_module(const char *kldname,
142 const char *modname, struct linker_file *parent,
143 struct mod_depend *verinfo, struct linker_file **lfpp);
144 static modlist_t modlist_lookup2(const char *name, struct mod_depend *verinfo);
147 linker_strdup(const char *str)
151 if ((result = malloc((strlen(str) + 1), M_LINKER, M_WAITOK)) != NULL)
157 linker_init(void *arg)
160 sx_init(&kld_sx, "kernel linker");
161 TAILQ_INIT(&classes);
162 TAILQ_INIT(&linker_files);
165 SYSINIT(linker, SI_SUB_KLD, SI_ORDER_FIRST, linker_init, 0);
168 linker_stop_class_add(void *arg)
171 linker_no_more_classes = 1;
174 SYSINIT(linker_class, SI_SUB_KLD, SI_ORDER_ANY, linker_stop_class_add, NULL);
177 linker_add_class(linker_class_t lc)
181 * We disallow any class registration past SI_ORDER_ANY
182 * of SI_SUB_KLD. We bump the reference count to keep the
183 * ops from being freed.
185 if (linker_no_more_classes == 1)
187 kobj_class_compile((kobj_class_t) lc);
188 ((kobj_class_t)lc)->refs++; /* XXX: kobj_mtx */
189 TAILQ_INSERT_TAIL(&classes, lc, link);
194 linker_file_sysinit(linker_file_t lf)
196 struct sysinit **start, **stop, **sipp, **xipp, *save;
198 KLD_DPF(FILE, ("linker_file_sysinit: calling SYSINITs for %s\n",
201 if (linker_file_lookup_set(lf, "sysinit_set", &start, &stop, NULL) != 0)
204 * Perform a bubble sort of the system initialization objects by
205 * their subsystem (primary key) and order (secondary key).
207 * Since some things care about execution order, this is the operation
208 * which ensures continued function.
210 for (sipp = start; sipp < stop; sipp++) {
211 for (xipp = sipp + 1; xipp < stop; xipp++) {
212 if ((*sipp)->subsystem < (*xipp)->subsystem ||
213 ((*sipp)->subsystem == (*xipp)->subsystem &&
214 (*sipp)->order <= (*xipp)->order))
223 * Traverse the (now) ordered list of system initialization tasks.
224 * Perform each task, and continue on to the next task.
227 for (sipp = start; sipp < stop; sipp++) {
228 if ((*sipp)->subsystem == SI_SUB_DUMMY)
229 continue; /* skip dummy task(s) */
232 (*((*sipp)->func)) ((*sipp)->udata);
238 linker_file_sysuninit(linker_file_t lf)
240 struct sysinit **start, **stop, **sipp, **xipp, *save;
242 KLD_DPF(FILE, ("linker_file_sysuninit: calling SYSUNINITs for %s\n",
245 if (linker_file_lookup_set(lf, "sysuninit_set", &start, &stop,
250 * Perform a reverse bubble sort of the system initialization objects
251 * by their subsystem (primary key) and order (secondary key).
253 * Since some things care about execution order, this is the operation
254 * which ensures continued function.
256 for (sipp = start; sipp < stop; sipp++) {
257 for (xipp = sipp + 1; xipp < stop; xipp++) {
258 if ((*sipp)->subsystem > (*xipp)->subsystem ||
259 ((*sipp)->subsystem == (*xipp)->subsystem &&
260 (*sipp)->order >= (*xipp)->order))
269 * Traverse the (now) ordered list of system initialization tasks.
270 * Perform each task, and continue on to the next task.
273 for (sipp = start; sipp < stop; sipp++) {
274 if ((*sipp)->subsystem == SI_SUB_DUMMY)
275 continue; /* skip dummy task(s) */
278 (*((*sipp)->func)) ((*sipp)->udata);
284 linker_file_register_sysctls(linker_file_t lf)
286 struct sysctl_oid **start, **stop, **oidp;
289 ("linker_file_register_sysctls: registering SYSCTLs for %s\n",
292 if (linker_file_lookup_set(lf, "sysctl_set", &start, &stop, NULL) != 0)
296 for (oidp = start; oidp < stop; oidp++)
297 sysctl_register_oid(*oidp);
302 linker_file_unregister_sysctls(linker_file_t lf)
304 struct sysctl_oid **start, **stop, **oidp;
306 KLD_DPF(FILE, ("linker_file_unregister_sysctls: registering SYSCTLs"
307 " for %s\n", lf->filename));
309 if (linker_file_lookup_set(lf, "sysctl_set", &start, &stop, NULL) != 0)
313 for (oidp = start; oidp < stop; oidp++)
314 sysctl_unregister_oid(*oidp);
319 linker_file_register_modules(linker_file_t lf)
321 struct mod_metadata **start, **stop, **mdp;
322 const moduledata_t *moddata;
323 int first_error, error;
325 KLD_DPF(FILE, ("linker_file_register_modules: registering modules"
326 " in %s\n", lf->filename));
328 if (linker_file_lookup_set(lf, "modmetadata_set", &start,
331 * This fallback should be unnecessary, but if we get booted
332 * from boot2 instead of loader and we are missing our
333 * metadata then we have to try the best we can.
335 if (lf == linker_kernel_file) {
336 start = SET_BEGIN(modmetadata_set);
337 stop = SET_LIMIT(modmetadata_set);
342 for (mdp = start; mdp < stop; mdp++) {
343 if ((*mdp)->md_type != MDT_MODULE)
345 moddata = (*mdp)->md_data;
346 KLD_DPF(FILE, ("Registering module %s in %s\n",
347 moddata->name, lf->filename));
348 error = module_register(moddata, lf);
350 printf("Module %s failed to register: %d\n",
351 moddata->name, error);
352 if (first_error == 0)
356 return (first_error);
360 linker_init_kernel_modules(void)
363 linker_file_register_modules(linker_kernel_file);
366 SYSINIT(linker_kernel, SI_SUB_KLD, SI_ORDER_ANY, linker_init_kernel_modules,
370 linker_load_file(const char *filename, linker_file_t *result)
374 int foundfile, error;
376 /* Refuse to load modules if securelevel raised */
381 lf = linker_find_file_by_name(filename);
383 KLD_DPF(FILE, ("linker_load_file: file %s is already loaded,"
384 " incrementing refs\n", filename));
393 * We do not need to protect (lock) classes here because there is
394 * no class registration past startup (SI_SUB_KLD, SI_ORDER_ANY)
395 * and there is no class deregistration mechanism at this time.
397 TAILQ_FOREACH(lc, &classes, link) {
398 KLD_DPF(FILE, ("linker_load_file: trying to load %s\n",
400 error = LINKER_LOAD_FILE(lc, filename, &lf);
402 * If we got something other than ENOENT, then it exists but
403 * we cannot load it for some other reason.
408 error = linker_file_register_modules(lf);
409 if (error == EEXIST) {
410 linker_file_unload(lf, LINKER_UNLOAD_FORCE);
414 linker_file_register_sysctls(lf);
415 linker_file_sysinit(lf);
417 lf->flags |= LINKER_FILE_LINKED;
423 * Less than ideal, but tells the user whether it failed to load or
424 * the module was not found.
428 * Format not recognized or otherwise unloadable.
429 * When loading a module that is statically built into
430 * the kernel EEXIST percolates back up as the return
431 * value. Preserve this so that apps like sysinstall
432 * can recognize this special case and not post bogus
438 error = ENOENT; /* Nothing found */
443 linker_reference_module(const char *modname, struct mod_depend *verinfo,
444 linker_file_t *result)
450 if ((mod = modlist_lookup2(modname, verinfo)) != NULL) {
451 *result = mod->container;
457 error = linker_load_module(NULL, modname, NULL, verinfo, result);
463 linker_release_module(const char *modname, struct mod_depend *verinfo,
471 KASSERT(modname != NULL,
472 ("linker_release_module: no file or name"));
473 mod = modlist_lookup2(modname, verinfo);
480 KASSERT(modname == NULL && verinfo == NULL,
481 ("linker_release_module: both file and name"));
482 error = linker_file_unload(lf, LINKER_UNLOAD_NORMAL);
488 linker_find_file_by_name(const char *filename)
493 koname = malloc(strlen(filename) + 4, M_LINKER, M_WAITOK);
494 sprintf(koname, "%s.ko", filename);
497 TAILQ_FOREACH(lf, &linker_files, link) {
498 if (strcmp(lf->filename, koname) == 0)
500 if (strcmp(lf->filename, filename) == 0)
503 free(koname, M_LINKER);
508 linker_find_file_by_id(int fileid)
513 TAILQ_FOREACH(lf, &linker_files, link)
514 if (lf->id == fileid && lf->flags & LINKER_FILE_LINKED)
520 linker_file_foreach(linker_predicate_t *predicate, void *context)
526 TAILQ_FOREACH(lf, &linker_files, link) {
527 retval = predicate(lf, context);
536 linker_make_file(const char *pathname, linker_class_t lc)
539 const char *filename;
542 filename = linker_basename(pathname);
544 KLD_DPF(FILE, ("linker_make_file: new file, filename='%s' for pathname='%s'\n", filename, pathname));
545 lf = (linker_file_t)kobj_create((kobj_class_t)lc, M_LINKER, M_WAITOK);
551 lf->filename = linker_strdup(filename);
552 lf->pathname = linker_strdup(pathname);
553 LINKER_GET_NEXT_FILE_ID(lf->id);
556 lf->loadcnt = ++loadcnt;
557 lf->sdt_probes = NULL;
559 STAILQ_INIT(&lf->common);
560 TAILQ_INIT(&lf->modules);
561 TAILQ_INSERT_TAIL(&linker_files, lf, link);
566 linker_file_unload(linker_file_t file, int flags)
569 modlist_t ml, nextml;
570 struct common_symbol *cp;
573 /* Refuse to unload modules if securelevel raised. */
578 KLD_DPF(FILE, ("linker_file_unload: lf->refs=%d\n", file->refs));
580 /* Easy case of just dropping a reference. */
581 if (file->refs > 1) {
586 KLD_DPF(FILE, ("linker_file_unload: file is unloading,"
587 " informing modules\n"));
590 * Inform any modules associated with this file.
593 for (mod = TAILQ_FIRST(&file->modules); mod; mod = next) {
594 next = module_getfnext(mod);
598 * Give the module a chance to veto the unload.
600 if ((error = module_unload(mod, flags)) != 0) {
601 KLD_DPF(FILE, ("linker_file_unload: module %p"
602 " vetoes unload\n", mod));
610 TAILQ_FOREACH_SAFE(ml, &found_modules, link, nextml) {
611 if (ml->container == file) {
612 TAILQ_REMOVE(&found_modules, ml, link);
618 * Don't try to run SYSUNINITs if we are unloaded due to a
621 if (file->flags & LINKER_FILE_LINKED) {
622 linker_file_sysuninit(file);
623 linker_file_unregister_sysctls(file);
625 TAILQ_REMOVE(&linker_files, file, link);
628 for (i = 0; i < file->ndeps; i++)
629 linker_file_unload(file->deps[i], flags);
630 free(file->deps, M_LINKER);
633 while ((cp = STAILQ_FIRST(&file->common)) != NULL) {
634 STAILQ_REMOVE_HEAD(&file->common, link);
639 if (file->filename) {
640 free(file->filename, M_LINKER);
641 file->filename = NULL;
643 if (file->pathname) {
644 free(file->pathname, M_LINKER);
645 file->pathname = NULL;
647 kobj_delete((kobj_t) file, M_LINKER);
652 linker_file_add_dependency(linker_file_t file, linker_file_t dep)
654 linker_file_t *newdeps;
657 newdeps = malloc((file->ndeps + 1) * sizeof(linker_file_t *),
658 M_LINKER, M_WAITOK | M_ZERO);
663 bcopy(file->deps, newdeps,
664 file->ndeps * sizeof(linker_file_t *));
665 free(file->deps, M_LINKER);
667 file->deps = newdeps;
668 file->deps[file->ndeps] = dep;
674 * Locate a linker set and its contents. This is a helper function to avoid
675 * linker_if.h exposure elsewhere. Note: firstp and lastp are really void **.
676 * This function is used in this file so we can avoid having lots of (void **)
680 linker_file_lookup_set(linker_file_t file, const char *name,
681 void *firstp, void *lastp, int *countp)
685 locked = KLD_LOCKED();
688 error = LINKER_LOOKUP_SET(file, name, firstp, lastp, countp);
695 * List all functions in a file.
698 linker_file_function_listall(linker_file_t lf,
699 int (*callback_func)(linker_file_t, linker_symval_t *, void *), void *arg)
701 return (LINKER_EACH_FUNCTION_NAMEVAL(lf, callback_func, arg));
705 linker_file_lookup_symbol(linker_file_t file, const char *name, int deps)
710 locked = KLD_LOCKED();
713 sym = linker_file_lookup_symbol_internal(file, name, deps);
720 linker_file_lookup_symbol_internal(linker_file_t file, const char *name,
724 linker_symval_t symval;
726 size_t common_size = 0;
730 KLD_DPF(SYM, ("linker_file_lookup_symbol: file=%p, name=%s, deps=%d\n",
733 if (LINKER_LOOKUP_SYMBOL(file, name, &sym) == 0) {
734 LINKER_SYMBOL_VALUES(file, sym, &symval);
735 if (symval.value == 0)
737 * For commons, first look them up in the
738 * dependencies and only allocate space if not found
741 common_size = symval.size;
743 KLD_DPF(SYM, ("linker_file_lookup_symbol: symbol"
744 ".value=%p\n", symval.value));
745 return (symval.value);
749 for (i = 0; i < file->ndeps; i++) {
750 address = linker_file_lookup_symbol_internal(
751 file->deps[i], name, 0);
753 KLD_DPF(SYM, ("linker_file_lookup_symbol:"
754 " deps value=%p\n", address));
759 if (common_size > 0) {
761 * This is a common symbol which was not found in the
762 * dependencies. We maintain a simple common symbol table in
765 struct common_symbol *cp;
767 STAILQ_FOREACH(cp, &file->common, link) {
768 if (strcmp(cp->name, name) == 0) {
769 KLD_DPF(SYM, ("linker_file_lookup_symbol:"
770 " old common value=%p\n", cp->address));
771 return (cp->address);
775 * Round the symbol size up to align.
777 common_size = (common_size + sizeof(int) - 1) & -sizeof(int);
778 cp = malloc(sizeof(struct common_symbol)
779 + common_size + strlen(name) + 1, M_LINKER,
781 cp->address = (caddr_t)(cp + 1);
782 cp->name = cp->address + common_size;
783 strcpy(cp->name, name);
784 bzero(cp->address, common_size);
785 STAILQ_INSERT_TAIL(&file->common, cp, link);
787 KLD_DPF(SYM, ("linker_file_lookup_symbol: new common"
788 " value=%p\n", cp->address));
789 return (cp->address);
791 KLD_DPF(SYM, ("linker_file_lookup_symbol: fail\n"));
796 * Both DDB and stack(9) rely on the kernel linker to provide forward and
797 * backward lookup of symbols. However, DDB and sometimes stack(9) need to
798 * do this in a lockfree manner. We provide a set of internal helper
799 * routines to perform these operations without locks, and then wrappers that
802 * linker_debug_lookup() is ifdef DDB as currently it's only used by DDB.
806 linker_debug_lookup(const char *symstr, c_linker_sym_t *sym)
810 TAILQ_FOREACH(lf, &linker_files, link) {
811 if (LINKER_LOOKUP_SYMBOL(lf, symstr, sym) == 0)
819 linker_debug_search_symbol(caddr_t value, c_linker_sym_t *sym, long *diffp)
822 c_linker_sym_t best, es;
823 u_long diff, bestdiff, off;
826 off = (uintptr_t)value;
828 TAILQ_FOREACH(lf, &linker_files, link) {
829 if (LINKER_SEARCH_SYMBOL(lf, value, &es, &diff) != 0)
831 if (es != 0 && diff < bestdiff) {
850 linker_debug_symbol_values(c_linker_sym_t sym, linker_symval_t *symval)
854 TAILQ_FOREACH(lf, &linker_files, link) {
855 if (LINKER_SYMBOL_VALUES(lf, sym, symval) == 0)
862 linker_debug_search_symbol_name(caddr_t value, char *buf, u_int buflen,
865 linker_symval_t symval;
870 error = linker_debug_search_symbol(value, &sym, offset);
873 error = linker_debug_symbol_values(sym, &symval);
876 strlcpy(buf, symval.name, buflen);
882 * DDB Helpers. DDB has to look across multiple files with their own symbol
883 * tables and string tables.
885 * Note that we do not obey list locking protocols here. We really don't need
886 * DDB to hang because somebody's got the lock held. We'll take the chance
887 * that the files list is inconsistant instead.
890 linker_ddb_lookup(const char *symstr, c_linker_sym_t *sym)
893 return (linker_debug_lookup(symstr, sym));
897 linker_ddb_search_symbol(caddr_t value, c_linker_sym_t *sym, long *diffp)
900 return (linker_debug_search_symbol(value, sym, diffp));
904 linker_ddb_symbol_values(c_linker_sym_t sym, linker_symval_t *symval)
907 return (linker_debug_symbol_values(sym, symval));
911 linker_ddb_search_symbol_name(caddr_t value, char *buf, u_int buflen,
915 return (linker_debug_search_symbol_name(value, buf, buflen, offset));
920 * stack(9) helper for non-debugging environemnts. Unlike DDB helpers, we do
921 * obey locking protocols, and offer a significantly less complex interface.
924 linker_search_symbol_name(caddr_t value, char *buf, u_int buflen,
930 error = linker_debug_search_symbol_name(value, buf, buflen, offset);
939 kern_kldload(struct thread *td, const char *file, int *fileid)
942 struct pmckern_map_in pkm;
944 const char *kldname, *modname;
948 if ((error = securelevel_gt(td->td_ucred, 0)) != 0)
951 if ((error = priv_check(td, PRIV_KLD_LOAD)) != 0)
955 * If file does not contain a qualified name or any dot in it
956 * (kldname.ko, or kldname.ver.ko) treat it as an interface
959 if (index(file, '/') || index(file, '.')) {
968 error = linker_load_module(kldname, modname, NULL, NULL, &lf);
972 pkm.pm_file = lf->filename;
973 pkm.pm_address = (uintptr_t) lf->address;
974 PMC_CALL_HOOK(td, PMC_FN_KLD_LOAD, (void *) &pkm);
985 kldload(struct thread *td, struct kldload_args *uap)
987 char *pathname = NULL;
990 td->td_retval[0] = -1;
992 pathname = malloc(MAXPATHLEN, M_TEMP, M_WAITOK);
993 error = copyinstr(uap->file, pathname, MAXPATHLEN, NULL);
995 error = kern_kldload(td, pathname, &fileid);
997 td->td_retval[0] = fileid;
999 free(pathname, M_TEMP);
1004 kern_kldunload(struct thread *td, int fileid, int flags)
1007 struct pmckern_map_out pkm;
1012 if ((error = securelevel_gt(td->td_ucred, 0)) != 0)
1015 if ((error = priv_check(td, PRIV_KLD_UNLOAD)) != 0)
1019 lf = linker_find_file_by_id(fileid);
1021 KLD_DPF(FILE, ("kldunload: lf->userrefs=%d\n", lf->userrefs));
1023 /* Check if there are DTrace probes enabled on this file. */
1024 if (lf->nenabled > 0) {
1025 printf("kldunload: attempt to unload file that has"
1026 " DTrace probes enabled\n");
1028 } else if (lf->userrefs == 0) {
1030 * XXX: maybe LINKER_UNLOAD_FORCE should override ?
1032 printf("kldunload: attempt to unload file that was"
1033 " loaded by the kernel\n");
1037 /* Save data needed by hwpmc(4) before unloading. */
1038 pkm.pm_address = (uintptr_t) lf->address;
1039 pkm.pm_size = lf->size;
1042 error = linker_file_unload(lf, flags);
1051 PMC_CALL_HOOK(td, PMC_FN_KLD_UNLOAD, (void *) &pkm);
1058 kldunload(struct thread *td, struct kldunload_args *uap)
1061 return (kern_kldunload(td, uap->fileid, LINKER_UNLOAD_NORMAL));
1065 kldunloadf(struct thread *td, struct kldunloadf_args *uap)
1068 if (uap->flags != LINKER_UNLOAD_NORMAL &&
1069 uap->flags != LINKER_UNLOAD_FORCE)
1071 return (kern_kldunload(td, uap->fileid, uap->flags));
1075 kldfind(struct thread *td, struct kldfind_args *uap)
1078 const char *filename;
1083 error = mac_kld_check_stat(td->td_ucred);
1088 td->td_retval[0] = -1;
1090 pathname = malloc(MAXPATHLEN, M_TEMP, M_WAITOK);
1091 if ((error = copyinstr(uap->file, pathname, MAXPATHLEN, NULL)) != 0)
1094 filename = linker_basename(pathname);
1096 lf = linker_find_file_by_name(filename);
1098 td->td_retval[0] = lf->id;
1103 free(pathname, M_TEMP);
1108 kldnext(struct thread *td, struct kldnext_args *uap)
1114 error = mac_kld_check_stat(td->td_ucred);
1120 if (uap->fileid == 0)
1121 lf = TAILQ_FIRST(&linker_files);
1123 lf = linker_find_file_by_id(uap->fileid);
1128 lf = TAILQ_NEXT(lf, link);
1131 /* Skip partially loaded files. */
1132 while (lf != NULL && !(lf->flags & LINKER_FILE_LINKED))
1133 lf = TAILQ_NEXT(lf, link);
1136 td->td_retval[0] = lf->id;
1138 td->td_retval[0] = 0;
1145 kldstat(struct thread *td, struct kldstat_args *uap)
1147 struct kld_file_stat stat;
1149 int error, namelen, version, version_num;
1152 * Check the version of the user's structure.
1154 if ((error = copyin(&uap->stat->version, &version, sizeof(version))) != 0)
1156 if (version == sizeof(struct kld_file_stat_1))
1158 else if (version == sizeof(struct kld_file_stat))
1164 error = mac_kld_check_stat(td->td_ucred);
1170 lf = linker_find_file_by_id(uap->fileid);
1176 /* Version 1 fields: */
1177 namelen = strlen(lf->filename) + 1;
1178 if (namelen > MAXPATHLEN)
1179 namelen = MAXPATHLEN;
1180 bcopy(lf->filename, &stat.name[0], namelen);
1181 stat.refs = lf->refs;
1183 stat.address = lf->address;
1184 stat.size = lf->size;
1185 if (version_num > 1) {
1186 /* Version 2 fields: */
1187 namelen = strlen(lf->pathname) + 1;
1188 if (namelen > MAXPATHLEN)
1189 namelen = MAXPATHLEN;
1190 bcopy(lf->pathname, &stat.pathname[0], namelen);
1194 td->td_retval[0] = 0;
1196 return (copyout(&stat, uap->stat, version));
1200 kldfirstmod(struct thread *td, struct kldfirstmod_args *uap)
1207 error = mac_kld_check_stat(td->td_ucred);
1213 lf = linker_find_file_by_id(uap->fileid);
1216 mp = TAILQ_FIRST(&lf->modules);
1218 td->td_retval[0] = module_getid(mp);
1220 td->td_retval[0] = 0;
1229 kldsym(struct thread *td, struct kldsym_args *uap)
1231 char *symstr = NULL;
1233 linker_symval_t symval;
1235 struct kld_sym_lookup lookup;
1239 error = mac_kld_check_stat(td->td_ucred);
1244 if ((error = copyin(uap->data, &lookup, sizeof(lookup))) != 0)
1246 if (lookup.version != sizeof(lookup) ||
1247 uap->cmd != KLDSYM_LOOKUP)
1249 symstr = malloc(MAXPATHLEN, M_TEMP, M_WAITOK);
1250 if ((error = copyinstr(lookup.symname, symstr, MAXPATHLEN, NULL)) != 0)
1253 if (uap->fileid != 0) {
1254 lf = linker_find_file_by_id(uap->fileid);
1257 else if (LINKER_LOOKUP_SYMBOL(lf, symstr, &sym) == 0 &&
1258 LINKER_SYMBOL_VALUES(lf, sym, &symval) == 0) {
1259 lookup.symvalue = (uintptr_t) symval.value;
1260 lookup.symsize = symval.size;
1261 error = copyout(&lookup, uap->data, sizeof(lookup));
1265 TAILQ_FOREACH(lf, &linker_files, link) {
1266 if (LINKER_LOOKUP_SYMBOL(lf, symstr, &sym) == 0 &&
1267 LINKER_SYMBOL_VALUES(lf, sym, &symval) == 0) {
1268 lookup.symvalue = (uintptr_t)symval.value;
1269 lookup.symsize = symval.size;
1270 error = copyout(&lookup, uap->data,
1280 free(symstr, M_TEMP);
1285 * Preloaded module support
1289 modlist_lookup(const char *name, int ver)
1293 TAILQ_FOREACH(mod, &found_modules, link) {
1294 if (strcmp(mod->name, name) == 0 &&
1295 (ver == 0 || mod->version == ver))
1302 modlist_lookup2(const char *name, struct mod_depend *verinfo)
1304 modlist_t mod, bestmod;
1307 if (verinfo == NULL)
1308 return (modlist_lookup(name, 0));
1310 TAILQ_FOREACH(mod, &found_modules, link) {
1311 if (strcmp(mod->name, name) != 0)
1314 if (ver == verinfo->md_ver_preferred)
1316 if (ver >= verinfo->md_ver_minimum &&
1317 ver <= verinfo->md_ver_maximum &&
1318 (bestmod == NULL || ver > bestmod->version))
1325 modlist_newmodule(const char *modname, int version, linker_file_t container)
1329 mod = malloc(sizeof(struct modlist), M_LINKER, M_NOWAIT | M_ZERO);
1331 panic("no memory for module list");
1332 mod->container = container;
1333 mod->name = modname;
1334 mod->version = version;
1335 TAILQ_INSERT_TAIL(&found_modules, mod, link);
1340 linker_addmodules(linker_file_t lf, struct mod_metadata **start,
1341 struct mod_metadata **stop, int preload)
1343 struct mod_metadata *mp, **mdp;
1344 const char *modname;
1347 for (mdp = start; mdp < stop; mdp++) {
1349 if (mp->md_type != MDT_VERSION)
1351 modname = mp->md_cval;
1352 ver = ((struct mod_version *)mp->md_data)->mv_version;
1353 if (modlist_lookup(modname, ver) != NULL) {
1354 printf("module %s already present!\n", modname);
1355 /* XXX what can we do? this is a build error. :-( */
1358 modlist_newmodule(modname, ver, lf);
1363 linker_preload(void *arg)
1366 const char *modname, *nmodname;
1368 linker_file_t lf, nlf;
1371 linker_file_list_t loaded_files;
1372 linker_file_list_t depended_files;
1373 struct mod_metadata *mp, *nmp;
1374 struct mod_metadata **start, **stop, **mdp, **nmdp;
1375 struct mod_depend *verinfo;
1379 struct sysinit **si_start, **si_stop;
1381 TAILQ_INIT(&loaded_files);
1382 TAILQ_INIT(&depended_files);
1383 TAILQ_INIT(&found_modules);
1387 while ((modptr = preload_search_next_name(modptr)) != NULL) {
1388 modname = (char *)preload_search_info(modptr, MODINFO_NAME);
1389 modtype = (char *)preload_search_info(modptr, MODINFO_TYPE);
1390 if (modname == NULL) {
1391 printf("Preloaded module at %p does not have a"
1392 " name!\n", modptr);
1395 if (modtype == NULL) {
1396 printf("Preloaded module at %p does not have a type!\n",
1401 printf("Preloaded %s \"%s\" at %p.\n", modtype, modname,
1404 TAILQ_FOREACH(lc, &classes, link) {
1405 error = LINKER_LINK_PRELOAD(lc, modname, &lf);
1411 TAILQ_INSERT_TAIL(&loaded_files, lf, loaded);
1415 * First get a list of stuff in the kernel.
1417 if (linker_file_lookup_set(linker_kernel_file, MDT_SETNAME, &start,
1419 linker_addmodules(linker_kernel_file, start, stop, 1);
1422 * This is a once-off kinky bubble sort to resolve relocation
1423 * dependency requirements.
1426 TAILQ_FOREACH(lf, &loaded_files, loaded) {
1427 error = linker_file_lookup_set(lf, MDT_SETNAME, &start,
1430 * First, look to see if we would successfully link with this
1433 resolves = 1; /* unless we know otherwise */
1435 for (mdp = start; mdp < stop; mdp++) {
1437 if (mp->md_type != MDT_DEPEND)
1439 modname = mp->md_cval;
1440 verinfo = mp->md_data;
1441 for (nmdp = start; nmdp < stop; nmdp++) {
1443 if (nmp->md_type != MDT_VERSION)
1445 nmodname = nmp->md_cval;
1446 if (strcmp(modname, nmodname) == 0)
1449 if (nmdp < stop) /* it's a self reference */
1453 * ok, the module isn't here yet, we
1456 if (modlist_lookup2(modname, verinfo) == NULL)
1461 * OK, if we found our modules, we can link. So, "provide"
1462 * the modules inside and add it to the end of the link order
1467 for (mdp = start; mdp < stop; mdp++) {
1469 if (mp->md_type != MDT_VERSION)
1471 modname = mp->md_cval;
1472 nver = ((struct mod_version *)
1473 mp->md_data)->mv_version;
1474 if (modlist_lookup(modname,
1476 printf("module %s already"
1477 " present!\n", modname);
1478 TAILQ_REMOVE(&loaded_files,
1480 linker_file_unload(lf,
1481 LINKER_UNLOAD_FORCE);
1482 /* we changed tailq next ptr */
1485 modlist_newmodule(modname, nver, lf);
1488 TAILQ_REMOVE(&loaded_files, lf, loaded);
1489 TAILQ_INSERT_TAIL(&depended_files, lf, loaded);
1491 * Since we provided modules, we need to restart the
1492 * sort so that the previous files that depend on us
1493 * have a chance. Also, we've busted the tailq next
1494 * pointer with the REMOVE.
1501 * At this point, we check to see what could not be resolved..
1503 while ((lf = TAILQ_FIRST(&loaded_files)) != NULL) {
1504 TAILQ_REMOVE(&loaded_files, lf, loaded);
1505 printf("KLD file %s is missing dependencies\n", lf->filename);
1506 linker_file_unload(lf, LINKER_UNLOAD_FORCE);
1510 * We made it. Finish off the linking in the order we determined.
1512 TAILQ_FOREACH_SAFE(lf, &depended_files, loaded, nlf) {
1513 if (linker_kernel_file) {
1514 linker_kernel_file->refs++;
1515 error = linker_file_add_dependency(lf,
1516 linker_kernel_file);
1518 panic("cannot add dependency");
1520 lf->userrefs++; /* so we can (try to) kldunload it */
1521 error = linker_file_lookup_set(lf, MDT_SETNAME, &start,
1524 for (mdp = start; mdp < stop; mdp++) {
1526 if (mp->md_type != MDT_DEPEND)
1528 modname = mp->md_cval;
1529 verinfo = mp->md_data;
1530 mod = modlist_lookup2(modname, verinfo);
1531 /* Don't count self-dependencies */
1532 if (lf == mod->container)
1534 mod->container->refs++;
1535 error = linker_file_add_dependency(lf,
1538 panic("cannot add dependency");
1542 * Now do relocation etc using the symbol search paths
1543 * established by the dependencies
1545 error = LINKER_LINK_PRELOAD_FINISH(lf);
1547 TAILQ_REMOVE(&depended_files, lf, loaded);
1548 printf("KLD file %s - could not finalize loading\n",
1550 linker_file_unload(lf, LINKER_UNLOAD_FORCE);
1553 linker_file_register_modules(lf);
1554 if (linker_file_lookup_set(lf, "sysinit_set", &si_start,
1555 &si_stop, NULL) == 0)
1556 sysinit_add(si_start, si_stop);
1557 linker_file_register_sysctls(lf);
1558 lf->flags |= LINKER_FILE_LINKED;
1560 /* woohoo! we made it! */
1563 SYSINIT(preload, SI_SUB_KLD, SI_ORDER_MIDDLE, linker_preload, 0);
1566 * Search for a not-loaded module by name.
1568 * Modules may be found in the following locations:
1570 * - preloaded (result is just the module name) - on disk (result is full path
1573 * If the module name is qualified in any way (contains path, etc.) the we
1574 * simply return a copy of it.
1576 * The search path can be manipulated via sysctl. Note that we use the ';'
1577 * character as a separator to be consistent with the bootloader.
1580 static char linker_hintfile[] = "linker.hints";
1581 static char linker_path[MAXPATHLEN] = "/boot/kernel;/boot/modules";
1583 SYSCTL_STRING(_kern, OID_AUTO, module_path, CTLFLAG_RW, linker_path,
1584 sizeof(linker_path), "module load search path");
1586 TUNABLE_STR("module_path", linker_path, sizeof(linker_path));
1588 static char *linker_ext_list[] = {
1595 * Check if file actually exists either with or without extension listed in
1596 * the linker_ext_list. (probably should be generic for the rest of the
1600 linker_lookup_file(const char *path, int pathlen, const char *name,
1601 int namelen, struct vattr *vap)
1603 struct nameidata nd;
1604 struct thread *td = curthread; /* XXX */
1605 char *result, **cpp, *sep;
1606 int error, len, extlen, reclen, flags, vfslocked;
1610 for (cpp = linker_ext_list; *cpp; cpp++) {
1615 extlen++; /* trailing '\0' */
1616 sep = (path[pathlen - 1] != '/') ? "/" : "";
1618 reclen = pathlen + strlen(sep) + namelen + extlen + 1;
1619 result = malloc(reclen, M_LINKER, M_WAITOK);
1620 for (cpp = linker_ext_list; *cpp; cpp++) {
1621 snprintf(result, reclen, "%.*s%s%.*s%s", pathlen, path, sep,
1622 namelen, name, *cpp);
1624 * Attempt to open the file, and return the path if
1625 * we succeed and it's a regular file.
1627 NDINIT(&nd, LOOKUP, FOLLOW | MPSAFE, UIO_SYSSPACE, result, td);
1629 error = vn_open(&nd, &flags, 0, NULL);
1631 vfslocked = NDHASGIANT(&nd);
1632 NDFREE(&nd, NDF_ONLY_PNBUF);
1633 type = nd.ni_vp->v_type;
1635 VOP_GETATTR(nd.ni_vp, vap, td->td_ucred, td);
1636 VOP_UNLOCK(nd.ni_vp, 0);
1637 vn_close(nd.ni_vp, FREAD, td->td_ucred, td);
1638 VFS_UNLOCK_GIANT(vfslocked);
1643 free(result, M_LINKER);
1647 #define INT_ALIGN(base, ptr) ptr = \
1648 (base) + (((ptr) - (base) + sizeof(int) - 1) & ~(sizeof(int) - 1))
1651 * Lookup KLD which contains requested module in the "linker.hints" file. If
1652 * version specification is available, then try to find the best KLD.
1653 * Otherwise just find the latest one.
1656 linker_hints_lookup(const char *path, int pathlen, const char *modname,
1657 int modnamelen, struct mod_depend *verinfo)
1659 struct thread *td = curthread; /* XXX */
1660 struct ucred *cred = td ? td->td_ucred : NULL;
1661 struct nameidata nd;
1662 struct vattr vattr, mattr;
1663 u_char *hints = NULL;
1664 u_char *cp, *recptr, *bufend, *result, *best, *pathbuf, *sep;
1665 int error, ival, bestver, *intp, reclen, found, flags, clen, blen;
1669 bestver = found = 0;
1671 sep = (path[pathlen - 1] != '/') ? "/" : "";
1672 reclen = imax(modnamelen, strlen(linker_hintfile)) + pathlen +
1674 pathbuf = malloc(reclen, M_LINKER, M_WAITOK);
1675 snprintf(pathbuf, reclen, "%.*s%s%s", pathlen, path, sep,
1678 NDINIT(&nd, LOOKUP, NOFOLLOW | MPSAFE, UIO_SYSSPACE, pathbuf, td);
1680 error = vn_open(&nd, &flags, 0, NULL);
1683 vfslocked = NDHASGIANT(&nd);
1684 NDFREE(&nd, NDF_ONLY_PNBUF);
1685 if (nd.ni_vp->v_type != VREG)
1688 error = VOP_GETATTR(nd.ni_vp, &vattr, cred, td);
1692 * XXX: we need to limit this number to some reasonable value
1694 if (vattr.va_size > 100 * 1024) {
1695 printf("hints file too large %ld\n", (long)vattr.va_size);
1698 hints = malloc(vattr.va_size, M_TEMP, M_WAITOK);
1701 error = vn_rdwr(UIO_READ, nd.ni_vp, (caddr_t)hints, vattr.va_size, 0,
1702 UIO_SYSSPACE, IO_NODELOCKED, cred, NOCRED, &reclen, td);
1705 VOP_UNLOCK(nd.ni_vp, 0);
1706 vn_close(nd.ni_vp, FREAD, cred, td);
1707 VFS_UNLOCK_GIANT(vfslocked);
1710 printf("can't read %d\n", reclen);
1713 intp = (int *)hints;
1715 if (ival != LINKER_HINTS_VERSION) {
1716 printf("hints file version mismatch %d\n", ival);
1719 bufend = hints + vattr.va_size;
1720 recptr = (u_char *)intp;
1722 while (recptr < bufend && !found) {
1723 intp = (int *)recptr;
1730 if (clen != modnamelen || bcmp(cp, modname, clen) != 0)
1733 INT_ALIGN(hints, cp);
1737 if (verinfo == NULL ||
1738 ival == verinfo->md_ver_preferred) {
1742 if (ival >= verinfo->md_ver_minimum &&
1743 ival <= verinfo->md_ver_maximum &&
1753 recptr += reclen + sizeof(int);
1756 * Finally check if KLD is in the place
1759 result = linker_lookup_file(path, pathlen, cp, clen, &mattr);
1761 result = linker_lookup_file(path, pathlen, best, blen, &mattr);
1764 * KLD is newer than hints file. What we should do now?
1766 if (result && timespeccmp(&mattr.va_mtime, &vattr.va_mtime, >))
1767 printf("warning: KLD '%s' is newer than the linker.hints"
1770 free(pathbuf, M_LINKER);
1772 free(hints, M_TEMP);
1773 if (nd.ni_vp != NULL) {
1774 VOP_UNLOCK(nd.ni_vp, 0);
1775 vn_close(nd.ni_vp, FREAD, cred, td);
1776 VFS_UNLOCK_GIANT(vfslocked);
1779 * If nothing found or hints is absent - fallback to the old
1780 * way by using "kldname[.ko]" as module name.
1782 if (!found && !bestver && result == NULL)
1783 result = linker_lookup_file(path, pathlen, modname,
1789 * Lookup KLD which contains requested module in the all directories.
1792 linker_search_module(const char *modname, int modnamelen,
1793 struct mod_depend *verinfo)
1795 char *cp, *ep, *result;
1798 * traverse the linker path
1800 for (cp = linker_path; *cp; cp = ep + 1) {
1801 /* find the end of this component */
1802 for (ep = cp; (*ep != 0) && (*ep != ';'); ep++);
1803 result = linker_hints_lookup(cp, ep - cp, modname,
1804 modnamelen, verinfo);
1814 * Search for module in all directories listed in the linker_path.
1817 linker_search_kld(const char *name)
1819 char *cp, *ep, *result;
1822 /* qualified at all? */
1823 if (index(name, '/'))
1824 return (linker_strdup(name));
1826 /* traverse the linker path */
1828 for (ep = linker_path; *ep; ep++) {
1830 /* find the end of this component */
1831 for (; *ep != 0 && *ep != ';'; ep++);
1832 result = linker_lookup_file(cp, ep - cp, name, len, NULL);
1840 linker_basename(const char *path)
1842 const char *filename;
1844 filename = rindex(path, '/');
1845 if (filename == NULL)
1854 struct hwpmc_context {
1857 struct pmckern_map_in *kobase;
1861 linker_hwpmc_list_object(linker_file_t lf, void *arg)
1863 struct hwpmc_context *hc;
1867 /* If we run out of mappings, fail. */
1868 if (hc->nobjects >= hc->nmappings)
1871 /* Save the info for this linker file. */
1872 hc->kobase[hc->nobjects].pm_file = lf->filename;
1873 hc->kobase[hc->nobjects].pm_address = (uintptr_t)lf->address;
1879 * Inform hwpmc about the set of kernel modules currently loaded.
1882 linker_hwpmc_list_objects(void)
1884 struct hwpmc_context hc;
1886 hc.nmappings = 15; /* a reasonable default */
1889 /* allocate nmappings+1 entries */
1890 MALLOC(hc.kobase, struct pmckern_map_in *,
1891 (hc.nmappings + 1) * sizeof(struct pmckern_map_in), M_LINKER,
1895 if (linker_file_foreach(linker_hwpmc_list_object, &hc) != 0) {
1896 hc.nmappings = hc.nobjects;
1897 FREE(hc.kobase, M_LINKER);
1901 KASSERT(hc.nobjects > 0, ("linker_hpwmc_list_objects: no kernel "
1904 /* The last entry of the malloced area comprises of all zeros. */
1905 KASSERT(hc.kobase[hc.nobjects].pm_file == NULL,
1906 ("linker_hwpmc_list_objects: last object not NULL"));
1908 return ((void *)hc.kobase);
1913 * Find a file which contains given module and load it, if "parent" is not
1914 * NULL, register a reference to it.
1917 linker_load_module(const char *kldname, const char *modname,
1918 struct linker_file *parent, struct mod_depend *verinfo,
1919 struct linker_file **lfpp)
1921 linker_file_t lfdep;
1922 const char *filename;
1927 if (modname == NULL) {
1929 * We have to load KLD
1931 KASSERT(verinfo == NULL, ("linker_load_module: verinfo"
1933 pathname = linker_search_kld(kldname);
1935 if (modlist_lookup2(modname, verinfo) != NULL)
1937 if (kldname != NULL)
1938 pathname = linker_strdup(kldname);
1939 else if (rootvnode == NULL)
1943 * Need to find a KLD with required module
1945 pathname = linker_search_module(modname,
1946 strlen(modname), verinfo);
1948 if (pathname == NULL)
1952 * Can't load more than one file with the same basename XXX:
1953 * Actually it should be possible to have multiple KLDs with
1954 * the same basename but different path because they can
1955 * provide different versions of the same modules.
1957 filename = linker_basename(pathname);
1958 if (linker_find_file_by_name(filename))
1961 error = linker_load_file(pathname, &lfdep);
1964 if (modname && verinfo &&
1965 modlist_lookup2(modname, verinfo) == NULL) {
1966 linker_file_unload(lfdep, LINKER_UNLOAD_FORCE);
1971 error = linker_file_add_dependency(parent, lfdep);
1978 free(pathname, M_LINKER);
1983 * This routine is responsible for finding dependencies of userland initiated
1984 * kldload(2)'s of files.
1987 linker_load_dependencies(linker_file_t lf)
1989 linker_file_t lfdep;
1990 struct mod_metadata **start, **stop, **mdp, **nmdp;
1991 struct mod_metadata *mp, *nmp;
1992 struct mod_depend *verinfo;
1994 const char *modname, *nmodname;
1995 int ver, error = 0, count;
1998 * All files are dependant on /kernel.
2001 if (linker_kernel_file) {
2002 linker_kernel_file->refs++;
2003 error = linker_file_add_dependency(lf, linker_kernel_file);
2007 if (linker_file_lookup_set(lf, MDT_SETNAME, &start, &stop,
2010 for (mdp = start; mdp < stop; mdp++) {
2012 if (mp->md_type != MDT_VERSION)
2014 modname = mp->md_cval;
2015 ver = ((struct mod_version *)mp->md_data)->mv_version;
2016 mod = modlist_lookup(modname, ver);
2018 printf("interface %s.%d already present in the KLD"
2019 " '%s'!\n", modname, ver,
2020 mod->container->filename);
2025 for (mdp = start; mdp < stop; mdp++) {
2027 if (mp->md_type != MDT_DEPEND)
2029 modname = mp->md_cval;
2030 verinfo = mp->md_data;
2032 for (nmdp = start; nmdp < stop; nmdp++) {
2034 if (nmp->md_type != MDT_VERSION)
2036 nmodname = nmp->md_cval;
2037 if (strcmp(modname, nmodname) == 0)
2040 if (nmdp < stop)/* early exit, it's a self reference */
2042 mod = modlist_lookup2(modname, verinfo);
2043 if (mod) { /* woohoo, it's loaded already */
2044 lfdep = mod->container;
2046 error = linker_file_add_dependency(lf, lfdep);
2051 error = linker_load_module(NULL, modname, lf, verinfo, NULL);
2053 printf("KLD %s: depends on %s - not available\n",
2054 lf->filename, modname);
2061 linker_addmodules(lf, start, stop, 0);
2066 sysctl_kern_function_list_iterate(const char *name, void *opaque)
2068 struct sysctl_req *req;
2071 return (SYSCTL_OUT(req, name, strlen(name) + 1));
2075 * Export a nul-separated, double-nul-terminated list of all function names
2079 sysctl_kern_function_list(SYSCTL_HANDLER_ARGS)
2085 error = mac_kld_check_stat(req->td->td_ucred);
2089 error = sysctl_wire_old_buffer(req, 0);
2093 TAILQ_FOREACH(lf, &linker_files, link) {
2094 error = LINKER_EACH_FUNCTION_NAME(lf,
2095 sysctl_kern_function_list_iterate, req);
2102 return (SYSCTL_OUT(req, "", 1));
2105 SYSCTL_PROC(_kern, OID_AUTO, function_list, CTLFLAG_RD,
2106 NULL, 0, sysctl_kern_function_list, "", "kernel function list");