/* * kobj_affix: * * Set an object's name and perform global relocs. May only be * called after the module and any requisite modules are loaded. */ int kobj_affix(kobj_t ko, const char *name) { int error; KASSERT(ko->ko_ksyms == false); KASSERT(ko->ko_loaded == false); kobj_setname(ko, name); /* Cache addresses of undefined symbols. */ error = kobj_checksyms(ko, true); /* Now do global relocations. */ if (error == 0) error = kobj_relocate(ko, false); /* * Now that we know the name, register the symbol table. * Do after global relocations because ksyms will pack * the table. */ if (error == 0) { ksyms_modload(ko->ko_name, ko->ko_symtab, ko->ko_symcnt * sizeof(Elf_Sym), ko->ko_strtab, ko->ko_strtabsz); ko->ko_ksyms = true; } /* Jettison unneeded memory post-link. */ kobj_jettison(ko); /* * Notify MD code that a module has been loaded. * * Most architectures use this opportunity to flush their caches. */ if (error == 0) { error = kobj_machdep(ko, (void *)ko->ko_address, ko->ko_size, true); if (error != 0) kobj_error(__func__, __LINE__, ko, "machine dependent init failed %d", error); ko->ko_loaded = true; } /* If there was an error, destroy the whole object. */ if (error != 0) { kobj_unload(ko); } return error; }
/* * kobj_affix: * * Set an object's name and perform global relocs. May only be * called after the module and any requisite modules are loaded. */ int kobj_affix(kobj_t ko, const char *name) { int error; KASSERT(ko->ko_ksyms == false); KASSERT(ko->ko_loaded == false); strlcpy(ko->ko_name, name, sizeof(ko->ko_name)); /* Now do global relocations. */ error = kobj_relocate(ko, false); /* * Now that we know the name, register the symbol table. * Do after global relocations because ksyms will pack it. */ ksyms_modload(ko->ko_name, ko->ko_symtab, ko->ko_symcnt * sizeof(Elf_Sym), ko->ko_strtab, ko->ko_strtabsz); ko->ko_ksyms = true; /* Jettison unneeded memory post-link. */ kobj_jettison(ko); /* Notify MD code that a module has been loaded. */ if (error == 0) { error = kobj_machdep(ko, (void *)ko->ko_address, ko->ko_size, true); if (error != 0) { kobj_error("machine dependent init failed"); } ko->ko_loaded = true; } /* If there was an error, destroy the whole object. */ if (error != 0) { kobj_unload(ko); } return error; }