aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
Diffstat (limited to 'arch')
-rw-r--r--arch/x86/kernel/Makefile2
-rw-r--r--arch/x86/kernel/module.c98
-rw-r--r--arch/x86/kernel/module_32.c62
-rw-r--r--arch/x86/kernel/module_64.c61
4 files changed, 99 insertions, 124 deletions
diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
index 4f78bd682125..1cd55c769cd0 100644
--- a/arch/x86/kernel/Makefile
+++ b/arch/x86/kernel/Makefile
@@ -73,7 +73,7 @@ obj-$(CONFIG_KEXEC) += machine_kexec_$(BITS).o
73obj-$(CONFIG_KEXEC) += relocate_kernel_$(BITS).o crash.o 73obj-$(CONFIG_KEXEC) += relocate_kernel_$(BITS).o crash.o
74obj-$(CONFIG_CRASH_DUMP) += crash_dump_$(BITS).o 74obj-$(CONFIG_CRASH_DUMP) += crash_dump_$(BITS).o
75obj-$(CONFIG_KPROBES) += kprobes.o 75obj-$(CONFIG_KPROBES) += kprobes.o
76obj-$(CONFIG_MODULES) += module_$(BITS).o 76obj-$(CONFIG_MODULES) += module.o module_$(BITS).o
77obj-$(CONFIG_EFI) += efi.o efi_$(BITS).o efi_stub_$(BITS).o 77obj-$(CONFIG_EFI) += efi.o efi_$(BITS).o efi_stub_$(BITS).o
78obj-$(CONFIG_DOUBLEFAULT) += doublefault_32.o 78obj-$(CONFIG_DOUBLEFAULT) += doublefault_32.o
79obj-$(CONFIG_KGDB) += kgdb.o 79obj-$(CONFIG_KGDB) += kgdb.o
diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
new file mode 100644
index 000000000000..1ea42d083494
--- /dev/null
+++ b/arch/x86/kernel/module.c
@@ -0,0 +1,98 @@
1/* Kernel module help for x86.
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#include <linux/mm.h>
26
27#include <asm/system.h>
28#include <asm/page.h>
29#include <asm/pgtable.h>
30
31#if 0
32#define DEBUGP printk
33#else
34#define DEBUGP(fmt...)
35#endif
36
37/* Free memory returned from module_alloc */
38void module_free(struct module *mod, void *module_region)
39{
40 vfree(module_region);
41 /* FIXME: If module_region == mod->init_region, trim exception
42 table entries. */
43}
44
45/* We don't need anything special. */
46int module_frob_arch_sections(Elf_Ehdr *hdr,
47 Elf_Shdr *sechdrs,
48 char *secstrings,
49 struct module *mod)
50{
51 return 0;
52}
53
54int module_finalize(const Elf_Ehdr *hdr,
55 const Elf_Shdr *sechdrs,
56 struct module *me)
57{
58 const Elf_Shdr *s, *text = NULL, *alt = NULL, *locks = NULL,
59 *para = NULL;
60 char *secstrings = (void *)hdr + sechdrs[hdr->e_shstrndx].sh_offset;
61
62 for (s = sechdrs; s < sechdrs + hdr->e_shnum; s++) {
63 if (!strcmp(".text", secstrings + s->sh_name))
64 text = s;
65 if (!strcmp(".altinstructions", secstrings + s->sh_name))
66 alt = s;
67 if (!strcmp(".smp_locks", secstrings + s->sh_name))
68 locks = s;
69 if (!strcmp(".parainstructions", secstrings + s->sh_name))
70 para = s;
71 }
72
73 if (alt) {
74 /* patch .altinstructions */
75 void *aseg = (void *)alt->sh_addr;
76 apply_alternatives(aseg, aseg + alt->sh_size);
77 }
78 if (locks && text) {
79 void *lseg = (void *)locks->sh_addr;
80 void *tseg = (void *)text->sh_addr;
81 alternatives_smp_module_add(me, me->name,
82 lseg, lseg + locks->sh_size,
83 tseg, tseg + text->sh_size);
84 }
85
86 if (para) {
87 void *pseg = (void *)para->sh_addr;
88 apply_paravirt(pseg, pseg + para->sh_size);
89 }
90
91 return module_bug_finalize(hdr, sechdrs, me);
92}
93
94void module_arch_cleanup(struct module *mod)
95{
96 alternatives_smp_module_del(mod);
97 module_bug_cleanup(mod);
98}
diff --git a/arch/x86/kernel/module_32.c b/arch/x86/kernel/module_32.c
index 0edd819050e7..6145e68feb04 100644
--- a/arch/x86/kernel/module_32.c
+++ b/arch/x86/kernel/module_32.c
@@ -37,23 +37,6 @@ void *module_alloc(unsigned long size)
37} 37}
38 38
39 39
40/* Free memory returned from module_alloc */
41void module_free(struct module *mod, void *module_region)
42{
43 vfree(module_region);
44 /* FIXME: If module_region == mod->init_region, trim exception
45 table entries. */
46}
47
48/* We don't need anything special. */
49int module_frob_arch_sections(Elf_Ehdr *hdr,
50 Elf_Shdr *sechdrs,
51 char *secstrings,
52 struct module *mod)
53{
54 return 0;
55}
56
57int apply_relocate(Elf32_Shdr *sechdrs, 40int apply_relocate(Elf32_Shdr *sechdrs,
58 const char *strtab, 41 const char *strtab,
59 unsigned int symindex, 42 unsigned int symindex,
@@ -105,48 +88,3 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
105 return -ENOEXEC; 88 return -ENOEXEC;
106} 89}
107 90
108int module_finalize(const Elf_Ehdr *hdr,
109 const Elf_Shdr *sechdrs,
110 struct module *me)
111{
112 const Elf_Shdr *s, *text = NULL, *alt = NULL, *locks = NULL,
113 *para = NULL;
114 char *secstrings = (void *)hdr + sechdrs[hdr->e_shstrndx].sh_offset;
115
116 for (s = sechdrs; s < sechdrs + hdr->e_shnum; s++) {
117 if (!strcmp(".text", secstrings + s->sh_name))
118 text = s;
119 if (!strcmp(".altinstructions", secstrings + s->sh_name))
120 alt = s;
121 if (!strcmp(".smp_locks", secstrings + s->sh_name))
122 locks = s;
123 if (!strcmp(".parainstructions", secstrings + s->sh_name))
124 para = s;
125 }
126
127 if (alt) {
128 /* patch .altinstructions */
129 void *aseg = (void *)alt->sh_addr;
130 apply_alternatives(aseg, aseg + alt->sh_size);
131 }
132 if (locks && text) {
133 void *lseg = (void *)locks->sh_addr;
134 void *tseg = (void *)text->sh_addr;
135 alternatives_smp_module_add(me, me->name,
136 lseg, lseg + locks->sh_size,
137 tseg, tseg + text->sh_size);
138 }
139
140 if (para) {
141 void *pseg = (void *)para->sh_addr;
142 apply_paravirt(pseg, pseg + para->sh_size);
143 }
144
145 return module_bug_finalize(hdr, sechdrs, me);
146}
147
148void module_arch_cleanup(struct module *mod)
149{
150 alternatives_smp_module_del(mod);
151 module_bug_cleanup(mod);
152}
diff --git a/arch/x86/kernel/module_64.c b/arch/x86/kernel/module_64.c
index c23880b90b5c..68ec7d87bb47 100644
--- a/arch/x86/kernel/module_64.c
+++ b/arch/x86/kernel/module_64.c
@@ -33,13 +33,6 @@
33#define DEBUGP(fmt...) 33#define DEBUGP(fmt...)
34 34
35#ifndef CONFIG_UML 35#ifndef CONFIG_UML
36void module_free(struct module *mod, void *module_region)
37{
38 vfree(module_region);
39 /* FIXME: If module_region == mod->init_region, trim exception
40 table entries. */
41}
42
43void *module_alloc(unsigned long size) 36void *module_alloc(unsigned long size)
44{ 37{
45 struct vm_struct *area; 38 struct vm_struct *area;
@@ -58,15 +51,6 @@ void *module_alloc(unsigned long size)
58} 51}
59#endif 52#endif
60 53
61/* We don't need anything special. */
62int module_frob_arch_sections(Elf_Ehdr *hdr,
63 Elf_Shdr *sechdrs,
64 char *secstrings,
65 struct module *mod)
66{
67 return 0;
68}
69
70int apply_relocate_add(Elf64_Shdr *sechdrs, 54int apply_relocate_add(Elf64_Shdr *sechdrs,
71 const char *strtab, 55 const char *strtab,
72 unsigned int symindex, 56 unsigned int symindex,
@@ -147,48 +131,3 @@ int apply_relocate(Elf_Shdr *sechdrs,
147 return -ENOSYS; 131 return -ENOSYS;
148} 132}
149 133
150int module_finalize(const Elf_Ehdr *hdr,
151 const Elf_Shdr *sechdrs,
152 struct module *me)
153{
154 const Elf_Shdr *s, *text = NULL, *alt = NULL, *locks = NULL,
155 *para = NULL;
156 char *secstrings = (void *)hdr + sechdrs[hdr->e_shstrndx].sh_offset;
157
158 for (s = sechdrs; s < sechdrs + hdr->e_shnum; s++) {
159 if (!strcmp(".text", secstrings + s->sh_name))
160 text = s;
161 if (!strcmp(".altinstructions", secstrings + s->sh_name))
162 alt = s;
163 if (!strcmp(".smp_locks", secstrings + s->sh_name))
164 locks = s;
165 if (!strcmp(".parainstructions", secstrings + s->sh_name))
166 para = s;
167 }
168
169 if (alt) {
170 /* patch .altinstructions */
171 void *aseg = (void *)alt->sh_addr;
172 apply_alternatives(aseg, aseg + alt->sh_size);
173 }
174 if (locks && text) {
175 void *lseg = (void *)locks->sh_addr;
176 void *tseg = (void *)text->sh_addr;
177 alternatives_smp_module_add(me, me->name,
178 lseg, lseg + locks->sh_size,
179 tseg, tseg + text->sh_size);
180 }
181
182 if (para) {
183 void *pseg = (void *)para->sh_addr;
184 apply_paravirt(pseg, pseg + para->sh_size);
185 }
186
187 return module_bug_finalize(hdr, sechdrs, me);
188}
189
190void module_arch_cleanup(struct module *mod)
191{
192 alternatives_smp_module_del(mod);
193 module_bug_cleanup(mod);
194}