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
,
45 printk(KERN_ERR
"module %s: RELOCATION unsupported\n",
50 int apply_relocate_add(Elf32_Shdr
*sechdrs
,
52 unsigned int symindex
,
57 Elf32_Rela
*rela
= (void *)sechdrs
[relsec
].sh_addr
;
59 DEBUGP("Applying relocate section %u to %u\n", relsec
,
60 sechdrs
[relsec
].sh_info
);
61 for (i
= 0; i
< sechdrs
[relsec
].sh_size
/ sizeof(*rela
); i
++) {
62 /* This is where to make the change */
63 uint32_t *loc
= (uint32_t *)(sechdrs
[sechdrs
[relsec
].sh_info
].sh_addr
65 /* This is the symbol it is referring to. Note that all
66 undefined symbols have been resolved. */
67 Elf32_Sym
*sym
= (Elf32_Sym
*)sechdrs
[symindex
].sh_addr
68 + ELF32_R_SYM(rela
[i
].r_info
);
69 uint32_t v
= sym
->st_value
+ rela
[i
].r_addend
;
71 switch (ELF32_R_TYPE(rela
[i
].r_info
)) {
73 loc
= (uint32_t *)((uint32_t)loc
- 1);
74 *loc
= (*loc
& 0xff000000) | ((*loc
& 0xffffff) + v
);
77 if (ELF32_R_SYM(rela
[i
].r_info
))
85 v
-= (unsigned long)loc
+ 2;
86 if ((Elf32_Sword
)v
> 0x7fff ||
87 (Elf32_Sword
)v
< -(Elf32_Sword
)0x8000)
90 *(unsigned short *)loc
= v
;
93 v
-= (unsigned long)loc
+ 1;
94 if ((Elf32_Sword
)v
> 0x7f ||
95 (Elf32_Sword
)v
< -(Elf32_Sword
)0x80)
98 *(unsigned char *)loc
= v
;
101 printk(KERN_ERR
"module %s: Unknown relocation: %u\n",
102 me
->name
, ELF32_R_TYPE(rela
[i
].r_info
));
108 printk(KERN_ERR
"module %s: relocation offset overflow: %08x\n",
109 me
->name
, rela
[i
].r_offset
);
113 int module_finalize(const Elf_Ehdr
*hdr
,
114 const Elf_Shdr
*sechdrs
,
120 void module_arch_cleanup(struct module
*mod
)