diff --git a/sys/kern/kern_linker.c b/sys/kern/kern_linker.c index abd7fdd9232..2eb6a9f3a74 100644 --- a/sys/kern/kern_linker.c +++ b/sys/kern/kern_linker.c @@ -331,6 +331,31 @@ out: return error; } +int +linker_reference_module(const char *modname, linker_file_t *result) +{ + char *pathname; + int res; + + /* + * There will be a system to look up or guess a file name from + * a module name. + * For now we just try to load a file with the same name. + */ + if ((pathname = linker_search_path(modname)) == NULL) + return (ENOENT); + + /* + * If the module is already loaded or built into the kernel, + * linker_load_file() simply bumps it's refcount. + */ + res = linker_load_file(pathname, result); + + free(pathname, M_LINKER); + + return (res); +} + linker_file_t linker_find_file_by_name(const char* filename) { diff --git a/sys/sys/linker.h b/sys/sys/linker.h index 671bbe8fd31..20ab83ec120 100644 --- a/sys/sys/linker.h +++ b/sys/sys/linker.h @@ -106,6 +106,11 @@ int linker_add_class(linker_class_t _cls); */ int linker_load_file(const char* _filename, linker_file_t* _result); +/* + * Obtain a reference to a module, loading it if required. + */ +int linker_reference_module(const char* _modname, linker_file_t* _result); + /* * Find a currently loaded file given its filename. */