Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Jonas Bonn | 74e08fc | 2011-06-30 21:22:11 +0200 | [diff] [blame] | 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 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | |
| 16 | /* Adjust arch-specific sections. Return 0 on success. */ |
| 17 | int module_frob_arch_sections(Elf_Ehdr *hdr, |
| 18 | Elf_Shdr *sechdrs, |
| 19 | char *secstrings, |
| 20 | struct module *mod); |
| 21 | |
Helge Deller | 088af9a | 2008-12-31 12:31:18 +0100 | [diff] [blame] | 22 | /* Additional bytes needed by arch in front of individual sections */ |
| 23 | unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section); |
| 24 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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. */ |
Rusty Russell | be1f221 | 2015-01-20 09:07:05 +1030 | [diff] [blame] | 30 | void module_memfree(void *module_region); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
Matthias Schiffer | 38b37d6 | 2019-06-07 12:49:11 +0200 | [diff] [blame] | 32 | /* Determines if the section name is an exit section (that is only used during |
| 33 | * module unloading) |
| 34 | */ |
| 35 | bool module_exit_section(const char *name); |
| 36 | |
David Howells | 786d35d | 2012-09-28 14:31:03 +0930 | [diff] [blame] | 37 | /* |
| 38 | * Apply the given relocation to the (simplified) ELF. Return -error |
| 39 | * or 0. |
| 40 | */ |
| 41 | #ifdef CONFIG_MODULES_USE_ELF_REL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | int apply_relocate(Elf_Shdr *sechdrs, |
| 43 | const char *strtab, |
| 44 | unsigned int symindex, |
| 45 | unsigned int relsec, |
| 46 | struct module *mod); |
David Howells | 786d35d | 2012-09-28 14:31:03 +0930 | [diff] [blame] | 47 | #else |
| 48 | static inline int apply_relocate(Elf_Shdr *sechdrs, |
| 49 | const char *strtab, |
| 50 | unsigned int symindex, |
| 51 | unsigned int relsec, |
| 52 | struct module *me) |
| 53 | { |
Rusty Russell | 3a611c3 | 2014-07-27 07:23:01 +0930 | [diff] [blame] | 54 | printk(KERN_ERR "module %s: REL relocation unsupported\n", |
| 55 | module_name(me)); |
David Howells | 786d35d | 2012-09-28 14:31:03 +0930 | [diff] [blame] | 56 | return -ENOEXEC; |
| 57 | } |
| 58 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
David Howells | 786d35d | 2012-09-28 14:31:03 +0930 | [diff] [blame] | 60 | /* |
| 61 | * Apply the given add relocation to the (simplified) ELF. Return |
| 62 | * -error or 0 |
| 63 | */ |
| 64 | #ifdef CONFIG_MODULES_USE_ELF_RELA |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | int apply_relocate_add(Elf_Shdr *sechdrs, |
| 66 | const char *strtab, |
| 67 | unsigned int symindex, |
| 68 | unsigned int relsec, |
| 69 | struct module *mod); |
David Howells | 786d35d | 2012-09-28 14:31:03 +0930 | [diff] [blame] | 70 | #else |
| 71 | static inline int apply_relocate_add(Elf_Shdr *sechdrs, |
| 72 | const char *strtab, |
| 73 | unsigned int symindex, |
| 74 | unsigned int relsec, |
| 75 | struct module *me) |
| 76 | { |
Rusty Russell | 3a611c3 | 2014-07-27 07:23:01 +0930 | [diff] [blame] | 77 | printk(KERN_ERR "module %s: REL relocation unsupported\n", |
| 78 | module_name(me)); |
David Howells | 786d35d | 2012-09-28 14:31:03 +0930 | [diff] [blame] | 79 | return -ENOEXEC; |
| 80 | } |
| 81 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | |
| 83 | /* Any final processing of module before access. Return -error or 0. */ |
| 84 | int module_finalize(const Elf_Ehdr *hdr, |
| 85 | const Elf_Shdr *sechdrs, |
| 86 | struct module *mod); |
| 87 | |
| 88 | /* Any cleanup needed when module leaves. */ |
| 89 | void module_arch_cleanup(struct module *mod); |
| 90 | |
Rusty Russell | d453cde | 2015-01-20 09:07:04 +1030 | [diff] [blame] | 91 | /* Any cleanup before freeing mod->module_init */ |
| 92 | void module_arch_freeing_init(struct module *mod); |
Andrey Ryabinin | d3733e5 | 2015-03-12 16:26:14 -0700 | [diff] [blame] | 93 | |
Daniel Axtens | 3c5c3cf | 2019-11-30 17:54:50 -0800 | [diff] [blame] | 94 | #if defined(CONFIG_KASAN) && !defined(CONFIG_KASAN_VMALLOC) |
Andrey Ryabinin | d3733e5 | 2015-03-12 16:26:14 -0700 | [diff] [blame] | 95 | #include <linux/kasan.h> |
| 96 | #define MODULE_ALIGN (PAGE_SIZE << KASAN_SHADOW_SCALE_SHIFT) |
| 97 | #else |
| 98 | #define MODULE_ALIGN PAGE_SIZE |
| 99 | #endif |
| 100 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | #endif |