11da177e4SLinus Torvalds #ifndef _LINUX_MODULELOADER_H 21da177e4SLinus Torvalds #define _LINUX_MODULELOADER_H 31da177e4SLinus Torvalds /* The stuff needed for archs to support modules. */ 41da177e4SLinus Torvalds 51da177e4SLinus Torvalds #include <linux/module.h> 61da177e4SLinus Torvalds #include <linux/elf.h> 71da177e4SLinus Torvalds 874e08fcfSJonas Bonn /* These may be implemented by architectures that need to hook into the 974e08fcfSJonas Bonn * module loader code. Architectures that don't need to do anything special 1074e08fcfSJonas Bonn * can just rely on the 'weak' default hooks defined in kernel/module.c. 1174e08fcfSJonas Bonn * Note, however, that at least one of apply_relocate or apply_relocate_add 1274e08fcfSJonas Bonn * must be implemented by each architecture. 1374e08fcfSJonas Bonn */ 141da177e4SLinus Torvalds 151da177e4SLinus Torvalds /* Adjust arch-specific sections. Return 0 on success. */ 161da177e4SLinus Torvalds int module_frob_arch_sections(Elf_Ehdr *hdr, 171da177e4SLinus Torvalds Elf_Shdr *sechdrs, 181da177e4SLinus Torvalds char *secstrings, 191da177e4SLinus Torvalds struct module *mod); 201da177e4SLinus Torvalds 21088af9a6SHelge Deller /* Additional bytes needed by arch in front of individual sections */ 22088af9a6SHelge Deller unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section); 23088af9a6SHelge Deller 241da177e4SLinus Torvalds /* Allocator used for allocating struct module, core sections and init 251da177e4SLinus Torvalds sections. Returns NULL on failure. */ 261da177e4SLinus Torvalds void *module_alloc(unsigned long size); 271da177e4SLinus Torvalds 281da177e4SLinus Torvalds /* Free memory returned from module_alloc. */ 291da177e4SLinus Torvalds void module_free(struct module *mod, void *module_region); 301da177e4SLinus Torvalds 31*786d35d4SDavid Howells /* 32*786d35d4SDavid Howells * Apply the given relocation to the (simplified) ELF. Return -error 33*786d35d4SDavid Howells * or 0. 34*786d35d4SDavid Howells */ 35*786d35d4SDavid Howells #ifdef CONFIG_MODULES_USE_ELF_REL 361da177e4SLinus Torvalds int apply_relocate(Elf_Shdr *sechdrs, 371da177e4SLinus Torvalds const char *strtab, 381da177e4SLinus Torvalds unsigned int symindex, 391da177e4SLinus Torvalds unsigned int relsec, 401da177e4SLinus Torvalds struct module *mod); 41*786d35d4SDavid Howells #else 42*786d35d4SDavid Howells static inline int apply_relocate(Elf_Shdr *sechdrs, 43*786d35d4SDavid Howells const char *strtab, 44*786d35d4SDavid Howells unsigned int symindex, 45*786d35d4SDavid Howells unsigned int relsec, 46*786d35d4SDavid Howells struct module *me) 47*786d35d4SDavid Howells { 48*786d35d4SDavid Howells printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name); 49*786d35d4SDavid Howells return -ENOEXEC; 50*786d35d4SDavid Howells } 51*786d35d4SDavid Howells #endif 521da177e4SLinus Torvalds 53*786d35d4SDavid Howells /* 54*786d35d4SDavid Howells * Apply the given add relocation to the (simplified) ELF. Return 55*786d35d4SDavid Howells * -error or 0 56*786d35d4SDavid Howells */ 57*786d35d4SDavid Howells #ifdef CONFIG_MODULES_USE_ELF_RELA 581da177e4SLinus Torvalds int apply_relocate_add(Elf_Shdr *sechdrs, 591da177e4SLinus Torvalds const char *strtab, 601da177e4SLinus Torvalds unsigned int symindex, 611da177e4SLinus Torvalds unsigned int relsec, 621da177e4SLinus Torvalds struct module *mod); 63*786d35d4SDavid Howells #else 64*786d35d4SDavid Howells static inline int apply_relocate_add(Elf_Shdr *sechdrs, 65*786d35d4SDavid Howells const char *strtab, 66*786d35d4SDavid Howells unsigned int symindex, 67*786d35d4SDavid Howells unsigned int relsec, 68*786d35d4SDavid Howells struct module *me) 69*786d35d4SDavid Howells { 70*786d35d4SDavid Howells printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name); 71*786d35d4SDavid Howells return -ENOEXEC; 72*786d35d4SDavid Howells } 73*786d35d4SDavid Howells #endif 741da177e4SLinus Torvalds 751da177e4SLinus Torvalds /* Any final processing of module before access. Return -error or 0. */ 761da177e4SLinus Torvalds int module_finalize(const Elf_Ehdr *hdr, 771da177e4SLinus Torvalds const Elf_Shdr *sechdrs, 781da177e4SLinus Torvalds struct module *mod); 791da177e4SLinus Torvalds 801da177e4SLinus Torvalds /* Any cleanup needed when module leaves. */ 811da177e4SLinus Torvalds void module_arch_cleanup(struct module *mod); 821da177e4SLinus Torvalds 831da177e4SLinus Torvalds #endif 84