1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_MODULELOADER_H
3 #define _LINUX_MODULELOADER_H
4 /* The stuff needed for archs to support modules. */
6 #include <linux/module.h>
9 /* These may be implemented by architectures that need to hook into the
10 * module loader code. Architectures that don't need to do anything special
11 * can just rely on the 'weak' default hooks defined in kernel/module.c.
12 * Note, however, that at least one of apply_relocate or apply_relocate_add
13 * must be implemented by each architecture.
16 /* Adjust arch-specific sections. Return 0 on success. */
17 int module_frob_arch_sections(Elf_Ehdr *hdr,
22 /* Additional bytes needed by arch in front of individual sections */
23 unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
25 /* Allocator used for allocating struct module, core sections and init
26 sections. Returns NULL on failure. */
27 void *module_alloc(unsigned long size);
29 /* Free memory returned from module_alloc. */
30 void module_memfree(void *module_region);
32 /* Determines if the section name is an init section (that is only used during
35 bool module_init_section(const char *name);
37 /* Determines if the section name is an exit section (that is only used during
40 bool module_exit_section(const char *name);
43 * Apply the given relocation to the (simplified) ELF. Return -error
46 #ifdef CONFIG_MODULES_USE_ELF_REL
47 int apply_relocate(Elf_Shdr *sechdrs,
49 unsigned int symindex,
53 static inline int apply_relocate(Elf_Shdr *sechdrs,
55 unsigned int symindex,
59 printk(KERN_ERR "module %s: REL relocation unsupported\n",
66 * Apply the given add relocation to the (simplified) ELF. Return
69 #ifdef CONFIG_MODULES_USE_ELF_RELA
70 int apply_relocate_add(Elf_Shdr *sechdrs,
72 unsigned int symindex,
76 static inline int apply_relocate_add(Elf_Shdr *sechdrs,
78 unsigned int symindex,
82 printk(KERN_ERR "module %s: REL relocation unsupported\n",
88 /* Any final processing of module before access. Return -error or 0. */
89 int module_finalize(const Elf_Ehdr *hdr,
90 const Elf_Shdr *sechdrs,
93 /* Any cleanup needed when module leaves. */
94 void module_arch_cleanup(struct module *mod);
96 /* Any cleanup before freeing mod->module_init */
97 void module_arch_freeing_init(struct module *mod);
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)
104 #define MODULE_ALIGN PAGE_SIZE