Skip to content

Commit 2d5bf28

Browse files
Amerigo Wangrustyrussell
authored andcommitted
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 <[email protected]> Cc: Ingo Molnar <[email protected]> Signed-off-by: Rusty Russell <[email protected]>
1 parent 2ead943 commit 2d5bf28

File tree

4 files changed

+99
-124
lines changed

4 files changed

+99
-124
lines changed

arch/x86/kernel/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ obj-$(CONFIG_KEXEC) += machine_kexec_$(BITS).o
7373
obj-$(CONFIG_KEXEC) += relocate_kernel_$(BITS).o crash.o
7474
obj-$(CONFIG_CRASH_DUMP) += crash_dump_$(BITS).o
7575
obj-$(CONFIG_KPROBES) += kprobes.o
76-
obj-$(CONFIG_MODULES) += module_$(BITS).o
76+
obj-$(CONFIG_MODULES) += module.o module_$(BITS).o
7777
obj-$(CONFIG_EFI) += efi.o efi_$(BITS).o efi_stub_$(BITS).o
7878
obj-$(CONFIG_DOUBLEFAULT) += doublefault_32.o
7979
obj-$(CONFIG_KGDB) += kgdb.o

arch/x86/kernel/module.c

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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 */
38+
void 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. */
46+
int module_frob_arch_sections(Elf_Ehdr *hdr,
47+
Elf_Shdr *sechdrs,
48+
char *secstrings,
49+
struct module *mod)
50+
{
51+
return 0;
52+
}
53+
54+
int 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+
94+
void module_arch_cleanup(struct module *mod)
95+
{
96+
alternatives_smp_module_del(mod);
97+
module_bug_cleanup(mod);
98+
}

arch/x86/kernel/module_32.c

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,6 @@ void *module_alloc(unsigned long size)
3737
}
3838

3939

40-
/* Free memory returned from module_alloc */
41-
void 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. */
49-
int module_frob_arch_sections(Elf_Ehdr *hdr,
50-
Elf_Shdr *sechdrs,
51-
char *secstrings,
52-
struct module *mod)
53-
{
54-
return 0;
55-
}
56-
5740
int apply_relocate(Elf32_Shdr *sechdrs,
5841
const char *strtab,
5942
unsigned int symindex,
@@ -105,48 +88,3 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
10588
return -ENOEXEC;
10689
}
10790

108-
int 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-
148-
void module_arch_cleanup(struct module *mod)
149-
{
150-
alternatives_smp_module_del(mod);
151-
module_bug_cleanup(mod);
152-
}

arch/x86/kernel/module_64.c

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,6 @@
3333
#define DEBUGP(fmt...)
3434

3535
#ifndef CONFIG_UML
36-
void 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-
4336
void *module_alloc(unsigned long size)
4437
{
4538
struct vm_struct *area;
@@ -58,15 +51,6 @@ void *module_alloc(unsigned long size)
5851
}
5952
#endif
6053

61-
/* We don't need anything special. */
62-
int module_frob_arch_sections(Elf_Ehdr *hdr,
63-
Elf_Shdr *sechdrs,
64-
char *secstrings,
65-
struct module *mod)
66-
{
67-
return 0;
68-
}
69-
7054
int apply_relocate_add(Elf64_Shdr *sechdrs,
7155
const char *strtab,
7256
unsigned int symindex,
@@ -147,48 +131,3 @@ int apply_relocate(Elf_Shdr *sechdrs,
147131
return -ENOSYS;
148132
}
149133

150-
int 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-
190-
void module_arch_cleanup(struct module *mod)
191-
{
192-
alternatives_smp_module_del(mod);
193-
module_bug_cleanup(mod);
194-
}

0 commit comments

Comments
 (0)