#include <linux/string.h>
#include <linux/kernel.h>
#include <linux/slab.h>
+#include <linux/bug.h>
#include <asm/system.h>
#include <asm/page.h>
#include <asm/pgtable.h>
#define DEBUGP(fmt...)
-
-static struct vm_struct *mod_vmlist;
+#ifndef CONFIG_UML
void module_free(struct module *mod, void *module_region)
{
- struct vm_struct **prevp, *map;
- int i;
- unsigned long addr = (unsigned long)module_region;
-
- if (!addr)
- return;
- write_lock(&vmlist_lock);
- for (prevp = &mod_vmlist ; (map = *prevp) ; prevp = &map->next) {
- if ((unsigned long)map->addr == addr) {
- *prevp = map->next;
- goto found;
- }
- }
- write_unlock(&vmlist_lock);
- printk("Trying to unmap nonexistent module vm area (%lx)\n", addr);
- return;
- found:
- unmap_vm_area(map);
- write_unlock(&vmlist_lock);
- if (map->pages) {
- for (i = 0; i < map->nr_pages; i++)
- if (map->pages[i])
- __free_page(map->pages[i]);
- kfree(map->pages);
- }
- kfree(map);
+ vfree(module_region);
+ /* FIXME: If module_region == mod->init_region, trim exception
+ table entries. */
}
void *module_alloc(unsigned long size)
{
- struct vm_struct **p, *tmp, *area;
- struct page **pages;
- void *addr;
- unsigned int nr_pages, array_size, i;
+ struct vm_struct *area;
if (!size)
- return NULL;
+ return NULL;
size = PAGE_ALIGN(size);
if (size > MODULES_LEN)
return NULL;
- area = (struct vm_struct *) kmalloc(sizeof(*area), GFP_KERNEL);
+ area = __get_vm_area(size, VM_ALLOC, MODULES_VADDR, MODULES_END);
if (!area)
return NULL;
- memset(area, 0, sizeof(struct vm_struct));
-
- write_lock(&vmlist_lock);
- addr = (void *) MODULES_VADDR;
- for (p = &mod_vmlist; (tmp = *p); p = &tmp->next) {
- void *next;
- DEBUGP("vmlist %p %lu addr %p\n", tmp->addr, tmp->size, addr);
- if (size + (unsigned long) addr + PAGE_SIZE < (unsigned long) tmp->addr)
- break;
- next = (void *) (tmp->size + (unsigned long) tmp->addr);
- if (next > addr)
- addr = next;
- }
- if ((unsigned long)addr + size >= MODULES_END) {
- write_unlock(&vmlist_lock);
- kfree(area);
- return NULL;
- }
- DEBUGP("addr %p\n", addr);
-
- area->next = *p;
- *p = area;
- area->size = size + PAGE_SIZE;
- area->addr = addr;
- write_unlock(&vmlist_lock);
-
- nr_pages = size >> PAGE_SHIFT;
- array_size = (nr_pages * sizeof(struct page *));
-
- area->nr_pages = nr_pages;
- area->pages = pages = kmalloc(array_size, GFP_KERNEL);
- if (!area->pages)
- goto fail;
-
- memset(area->pages, 0, array_size);
- for (i = 0; i < nr_pages; i++) {
- area->pages[i] = alloc_page(GFP_KERNEL);
- if (area->pages[i] == NULL)
- goto fail;
- }
-
- if (map_vm_area(area, PAGE_KERNEL_EXEC, &pages))
- goto fail;
-
- memset(addr, 0, size);
- DEBUGP("module_alloc size %lu = %p\n", size, addr);
- return addr;
-
-fail:
- module_free(NULL, addr);
- return NULL;
+ return __vmalloc_area(area, GFP_KERNEL, PAGE_KERNEL_EXEC);
}
+#endif
/* We don't need anything special. */
int module_frob_arch_sections(Elf_Ehdr *hdr,
return -ENOSYS;
}
-extern void apply_alternatives(void *start, void *end);
-
int module_finalize(const Elf_Ehdr *hdr,
- const Elf_Shdr *sechdrs,
- struct module *me)
+ const Elf_Shdr *sechdrs,
+ struct module *me)
{
- const Elf_Shdr *s;
+ const Elf_Shdr *s, *text = NULL, *alt = NULL, *locks = NULL;
char *secstrings = (void *)hdr + sechdrs[hdr->e_shstrndx].sh_offset;
- /* look for .altinstructions to patch */
- for (s = sechdrs; s < sechdrs + hdr->e_shnum; s++) {
- void *seg;
- if (strcmp(".altinstructions", secstrings + s->sh_name))
- continue;
- seg = (void *)s->sh_addr;
- apply_alternatives(seg, seg + s->sh_size);
- }
- return 0;
+ for (s = sechdrs; s < sechdrs + hdr->e_shnum; s++) {
+ if (!strcmp(".text", secstrings + s->sh_name))
+ text = s;
+ if (!strcmp(".altinstructions", secstrings + s->sh_name))
+ alt = s;
+ if (!strcmp(".smp_locks", secstrings + s->sh_name))
+ locks= s;
+ }
+
+ if (alt) {
+ /* patch .altinstructions */
+ void *aseg = (void *)alt->sh_addr;
+ apply_alternatives(aseg, aseg + alt->sh_size);
+ }
+ if (locks && text) {
+ void *lseg = (void *)locks->sh_addr;
+ void *tseg = (void *)text->sh_addr;
+ alternatives_smp_module_add(me, me->name,
+ lseg, lseg + locks->sh_size,
+ tseg, tseg + text->sh_size);
+ }
+
+ return module_bug_finalize(hdr, sechdrs, me);
}
void module_arch_cleanup(struct module *mod)
{
+ alternatives_smp_module_del(mod);
+ module_bug_cleanup(mod);
}