1 /* Kernel module help for x86.
2 Copyright (C) 2001 Rusty Russell.
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.
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.
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
18 #include <linux/moduleloader.h>
19 #include <linux/elf.h>
20 #include <linux/vmalloc.h>
22 #include <linux/string.h>
23 #include <linux/kernel.h>
24 #include <linux/bug.h>
27 #include <asm/system.h>
29 #include <asm/pgtable.h>
34 #define DEBUGP(fmt...)
37 /* Free memory returned from module_alloc */
38 void module_free(struct module *mod, void *module_region)
41 /* FIXME: If module_region == mod->init_region, trim exception
45 /* We don't need anything special. */
46 int module_frob_arch_sections(Elf_Ehdr *hdr,
54 int module_finalize(const Elf_Ehdr *hdr,
55 const Elf_Shdr *sechdrs,
58 const Elf_Shdr *s, *text = NULL, *alt = NULL, *locks = NULL,
60 char *secstrings = (void *)hdr + sechdrs[hdr->e_shstrndx].sh_offset;
62 for (s = sechdrs; s < sechdrs + hdr->e_shnum; s++) {
63 if (!strcmp(".text", secstrings + s->sh_name))
65 if (!strcmp(".altinstructions", secstrings + s->sh_name))
67 if (!strcmp(".smp_locks", secstrings + s->sh_name))
69 if (!strcmp(".parainstructions", secstrings + s->sh_name))
74 /* patch .altinstructions */
75 void *aseg = (void *)alt->sh_addr;
76 apply_alternatives(aseg, aseg + alt->sh_size);
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);
87 void *pseg = (void *)para->sh_addr;
88 apply_paravirt(pseg, pseg + para->sh_size);
91 return module_bug_finalize(hdr, sechdrs, me);
94 void module_arch_cleanup(struct module *mod)
96 alternatives_smp_module_del(mod);
97 module_bug_cleanup(mod);