Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

modules: add default loader hook implementations

The module loader code allows architectures to hook into the code by
providing a small number of entry points that each arch must implement.
This patch provides __weakly linked generic implementations of these
entry points for architectures that don't need to do anything special.

Signed-off-by: Jonas Bonn <jonas@southpole.se>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>

authored by

Jonas Bonn and committed by
Rusty Russell
74e08fcf 81c74136

+55 -1
+6 -1
include/linux/moduleloader.h
··· 5 5 #include <linux/module.h> 6 6 #include <linux/elf.h> 7 7 8 - /* These must be implemented by the specific architecture */ 8 + /* These may be implemented by architectures that need to hook into the 9 + * module loader code. Architectures that don't need to do anything special 10 + * can just rely on the 'weak' default hooks defined in kernel/module.c. 11 + * Note, however, that at least one of apply_relocate or apply_relocate_add 12 + * must be implemented by each architecture. 13 + */ 9 14 10 15 /* Adjust arch-specific sections. Return 0 on success. */ 11 16 int module_frob_arch_sections(Elf_Ehdr *hdr,
+49
kernel/module.c
··· 1697 1697 static void unset_module_init_ro_nx(struct module *mod) { } 1698 1698 #endif 1699 1699 1700 + void __weak module_free(struct module *mod, void *module_region) 1701 + { 1702 + vfree(module_region); 1703 + } 1704 + 1705 + void __weak module_arch_cleanup(struct module *mod) 1706 + { 1707 + } 1708 + 1700 1709 /* Free a module, remove from lists, etc. */ 1701 1710 static void free_module(struct module *mod) 1702 1711 { ··· 1858 1849 } 1859 1850 1860 1851 return ret; 1852 + } 1853 + 1854 + int __weak apply_relocate(Elf_Shdr *sechdrs, 1855 + const char *strtab, 1856 + unsigned int symindex, 1857 + unsigned int relsec, 1858 + struct module *me) 1859 + { 1860 + pr_err("module %s: REL relocation unsupported\n", me->name); 1861 + return -ENOEXEC; 1862 + } 1863 + 1864 + int __weak apply_relocate_add(Elf_Shdr *sechdrs, 1865 + const char *strtab, 1866 + unsigned int symindex, 1867 + unsigned int relsec, 1868 + struct module *me) 1869 + { 1870 + pr_err("module %s: RELA relocation unsupported\n", me->name); 1871 + return -ENOEXEC; 1861 1872 } 1862 1873 1863 1874 static int apply_relocations(struct module *mod, const struct load_info *info) ··· 2262 2233 { 2263 2234 if (debug) 2264 2235 ddebug_remove_module(debug->modname); 2236 + } 2237 + 2238 + void * __weak module_alloc(unsigned long size) 2239 + { 2240 + return size == 0 ? NULL : vmalloc_exec(size); 2265 2241 } 2266 2242 2267 2243 static void *module_alloc_update_bounds(unsigned long size) ··· 2679 2645 set_fs(old_fs); 2680 2646 } 2681 2647 2648 + int __weak module_frob_arch_sections(Elf_Ehdr *hdr, 2649 + Elf_Shdr *sechdrs, 2650 + char *secstrings, 2651 + struct module *mod) 2652 + { 2653 + return 0; 2654 + } 2655 + 2682 2656 static struct module *layout_and_allocate(struct load_info *info) 2683 2657 { 2684 2658 /* Module within temporary copy. */ ··· 2756 2714 percpu_modfree(mod); 2757 2715 module_free(mod, mod->module_init); 2758 2716 module_free(mod, mod->module_core); 2717 + } 2718 + 2719 + int __weak module_finalize(const Elf_Ehdr *hdr, 2720 + const Elf_Shdr *sechdrs, 2721 + struct module *me) 2722 + { 2723 + return 0; 2759 2724 } 2760 2725 2761 2726 static int post_relocation(struct module *mod, const struct load_info *info)