kern_linker.c (59603) | kern_linker.c (59751) |
---|---|
1/*- 2 * Copyright (c) 1997-2000 Doug Rabson 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 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 24 * SUCH DAMAGE. 25 * | 1/*- 2 * Copyright (c) 1997-2000 Doug Rabson 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 9 unchanged lines hidden (view full) --- 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 24 * SUCH DAMAGE. 25 * |
26 * $FreeBSD: head/sys/kern/kern_linker.c 59603 2000-04-24 17:08:04Z dfr $ | 26 * $FreeBSD: head/sys/kern/kern_linker.c 59751 2000-04-29 13:19:31Z peter $ |
27 */ 28 29#include "opt_ddb.h" 30 31#include <sys/param.h> 32#include <sys/kernel.h> 33#include <sys/systm.h> 34#include <sys/malloc.h> --- 12 unchanged lines hidden (view full) --- 47#include <vm/vm_zone.h> 48 49#include "linker_if.h" 50 51#ifdef KLD_DEBUG 52int kld_debug = 0; 53#endif 54 | 27 */ 28 29#include "opt_ddb.h" 30 31#include <sys/param.h> 32#include <sys/kernel.h> 33#include <sys/systm.h> 34#include <sys/malloc.h> --- 12 unchanged lines hidden (view full) --- 47#include <vm/vm_zone.h> 48 49#include "linker_if.h" 50 51#ifdef KLD_DEBUG 52int kld_debug = 0; 53#endif 54 |
55MALLOC_DEFINE(M_LINKER, "kld", "kernel linker"); 56linker_file_t linker_current_file; | 55static char *linker_search_path(const char *name); 56static const char *linker_basename(const char* path); 57 58MALLOC_DEFINE(M_LINKER, "linker", "kernel linker"); 59 |
57linker_file_t linker_kernel_file; 58 59static struct lock lock; /* lock for the file list */ 60static linker_class_list_t classes; 61static linker_file_list_t linker_files; 62static int next_file_id = 1; 63 | 60linker_file_t linker_kernel_file; 61 62static struct lock lock; /* lock for the file list */ 63static linker_class_list_t classes; 64static linker_file_list_t linker_files; 65static int next_file_id = 1; 66 |
67/* XXX wrong name; we're looking at version provision tags here, not modules */ 68typedef TAILQ_HEAD(, modlist) modlisthead_t; 69struct modlist { 70 TAILQ_ENTRY(modlist) link; /* chain together all modules */ 71 linker_file_t container; 72 const char *name; 73}; 74typedef struct modlist *modlist_t; 75static modlisthead_t found_modules; 76 |
|
64static char * 65linker_strdup(const char *str) 66{ 67 char *result; 68 69 if ((result = malloc((strlen(str) + 1), M_LINKER, M_WAITOK)) != NULL) 70 strcpy(result, str); 71 return(result); --- 8 unchanged lines hidden (view full) --- 80} 81 82SYSINIT(linker, SI_SUB_KLD, SI_ORDER_FIRST, linker_init, 0); 83 84int 85linker_add_class(linker_class_t lc) 86{ 87 kobj_class_compile((kobj_class_t) lc); | 77static char * 78linker_strdup(const char *str) 79{ 80 char *result; 81 82 if ((result = malloc((strlen(str) + 1), M_LINKER, M_WAITOK)) != NULL) 83 strcpy(result, str); 84 return(result); --- 8 unchanged lines hidden (view full) --- 93} 94 95SYSINIT(linker, SI_SUB_KLD, SI_ORDER_FIRST, linker_init, 0); 96 97int 98linker_add_class(linker_class_t lc) 99{ 100 kobj_class_compile((kobj_class_t) lc); |
88 TAILQ_INSERT_HEAD(&classes, lc, link); | 101 TAILQ_INSERT_TAIL(&classes, lc, link); |
89 return 0; 90} 91 92static void 93linker_file_sysinit(linker_file_t lf) 94{ 95 struct linker_set* sysinits; 96 struct sysinit** sipp; 97 struct sysinit** xipp; 98 struct sysinit* save; | 102 return 0; 103} 104 105static void 106linker_file_sysinit(linker_file_t lf) 107{ 108 struct linker_set* sysinits; 109 struct sysinit** sipp; 110 struct sysinit** xipp; 111 struct sysinit* save; |
99 const moduledata_t *moddata; 100 int error; | |
101 102 KLD_DPF(FILE, ("linker_file_sysinit: calling SYSINITs for %s\n", 103 lf->filename)); 104 105 sysinits = (struct linker_set*) 106 linker_file_lookup_symbol(lf, "sysinit_set", 0); 107 108 KLD_DPF(FILE, ("linker_file_sysinit: SYSINITs %p\n", sysinits)); 109 if (!sysinits) 110 return; | 112 113 KLD_DPF(FILE, ("linker_file_sysinit: calling SYSINITs for %s\n", 114 lf->filename)); 115 116 sysinits = (struct linker_set*) 117 linker_file_lookup_symbol(lf, "sysinit_set", 0); 118 119 KLD_DPF(FILE, ("linker_file_sysinit: SYSINITs %p\n", sysinits)); 120 if (!sysinits) 121 return; |
111 112 /* HACK ALERT! */ 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); 117 if (error) 118 printf("linker_file_sysinit \"%s\" failed to register! %d\n", 119 lf->filename, error); 120 } 121 } 122 | |
123 /* 124 * Perform a bubble sort of the system initialization objects by 125 * their subsystem (primary key) and order (secondary key). 126 * 127 * Since some things care about execution order, this is the 128 * operation which ensures continued function. 129 */ 130 for (sipp = (struct sysinit **)sysinits->ls_items; *sipp; sipp++) { --- 54 unchanged lines hidden (view full) --- 185 (*sipp)->order >= (*xipp)->order)) 186 continue; /* skip*/ 187 save = *sipp; 188 *sipp = *xipp; 189 *xipp = save; 190 } 191 } 192 | 122 /* 123 * Perform a bubble sort of the system initialization objects by 124 * their subsystem (primary key) and order (secondary key). 125 * 126 * Since some things care about execution order, this is the 127 * operation which ensures continued function. 128 */ 129 for (sipp = (struct sysinit **)sysinits->ls_items; *sipp; sipp++) { --- 54 unchanged lines hidden (view full) --- 184 (*sipp)->order >= (*xipp)->order)) 185 continue; /* skip*/ 186 save = *sipp; 187 *sipp = *xipp; 188 *xipp = save; 189 } 190 } 191 |
193 | |
194 /* 195 * Traverse the (now) ordered list of system initialization tasks. 196 * Perform each task, and continue on to the next task. 197 */ 198 for (sipp = (struct sysinit **)sysuninits->ls_items; *sipp; sipp++) { 199 if ((*sipp)->subsystem == SI_SUB_DUMMY) 200 continue; /* skip dummy task(s)*/ 201 --- 33 unchanged lines hidden (view full) --- 235 236 KLD_DPF(FILE, ("linker_file_unregister_sysctls: SYSCTLs %p\n", sysctls)); 237 if (!sysctls) 238 return; 239 240 sysctl_unregister_set(sysctls); 241} 242 | 192 /* 193 * Traverse the (now) ordered list of system initialization tasks. 194 * Perform each task, and continue on to the next task. 195 */ 196 for (sipp = (struct sysinit **)sysuninits->ls_items; *sipp; sipp++) { 197 if ((*sipp)->subsystem == SI_SUB_DUMMY) 198 continue; /* skip dummy task(s)*/ 199 --- 33 unchanged lines hidden (view full) --- 233 234 KLD_DPF(FILE, ("linker_file_unregister_sysctls: SYSCTLs %p\n", sysctls)); 235 if (!sysctls) 236 return; 237 238 sysctl_unregister_set(sysctls); 239} 240 |
241static int 242linker_file_register_modules(linker_file_t lf) 243{ 244 int error, mcount; 245 struct linker_set *modules; 246 struct mod_metadata **mdpp; 247 const moduledata_t *moddata; 248 struct sysinit **sipp; 249 250 KLD_DPF(FILE, ("linker_file_register_modules: registering modules in %s\n", 251 lf->filename)); 252 253 modules = (struct linker_set*) 254 linker_file_lookup_symbol(lf, "modmetadata_set", 0); 255 mcount = 0; 256 if (modules) { 257 for (mdpp = (struct mod_metadata**)modules->ls_items; *mdpp; mdpp++) { 258 if ((*mdpp)->md_type != MDT_MODULE) 259 continue; 260 mcount++; 261 moddata = (*mdpp)->md_data; 262 KLD_DPF(FILE, ("Registering module %s in %s\n", 263 moddata->name, lf->filename)); 264 error = module_register(moddata, lf); 265 if (error) 266 printf("Module %s failed to register: %d\n", moddata->name, error); 267 } 268 } 269 if (mcount) 270 return mcount; /* Do not mix old and new style */ 271 272 /* Hack - handle old kld's without metadata */ 273 modules = (struct linker_set*) 274 linker_file_lookup_symbol(lf, "sysinit_set", 0); 275 if (modules) { 276 for (sipp = (struct sysinit **)modules->ls_items; *sipp; sipp++) { 277 if ((*sipp)->func != module_register_init) 278 continue; 279 mcount++; 280 moddata = (*sipp)->udata; 281 printf("Old-style KLD file %s found\n", moddata->name); 282 error = module_register(moddata, lf); 283 if (error) 284 printf("Old-style KLD file %s failed to register: %d\n", moddata->name, error); 285 } 286 } 287 return mcount; 288} 289 290static void 291linker_init_kernel_modules(void) 292{ 293 linker_file_register_modules(linker_kernel_file); 294} 295 296SYSINIT(linker_kernel, SI_SUB_KLD, SI_ORDER_ANY, linker_init_kernel_modules, 0); 297 |
|
243int 244linker_load_file(const char* filename, linker_file_t* result) 245{ 246 linker_class_t lc; 247 linker_file_t lf; 248 int foundfile, error = 0; | 298int 299linker_load_file(const char* filename, linker_file_t* result) 300{ 301 linker_class_t lc; 302 linker_file_t lf; 303 int foundfile, error = 0; |
249 char *koname = NULL; | |
250 251 lf = linker_find_file_by_name(filename); 252 if (lf) { 253 KLD_DPF(FILE, ("linker_load_file: file %s is already loaded, incrementing refs\n", filename)); 254 *result = lf; 255 lf->refs++; 256 goto out; 257 } 258 | 304 305 lf = linker_find_file_by_name(filename); 306 if (lf) { 307 KLD_DPF(FILE, ("linker_load_file: file %s is already loaded, incrementing refs\n", filename)); 308 *result = lf; 309 lf->refs++; 310 goto out; 311 } 312 |
259 koname = malloc(strlen(filename) + 4, M_LINKER, M_WAITOK); 260 if (koname == NULL) { 261 error = ENOMEM; 262 goto out; 263 } 264 sprintf(koname, "%s.ko", filename); | |
265 lf = NULL; 266 foundfile = 0; 267 for (lc = TAILQ_FIRST(&classes); lc; lc = TAILQ_NEXT(lc, link)) { 268 KLD_DPF(FILE, ("linker_load_file: trying to load %s as %s\n", 269 filename, lc->desc)); | 313 lf = NULL; 314 foundfile = 0; 315 for (lc = TAILQ_FIRST(&classes); lc; lc = TAILQ_NEXT(lc, link)) { 316 KLD_DPF(FILE, ("linker_load_file: trying to load %s as %s\n", 317 filename, lc->desc)); |
270 271 error = LINKER_LOAD_FILE(lc, koname, &lf); /* First with .ko */ 272 if (lf == NULL && error == ENOENT) 273 error = LINKER_LOAD_FILE(lc, filename, &lf); /* Then try without */ | 318 error = LINKER_LOAD_FILE(lc, filename, &lf); |
274 /* 275 * If we got something other than ENOENT, then it exists but we cannot 276 * load it for some other reason. 277 */ 278 if (error != ENOENT) 279 foundfile = 1; 280 if (lf) { | 319 /* 320 * If we got something other than ENOENT, then it exists but we cannot 321 * load it for some other reason. 322 */ 323 if (error != ENOENT) 324 foundfile = 1; 325 if (lf) { |
326 linker_file_register_modules(lf); |
|
281 linker_file_register_sysctls(lf); 282 linker_file_sysinit(lf); | 327 linker_file_register_sysctls(lf); 328 linker_file_sysinit(lf); |
329 lf->flags |= LINKER_FILE_LINKED; |
|
283 284 *result = lf; 285 error = 0; 286 goto out; 287 } 288 } 289 /* 290 * Less than ideal, but tells the user whether it failed to load or 291 * the module was not found. 292 */ 293 if (foundfile) 294 error = ENOEXEC; /* Format not recognised (or unloadable) */ 295 else 296 error = ENOENT; /* Nothing found */ 297 298out: | 330 331 *result = lf; 332 error = 0; 333 goto out; 334 } 335 } 336 /* 337 * Less than ideal, but tells the user whether it failed to load or 338 * the module was not found. 339 */ 340 if (foundfile) 341 error = ENOEXEC; /* Format not recognised (or unloadable) */ 342 else 343 error = ENOENT; /* Nothing found */ 344 345out: |
299 if (koname) 300 free(koname, M_LINKER); | |
301 return error; 302} 303 304linker_file_t 305linker_find_file_by_name(const char* filename) 306{ 307 linker_file_t lf = 0; 308 char *koname; --- 33 unchanged lines hidden (view full) --- 342} 343 344linker_file_t 345linker_make_file(const char* pathname, linker_class_t lc) 346{ 347 linker_file_t lf = 0; 348 const char *filename; 349 | 346 return error; 347} 348 349linker_file_t 350linker_find_file_by_name(const char* filename) 351{ 352 linker_file_t lf = 0; 353 char *koname; --- 33 unchanged lines hidden (view full) --- 387} 388 389linker_file_t 390linker_make_file(const char* pathname, linker_class_t lc) 391{ 392 linker_file_t lf = 0; 393 const char *filename; 394 |
350 filename = rindex(pathname, '/'); 351 if (filename && filename[1]) 352 filename++; 353 else 354 filename = pathname; | 395 filename = linker_basename(pathname); |
355 356 KLD_DPF(FILE, ("linker_make_file: new file, filename=%s\n", filename)); 357 lockmgr(&lock, LK_EXCLUSIVE, 0, curproc); 358 lf = (linker_file_t) kobj_create((kobj_class_t) lc, M_LINKER, M_WAITOK); 359 if (!lf) 360 goto out; 361 362 lf->refs = 1; --- 12 unchanged lines hidden (view full) --- 375 lockmgr(&lock, LK_RELEASE, 0, curproc); 376 return lf; 377} 378 379int 380linker_file_unload(linker_file_t file) 381{ 382 module_t mod, next; | 396 397 KLD_DPF(FILE, ("linker_make_file: new file, filename=%s\n", filename)); 398 lockmgr(&lock, LK_EXCLUSIVE, 0, curproc); 399 lf = (linker_file_t) kobj_create((kobj_class_t) lc, M_LINKER, M_WAITOK); 400 if (!lf) 401 goto out; 402 403 lf->refs = 1; --- 12 unchanged lines hidden (view full) --- 416 lockmgr(&lock, LK_RELEASE, 0, curproc); 417 return lf; 418} 419 420int 421linker_file_unload(linker_file_t file) 422{ 423 module_t mod, next; |
424 modlist_t ml, nextml; |
|
383 struct common_symbol* cp; 384 int error = 0; 385 int i; 386 387 KLD_DPF(FILE, ("linker_file_unload: lf->refs=%d\n", file->refs)); 388 lockmgr(&lock, LK_EXCLUSIVE, 0, curproc); 389 if (file->refs == 1) { 390 KLD_DPF(FILE, ("linker_file_unload: file is unloading, informing modules\n")); --- 18 unchanged lines hidden (view full) --- 409 } 410 411 file->refs--; 412 if (file->refs > 0) { 413 lockmgr(&lock, LK_RELEASE, 0, curproc); 414 goto out; 415 } 416 | 425 struct common_symbol* cp; 426 int error = 0; 427 int i; 428 429 KLD_DPF(FILE, ("linker_file_unload: lf->refs=%d\n", file->refs)); 430 lockmgr(&lock, LK_EXCLUSIVE, 0, curproc); 431 if (file->refs == 1) { 432 KLD_DPF(FILE, ("linker_file_unload: file is unloading, informing modules\n")); --- 18 unchanged lines hidden (view full) --- 451 } 452 453 file->refs--; 454 if (file->refs > 0) { 455 lockmgr(&lock, LK_RELEASE, 0, curproc); 456 goto out; 457 } 458 |
459 for (ml = TAILQ_FIRST(&found_modules); ml; ml = nextml) { 460 nextml = TAILQ_NEXT(ml, link); 461 if (ml->container == file) { 462 TAILQ_REMOVE(&found_modules, ml, link); 463 } 464 } 465 |
|
417 /* Don't try to run SYSUNINITs if we are unloaded due to a link error */ 418 if (file->flags & LINKER_FILE_LINKED) { 419 linker_file_sysuninit(file); 420 linker_file_unregister_sysctls(file); 421 } 422 423 TAILQ_REMOVE(&linker_files, file, link); 424 lockmgr(&lock, LK_RELEASE, 0, curproc); 425 | 466 /* Don't try to run SYSUNINITs if we are unloaded due to a link error */ 467 if (file->flags & LINKER_FILE_LINKED) { 468 linker_file_sysuninit(file); 469 linker_file_unregister_sysctls(file); 470 } 471 472 TAILQ_REMOVE(&linker_files, file, link); 473 lockmgr(&lock, LK_RELEASE, 0, curproc); 474 |
426 for (i = 0; i < file->ndeps; i++) 427 linker_file_unload(file->deps[i]); 428 free(file->deps, M_LINKER); | 475 if (file->deps) { 476 for (i = 0; i < file->ndeps; i++) 477 linker_file_unload(file->deps[i]); 478 free(file->deps, M_LINKER); 479 file->deps = NULL; 480 } |
429 430 for (cp = STAILQ_FIRST(&file->common); cp; 431 cp = STAILQ_FIRST(&file->common)) { 432 STAILQ_REMOVE(&file->common, cp, common_symbol, link); 433 free(cp, M_LINKER); 434 } 435 436 LINKER_UNLOAD(file); | 481 482 for (cp = STAILQ_FIRST(&file->common); cp; 483 cp = STAILQ_FIRST(&file->common)) { 484 STAILQ_REMOVE(&file->common, cp, common_symbol, link); 485 free(cp, M_LINKER); 486 } 487 488 LINKER_UNLOAD(file); |
437 free(file->filename, M_LINKER); | 489 if (file->filename) { 490 free(file->filename, M_LINKER); 491 file->filename = NULL; 492 } |
438 kobj_delete((kobj_t) file, M_LINKER); 439 440out: 441 return error; 442} 443 444int 445linker_file_add_dependancy(linker_file_t file, linker_file_t dep) --- 17 unchanged lines hidden (view full) --- 463 return 0; 464} 465 466caddr_t 467linker_file_lookup_symbol(linker_file_t file, const char* name, int deps) 468{ 469 c_linker_sym_t sym; 470 linker_symval_t symval; | 493 kobj_delete((kobj_t) file, M_LINKER); 494 495out: 496 return error; 497} 498 499int 500linker_file_add_dependancy(linker_file_t file, linker_file_t dep) --- 17 unchanged lines hidden (view full) --- 518 return 0; 519} 520 521caddr_t 522linker_file_lookup_symbol(linker_file_t file, const char* name, int deps) 523{ 524 c_linker_sym_t sym; 525 linker_symval_t symval; |
471 linker_file_t lf; | |
472 caddr_t address; 473 size_t common_size = 0; 474 int i; 475 476 KLD_DPF(SYM, ("linker_file_lookup_symbol: file=%x, name=%s, deps=%d\n", 477 file, name, deps)); 478 479 if (LINKER_LOOKUP_SYMBOL(file, name, &sym) == 0) { --- 13 unchanged lines hidden (view full) --- 493 if (deps) { 494 for (i = 0; i < file->ndeps; i++) { 495 address = linker_file_lookup_symbol(file->deps[i], name, 0); 496 if (address) { 497 KLD_DPF(SYM, ("linker_file_lookup_symbol: deps value=%x\n", address)); 498 return address; 499 } 500 } | 526 caddr_t address; 527 size_t common_size = 0; 528 int i; 529 530 KLD_DPF(SYM, ("linker_file_lookup_symbol: file=%x, name=%s, deps=%d\n", 531 file, name, deps)); 532 533 if (LINKER_LOOKUP_SYMBOL(file, name, &sym) == 0) { --- 13 unchanged lines hidden (view full) --- 547 if (deps) { 548 for (i = 0; i < file->ndeps; i++) { 549 address = linker_file_lookup_symbol(file->deps[i], name, 0); 550 if (address) { 551 KLD_DPF(SYM, ("linker_file_lookup_symbol: deps value=%x\n", address)); 552 return address; 553 } 554 } |
501 502 /* If we have not found it in the dependencies, search globally */ 503 for (lf = TAILQ_FIRST(&linker_files); lf; lf = TAILQ_NEXT(lf, link)) { 504 /* But skip the current file if it's on the list */ 505 if (lf == file) 506 continue; 507 /* And skip the files we searched above */ 508 for (i = 0; i < file->ndeps; i++) 509 if (lf == file->deps[i]) 510 break; 511 if (i < file->ndeps) 512 continue; 513 address = linker_file_lookup_symbol(lf, name, 0); 514 if (address) { 515 KLD_DPF(SYM, ("linker_file_lookup_symbol: global value=%x\n", address)); 516 return address; 517 } 518 } | |
519 } 520 521 if (common_size > 0) { 522 /* 523 * This is a common symbol which was not found in the 524 * dependancies. We maintain a simple common symbol table in 525 * the file object. 526 */ --- 104 unchanged lines hidden (view full) --- 631 632/* 633 * Syscalls. 634 */ 635 636int 637kldload(struct proc* p, struct kldload_args* uap) 638{ | 555 } 556 557 if (common_size > 0) { 558 /* 559 * This is a common symbol which was not found in the 560 * dependancies. We maintain a simple common symbol table in 561 * the file object. 562 */ --- 104 unchanged lines hidden (view full) --- 667 668/* 669 * Syscalls. 670 */ 671 672int 673kldload(struct proc* p, struct kldload_args* uap) 674{ |
639 char* filename = NULL, *modulename; | 675 char* pathname, *realpath; 676 const char *filename; |
640 linker_file_t lf; 641 int error = 0; 642 643 p->p_retval[0] = -1; 644 645 if (securelevel > 0) 646 return EPERM; 647 648 if ((error = suser(p)) != 0) 649 return error; 650 | 677 linker_file_t lf; 678 int error = 0; 679 680 p->p_retval[0] = -1; 681 682 if (securelevel > 0) 683 return EPERM; 684 685 if ((error = suser(p)) != 0) 686 return error; 687 |
651 filename = malloc(MAXPATHLEN, M_TEMP, M_WAITOK); 652 if ((error = copyinstr(SCARG(uap, file), filename, MAXPATHLEN, NULL)) != 0) | 688 realpath = NULL; 689 pathname = malloc(MAXPATHLEN, M_TEMP, M_WAITOK); 690 if ((error = copyinstr(SCARG(uap, file), pathname, MAXPATHLEN, NULL)) != 0) |
653 goto out; 654 | 691 goto out; 692 |
655 /* Can't load more than one module with the same name */ 656 modulename = rindex(filename, '/'); 657 if (modulename == NULL) 658 modulename = filename; 659 else 660 modulename++; 661 if (linker_find_file_by_name(modulename)) { | 693 realpath = linker_search_path(pathname); 694 if (realpath == NULL) { 695 error = ENOENT; 696 goto out; 697 } 698 /* Can't load more than one file with the same name */ 699 filename = linker_basename(realpath); 700 if (linker_find_file_by_name(filename)) { |
662 error = EEXIST; 663 goto out; 664 } 665 | 701 error = EEXIST; 702 goto out; 703 } 704 |
666 if ((error = linker_load_file(filename, &lf)) != 0) | 705 if ((error = linker_load_file(realpath, &lf)) != 0) |
667 goto out; 668 669 lf->userrefs++; 670 p->p_retval[0] = lf->id; 671 672out: | 706 goto out; 707 708 lf->userrefs++; 709 p->p_retval[0] = lf->id; 710 711out: |
673 if (filename) 674 free(filename, M_TEMP); | 712 if (pathname) 713 free(pathname, M_TEMP); 714 if (realpath) 715 free(realpath, M_LINKER); |
675 return error; 676} 677 678int 679kldunload(struct proc* p, struct kldunload_args* uap) 680{ 681 linker_file_t lf; 682 int error = 0; 683 684 if (securelevel > 0) 685 return EPERM; 686 687 if ((error = suser(p)) != 0) 688 return error; 689 690 lf = linker_find_file_by_id(SCARG(uap, fileid)); 691 if (lf) { 692 KLD_DPF(FILE, ("kldunload: lf->userrefs=%d\n", lf->userrefs)); 693 if (lf->userrefs == 0) { | 716 return error; 717} 718 719int 720kldunload(struct proc* p, struct kldunload_args* uap) 721{ 722 linker_file_t lf; 723 int error = 0; 724 725 if (securelevel > 0) 726 return EPERM; 727 728 if ((error = suser(p)) != 0) 729 return error; 730 731 lf = linker_find_file_by_id(SCARG(uap, fileid)); 732 if (lf) { 733 KLD_DPF(FILE, ("kldunload: lf->userrefs=%d\n", lf->userrefs)); 734 if (lf->userrefs == 0) { |
694 printf("linkerunload: attempt to unload file that was loaded by the kernel\n"); | 735 printf("kldunload: attempt to unload file that was loaded by the kernel\n"); |
695 error = EBUSY; 696 goto out; 697 } 698 lf->userrefs--; 699 error = linker_file_unload(lf); 700 if (error) 701 lf->userrefs++; 702 } else 703 error = ENOENT; 704 705out: 706 return error; 707} 708 709int 710kldfind(struct proc* p, struct kldfind_args* uap) 711{ | 736 error = EBUSY; 737 goto out; 738 } 739 lf->userrefs--; 740 error = linker_file_unload(lf); 741 if (error) 742 lf->userrefs++; 743 } else 744 error = ENOENT; 745 746out: 747 return error; 748} 749 750int 751kldfind(struct proc* p, struct kldfind_args* uap) 752{ |
712 char* filename = NULL, *modulename; | 753 char* pathname; 754 const char *filename; |
713 linker_file_t lf; 714 int error = 0; 715 716 p->p_retval[0] = -1; 717 | 755 linker_file_t lf; 756 int error = 0; 757 758 p->p_retval[0] = -1; 759 |
718 filename = malloc(MAXPATHLEN, M_TEMP, M_WAITOK); 719 if ((error = copyinstr(SCARG(uap, file), filename, MAXPATHLEN, NULL)) != 0) | 760 pathname = malloc(MAXPATHLEN, M_TEMP, M_WAITOK); 761 if ((error = copyinstr(SCARG(uap, file), pathname, MAXPATHLEN, NULL)) != 0) |
720 goto out; 721 | 762 goto out; 763 |
722 modulename = rindex(filename, '/'); 723 if (modulename == NULL) 724 modulename = filename; | 764 filename = linker_basename(pathname); |
725 | 765 |
726 lf = linker_find_file_by_name(modulename); | 766 lf = linker_find_file_by_name(filename); |
727 if (lf) 728 p->p_retval[0] = lf->id; 729 else 730 error = ENOENT; 731 732out: | 767 if (lf) 768 p->p_retval[0] = lf->id; 769 else 770 error = ENOENT; 771 772out: |
733 if (filename) 734 free(filename, M_TEMP); | 773 if (pathname) 774 free(pathname, M_TEMP); |
735 return error; 736} 737 738int 739kldnext(struct proc* p, struct kldnext_args* uap) 740{ 741 linker_file_t lf; 742 int error = 0; --- 135 unchanged lines hidden (view full) --- 878 free(symstr, M_TEMP); 879 return error; 880} 881 882/* 883 * Preloaded module support 884 */ 885 | 775 return error; 776} 777 778int 779kldnext(struct proc* p, struct kldnext_args* uap) 780{ 781 linker_file_t lf; 782 int error = 0; --- 135 unchanged lines hidden (view full) --- 918 free(symstr, M_TEMP); 919 return error; 920} 921 922/* 923 * Preloaded module support 924 */ 925 |
926static modlist_t 927modlist_lookup(const char *name) 928{ 929 modlist_t mod; 930 931 for (mod = TAILQ_FIRST(&found_modules); mod; mod = TAILQ_NEXT(mod, link)) { 932 if (!strcmp(mod->name, name)) 933 return mod; 934 } 935 return NULL; 936} 937 938/* 939 * This routine is cheap and nasty but will work for data pointers. 940 */ 941static void * 942linker_reloc_ptr(linker_file_t lf, void *offset) 943{ 944 return lf->address + (uintptr_t)offset; 945} 946 |
|
886static void 887linker_preload(void* arg) 888{ 889 caddr_t modptr; 890 char *modname; 891 char *modtype; 892 linker_file_t lf; 893 linker_class_t lc; | 947static void 948linker_preload(void* arg) 949{ 950 caddr_t modptr; 951 char *modname; 952 char *modtype; 953 linker_file_t lf; 954 linker_class_t lc; |
894 int error; | 955 int error, mcount; |
895 struct linker_set *sysinits; | 956 struct linker_set *sysinits; |
896 struct sysinit **sipp; 897 const moduledata_t *moddata; | 957 linker_file_list_t loaded_files; 958 linker_file_list_t depended_files; 959 struct linker_set *deps; 960 struct mod_metadata *mp; 961 int i; 962 int resolves; 963 modlist_t mod; |
898 | 964 |
965 TAILQ_INIT(&loaded_files); 966 TAILQ_INIT(&depended_files); 967 TAILQ_INIT(&found_modules); 968 error = 0; 969 |
|
899 modptr = NULL; 900 while ((modptr = preload_search_next_name(modptr)) != NULL) { 901 modname = (char *)preload_search_info(modptr, MODINFO_NAME); 902 modtype = (char *)preload_search_info(modptr, MODINFO_TYPE); 903 if (modname == NULL) { 904 printf("Preloaded module at %p does not have a name!\n", modptr); 905 continue; 906 } 907 if (modtype == NULL) { 908 printf("Preloaded module at %p does not have a type!\n", modptr); 909 continue; 910 } 911 printf("Preloaded %s \"%s\" at %p.\n", modtype, modname, modptr); | 970 modptr = NULL; 971 while ((modptr = preload_search_next_name(modptr)) != NULL) { 972 modname = (char *)preload_search_info(modptr, MODINFO_NAME); 973 modtype = (char *)preload_search_info(modptr, MODINFO_TYPE); 974 if (modname == NULL) { 975 printf("Preloaded module at %p does not have a name!\n", modptr); 976 continue; 977 } 978 if (modtype == NULL) { 979 printf("Preloaded module at %p does not have a type!\n", modptr); 980 continue; 981 } 982 printf("Preloaded %s \"%s\" at %p.\n", modtype, modname, modptr); |
912 lf = linker_find_file_by_name(modname); 913 if (lf) { 914 lf->userrefs++; 915 continue; 916 } | |
917 lf = NULL; 918 for (lc = TAILQ_FIRST(&classes); lc; lc = TAILQ_NEXT(lc, link)) { | 983 lf = NULL; 984 for (lc = TAILQ_FIRST(&classes); lc; lc = TAILQ_NEXT(lc, link)) { |
919 error = LINKER_LOAD_FILE(lc, modname, &lf); | 985 error = LINKER_LINK_PRELOAD(lc, modname, &lf); |
920 if (error) { 921 lf = NULL; 922 break; 923 } 924 } | 986 if (error) { 987 lf = NULL; 988 break; 989 } 990 } |
925 if (lf) { 926 lf->userrefs++; | 991 if (lf) 992 TAILQ_INSERT_TAIL(&loaded_files, lf, loaded); 993 } |
927 | 994 |
928 sysinits = (struct linker_set*) 929 linker_file_lookup_symbol(lf, "sysinit_set", 0); 930 if (sysinits) { 931 /* HACK ALERT! 932 * This is to set the sysinit moduledata so that the module 933 * can attach itself to the correct containing file. 934 * The sysinit could be run at *any* time. 935 */ 936 for (sipp = (struct sysinit **)sysinits->ls_items; *sipp; sipp++) { 937 if ((*sipp)->func == module_register_init) { 938 moddata = (*sipp)->udata; 939 error = module_register(moddata, lf); 940 if (error) 941 printf("Preloaded %s \"%s\" failed to register: %d\n", 942 modtype, modname, error); | 995 /* 996 * First get a list of stuff in the kernel. 997 */ 998 deps = (struct linker_set*) 999 linker_file_lookup_symbol(linker_kernel_file, MDT_SETNAME, 0); 1000 if (deps) { 1001 for (i = 0; i < deps->ls_length; i++) { 1002 mp = deps->ls_items[i]; 1003 if (mp->md_type != MDT_VERSION) 1004 continue; 1005 modname = mp->md_cval; 1006 if (modlist_lookup(modname) != NULL) { 1007 printf("module %s already present!\n", modname); 1008 /* XXX what can we do? this is a build error. :-( */ 1009 continue; 1010 } 1011 mod = malloc(sizeof(struct modlist), M_LINKER, M_NOWAIT); 1012 if (mod == NULL) 1013 panic("no memory for module list"); 1014 bzero(mod, sizeof(*mod)); 1015 mod->container = linker_kernel_file; 1016 mod->name = modname; 1017 TAILQ_INSERT_TAIL(&found_modules, mod, link); 1018 } 1019 } 1020 1021 /* 1022 * this is a once-off kinky bubble sort 1023 * resolve relocation dependency requirements 1024 */ 1025restart: 1026 for (lf = TAILQ_FIRST(&loaded_files); lf; lf = TAILQ_NEXT(lf, loaded)) { 1027 deps = (struct linker_set*) 1028 linker_file_lookup_symbol(lf, MDT_SETNAME, 0); 1029 /* 1030 * First, look to see if we would successfully link with this stuff. 1031 */ 1032 resolves = 1; /* unless we know otherwise */ 1033 if (deps) { 1034 for (i = 0; i < deps->ls_length; i++) { 1035 mp = linker_reloc_ptr(lf, deps->ls_items[i]); 1036 if (mp->md_type != MDT_DEPEND) 1037 continue; 1038 modname = linker_reloc_ptr(lf, mp->md_cval); 1039 if (modlist_lookup(modname) == NULL) { 1040 /* ok, the module isn't here yet, we are not finished */ 1041 resolves = 0; 1042 } 1043 } 1044 } 1045 /* 1046 * OK, if we found our modules, we can link. So, "provide" the 1047 * modules inside and add it to the end of the link order list. 1048 */ 1049 if (resolves) { 1050 if (deps) { 1051 for (i = 0; i < deps->ls_length; i++) { 1052 mp = linker_reloc_ptr(lf, deps->ls_items[i]); 1053 if (mp->md_type != MDT_VERSION) 1054 continue; 1055 modname = linker_reloc_ptr(lf, mp->md_cval); 1056 if (modlist_lookup(modname) != NULL) { 1057 printf("module %s already present!\n", modname); 1058 linker_file_unload(lf); 1059 TAILQ_REMOVE(&loaded_files, lf, loaded); 1060 goto restart; /* we changed the tailq next ptr */ |
943 } | 1061 } |
1062 mod = malloc(sizeof(struct modlist), M_LINKER, M_NOWAIT); 1063 if (mod == NULL) 1064 panic("no memory for module list"); 1065 bzero(mod, sizeof(*mod)); 1066 mod->container = lf; 1067 mod->name = modname; 1068 TAILQ_INSERT_TAIL(&found_modules, mod, link); |
|
944 } | 1069 } |
945 sysinit_add((struct sysinit **)sysinits->ls_items); | |
946 } | 1070 } |
947 linker_file_register_sysctls(lf); | 1071 TAILQ_REMOVE(&loaded_files, lf, loaded); 1072 TAILQ_INSERT_TAIL(&depended_files, lf, loaded); 1073 /* 1074 * Since we provided modules, we need to restart the sort so 1075 * that the previous files that depend on us have a chance. 1076 * Also, we've busted the tailq next pointer with the REMOVE. 1077 */ 1078 goto restart; |
948 } 949 } | 1079 } 1080 } |
1081 1082 /* 1083 * At this point, we check to see what could not be resolved.. 1084 */ 1085 for (lf = TAILQ_FIRST(&loaded_files); lf; lf = TAILQ_NEXT(lf, loaded)) { 1086 printf("KLD file %s is missing dependencies\n", lf->filename); 1087 linker_file_unload(lf); 1088 TAILQ_REMOVE(&loaded_files, lf, loaded); 1089 } 1090 1091 /* 1092 * We made it. Finish off the linking in the order we determined. 1093 */ 1094 for (lf = TAILQ_FIRST(&depended_files); lf; lf = TAILQ_NEXT(lf, loaded)) { 1095 if (linker_kernel_file) { 1096 linker_kernel_file->refs++; 1097 error = linker_file_add_dependancy(lf, linker_kernel_file); 1098 if (error) 1099 panic("cannot add dependency"); 1100 } 1101 lf->userrefs++; /* so we can (try to) kldunload it */ 1102 deps = (struct linker_set*) 1103 linker_file_lookup_symbol(lf, MDT_SETNAME, 0); 1104 if (deps) { 1105 for (i = 0; i < deps->ls_length; i++) { 1106 mp = linker_reloc_ptr(lf, deps->ls_items[i]); 1107 if (mp->md_type != MDT_DEPEND) 1108 continue; 1109 modname = linker_reloc_ptr(lf, mp->md_cval); 1110 mod = modlist_lookup(modname); 1111 mod->container->refs++; 1112 error = linker_file_add_dependancy(lf, mod->container); 1113 if (error) 1114 panic("cannot add dependency"); 1115 } 1116 } 1117 1118 /* Now do relocation etc using the symbol search paths established by the dependencies */ 1119 error = LINKER_LINK_PRELOAD_FINISH(lf); 1120 if (error) { 1121 printf("KLD file %s - could not finalize loading\n", lf->filename); 1122 linker_file_unload(lf); 1123 continue; 1124 } 1125 1126 mcount = linker_file_register_modules(lf); 1127 sysinits = (struct linker_set*) 1128 linker_file_lookup_symbol(lf, "sysinit_set", 0); 1129 if (sysinits) 1130 sysinit_add((struct sysinit **)sysinits->ls_items); 1131 linker_file_register_sysctls(lf); 1132 lf->flags |= LINKER_FILE_LINKED; 1133 } 1134 /* woohoo! we made it! */ |
|
950} 951 952SYSINIT(preload, SI_SUB_KLD, SI_ORDER_MIDDLE, linker_preload, 0); 953 954/* 955 * Search for a not-loaded module by name. 956 * 957 * Modules may be found in the following locations: --- 8 unchanged lines hidden (view full) --- 966 * character as a separator to be consistent with the bootloader. 967 */ 968 969static char linker_path[MAXPATHLEN] = "/;/boot/;/modules/"; 970 971SYSCTL_STRING(_kern, OID_AUTO, module_path, CTLFLAG_RW, linker_path, 972 sizeof(linker_path), "module load search path"); 973 | 1135} 1136 1137SYSINIT(preload, SI_SUB_KLD, SI_ORDER_MIDDLE, linker_preload, 0); 1138 1139/* 1140 * Search for a not-loaded module by name. 1141 * 1142 * Modules may be found in the following locations: --- 8 unchanged lines hidden (view full) --- 1151 * character as a separator to be consistent with the bootloader. 1152 */ 1153 1154static char linker_path[MAXPATHLEN] = "/;/boot/;/modules/"; 1155 1156SYSCTL_STRING(_kern, OID_AUTO, module_path, CTLFLAG_RW, linker_path, 1157 sizeof(linker_path), "module load search path"); 1158 |
974char * | 1159static char *linker_ext_list[] = { 1160 ".ko", 1161 "", 1162 NULL 1163}; 1164 1165static char * |
975linker_search_path(const char *name) 976{ 977 struct nameidata nd; 978 struct proc *p = curproc; /* XXX */ | 1166linker_search_path(const char *name) 1167{ 1168 struct nameidata nd; 1169 struct proc *p = curproc; /* XXX */ |
979 char *cp, *ep, *result; 980 int error; | 1170 char *cp, *ep, *result, **cpp; 1171 int error, extlen, len; |
981 enum vtype type; 982 983 /* qualified at all? */ 984 if (index(name, '/')) 985 return(linker_strdup(name)); 986 | 1172 enum vtype type; 1173 1174 /* qualified at all? */ 1175 if (index(name, '/')) 1176 return(linker_strdup(name)); 1177 |
1178 extlen = 0; 1179 for (cpp = linker_ext_list; *cpp; cpp++) { 1180 len = strlen(*cpp); 1181 if (len > extlen) 1182 extlen = len; 1183 } 1184 extlen++; /* trailing '\0' */ 1185 |
|
987 /* traverse the linker path */ 988 cp = linker_path; | 1186 /* traverse the linker path */ 1187 cp = linker_path; |
1188 len = strlen(name); |
|
989 for (;;) { 990 991 /* find the end of this component */ 992 for (ep = cp; (*ep != 0) && (*ep != ';'); ep++) 993 ; | 1189 for (;;) { 1190 1191 /* find the end of this component */ 1192 for (ep = cp; (*ep != 0) && (*ep != ';'); ep++) 1193 ; |
994 result = malloc((strlen(name) + (ep - cp) + 1), M_LINKER, M_WAITOK); | 1194 result = malloc((len + (ep - cp) + extlen), M_LINKER, M_WAITOK); |
995 if (result == NULL) /* actually ENOMEM */ 996 return(NULL); | 1195 if (result == NULL) /* actually ENOMEM */ 1196 return(NULL); |
1197 for (cpp = linker_ext_list; *cpp; cpp++) { 1198 strncpy(result, cp, ep - cp); 1199 strcpy(result + (ep - cp), name); 1200 strcat(result, *cpp); |
|
997 | 1201 |
998 strncpy(result, cp, ep - cp); 999 strcpy(result + (ep - cp), name); 1000 1001 /* 1002 * Attempt to open the file, and return the path if we succeed and it's 1003 * a regular file. 1004 */ 1005 NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, result, p); 1006 error = vn_open(&nd, FREAD, 0); 1007 if (error == 0) { 1008 NDFREE(&nd, NDF_ONLY_PNBUF); 1009 type = nd.ni_vp->v_type; 1010 VOP_UNLOCK(nd.ni_vp, 0, p); 1011 vn_close(nd.ni_vp, FREAD, p->p_ucred, p); 1012 if (type == VREG) 1013 return(result); | 1202 /* 1203 * Attempt to open the file, and return the path if we succeed 1204 * and it's a regular file. 1205 */ 1206 NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, result, p); 1207 error = vn_open(&nd, FREAD, 0); 1208 if (error == 0) { 1209 NDFREE(&nd, NDF_ONLY_PNBUF); 1210 type = nd.ni_vp->v_type; 1211 VOP_UNLOCK(nd.ni_vp, 0, p); 1212 vn_close(nd.ni_vp, FREAD, p->p_ucred, p); 1213 if (type == VREG) 1214 return(result); 1215 } |
1014 } 1015 free(result, M_LINKER); 1016 1017 if (*ep == 0) 1018 break; 1019 cp = ep + 1; 1020 } 1021 return(NULL); 1022} | 1216 } 1217 free(result, M_LINKER); 1218 1219 if (*ep == 0) 1220 break; 1221 cp = ep + 1; 1222 } 1223 return(NULL); 1224} |
1225 1226static const char * 1227linker_basename(const char* path) 1228{ 1229 const char *filename; 1230 1231 filename = rindex(path, '/'); 1232 if (filename == NULL) 1233 return path; 1234 if (filename[1]) 1235 filename++; 1236 return filename; 1237} 1238 1239/* 1240 * Find a file which contains given module and load it, 1241 * if "parent" is not NULL, register a reference to it. 1242 */ 1243static int 1244linker_load_module(const char *modname, struct linker_file *parent) 1245{ 1246 linker_file_t lfdep; 1247 const char *filename; 1248 char *pathname; 1249 int error; 1250 1251 /* 1252 * There will be a system to look up or guess a file name from 1253 * a module name. 1254 * For now we just try to load a file with the same name. 1255 */ 1256 pathname = linker_search_path(modname); 1257 if (pathname == NULL) 1258 return ENOENT; 1259 1260 /* Can't load more than one file with the same basename */ 1261 filename = linker_basename(pathname); 1262 if (linker_find_file_by_name(filename)) { 1263 error = EEXIST; 1264 goto out; 1265 } 1266 1267 do { 1268 error = linker_load_file(pathname, &lfdep); 1269 if (error) 1270 break; 1271 if (parent) { 1272 error = linker_file_add_dependancy(parent, lfdep); 1273 if (error) 1274 break; 1275 } 1276 } while(0); 1277out: 1278 if (pathname) 1279 free(pathname, M_LINKER); 1280 return error; 1281} 1282 1283/* 1284 * This routine is responsible for finding dependencies of userland 1285 * initiated kldload(2)'s of files. 1286 */ 1287int 1288linker_load_dependancies(linker_file_t lf) 1289{ 1290 linker_file_t lfdep; 1291 struct linker_set *deps; 1292 struct mod_metadata *mp, *nmp; 1293 modlist_t mod; 1294 char *modname, *nmodname; 1295 int i, j, error = 0; 1296 1297 /* 1298 * All files are dependant on /kernel. 1299 */ 1300 if (linker_kernel_file) { 1301 linker_kernel_file->refs++; 1302 error = linker_file_add_dependancy(lf, linker_kernel_file); 1303 if (error) 1304 return error; 1305 } 1306 1307 deps = (struct linker_set*) 1308 linker_file_lookup_symbol(lf, MDT_SETNAME, 0); 1309 if (deps != NULL) { 1310 for (i = 0; i < deps->ls_length; i++) { 1311 mp = linker_reloc_ptr(lf, deps->ls_items[i]); 1312 if (mp->md_type != MDT_VERSION) 1313 continue; 1314 modname = linker_reloc_ptr(lf, mp->md_cval); 1315 if (modlist_lookup(modname) != NULL) { 1316 printf("module %s already present!\n", modname); 1317 return EEXIST; 1318 } 1319 } 1320 } 1321 if (deps != NULL) { 1322 for (i = 0; i < deps->ls_length; i++) { 1323 mp = linker_reloc_ptr(lf, deps->ls_items[i]); 1324 if (mp->md_type != MDT_DEPEND) 1325 continue; 1326 modname = linker_reloc_ptr(lf, mp->md_cval); 1327 nmodname = NULL; 1328 for (j = 0; j < deps->ls_length; j++) { 1329 nmp = linker_reloc_ptr(lf, deps->ls_items[j]); 1330 if (nmp->md_type != MDT_VERSION) 1331 continue; 1332 nmodname = linker_reloc_ptr(lf, nmp->md_cval); 1333 if (strcmp(modname, nmodname) == 0) 1334 break; 1335 } 1336 if (j < deps->ls_length) /* early exit, it's a self reference */ 1337 continue; 1338 mod = modlist_lookup(modname); 1339 if (mod) { /* woohoo, it's loaded already */ 1340 lfdep = mod->container; 1341 lfdep->refs++; 1342 error = linker_file_add_dependancy(lf, lfdep); 1343 if (error) 1344 break; 1345 continue; 1346 } 1347 error = linker_load_module(modname, lf); 1348 if (error) { 1349 printf("KLD %s: depends on %s - not available\n", 1350 lf->filename, modname); 1351 break; 1352 } 1353 } 1354 1355 } 1356 if (error == 0 && deps) { 1357 for (i = 0; i < deps->ls_length; i++) { 1358 mp = linker_reloc_ptr(lf, deps->ls_items[i]); 1359 if (mp->md_type != MDT_VERSION) 1360 continue; 1361 modname = linker_reloc_ptr(lf, mp->md_cval); 1362 mod = malloc(sizeof(struct modlist), M_LINKER, M_NOWAIT); 1363 if (mod == NULL) 1364 panic("no memory for module list"); 1365 bzero(mod, sizeof(*mod)); 1366 mod->container = lf; 1367 mod->name = modname; 1368 TAILQ_INSERT_TAIL(&found_modules, mod, link); 1369 } 1370 } 1371 return error; 1372} |
|