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)
28 /* We don't need anything special. */
29 int module_frob_arch_sections(Elf_Ehdr *hdr,
37 int apply_relocate(Elf32_Shdr *sechdrs,
39 unsigned int symindex,
43 printk(KERN_ERR "module %s: RELOCATION unsupported\n",
48 int apply_relocate_add(Elf32_Shdr *sechdrs,
50 unsigned int symindex,
55 Elf32_Rela *rela = (void *)sechdrs[relsec].sh_addr;
57 DEBUGP("Applying relocate section %u to %u\n", relsec,
58 sechdrs[relsec].sh_info);
59 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rela); i++) {
60 /* This is where to make the change */
61 uint32_t *loc = (uint32_t *)(sechdrs[sechdrs[relsec].sh_info].sh_addr
63 /* This is the symbol it is referring to. Note that all
64 undefined symbols have been resolved. */
65 Elf32_Sym *sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
66 + ELF32_R_SYM(rela[i].r_info);
67 uint32_t v = sym->st_value + rela[i].r_addend;
69 switch (ELF32_R_TYPE(rela[i].r_info)) {
71 loc = (uint32_t *)((uint32_t)loc - 1);
72 *loc = (*loc & 0xff000000) | ((*loc & 0xffffff) + v);
75 if (ELF32_R_SYM(rela[i].r_info))
83 v -= (unsigned long)loc + 2;
84 if ((Elf32_Sword)v > 0x7fff ||
85 (Elf32_Sword)v < -(Elf32_Sword)0x8000)
88 *(unsigned short *)loc = v;
91 v -= (unsigned long)loc + 1;
92 if ((Elf32_Sword)v > 0x7f ||
93 (Elf32_Sword)v < -(Elf32_Sword)0x80)
96 *(unsigned char *)loc = v;
99 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
100 me->name, ELF32_R_TYPE(rela[i].r_info));
106 printk(KERN_ERR "module %s: relocation offset overflow: %08x\n",
107 me->name, rela[i].r_offset);
111 int module_finalize(const Elf_Ehdr *hdr,
112 const Elf_Shdr *sechdrs,
115 return module_bug_finalize(hdr, sechdrs, me);
118 void module_arch_cleanup(struct module *mod)
120 module_bug_cleanup(mod);