1 #include <linux/moduleloader.h>
3 #include <linux/vmalloc.h>
5 #include <linux/string.h>
6 #include <linux/kernel.h>
11 #define DEBUGP(fmt...)
14 void *module_alloc(unsigned long size)
22 /* Free memory returned from module_alloc */
23 void module_free(struct module *mod, void *module_region)
26 /* FIXME: If module_region == mod->init_region, trim exception
30 /* We don't need anything special. */
31 int module_frob_arch_sections(Elf_Ehdr *hdr,
39 int apply_relocate(Elf32_Shdr *sechdrs,
41 unsigned int symindex,
46 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
50 DEBUGP("Applying relocate section %u to %u\n", relsec,
51 sechdrs[relsec].sh_info);
52 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
53 /* This is where to make the change */
54 location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
56 /* This is the symbol it is referring to. Note that all
57 undefined symbols have been resolved. */
58 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
59 + ELF32_R_SYM(rel[i].r_info);
61 switch (ELF32_R_TYPE(rel[i].r_info)) {
63 /* We add the value into the location given */
64 *location += sym->st_value;
67 /* Add the value, subtract its postition */
68 *location += sym->st_value - (uint32_t)location;
71 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
72 me->name, ELF32_R_TYPE(rel[i].r_info));
79 int apply_relocate_add(Elf32_Shdr *sechdrs,
81 unsigned int symindex,
86 Elf32_Rela *rel = (void *)sechdrs[relsec].sh_addr;
90 DEBUGP("Applying relocate_add section %u to %u\n", relsec,
91 sechdrs[relsec].sh_info);
92 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
93 /* This is where to make the change */
94 location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
96 /* This is the symbol it is referring to. Note that all
97 undefined symbols have been resolved. */
98 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
99 + ELF32_R_SYM(rel[i].r_info);
101 switch (ELF32_R_TYPE(rel[i].r_info)) {
103 /* We add the value into the location given */
104 *location = rel[i].r_addend + sym->st_value;
107 /* Add the value, subtract its postition */
108 *location = rel[i].r_addend + sym->st_value - (uint32_t)location;
111 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
112 me->name, ELF32_R_TYPE(rel[i].r_info));
119 int module_finalize(const Elf_Ehdr *hdr,
120 const Elf_Shdr *sechdrs,
126 void module_arch_cleanup(struct module *mod)