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 /* arch may override to do additional checking of ELF header architecture */
17 bool module_elf_check_arch(Elf_Ehdr
*hdr
);
19 /* Adjust arch-specific sections. Return 0 on success. */
20 int module_frob_arch_sections(Elf_Ehdr
*hdr
,
25 /* Additional bytes needed by arch in front of individual sections */
26 unsigned int arch_mod_section_prepend(struct module
*mod
, unsigned int section
);
28 /* Determines if the section name is an init section (that is only used during
31 bool module_init_section(const char *name
);
33 /* Determines if the section name is an exit section (that is only used during
36 bool module_exit_section(const char *name
);
38 /* Describes whether within_module_init() will consider this an init section
39 * or not. This behaviour changes with CONFIG_MODULE_UNLOAD.
41 bool module_init_layout_section(const char *sname
);
44 * Apply the given relocation to the (simplified) ELF. Return -error
47 #ifdef CONFIG_MODULES_USE_ELF_REL
48 int apply_relocate(Elf_Shdr
*sechdrs
,
50 unsigned int symindex
,
54 static inline int apply_relocate(Elf_Shdr
*sechdrs
,
56 unsigned int symindex
,
60 printk(KERN_ERR
"module %s: REL relocation unsupported\n",
67 * Apply the given add relocation to the (simplified) ELF. Return
70 #ifdef CONFIG_MODULES_USE_ELF_RELA
71 int apply_relocate_add(Elf_Shdr
*sechdrs
,
73 unsigned int symindex
,
76 #ifdef CONFIG_LIVEPATCH
78 * Some architectures (namely x86_64 and ppc64) perform sanity checks when
79 * applying relocations. If a patched module gets unloaded and then later
80 * reloaded (and re-patched), klp re-applies relocations to the replacement
81 * function(s). Any leftover relocations from the previous loading of the
82 * patched module might trigger the sanity checks.
84 * To prevent that, when unloading a patched module, clear out any relocations
85 * that might trigger arch-specific sanity checks on a future module reload.
87 void clear_relocate_add(Elf_Shdr
*sechdrs
,
89 unsigned int symindex
,
94 static inline int apply_relocate_add(Elf_Shdr
*sechdrs
,
96 unsigned int symindex
,
100 printk(KERN_ERR
"module %s: REL relocation unsupported\n",
106 /* Any final processing of module before access. Return -error or 0. */
107 int module_finalize(const Elf_Ehdr
*hdr
,
108 const Elf_Shdr
*sechdrs
,
111 int module_post_finalize(const Elf_Ehdr
*hdr
,
112 const Elf_Shdr
*sechdrs
,
115 #ifdef CONFIG_MODULES
116 void flush_module_init_free_work(void);
118 static inline void flush_module_init_free_work(void)
123 /* Any cleanup needed when module leaves. */
124 void module_arch_cleanup(struct module
*mod
);
126 /* Any cleanup before freeing mod->module_init */
127 void module_arch_freeing_init(struct module
*mod
);