Merge tag 'xfs-6.4-rc1-fixes' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux
[linux-block.git] / include / linux / moduleloader.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
1da177e4
LT
2#ifndef _LINUX_MODULELOADER_H
3#define _LINUX_MODULELOADER_H
4/* The stuff needed for archs to support modules. */
5
6#include <linux/module.h>
7#include <linux/elf.h>
8
74e08fcf
JB
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.
14 */
1da177e4 15
f9231a99
NP
16/* arch may override to do additional checking of ELF header architecture */
17bool module_elf_check_arch(Elf_Ehdr *hdr);
18
1da177e4
LT
19/* Adjust arch-specific sections. Return 0 on success. */
20int module_frob_arch_sections(Elf_Ehdr *hdr,
21 Elf_Shdr *sechdrs,
22 char *secstrings,
23 struct module *mod);
24
088af9a6
HD
25/* Additional bytes needed by arch in front of individual sections */
26unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
27
1da177e4
LT
28/* Allocator used for allocating struct module, core sections and init
29 sections. Returns NULL on failure. */
30void *module_alloc(unsigned long size);
31
32/* Free memory returned from module_alloc. */
be1f221c 33void module_memfree(void *module_region);
1da177e4 34
23189766
VW
35/* Determines if the section name is an init section (that is only used during
36 * module loading).
37 */
38bool module_init_section(const char *name);
39
38b37d63
MS
40/* Determines if the section name is an exit section (that is only used during
41 * module unloading)
42 */
43bool module_exit_section(const char *name);
44
786d35d4
DH
45/*
46 * Apply the given relocation to the (simplified) ELF. Return -error
47 * or 0.
48 */
49#ifdef CONFIG_MODULES_USE_ELF_REL
1da177e4
LT
50int apply_relocate(Elf_Shdr *sechdrs,
51 const char *strtab,
52 unsigned int symindex,
53 unsigned int relsec,
54 struct module *mod);
786d35d4
DH
55#else
56static inline int apply_relocate(Elf_Shdr *sechdrs,
57 const char *strtab,
58 unsigned int symindex,
59 unsigned int relsec,
60 struct module *me)
61{
3a611c3c
RR
62 printk(KERN_ERR "module %s: REL relocation unsupported\n",
63 module_name(me));
786d35d4
DH
64 return -ENOEXEC;
65}
66#endif
1da177e4 67
786d35d4
DH
68/*
69 * Apply the given add relocation to the (simplified) ELF. Return
70 * -error or 0
71 */
72#ifdef CONFIG_MODULES_USE_ELF_RELA
1da177e4
LT
73int apply_relocate_add(Elf_Shdr *sechdrs,
74 const char *strtab,
75 unsigned int symindex,
76 unsigned int relsec,
77 struct module *mod);
0c05e7bd
SL
78#ifdef CONFIG_LIVEPATCH
79/*
80 * Some architectures (namely x86_64 and ppc64) perform sanity checks when
81 * applying relocations. If a patched module gets unloaded and then later
82 * reloaded (and re-patched), klp re-applies relocations to the replacement
83 * function(s). Any leftover relocations from the previous loading of the
84 * patched module might trigger the sanity checks.
85 *
86 * To prevent that, when unloading a patched module, clear out any relocations
87 * that might trigger arch-specific sanity checks on a future module reload.
88 */
89void clear_relocate_add(Elf_Shdr *sechdrs,
90 const char *strtab,
91 unsigned int symindex,
92 unsigned int relsec,
93 struct module *me);
94#endif
786d35d4
DH
95#else
96static inline int apply_relocate_add(Elf_Shdr *sechdrs,
97 const char *strtab,
98 unsigned int symindex,
99 unsigned int relsec,
100 struct module *me)
101{
3a611c3c
RR
102 printk(KERN_ERR "module %s: REL relocation unsupported\n",
103 module_name(me));
786d35d4
DH
104 return -ENOEXEC;
105}
106#endif
1da177e4
LT
107
108/* Any final processing of module before access. Return -error or 0. */
109int module_finalize(const Elf_Ehdr *hdr,
110 const Elf_Shdr *sechdrs,
111 struct module *mod);
112
113/* Any cleanup needed when module leaves. */
114void module_arch_cleanup(struct module *mod);
115
d453cded
RR
116/* Any cleanup before freeing mod->module_init */
117void module_arch_freeing_init(struct module *mod);
d3733e5c 118
0fea6e9a
AK
119#if (defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)) && \
120 !defined(CONFIG_KASAN_VMALLOC)
d3733e5c
AR
121#include <linux/kasan.h>
122#define MODULE_ALIGN (PAGE_SIZE << KASAN_SHADOW_SCALE_SHIFT)
123#else
124#define MODULE_ALIGN PAGE_SIZE
125#endif
126
1da177e4 127#endif