aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kernel/module.c
diff options
context:
space:
mode:
authorAmerigo Wang <amwang@redhat.com>2009-06-03 21:46:09 -0400
committerRusty Russell <rusty@rustcorp.com.au>2009-06-12 08:17:00 -0400
commit2d5bf28fb9e3c178db4f5536e2fe38d3a5ed7f40 (patch)
tree30997ca66fea0b95f82b546ecbcd91e249223fb3 /arch/x86/kernel/module.c
parent2ead9439f0c6ed03faafe27abe8bc1dd256d117b (diff)
x86 module: merge the same functions in module_32.c and module_64.c
Merge the same functions both in module_32.c and module_64.c into module.c. This is the first step to merge both of them finally. 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/x86/kernel/module.c')
-rw-r--r--arch/x86/kernel/module.c98
1 files changed, 98 insertions, 0 deletions
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}