1 #include <linux/moduleloader.h>
3 #include <linux/vmalloc.h>
5 #include <linux/string.h>
6 #include <linux/kernel.h>
10 void *module_alloc(unsigned long size
)
18 /* Free memory returned from module_alloc */
19 void module_free(struct module
*mod
, void *module_region
)
24 /* We don't need anything special. */
25 int module_frob_arch_sections(Elf_Ehdr
*hdr
,
33 int apply_relocate(Elf32_Shdr
*sechdrs
,
35 unsigned int symindex
,
40 Elf32_Rel
*rel
= (void *)sechdrs
[relsec
].sh_addr
;
44 DEBUGP("Applying relocate section %u to %u\n", relsec
,
45 sechdrs
[relsec
].sh_info
);
46 for (i
= 0; i
< sechdrs
[relsec
].sh_size
/ sizeof(*rel
); i
++) {
47 /* This is where to make the change */
48 location
= (void *)sechdrs
[sechdrs
[relsec
].sh_info
].sh_addr
50 /* This is the symbol it is referring to. Note that all
51 undefined symbols have been resolved. */
52 sym
= (Elf32_Sym
*)sechdrs
[symindex
].sh_addr
53 + ELF32_R_SYM(rel
[i
].r_info
);
55 switch (ELF32_R_TYPE(rel
[i
].r_info
)) {
57 /* We add the value into the location given */
58 *location
+= sym
->st_value
;
61 /* Add the value, subtract its postition */
62 *location
+= sym
->st_value
- (uint32_t)location
;
65 printk(KERN_ERR
"module %s: Unknown relocation: %u\n",
66 me
->name
, ELF32_R_TYPE(rel
[i
].r_info
));
73 int apply_relocate_add(Elf32_Shdr
*sechdrs
,
75 unsigned int symindex
,
80 Elf32_Rela
*rel
= (void *)sechdrs
[relsec
].sh_addr
;
84 DEBUGP("Applying relocate_add section %u to %u\n", relsec
,
85 sechdrs
[relsec
].sh_info
);
86 for (i
= 0; i
< sechdrs
[relsec
].sh_size
/ sizeof(*rel
); i
++) {
87 /* This is where to make the change */
88 location
= (void *)sechdrs
[sechdrs
[relsec
].sh_info
].sh_addr
90 /* This is the symbol it is referring to. Note that all
91 undefined symbols have been resolved. */
92 sym
= (Elf32_Sym
*)sechdrs
[symindex
].sh_addr
93 + ELF32_R_SYM(rel
[i
].r_info
);
95 switch (ELF32_R_TYPE(rel
[i
].r_info
)) {
97 /* We add the value into the location given */
98 *location
= rel
[i
].r_addend
+ sym
->st_value
;
101 /* Add the value, subtract its postition */
102 *location
= rel
[i
].r_addend
+ sym
->st_value
- (uint32_t)location
;
105 printk(KERN_ERR
"module %s: Unknown relocation: %u\n",
106 me
->name
, ELF32_R_TYPE(rel
[i
].r_info
));
113 int module_finalize(const Elf_Ehdr
*hdr
,
114 const Elf_Shdr
*sechdrs
,
120 void module_arch_cleanup(struct module
*mod
)