Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _LINUX_MODULELOADER_H
0003 #define _LINUX_MODULELOADER_H
0004 /* The stuff needed for archs to support modules. */
0005 
0006 #include <linux/module.h>
0007 #include <linux/elf.h>
0008 
0009 /* These may be implemented by architectures that need to hook into the
0010  * module loader code.  Architectures that don't need to do anything special
0011  * can just rely on the 'weak' default hooks defined in kernel/module.c.
0012  * Note, however, that at least one of apply_relocate or apply_relocate_add
0013  * must be implemented by each architecture.
0014  */
0015 
0016 /* Adjust arch-specific sections.  Return 0 on success.  */
0017 int module_frob_arch_sections(Elf_Ehdr *hdr,
0018                   Elf_Shdr *sechdrs,
0019                   char *secstrings,
0020                   struct module *mod);
0021 
0022 /* Additional bytes needed by arch in front of individual sections */
0023 unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
0024 
0025 /* Allocator used for allocating struct module, core sections and init
0026    sections.  Returns NULL on failure. */
0027 void *module_alloc(unsigned long size);
0028 
0029 /* Free memory returned from module_alloc. */
0030 void module_memfree(void *module_region);
0031 
0032 /* Determines if the section name is an init section (that is only used during
0033  * module loading).
0034  */
0035 bool module_init_section(const char *name);
0036 
0037 /* Determines if the section name is an exit section (that is only used during
0038  * module unloading)
0039  */
0040 bool module_exit_section(const char *name);
0041 
0042 /*
0043  * Apply the given relocation to the (simplified) ELF.  Return -error
0044  * or 0.
0045  */
0046 #ifdef CONFIG_MODULES_USE_ELF_REL
0047 int apply_relocate(Elf_Shdr *sechdrs,
0048            const char *strtab,
0049            unsigned int symindex,
0050            unsigned int relsec,
0051            struct module *mod);
0052 #else
0053 static inline int apply_relocate(Elf_Shdr *sechdrs,
0054                  const char *strtab,
0055                  unsigned int symindex,
0056                  unsigned int relsec,
0057                  struct module *me)
0058 {
0059     printk(KERN_ERR "module %s: REL relocation unsupported\n",
0060            module_name(me));
0061     return -ENOEXEC;
0062 }
0063 #endif
0064 
0065 /*
0066  * Apply the given add relocation to the (simplified) ELF.  Return
0067  * -error or 0
0068  */
0069 #ifdef CONFIG_MODULES_USE_ELF_RELA
0070 int apply_relocate_add(Elf_Shdr *sechdrs,
0071                const char *strtab,
0072                unsigned int symindex,
0073                unsigned int relsec,
0074                struct module *mod);
0075 #else
0076 static inline int apply_relocate_add(Elf_Shdr *sechdrs,
0077                      const char *strtab,
0078                      unsigned int symindex,
0079                      unsigned int relsec,
0080                      struct module *me)
0081 {
0082     printk(KERN_ERR "module %s: REL relocation unsupported\n",
0083            module_name(me));
0084     return -ENOEXEC;
0085 }
0086 #endif
0087 
0088 /* Any final processing of module before access.  Return -error or 0. */
0089 int module_finalize(const Elf_Ehdr *hdr,
0090             const Elf_Shdr *sechdrs,
0091             struct module *mod);
0092 
0093 /* Any cleanup needed when module leaves. */
0094 void module_arch_cleanup(struct module *mod);
0095 
0096 /* Any cleanup before freeing mod->module_init */
0097 void module_arch_freeing_init(struct module *mod);
0098 
0099 #if (defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS)) && \
0100         !defined(CONFIG_KASAN_VMALLOC)
0101 #include <linux/kasan.h>
0102 #define MODULE_ALIGN (PAGE_SIZE << KASAN_SHADOW_SCALE_SHIFT)
0103 #else
0104 #define MODULE_ALIGN PAGE_SIZE
0105 #endif
0106 
0107 #endif