1 /* SPDX-License-Identifier: GPL-2.0 */ 1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef _LINUX_MODULELOADER_H 2 #ifndef _LINUX_MODULELOADER_H 3 #define _LINUX_MODULELOADER_H 3 #define _LINUX_MODULELOADER_H 4 /* The stuff needed for archs to support modul 4 /* The stuff needed for archs to support modules. */ 5 5 6 #include <linux/module.h> 6 #include <linux/module.h> 7 #include <linux/elf.h> 7 #include <linux/elf.h> 8 8 9 /* These may be implemented by architectures t 9 /* These may be implemented by architectures that need to hook into the 10 * module loader code. Architectures that don 10 * module loader code. Architectures that don't need to do anything special 11 * can just rely on the 'weak' default hooks d 11 * can just rely on the 'weak' default hooks defined in kernel/module.c. 12 * Note, however, that at least one of apply_r 12 * Note, however, that at least one of apply_relocate or apply_relocate_add 13 * must be implemented by each architecture. 13 * must be implemented by each architecture. 14 */ 14 */ 15 15 16 /* arch may override to do additional checking << 17 bool module_elf_check_arch(Elf_Ehdr *hdr); << 18 << 19 /* Adjust arch-specific sections. Return 0 on 16 /* Adjust arch-specific sections. Return 0 on success. */ 20 int module_frob_arch_sections(Elf_Ehdr *hdr, 17 int module_frob_arch_sections(Elf_Ehdr *hdr, 21 Elf_Shdr *sechdr 18 Elf_Shdr *sechdrs, 22 char *secstrings 19 char *secstrings, 23 struct module *m 20 struct module *mod); 24 21 25 /* Additional bytes needed by arch in front of 22 /* Additional bytes needed by arch in front of individual sections */ 26 unsigned int arch_mod_section_prepend(struct m 23 unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section); 27 24 >> 25 /* Allocator used for allocating struct module, core sections and init >> 26 sections. Returns NULL on failure. */ >> 27 void *module_alloc(unsigned long size); >> 28 >> 29 /* Free memory returned from module_alloc. */ >> 30 void module_memfree(void *module_region); >> 31 28 /* Determines if the section name is an init s 32 /* Determines if the section name is an init section (that is only used during 29 * module loading). 33 * module loading). 30 */ 34 */ 31 bool module_init_section(const char *name); 35 bool module_init_section(const char *name); 32 36 33 /* Determines if the section name is an exit s 37 /* Determines if the section name is an exit section (that is only used during 34 * module unloading) 38 * module unloading) 35 */ 39 */ 36 bool module_exit_section(const char *name); 40 bool module_exit_section(const char *name); 37 41 38 /* Describes whether within_module_init() will << 39 * or not. This behaviour changes with CONFIG_ << 40 */ << 41 bool module_init_layout_section(const char *sn << 42 << 43 /* 42 /* 44 * Apply the given relocation to the (simplifi 43 * Apply the given relocation to the (simplified) ELF. Return -error 45 * or 0. 44 * or 0. 46 */ 45 */ 47 #ifdef CONFIG_MODULES_USE_ELF_REL 46 #ifdef CONFIG_MODULES_USE_ELF_REL 48 int apply_relocate(Elf_Shdr *sechdrs, 47 int apply_relocate(Elf_Shdr *sechdrs, 49 const char *strtab, 48 const char *strtab, 50 unsigned int symindex, 49 unsigned int symindex, 51 unsigned int relsec, 50 unsigned int relsec, 52 struct module *mod); 51 struct module *mod); 53 #else 52 #else 54 static inline int apply_relocate(Elf_Shdr *sec 53 static inline int apply_relocate(Elf_Shdr *sechdrs, 55 const char *s 54 const char *strtab, 56 unsigned int 55 unsigned int symindex, 57 unsigned int 56 unsigned int relsec, 58 struct module 57 struct module *me) 59 { 58 { 60 printk(KERN_ERR "module %s: REL reloca 59 printk(KERN_ERR "module %s: REL relocation unsupported\n", 61 module_name(me)); 60 module_name(me)); 62 return -ENOEXEC; 61 return -ENOEXEC; 63 } 62 } 64 #endif 63 #endif 65 64 66 /* 65 /* 67 * Apply the given add relocation to the (simp 66 * Apply the given add relocation to the (simplified) ELF. Return 68 * -error or 0 67 * -error or 0 69 */ 68 */ 70 #ifdef CONFIG_MODULES_USE_ELF_RELA 69 #ifdef CONFIG_MODULES_USE_ELF_RELA 71 int apply_relocate_add(Elf_Shdr *sechdrs, 70 int apply_relocate_add(Elf_Shdr *sechdrs, 72 const char *strtab, 71 const char *strtab, 73 unsigned int symindex, 72 unsigned int symindex, 74 unsigned int relsec, 73 unsigned int relsec, 75 struct module *mod); 74 struct module *mod); 76 #ifdef CONFIG_LIVEPATCH << 77 /* << 78 * Some architectures (namely x86_64 and ppc64 << 79 * applying relocations. If a patched module << 80 * reloaded (and re-patched), klp re-applies r << 81 * function(s). Any leftover relocations from << 82 * patched module might trigger the sanity che << 83 * << 84 * To prevent that, when unloading a patched m << 85 * that might trigger arch-specific sanity che << 86 */ << 87 void clear_relocate_add(Elf_Shdr *sechdrs, << 88 const char *strtab, << 89 unsigned int symindex, << 90 unsigned int relsec, << 91 struct module *me); << 92 #endif << 93 #else 75 #else 94 static inline int apply_relocate_add(Elf_Shdr 76 static inline int apply_relocate_add(Elf_Shdr *sechdrs, 95 const cha 77 const char *strtab, 96 unsigned 78 unsigned int symindex, 97 unsigned 79 unsigned int relsec, 98 struct mo 80 struct module *me) 99 { 81 { 100 printk(KERN_ERR "module %s: REL reloca 82 printk(KERN_ERR "module %s: REL relocation unsupported\n", 101 module_name(me)); 83 module_name(me)); 102 return -ENOEXEC; 84 return -ENOEXEC; 103 } 85 } 104 #endif 86 #endif 105 87 106 /* Any final processing of module before acces 88 /* Any final processing of module before access. Return -error or 0. */ 107 int module_finalize(const Elf_Ehdr *hdr, 89 int module_finalize(const Elf_Ehdr *hdr, 108 const Elf_Shdr *sechdrs, 90 const Elf_Shdr *sechdrs, 109 struct module *mod); 91 struct module *mod); 110 92 111 #ifdef CONFIG_MODULES << 112 void flush_module_init_free_work(void); << 113 #else << 114 static inline void flush_module_init_free_work << 115 { << 116 } << 117 #endif << 118 << 119 /* Any cleanup needed when module leaves. */ 93 /* Any cleanup needed when module leaves. */ 120 void module_arch_cleanup(struct module *mod); 94 void module_arch_cleanup(struct module *mod); 121 95 122 /* Any cleanup before freeing mod->module_init 96 /* Any cleanup before freeing mod->module_init */ 123 void module_arch_freeing_init(struct module *m 97 void module_arch_freeing_init(struct module *mod); >> 98 >> 99 #if (defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)) && \ >> 100 !defined(CONFIG_KASAN_VMALLOC) >> 101 #include <linux/kasan.h> >> 102 #define MODULE_ALIGN (PAGE_SIZE << KASAN_SHADOW_SCALE_SHIFT) >> 103 #else >> 104 #define MODULE_ALIGN PAGE_SIZE >> 105 #endif 124 106 125 #endif 107 #endif 126 108
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.