MCPcopy Create free account
hub / github.com/F-Stack/f-stack / linker_load_module

Function linker_load_module

freebsd/kern/kern_linker.c:2086–2152  ·  view source on GitHub ↗

* Find a file which contains given module and load it, if "parent" is not * NULL, register a reference to it. */

Source from the content-addressed store, hash-verified

2084 * NULL, register a reference to it.
2085 */
2086static int
2087linker_load_module(const char *kldname, const char *modname,
2088 struct linker_file *parent, const struct mod_depend *verinfo,
2089 struct linker_file **lfpp)
2090{
2091 linker_file_t lfdep;
2092 const char *filename;
2093 char *pathname;
2094 int error;
2095
2096 sx_assert(&kld_sx, SA_XLOCKED);
2097 if (modname == NULL) {
2098 /*
2099 * We have to load KLD
2100 */
2101 KASSERT(verinfo == NULL, ("linker_load_module: verinfo"
2102 " is not NULL"));
2103 if (!linker_root_mounted())
2104 return (ENXIO);
2105 pathname = linker_search_kld(kldname);
2106 } else {
2107 if (modlist_lookup2(modname, verinfo) != NULL)
2108 return (EEXIST);
2109 if (!linker_root_mounted())
2110 return (ENXIO);
2111 if (kldname != NULL)
2112 pathname = strdup(kldname, M_LINKER);
2113 else
2114 /*
2115 * Need to find a KLD with required module
2116 */
2117 pathname = linker_search_module(modname,
2118 strlen(modname), verinfo);
2119 }
2120 if (pathname == NULL)
2121 return (ENOENT);
2122
2123 /*
2124 * Can't load more than one file with the same basename XXX:
2125 * Actually it should be possible to have multiple KLDs with
2126 * the same basename but different path because they can
2127 * provide different versions of the same modules.
2128 */
2129 filename = linker_basename(pathname);
2130 if (linker_find_file_by_name(filename))
2131 error = EEXIST;
2132 else do {
2133 error = linker_load_file(pathname, &lfdep);
2134 if (error)
2135 break;
2136 if (modname && verinfo &&
2137 modlist_lookup2(modname, verinfo) == NULL) {
2138 linker_file_unload(lfdep, LINKER_UNLOAD_FORCE);
2139 error = ENOENT;
2140 break;
2141 }
2142 if (parent) {
2143 error = linker_file_add_dependency(parent, lfdep);

Callers 3

linker_reference_moduleFunction · 0.85
kern_kldloadFunction · 0.85
linker_load_dependenciesFunction · 0.85

Calls 11

linker_root_mountedFunction · 0.85
linker_search_kldFunction · 0.85
modlist_lookup2Function · 0.85
strdupFunction · 0.85
linker_search_moduleFunction · 0.85
linker_basenameFunction · 0.85
linker_find_file_by_nameFunction · 0.85
linker_load_fileFunction · 0.85
linker_file_unloadFunction · 0.85
freeFunction · 0.70

Tested by

no test coverage detected