Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef _LINUX_MODULELOADER_H |
| 2 | #define _LINUX_MODULELOADER_H |
| 3 | /* The stuff needed for archs to support modules. */ |
| 4 | |
| 5 | #include <linux/module.h> |
| 6 | #include <linux/elf.h> |
| 7 | |
Jonas Bonn | 74e08fc | 2011-06-30 21:22:11 +0200 | [diff] [blame] | 8 | /* These may be implemented by architectures that need to hook into the |
| 9 | * module loader code. Architectures that don't need to do anything special |
| 10 | * can just rely on the 'weak' default hooks defined in kernel/module.c. |
| 11 | * Note, however, that at least one of apply_relocate or apply_relocate_add |
| 12 | * must be implemented by each architecture. |
| 13 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | |
| 15 | /* Adjust arch-specific sections. Return 0 on success. */ |
| 16 | int module_frob_arch_sections(Elf_Ehdr *hdr, |
| 17 | Elf_Shdr *sechdrs, |
| 18 | char *secstrings, |
| 19 | struct module *mod); |
| 20 | |
Helge Deller | 088af9a | 2008-12-31 12:31:18 +0100 | [diff] [blame] | 21 | /* Additional bytes needed by arch in front of individual sections */ |
| 22 | unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section); |
| 23 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | /* Allocator used for allocating struct module, core sections and init |
| 25 | sections. Returns NULL on failure. */ |
| 26 | void *module_alloc(unsigned long size); |
| 27 | |
| 28 | /* Free memory returned from module_alloc. */ |
Rusty Russell | be1f221 | 2015-01-20 09:07:05 +1030 | [diff] [blame] | 29 | void module_memfree(void *module_region); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | |
David Howells | 786d35d | 2012-09-28 14:31:03 +0930 | [diff] [blame] | 31 | /* |
| 32 | * Apply the given relocation to the (simplified) ELF. Return -error |
| 33 | * or 0. |
| 34 | */ |
| 35 | #ifdef CONFIG_MODULES_USE_ELF_REL |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | int apply_relocate(Elf_Shdr *sechdrs, |
| 37 | const char *strtab, |
| 38 | unsigned int symindex, |
| 39 | unsigned int relsec, |
| 40 | struct module *mod); |
David Howells | 786d35d | 2012-09-28 14:31:03 +0930 | [diff] [blame] | 41 | #else |
| 42 | static inline int apply_relocate(Elf_Shdr *sechdrs, |
| 43 | const char *strtab, |
| 44 | unsigned int symindex, |
| 45 | unsigned int relsec, |
| 46 | struct module *me) |
| 47 | { |
Rusty Russell | 3a611c3 | 2014-07-27 07:23:01 +0930 | [diff] [blame] | 48 | printk(KERN_ERR "module %s: REL relocation unsupported\n", |
| 49 | module_name(me)); |
David Howells | 786d35d | 2012-09-28 14:31:03 +0930 | [diff] [blame] | 50 | return -ENOEXEC; |
| 51 | } |
| 52 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
David Howells | 786d35d | 2012-09-28 14:31:03 +0930 | [diff] [blame] | 54 | /* |
| 55 | * Apply the given add relocation to the (simplified) ELF. Return |
| 56 | * -error or 0 |
| 57 | */ |
| 58 | #ifdef CONFIG_MODULES_USE_ELF_RELA |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | int apply_relocate_add(Elf_Shdr *sechdrs, |
| 60 | const char *strtab, |
| 61 | unsigned int symindex, |
| 62 | unsigned int relsec, |
| 63 | struct module *mod); |
David Howells | 786d35d | 2012-09-28 14:31:03 +0930 | [diff] [blame] | 64 | #else |
| 65 | static inline int apply_relocate_add(Elf_Shdr *sechdrs, |
| 66 | const char *strtab, |
| 67 | unsigned int symindex, |
| 68 | unsigned int relsec, |
| 69 | struct module *me) |
| 70 | { |
Rusty Russell | 3a611c3 | 2014-07-27 07:23:01 +0930 | [diff] [blame] | 71 | printk(KERN_ERR "module %s: REL relocation unsupported\n", |
| 72 | module_name(me)); |
David Howells | 786d35d | 2012-09-28 14:31:03 +0930 | [diff] [blame] | 73 | return -ENOEXEC; |
| 74 | } |
| 75 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | |
| 77 | /* Any final processing of module before access. Return -error or 0. */ |
| 78 | int module_finalize(const Elf_Ehdr *hdr, |
| 79 | const Elf_Shdr *sechdrs, |
| 80 | struct module *mod); |
| 81 | |
| 82 | /* Any cleanup needed when module leaves. */ |
| 83 | void module_arch_cleanup(struct module *mod); |
| 84 | |
Rusty Russell | d453cde | 2015-01-20 09:07:04 +1030 | [diff] [blame] | 85 | /* Any cleanup before freeing mod->module_init */ |
| 86 | void module_arch_freeing_init(struct module *mod); |
Andrey Ryabinin | d3733e5 | 2015-03-12 16:26:14 -0700 | [diff] [blame] | 87 | |
| 88 | #ifdef CONFIG_KASAN |
| 89 | #include <linux/kasan.h> |
| 90 | #define MODULE_ALIGN (PAGE_SIZE << KASAN_SHADOW_SCALE_SHIFT) |
| 91 | #else |
| 92 | #define MODULE_ALIGN PAGE_SIZE |
| 93 | #endif |
| 94 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | #endif |