diff options
author | Amerigo Wang <amwang@redhat.com> | 2009-06-03 21:46:19 -0400 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2009-06-12 08:17:01 -0400 |
commit | 0fdc83b950df9e2eb45db6fca9c3d92c66fd5028 (patch) | |
tree | 5ee9b81828c90a9aa8072cd68d7e0a5edbbc4032 /arch | |
parent | 2d5bf28fb9e3c178db4f5536e2fe38d3a5ed7f40 (diff) |
x86 module: merge the rest functions with macros
Merge the rest functions together, with proper preprocessing directives.
Finally remove module_{32|64}.c.
Signed-off-by: WANG Cong <amwang@redhat.com>
Cc: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'arch')
-rw-r--r-- | arch/x86/kernel/Makefile | 2 | ||||
-rw-r--r-- | arch/x86/kernel/module.c | 160 | ||||
-rw-r--r-- | arch/x86/kernel/module_32.c | 90 | ||||
-rw-r--r-- | arch/x86/kernel/module_64.c | 133 |
4 files changed, 161 insertions, 224 deletions
diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile index 1cd55c769cd0..f3477bb84566 100644 --- a/arch/x86/kernel/Makefile +++ b/arch/x86/kernel/Makefile | |||
@@ -73,7 +73,7 @@ obj-$(CONFIG_KEXEC) += machine_kexec_$(BITS).o | |||
73 | obj-$(CONFIG_KEXEC) += relocate_kernel_$(BITS).o crash.o | 73 | obj-$(CONFIG_KEXEC) += relocate_kernel_$(BITS).o crash.o |
74 | obj-$(CONFIG_CRASH_DUMP) += crash_dump_$(BITS).o | 74 | obj-$(CONFIG_CRASH_DUMP) += crash_dump_$(BITS).o |
75 | obj-$(CONFIG_KPROBES) += kprobes.o | 75 | obj-$(CONFIG_KPROBES) += kprobes.o |
76 | obj-$(CONFIG_MODULES) += module.o module_$(BITS).o | 76 | obj-$(CONFIG_MODULES) += module.o |
77 | obj-$(CONFIG_EFI) += efi.o efi_$(BITS).o efi_stub_$(BITS).o | 77 | obj-$(CONFIG_EFI) += efi.o efi_$(BITS).o efi_stub_$(BITS).o |
78 | obj-$(CONFIG_DOUBLEFAULT) += doublefault_32.o | 78 | obj-$(CONFIG_DOUBLEFAULT) += doublefault_32.o |
79 | obj-$(CONFIG_KGDB) += kgdb.o | 79 | obj-$(CONFIG_KGDB) += kgdb.o |
diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c index 1ea42d083494..b92fbcf48609 100644 --- a/arch/x86/kernel/module.c +++ b/arch/x86/kernel/module.c | |||
@@ -34,6 +34,32 @@ | |||
34 | #define DEBUGP(fmt...) | 34 | #define DEBUGP(fmt...) |
35 | #endif | 35 | #endif |
36 | 36 | ||
37 | #if defined(CONFIG_UML) || defined(CONFIG_X86_32) | ||
38 | void *module_alloc(unsigned long size) | ||
39 | { | ||
40 | if (size == 0) | ||
41 | return NULL; | ||
42 | return vmalloc_exec(size); | ||
43 | } | ||
44 | #else /*X86_64*/ | ||
45 | void *module_alloc(unsigned long size) | ||
46 | { | ||
47 | struct vm_struct *area; | ||
48 | |||
49 | if (!size) | ||
50 | return NULL; | ||
51 | size = PAGE_ALIGN(size); | ||
52 | if (size > MODULES_LEN) | ||
53 | return NULL; | ||
54 | |||
55 | area = __get_vm_area(size, VM_ALLOC, MODULES_VADDR, MODULES_END); | ||
56 | if (!area) | ||
57 | return NULL; | ||
58 | |||
59 | return __vmalloc_area(area, GFP_KERNEL, PAGE_KERNEL_EXEC); | ||
60 | } | ||
61 | #endif | ||
62 | |||
37 | /* Free memory returned from module_alloc */ | 63 | /* Free memory returned from module_alloc */ |
38 | void module_free(struct module *mod, void *module_region) | 64 | void module_free(struct module *mod, void *module_region) |
39 | { | 65 | { |
@@ -51,6 +77,140 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, | |||
51 | return 0; | 77 | return 0; |
52 | } | 78 | } |
53 | 79 | ||
80 | #ifdef CONFIG_X86_32 | ||
81 | int apply_relocate(Elf32_Shdr *sechdrs, | ||
82 | const char *strtab, | ||
83 | unsigned int symindex, | ||
84 | unsigned int relsec, | ||
85 | struct module *me) | ||
86 | { | ||
87 | unsigned int i; | ||
88 | Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr; | ||
89 | Elf32_Sym *sym; | ||
90 | uint32_t *location; | ||
91 | |||
92 | DEBUGP("Applying relocate section %u to %u\n", relsec, | ||
93 | sechdrs[relsec].sh_info); | ||
94 | for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) { | ||
95 | /* This is where to make the change */ | ||
96 | location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr | ||
97 | + rel[i].r_offset; | ||
98 | /* This is the symbol it is referring to. Note that all | ||
99 | undefined symbols have been resolved. */ | ||
100 | sym = (Elf32_Sym *)sechdrs[symindex].sh_addr | ||
101 | + ELF32_R_SYM(rel[i].r_info); | ||
102 | |||
103 | switch (ELF32_R_TYPE(rel[i].r_info)) { | ||
104 | case R_386_32: | ||
105 | /* We add the value into the location given */ | ||
106 | *location += sym->st_value; | ||
107 | break; | ||
108 | case R_386_PC32: | ||
109 | /* Add the value, subtract its postition */ | ||
110 | *location += sym->st_value - (uint32_t)location; | ||
111 | break; | ||
112 | default: | ||
113 | printk(KERN_ERR "module %s: Unknown relocation: %u\n", | ||
114 | me->name, ELF32_R_TYPE(rel[i].r_info)); | ||
115 | return -ENOEXEC; | ||
116 | } | ||
117 | } | ||
118 | return 0; | ||
119 | } | ||
120 | |||
121 | int apply_relocate_add(Elf32_Shdr *sechdrs, | ||
122 | const char *strtab, | ||
123 | unsigned int symindex, | ||
124 | unsigned int relsec, | ||
125 | struct module *me) | ||
126 | { | ||
127 | printk(KERN_ERR "module %s: ADD RELOCATION unsupported\n", | ||
128 | me->name); | ||
129 | return -ENOEXEC; | ||
130 | } | ||
131 | #else /*X86_64*/ | ||
132 | int apply_relocate_add(Elf64_Shdr *sechdrs, | ||
133 | const char *strtab, | ||
134 | unsigned int symindex, | ||
135 | unsigned int relsec, | ||
136 | struct module *me) | ||
137 | { | ||
138 | unsigned int i; | ||
139 | Elf64_Rela *rel = (void *)sechdrs[relsec].sh_addr; | ||
140 | Elf64_Sym *sym; | ||
141 | void *loc; | ||
142 | u64 val; | ||
143 | |||
144 | DEBUGP("Applying relocate section %u to %u\n", relsec, | ||
145 | sechdrs[relsec].sh_info); | ||
146 | for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) { | ||
147 | /* This is where to make the change */ | ||
148 | loc = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr | ||
149 | + rel[i].r_offset; | ||
150 | |||
151 | /* This is the symbol it is referring to. Note that all | ||
152 | undefined symbols have been resolved. */ | ||
153 | sym = (Elf64_Sym *)sechdrs[symindex].sh_addr | ||
154 | + ELF64_R_SYM(rel[i].r_info); | ||
155 | |||
156 | DEBUGP("type %d st_value %Lx r_addend %Lx loc %Lx\n", | ||
157 | (int)ELF64_R_TYPE(rel[i].r_info), | ||
158 | sym->st_value, rel[i].r_addend, (u64)loc); | ||
159 | |||
160 | val = sym->st_value + rel[i].r_addend; | ||
161 | |||
162 | switch (ELF64_R_TYPE(rel[i].r_info)) { | ||
163 | case R_X86_64_NONE: | ||
164 | break; | ||
165 | case R_X86_64_64: | ||
166 | *(u64 *)loc = val; | ||
167 | break; | ||
168 | case R_X86_64_32: | ||
169 | *(u32 *)loc = val; | ||
170 | if (val != *(u32 *)loc) | ||
171 | goto overflow; | ||
172 | break; | ||
173 | case R_X86_64_32S: | ||
174 | *(s32 *)loc = val; | ||
175 | if ((s64)val != *(s32 *)loc) | ||
176 | goto overflow; | ||
177 | break; | ||
178 | case R_X86_64_PC32: | ||
179 | val -= (u64)loc; | ||
180 | *(u32 *)loc = val; | ||
181 | #if 0 | ||
182 | if ((s64)val != *(s32 *)loc) | ||
183 | goto overflow; | ||
184 | #endif | ||
185 | break; | ||
186 | default: | ||
187 | printk(KERN_ERR "module %s: Unknown rela relocation: %llu\n", | ||
188 | me->name, ELF64_R_TYPE(rel[i].r_info)); | ||
189 | return -ENOEXEC; | ||
190 | } | ||
191 | } | ||
192 | return 0; | ||
193 | |||
194 | overflow: | ||
195 | printk(KERN_ERR "overflow in relocation type %d val %Lx\n", | ||
196 | (int)ELF64_R_TYPE(rel[i].r_info), val); | ||
197 | printk(KERN_ERR "`%s' likely not compiled with -mcmodel=kernel\n", | ||
198 | me->name); | ||
199 | return -ENOEXEC; | ||
200 | } | ||
201 | |||
202 | int apply_relocate(Elf_Shdr *sechdrs, | ||
203 | const char *strtab, | ||
204 | unsigned int symindex, | ||
205 | unsigned int relsec, | ||
206 | struct module *me) | ||
207 | { | ||
208 | printk(KERN_ERR "non add relocation not supported\n"); | ||
209 | return -ENOSYS; | ||
210 | } | ||
211 | |||
212 | #endif | ||
213 | |||
54 | int module_finalize(const Elf_Ehdr *hdr, | 214 | int module_finalize(const Elf_Ehdr *hdr, |
55 | const Elf_Shdr *sechdrs, | 215 | const Elf_Shdr *sechdrs, |
56 | struct module *me) | 216 | struct module *me) |
diff --git a/arch/x86/kernel/module_32.c b/arch/x86/kernel/module_32.c deleted file mode 100644 index 6145e68feb04..000000000000 --- a/arch/x86/kernel/module_32.c +++ /dev/null | |||
@@ -1,90 +0,0 @@ | |||
1 | /* Kernel module help for i386. | ||
2 | Copyright (C) 2001 Rusty Russell. | ||
3 | |||
4 | This program is free software; you can redistribute it and/or modify | ||
5 | it under the terms of the GNU General Public License as published by | ||
6 | the Free Software Foundation; either version 2 of the License, or | ||
7 | (at your option) any later version. | ||
8 | |||
9 | This program is distributed in the hope that it will be useful, | ||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | GNU General Public License for more details. | ||
13 | |||
14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program; if not, write to the Free Software | ||
16 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
17 | */ | ||
18 | #include <linux/moduleloader.h> | ||
19 | #include <linux/elf.h> | ||
20 | #include <linux/vmalloc.h> | ||
21 | #include <linux/fs.h> | ||
22 | #include <linux/string.h> | ||
23 | #include <linux/kernel.h> | ||
24 | #include <linux/bug.h> | ||
25 | |||
26 | #if 0 | ||
27 | #define DEBUGP printk | ||
28 | #else | ||
29 | #define DEBUGP(fmt...) | ||
30 | #endif | ||
31 | |||
32 | void *module_alloc(unsigned long size) | ||
33 | { | ||
34 | if (size == 0) | ||
35 | return NULL; | ||
36 | return vmalloc_exec(size); | ||
37 | } | ||
38 | |||
39 | |||
40 | int apply_relocate(Elf32_Shdr *sechdrs, | ||
41 | const char *strtab, | ||
42 | unsigned int symindex, | ||
43 | unsigned int relsec, | ||
44 | struct module *me) | ||
45 | { | ||
46 | unsigned int i; | ||
47 | Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr; | ||
48 | Elf32_Sym *sym; | ||
49 | uint32_t *location; | ||
50 | |||
51 | DEBUGP("Applying relocate section %u to %u\n", relsec, | ||
52 | sechdrs[relsec].sh_info); | ||
53 | for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) { | ||
54 | /* This is where to make the change */ | ||
55 | location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr | ||
56 | + rel[i].r_offset; | ||
57 | /* This is the symbol it is referring to. Note that all | ||
58 | undefined symbols have been resolved. */ | ||
59 | sym = (Elf32_Sym *)sechdrs[symindex].sh_addr | ||
60 | + ELF32_R_SYM(rel[i].r_info); | ||
61 | |||
62 | switch (ELF32_R_TYPE(rel[i].r_info)) { | ||
63 | case R_386_32: | ||
64 | /* We add the value into the location given */ | ||
65 | *location += sym->st_value; | ||
66 | break; | ||
67 | case R_386_PC32: | ||
68 | /* Add the value, subtract its postition */ | ||
69 | *location += sym->st_value - (uint32_t)location; | ||
70 | break; | ||
71 | default: | ||
72 | printk(KERN_ERR "module %s: Unknown relocation: %u\n", | ||
73 | me->name, ELF32_R_TYPE(rel[i].r_info)); | ||
74 | return -ENOEXEC; | ||
75 | } | ||
76 | } | ||
77 | return 0; | ||
78 | } | ||
79 | |||
80 | int apply_relocate_add(Elf32_Shdr *sechdrs, | ||
81 | const char *strtab, | ||
82 | unsigned int symindex, | ||
83 | unsigned int relsec, | ||
84 | struct module *me) | ||
85 | { | ||
86 | printk(KERN_ERR "module %s: ADD RELOCATION unsupported\n", | ||
87 | me->name); | ||
88 | return -ENOEXEC; | ||
89 | } | ||
90 | |||
diff --git a/arch/x86/kernel/module_64.c b/arch/x86/kernel/module_64.c deleted file mode 100644 index 68ec7d87bb47..000000000000 --- a/arch/x86/kernel/module_64.c +++ /dev/null | |||
@@ -1,133 +0,0 @@ | |||
1 | /* Kernel module help for x86-64 | ||
2 | Copyright (C) 2001 Rusty Russell. | ||
3 | Copyright (C) 2002,2003 Andi Kleen, SuSE Labs. | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2 of the License, or | ||
8 | (at your option) any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with this program; if not, write to the Free Software | ||
17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | */ | ||
19 | #include <linux/moduleloader.h> | ||
20 | #include <linux/elf.h> | ||
21 | #include <linux/vmalloc.h> | ||
22 | #include <linux/fs.h> | ||
23 | #include <linux/string.h> | ||
24 | #include <linux/kernel.h> | ||
25 | #include <linux/mm.h> | ||
26 | #include <linux/slab.h> | ||
27 | #include <linux/bug.h> | ||
28 | |||
29 | #include <asm/system.h> | ||
30 | #include <asm/page.h> | ||
31 | #include <asm/pgtable.h> | ||
32 | |||
33 | #define DEBUGP(fmt...) | ||
34 | |||
35 | #ifndef CONFIG_UML | ||
36 | void *module_alloc(unsigned long size) | ||
37 | { | ||
38 | struct vm_struct *area; | ||
39 | |||
40 | if (!size) | ||
41 | return NULL; | ||
42 | size = PAGE_ALIGN(size); | ||
43 | if (size > MODULES_LEN) | ||
44 | return NULL; | ||
45 | |||
46 | area = __get_vm_area(size, VM_ALLOC, MODULES_VADDR, MODULES_END); | ||
47 | if (!area) | ||
48 | return NULL; | ||
49 | |||
50 | return __vmalloc_area(area, GFP_KERNEL, PAGE_KERNEL_EXEC); | ||
51 | } | ||
52 | #endif | ||
53 | |||
54 | int apply_relocate_add(Elf64_Shdr *sechdrs, | ||
55 | const char *strtab, | ||
56 | unsigned int symindex, | ||
57 | unsigned int relsec, | ||
58 | struct module *me) | ||
59 | { | ||
60 | unsigned int i; | ||
61 | Elf64_Rela *rel = (void *)sechdrs[relsec].sh_addr; | ||
62 | Elf64_Sym *sym; | ||
63 | void *loc; | ||
64 | u64 val; | ||
65 | |||
66 | DEBUGP("Applying relocate section %u to %u\n", relsec, | ||
67 | sechdrs[relsec].sh_info); | ||
68 | for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) { | ||
69 | /* This is where to make the change */ | ||
70 | loc = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr | ||
71 | + rel[i].r_offset; | ||
72 | |||
73 | /* This is the symbol it is referring to. Note that all | ||
74 | undefined symbols have been resolved. */ | ||
75 | sym = (Elf64_Sym *)sechdrs[symindex].sh_addr | ||
76 | + ELF64_R_SYM(rel[i].r_info); | ||
77 | |||
78 | DEBUGP("type %d st_value %Lx r_addend %Lx loc %Lx\n", | ||
79 | (int)ELF64_R_TYPE(rel[i].r_info), | ||
80 | sym->st_value, rel[i].r_addend, (u64)loc); | ||
81 | |||
82 | val = sym->st_value + rel[i].r_addend; | ||
83 | |||
84 | switch (ELF64_R_TYPE(rel[i].r_info)) { | ||
85 | case R_X86_64_NONE: | ||
86 | break; | ||
87 | case R_X86_64_64: | ||
88 | *(u64 *)loc = val; | ||
89 | break; | ||
90 | case R_X86_64_32: | ||
91 | *(u32 *)loc = val; | ||
92 | if (val != *(u32 *)loc) | ||
93 | goto overflow; | ||
94 | break; | ||
95 | case R_X86_64_32S: | ||
96 | *(s32 *)loc = val; | ||
97 | if ((s64)val != *(s32 *)loc) | ||
98 | goto overflow; | ||
99 | break; | ||
100 | case R_X86_64_PC32: | ||
101 | val -= (u64)loc; | ||
102 | *(u32 *)loc = val; | ||
103 | #if 0 | ||
104 | if ((s64)val != *(s32 *)loc) | ||
105 | goto overflow; | ||
106 | #endif | ||
107 | break; | ||
108 | default: | ||
109 | printk(KERN_ERR "module %s: Unknown rela relocation: %llu\n", | ||
110 | me->name, ELF64_R_TYPE(rel[i].r_info)); | ||
111 | return -ENOEXEC; | ||
112 | } | ||
113 | } | ||
114 | return 0; | ||
115 | |||
116 | overflow: | ||
117 | printk(KERN_ERR "overflow in relocation type %d val %Lx\n", | ||
118 | (int)ELF64_R_TYPE(rel[i].r_info), val); | ||
119 | printk(KERN_ERR "`%s' likely not compiled with -mcmodel=kernel\n", | ||
120 | me->name); | ||
121 | return -ENOEXEC; | ||
122 | } | ||
123 | |||
124 | int apply_relocate(Elf_Shdr *sechdrs, | ||
125 | const char *strtab, | ||
126 | unsigned int symindex, | ||
127 | unsigned int relsec, | ||
128 | struct module *me) | ||
129 | { | ||
130 | printk(KERN_ERR "non add relocation not supported\n"); | ||
131 | return -ENOSYS; | ||
132 | } | ||
133 | |||