| 412 | NULL); |
| 413 | |
| 414 | static int |
| 415 | linker_load_file(const char *filename, linker_file_t *result) |
| 416 | { |
| 417 | linker_class_t lc; |
| 418 | linker_file_t lf; |
| 419 | int foundfile, error, modules; |
| 420 | |
| 421 | /* Refuse to load modules if securelevel raised */ |
| 422 | if (prison0.pr_securelevel > 0) |
| 423 | return (EPERM); |
| 424 | |
| 425 | sx_assert(&kld_sx, SA_XLOCKED); |
| 426 | lf = linker_find_file_by_name(filename); |
| 427 | if (lf) { |
| 428 | KLD_DPF(FILE, ("linker_load_file: file %s is already loaded," |
| 429 | " incrementing refs\n", filename)); |
| 430 | *result = lf; |
| 431 | lf->refs++; |
| 432 | return (0); |
| 433 | } |
| 434 | foundfile = 0; |
| 435 | error = 0; |
| 436 | |
| 437 | /* |
| 438 | * We do not need to protect (lock) classes here because there is |
| 439 | * no class registration past startup (SI_SUB_KLD, SI_ORDER_ANY) |
| 440 | * and there is no class deregistration mechanism at this time. |
| 441 | */ |
| 442 | TAILQ_FOREACH(lc, &classes, link) { |
| 443 | KLD_DPF(FILE, ("linker_load_file: trying to load %s\n", |
| 444 | filename)); |
| 445 | error = LINKER_LOAD_FILE(lc, filename, &lf); |
| 446 | /* |
| 447 | * If we got something other than ENOENT, then it exists but |
| 448 | * we cannot load it for some other reason. |
| 449 | */ |
| 450 | if (error != ENOENT) |
| 451 | foundfile = 1; |
| 452 | if (lf) { |
| 453 | error = linker_file_register_modules(lf); |
| 454 | if (error == EEXIST) { |
| 455 | linker_file_unload(lf, LINKER_UNLOAD_FORCE); |
| 456 | return (error); |
| 457 | } |
| 458 | modules = !TAILQ_EMPTY(&lf->modules); |
| 459 | linker_file_register_sysctls(lf, false); |
| 460 | linker_file_sysinit(lf); |
| 461 | lf->flags |= LINKER_FILE_LINKED; |
| 462 | |
| 463 | /* |
| 464 | * If all of the modules in this file failed |
| 465 | * to load, unload the file and return an |
| 466 | * error of ENOEXEC. |
| 467 | */ |
| 468 | if (modules && TAILQ_EMPTY(&lf->modules)) { |
| 469 | linker_file_unload(lf, LINKER_UNLOAD_FORCE); |
| 470 | return (ENOEXEC); |
| 471 | } |
no test coverage detected