2 * Copyright (c) 1997 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
26 * $FreeBSD: src/sys/kern/kern_linker.c,v 1.41.2.3 2001/11/21 17:50:35 luigi Exp $
27 * $DragonFly: src/sys/kern/kern_linker.c,v 1.6 2003/06/27 01:53:25 dillon Exp $
32 #include <sys/param.h>
33 #include <sys/kernel.h>
34 #include <sys/systm.h>
35 #include <sys/malloc.h>
36 #include <sys/sysproto.h>
37 #include <sys/sysent.h>
40 #include <sys/module.h>
41 #include <sys/linker.h>
42 #include <sys/fcntl.h>
43 #include <sys/libkern.h>
44 #include <sys/namei.h>
45 #include <sys/vnode.h>
46 #include <sys/sysctl.h>
48 #include <vm/vm_zone.h>
54 MALLOC_DEFINE(M_LINKER, "kld", "kernel linker");
55 linker_file_t linker_current_file;
56 linker_file_t linker_kernel_file;
58 static struct lock lock; /* lock for the file list */
59 static linker_class_list_t classes;
60 static linker_file_list_t linker_files;
61 static int next_file_id = 1;
64 linker_init(void* arg)
66 lockinit(&lock, PVM, "klink", 0, 0);
68 TAILQ_INIT(&linker_files);
71 SYSINIT(linker, SI_SUB_KLD, SI_ORDER_FIRST, linker_init, 0);
74 linker_add_class(const char* desc, void* priv,
75 struct linker_class_ops* ops)
79 lc = malloc(sizeof(struct linker_class), M_LINKER, M_NOWAIT);
82 bzero(lc, sizeof(*lc));
87 TAILQ_INSERT_HEAD(&classes, lc, link);
93 linker_file_sysinit(linker_file_t lf)
95 struct linker_set* sysinits;
96 struct sysinit** sipp;
97 struct sysinit** xipp;
99 const moduledata_t *moddata;
102 KLD_DPF(FILE, ("linker_file_sysinit: calling SYSINITs for %s\n",
105 sysinits = (struct linker_set*)
106 linker_file_lookup_symbol(lf, "sysinit_set", 0);
108 KLD_DPF(FILE, ("linker_file_sysinit: SYSINITs %p\n", sysinits));
110 return 0; /* XXX is this correct ? No sysinit ? */
113 for (sipp = (struct sysinit **)sysinits->ls_items; *sipp; sipp++) {
114 if ((*sipp)->func == module_register_init) {
115 moddata = (*sipp)->udata;
116 error = module_register(moddata, lf);
118 printf("linker_file_sysinit \"%s\" failed to register! %d\n",
119 lf->filename, error);
126 * Perform a bubble sort of the system initialization objects by
127 * their subsystem (primary key) and order (secondary key).
129 * Since some things care about execution order, this is the
130 * operation which ensures continued function.
132 for (sipp = (struct sysinit **)sysinits->ls_items; *sipp; sipp++) {
133 for (xipp = sipp + 1; *xipp; xipp++) {
134 if ((*sipp)->subsystem < (*xipp)->subsystem ||
135 ((*sipp)->subsystem == (*xipp)->subsystem &&
136 (*sipp)->order <= (*xipp)->order))
146 * Traverse the (now) ordered list of system initialization tasks.
147 * Perform each task, and continue on to the next task.
149 for (sipp = (struct sysinit **)sysinits->ls_items; *sipp; sipp++) {
150 if ((*sipp)->subsystem == SI_SUB_DUMMY)
151 continue; /* skip dummy task(s)*/
154 (*((*sipp)->func))((*sipp)->udata);
156 return 0; /* no errors */
160 linker_file_sysuninit(linker_file_t lf)
162 struct linker_set* sysuninits;
163 struct sysinit** sipp;
164 struct sysinit** xipp;
165 struct sysinit* save;
167 KLD_DPF(FILE, ("linker_file_sysuninit: calling SYSUNINITs for %s\n",
170 sysuninits = (struct linker_set*)
171 linker_file_lookup_symbol(lf, "sysuninit_set", 0);
173 KLD_DPF(FILE, ("linker_file_sysuninit: SYSUNINITs %p\n", sysuninits));
178 * Perform a reverse bubble sort of the system initialization objects
179 * by their subsystem (primary key) and order (secondary key).
181 * Since some things care about execution order, this is the
182 * operation which ensures continued function.
184 for (sipp = (struct sysinit **)sysuninits->ls_items; *sipp; sipp++) {
185 for (xipp = sipp + 1; *xipp; xipp++) {
186 if ((*sipp)->subsystem > (*xipp)->subsystem ||
187 ((*sipp)->subsystem == (*xipp)->subsystem &&
188 (*sipp)->order >= (*xipp)->order))
198 * Traverse the (now) ordered list of system initialization tasks.
199 * Perform each task, and continue on to the next task.
201 for (sipp = (struct sysinit **)sysuninits->ls_items; *sipp; sipp++) {
202 if ((*sipp)->subsystem == SI_SUB_DUMMY)
203 continue; /* skip dummy task(s)*/
206 (*((*sipp)->func))((*sipp)->udata);
211 linker_file_register_sysctls(linker_file_t lf)
213 struct linker_set* sysctls;
215 KLD_DPF(FILE, ("linker_file_register_sysctls: registering SYSCTLs for %s\n",
218 sysctls = (struct linker_set*)
219 linker_file_lookup_symbol(lf, "sysctl_set", 0);
221 KLD_DPF(FILE, ("linker_file_register_sysctls: SYSCTLs %p\n", sysctls));
225 sysctl_register_set(sysctls);
229 linker_file_unregister_sysctls(linker_file_t lf)
231 struct linker_set* sysctls;
233 KLD_DPF(FILE, ("linker_file_unregister_sysctls: registering SYSCTLs for %s\n",
236 sysctls = (struct linker_set*)
237 linker_file_lookup_symbol(lf, "sysctl_set", 0);
239 KLD_DPF(FILE, ("linker_file_unregister_sysctls: SYSCTLs %p\n", sysctls));
243 sysctl_unregister_set(sysctls);
247 linker_load_file(const char* filename, linker_file_t* result)
251 int foundfile, error = 0;
254 /* Refuse to load modules if securelevel raised */
258 lf = linker_find_file_by_name(filename);
260 KLD_DPF(FILE, ("linker_load_file: file %s is already loaded, incrementing refs\n", filename));
266 koname = malloc(strlen(filename) + 4, M_LINKER, M_WAITOK);
267 if (koname == NULL) {
271 sprintf(koname, "%s.ko", filename);
274 for (lc = TAILQ_FIRST(&classes); lc; lc = TAILQ_NEXT(lc, link)) {
275 KLD_DPF(FILE, ("linker_load_file: trying to load %s as %s\n",
276 filename, lc->desc));
278 error = lc->ops->load_file(koname, &lf); /* First with .ko */
279 if (lf == NULL && error == ENOENT)
280 error = lc->ops->load_file(filename, &lf); /* Then try without */
282 * If we got something other than ENOENT, then it exists but we cannot
283 * load it for some other reason.
288 linker_file_register_sysctls(lf);
289 error = linker_file_sysinit(lf);
296 * Less than ideal, but tells the user whether it failed to load or
297 * the module was not found.
300 error = ENOEXEC; /* Format not recognised (or unloadable) */
302 error = ENOENT; /* Nothing found */
306 free(koname, M_LINKER);
311 linker_find_file_by_name(const char* filename)
313 linker_file_t lf = 0;
316 koname = malloc(strlen(filename) + 4, M_LINKER, M_WAITOK);
319 sprintf(koname, "%s.ko", filename);
321 lockmgr(&lock, LK_SHARED, 0, curthread);
322 for (lf = TAILQ_FIRST(&linker_files); lf; lf = TAILQ_NEXT(lf, link)) {
323 if (!strcmp(lf->filename, koname))
325 if (!strcmp(lf->filename, filename))
328 lockmgr(&lock, LK_RELEASE, 0, curthread);
332 free(koname, M_LINKER);
337 linker_find_file_by_id(int fileid)
339 linker_file_t lf = 0;
341 lockmgr(&lock, LK_SHARED, 0, curthread);
342 for (lf = TAILQ_FIRST(&linker_files); lf; lf = TAILQ_NEXT(lf, link))
343 if (lf->id == fileid)
345 lockmgr(&lock, LK_RELEASE, 0, curthread);
351 linker_make_file(const char* pathname, void* priv, struct linker_file_ops* ops)
353 linker_file_t lf = 0;
355 const char *filename;
357 filename = rindex(pathname, '/');
358 if (filename && filename[1])
363 KLD_DPF(FILE, ("linker_make_file: new file, filename=%s\n", filename));
364 lockmgr(&lock, LK_EXCLUSIVE, 0, curthread);
365 namelen = strlen(filename) + 1;
366 lf = malloc(sizeof(struct linker_file) + namelen, M_LINKER, M_WAITOK);
369 bzero(lf, sizeof(*lf));
374 lf->filename = (char*) (lf + 1);
375 strcpy(lf->filename, filename);
376 lf->id = next_file_id++;
379 STAILQ_INIT(&lf->common);
380 TAILQ_INIT(&lf->modules);
384 TAILQ_INSERT_TAIL(&linker_files, lf, link);
387 lockmgr(&lock, LK_RELEASE, 0, curthread);
392 linker_file_unload(linker_file_t file)
395 struct common_symbol* cp;
399 /* Refuse to unload modules if securelevel raised */
403 KLD_DPF(FILE, ("linker_file_unload: lf->refs=%d\n", file->refs));
404 lockmgr(&lock, LK_EXCLUSIVE, 0, curthread);
405 if (file->refs == 1) {
406 KLD_DPF(FILE, ("linker_file_unload: file is unloading, informing modules\n"));
408 * Inform any modules associated with this file.
410 for (mod = TAILQ_FIRST(&file->modules); mod; mod = next) {
411 next = module_getfnext(mod);
414 * Give the module a chance to veto the unload.
416 if ((error = module_unload(mod)) != 0) {
417 KLD_DPF(FILE, ("linker_file_unload: module %x vetoes unload\n",
419 lockmgr(&lock, LK_RELEASE, 0, curthread);
428 if (file->refs > 0) {
429 lockmgr(&lock, LK_RELEASE, 0, curthread);
433 /* Don't try to run SYSUNINITs if we are unloaded due to a link error */
434 if (file->flags & LINKER_FILE_LINKED) {
435 linker_file_sysuninit(file);
436 linker_file_unregister_sysctls(file);
439 TAILQ_REMOVE(&linker_files, file, link);
440 lockmgr(&lock, LK_RELEASE, 0, curthread);
442 for (i = 0; i < file->ndeps; i++)
443 linker_file_unload(file->deps[i]);
444 free(file->deps, M_LINKER);
446 for (cp = STAILQ_FIRST(&file->common); cp;
447 cp = STAILQ_FIRST(&file->common)) {
448 STAILQ_REMOVE(&file->common, cp, common_symbol, link);
452 file->ops->unload(file);
453 free(file, M_LINKER);
460 linker_file_add_dependancy(linker_file_t file, linker_file_t dep)
462 linker_file_t* newdeps;
464 newdeps = malloc((file->ndeps + 1) * sizeof(linker_file_t*),
468 bzero(newdeps, (file->ndeps + 1) * sizeof(linker_file_t*));
471 bcopy(file->deps, newdeps, file->ndeps * sizeof(linker_file_t*));
472 free(file->deps, M_LINKER);
474 file->deps = newdeps;
475 file->deps[file->ndeps] = dep;
482 linker_file_lookup_symbol(linker_file_t file, const char* name, int deps)
485 linker_symval_t symval;
488 size_t common_size = 0;
491 KLD_DPF(SYM, ("linker_file_lookup_symbol: file=%x, name=%s, deps=%d\n",
494 if (file->ops->lookup_symbol(file, name, &sym) == 0) {
495 file->ops->symbol_values(file, sym, &symval);
496 if (symval.value == 0)
498 * For commons, first look them up in the dependancies and
499 * only allocate space if not found there.
501 common_size = symval.size;
503 KLD_DPF(SYM, ("linker_file_lookup_symbol: symbol.value=%x\n", symval.value));
509 for (i = 0; i < file->ndeps; i++) {
510 address = linker_file_lookup_symbol(file->deps[i], name, 0);
512 KLD_DPF(SYM, ("linker_file_lookup_symbol: deps value=%x\n", address));
517 /* If we have not found it in the dependencies, search globally */
518 for (lf = TAILQ_FIRST(&linker_files); lf; lf = TAILQ_NEXT(lf, link)) {
519 /* But skip the current file if it's on the list */
522 /* And skip the files we searched above */
523 for (i = 0; i < file->ndeps; i++)
524 if (lf == file->deps[i])
528 address = linker_file_lookup_symbol(lf, name, 0);
530 KLD_DPF(SYM, ("linker_file_lookup_symbol: global value=%x\n", address));
536 if (common_size > 0) {
538 * This is a common symbol which was not found in the
539 * dependancies. We maintain a simple common symbol table in
542 struct common_symbol* cp;
544 for (cp = STAILQ_FIRST(&file->common); cp;
545 cp = STAILQ_NEXT(cp, link))
546 if (!strcmp(cp->name, name)) {
547 KLD_DPF(SYM, ("linker_file_lookup_symbol: old common value=%x\n", cp->address));
552 * Round the symbol size up to align.
554 common_size = (common_size + sizeof(int) - 1) & -sizeof(int);
555 cp = malloc(sizeof(struct common_symbol)
560 KLD_DPF(SYM, ("linker_file_lookup_symbol: nomem\n"));
563 bzero(cp, sizeof(struct common_symbol) + common_size + strlen(name)+ 1);
565 cp->address = (caddr_t) (cp + 1);
566 cp->name = cp->address + common_size;
567 strcpy(cp->name, name);
568 bzero(cp->address, common_size);
569 STAILQ_INSERT_TAIL(&file->common, cp, link);
571 KLD_DPF(SYM, ("linker_file_lookup_symbol: new common value=%x\n", cp->address));
575 KLD_DPF(SYM, ("linker_file_lookup_symbol: fail\n"));
581 * DDB Helpers. DDB has to look across multiple files with their own
582 * symbol tables and string tables.
584 * Note that we do not obey list locking protocols here. We really don't
585 * need DDB to hang because somebody's got the lock held. We'll take the
586 * chance that the files list is inconsistant instead.
590 linker_ddb_lookup(const char *symstr, c_linker_sym_t *sym)
594 for (lf = TAILQ_FIRST(&linker_files); lf; lf = TAILQ_NEXT(lf, link)) {
595 if (lf->ops->lookup_symbol(lf, symstr, sym) == 0)
602 linker_ddb_search_symbol(caddr_t value, c_linker_sym_t *sym, long *diffp)
605 u_long off = (uintptr_t)value;
606 u_long diff, bestdiff;
612 for (lf = TAILQ_FIRST(&linker_files); lf; lf = TAILQ_NEXT(lf, link)) {
613 if (lf->ops->search_symbol(lf, value, &es, &diff) != 0)
615 if (es != 0 && diff < bestdiff) {
634 linker_ddb_symbol_values(c_linker_sym_t sym, linker_symval_t *symval)
638 for (lf = TAILQ_FIRST(&linker_files); lf; lf = TAILQ_NEXT(lf, link)) {
639 if (lf->ops->symbol_values(lf, sym, symval) == 0)
652 kldload(struct kldload_args *uap)
654 struct thread *td = curthread;
655 struct proc *p = td->td_proc;
656 char* filename = NULL, *modulename;
662 if (securelevel > 0) /* redundant, but that's OK */
665 if ((error = suser(td)) != 0)
668 filename = malloc(MAXPATHLEN, M_TEMP, M_WAITOK);
669 if ((error = copyinstr(SCARG(uap, file), filename, MAXPATHLEN, NULL)) != 0)
672 /* Can't load more than one module with the same name */
673 modulename = rindex(filename, '/');
674 if (modulename == NULL)
675 modulename = filename;
678 if (linker_find_file_by_name(modulename)) {
683 if ((error = linker_load_file(filename, &lf)) != 0)
687 p->p_retval[0] = lf->id;
691 free(filename, M_TEMP);
696 kldunload(struct kldunload_args *uap)
698 struct thread *td = curthread;
702 if (securelevel > 0) /* redundant, but that's OK */
705 if ((error = suser(td)) != 0)
708 lf = linker_find_file_by_id(SCARG(uap, fileid));
710 KLD_DPF(FILE, ("kldunload: lf->userrefs=%d\n", lf->userrefs));
711 if (lf->userrefs == 0) {
712 printf("linkerunload: attempt to unload file that was loaded by the kernel\n");
717 error = linker_file_unload(lf);
728 kldfind(struct kldfind_args *uap)
730 struct proc *p = curproc;
731 char *filename = NULL, *modulename;
737 filename = malloc(MAXPATHLEN, M_TEMP, M_WAITOK);
738 if ((error = copyinstr(SCARG(uap, file), filename, MAXPATHLEN, NULL)) != 0)
741 modulename = rindex(filename, '/');
742 if (modulename == NULL)
743 modulename = filename;
745 lf = linker_find_file_by_name(modulename);
747 p->p_retval[0] = lf->id;
753 free(filename, M_TEMP);
758 kldnext(struct kldnext_args *uap)
760 struct proc *p = curproc;
764 if (SCARG(uap, fileid) == 0) {
765 if (TAILQ_FIRST(&linker_files))
766 p->p_retval[0] = TAILQ_FIRST(&linker_files)->id;
772 lf = linker_find_file_by_id(SCARG(uap, fileid));
774 if (TAILQ_NEXT(lf, link))
775 p->p_retval[0] = TAILQ_NEXT(lf, link)->id;
785 kldstat(struct kldstat_args *uap)
787 struct proc *p = curproc;
791 struct kld_file_stat* stat;
794 lf = linker_find_file_by_id(SCARG(uap, fileid));
800 stat = SCARG(uap, stat);
803 * Check the version of the user's structure.
805 if ((error = copyin(&stat->version, &version, sizeof(version))) != 0)
807 if (version != sizeof(struct kld_file_stat)) {
812 namelen = strlen(lf->filename) + 1;
813 if (namelen > MAXPATHLEN)
814 namelen = MAXPATHLEN;
815 if ((error = copyout(lf->filename, &stat->name[0], namelen)) != 0)
817 if ((error = copyout(&lf->refs, &stat->refs, sizeof(int))) != 0)
819 if ((error = copyout(&lf->id, &stat->id, sizeof(int))) != 0)
821 if ((error = copyout(&lf->address, &stat->address, sizeof(caddr_t))) != 0)
823 if ((error = copyout(&lf->size, &stat->size, sizeof(size_t))) != 0)
833 kldfirstmod(struct kldfirstmod_args *uap)
835 struct proc *p = curproc;
839 lf = linker_find_file_by_id(SCARG(uap, fileid));
841 if (TAILQ_FIRST(&lf->modules))
842 p->p_retval[0] = module_getid(TAILQ_FIRST(&lf->modules));
852 kldsym(struct kldsym_args *uap)
856 linker_symval_t symval;
858 struct kld_sym_lookup lookup;
861 if ((error = copyin(SCARG(uap, data), &lookup, sizeof(lookup))) != 0)
863 if (lookup.version != sizeof(lookup) || SCARG(uap, cmd) != KLDSYM_LOOKUP) {
868 symstr = malloc(MAXPATHLEN, M_TEMP, M_WAITOK);
869 if ((error = copyinstr(lookup.symname, symstr, MAXPATHLEN, NULL)) != 0)
872 if (SCARG(uap, fileid) != 0) {
873 lf = linker_find_file_by_id(SCARG(uap, fileid));
878 if (lf->ops->lookup_symbol(lf, symstr, &sym) == 0 &&
879 lf->ops->symbol_values(lf, sym, &symval) == 0) {
880 lookup.symvalue = (uintptr_t)symval.value;
881 lookup.symsize = symval.size;
882 error = copyout(&lookup, SCARG(uap, data), sizeof(lookup));
886 for (lf = TAILQ_FIRST(&linker_files); lf; lf = TAILQ_NEXT(lf, link)) {
887 if (lf->ops->lookup_symbol(lf, symstr, &sym) == 0 &&
888 lf->ops->symbol_values(lf, sym, &symval) == 0) {
889 lookup.symvalue = (uintptr_t)symval.value;
890 lookup.symsize = symval.size;
891 error = copyout(&lookup, SCARG(uap, data), sizeof(lookup));
900 free(symstr, M_TEMP);
905 * Preloaded module support
909 linker_preload(void* arg)
917 struct linker_set *sysinits;
918 struct sysinit **sipp;
919 const moduledata_t *moddata;
922 while ((modptr = preload_search_next_name(modptr)) != NULL) {
923 modname = (char *)preload_search_info(modptr, MODINFO_NAME);
924 modtype = (char *)preload_search_info(modptr, MODINFO_TYPE);
925 if (modname == NULL) {
926 printf("Preloaded module at %p does not have a name!\n", modptr);
929 if (modtype == NULL) {
930 printf("Preloaded module at %p does not have a type!\n", modptr);
933 printf("Preloaded %s \"%s\" at %p.\n", modtype, modname, modptr);
934 lf = linker_find_file_by_name(modname);
940 for (lc = TAILQ_FIRST(&classes); lc; lc = TAILQ_NEXT(lc, link)) {
941 error = lc->ops->load_file(modname, &lf);
950 sysinits = (struct linker_set*)
951 linker_file_lookup_symbol(lf, "sysinit_set", 0);
954 * This is to set the sysinit moduledata so that the module
955 * can attach itself to the correct containing file.
956 * The sysinit could be run at *any* time.
958 for (sipp = (struct sysinit **)sysinits->ls_items; *sipp; sipp++) {
959 if ((*sipp)->func == module_register_init) {
960 moddata = (*sipp)->udata;
961 error = module_register(moddata, lf);
963 printf("Preloaded %s \"%s\" failed to register: %d\n",
964 modtype, modname, error);
967 sysinit_add((struct sysinit **)sysinits->ls_items);
969 linker_file_register_sysctls(lf);
974 SYSINIT(preload, SI_SUB_KLD, SI_ORDER_MIDDLE, linker_preload, 0);
977 * Search for a not-loaded module by name.
979 * Modules may be found in the following locations:
981 * - preloaded (result is just the module name)
982 * - on disk (result is full path to module)
984 * If the module name is qualified in any way (contains path, etc.)
985 * the we simply return a copy of it.
987 * The search path can be manipulated via sysctl. Note that we use the ';'
988 * character as a separator to be consistent with the bootloader.
991 static char linker_path[MAXPATHLEN] = "/;/boot/;/modules/";
993 SYSCTL_STRING(_kern, OID_AUTO, module_path, CTLFLAG_RW, linker_path,
994 sizeof(linker_path), "module load search path");
997 linker_strdup(const char *str)
1001 if ((result = malloc((strlen(str) + 1), M_LINKER, M_WAITOK)) != NULL)
1002 strcpy(result, str);
1007 linker_search_path(const char *name)
1009 struct nameidata nd;
1010 struct thread *td = curthread;
1011 char *cp, *ep, *result;
1015 /* qualified at all? */
1016 if (index(name, '/'))
1017 return(linker_strdup(name));
1019 /* traverse the linker path */
1023 /* find the end of this component */
1024 for (ep = cp; (*ep != 0) && (*ep != ';'); ep++)
1026 result = malloc((strlen(name) + (ep - cp) + 1), M_LINKER, M_WAITOK);
1027 if (result == NULL) /* actually ENOMEM */
1030 strncpy(result, cp, ep - cp);
1031 strcpy(result + (ep - cp), name);
1034 * Attempt to open the file, and return the path if we succeed and it's
1037 NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, result, td);
1038 error = vn_open(&nd, FREAD, 0);
1040 NDFREE(&nd, NDF_ONLY_PNBUF);
1041 type = nd.ni_vp->v_type;
1042 VOP_UNLOCK(nd.ni_vp, 0, td);
1043 vn_close(nd.ni_vp, FREAD, td);
1047 free(result, M_LINKER);