[Patch 4/5] module: trim exception table in module_free()

From: Amerigo Wang
Date: Wed Jun 03 2009 - 21:47:58 EST



Just as the comment said, trim the exception table entries when
module_free() mod->module_init.

Currently, this is only done for x86. Other platforms should
also fix it like this (except sparc32).

Signed-off-by: WANG Cong <amwang@xxxxxxxxxx>
Cc: Rusty Russell <rusty@xxxxxxxxxxxxxxx>

---
Index: linux-2.6/arch/x86/kernel/module.c
===================================================================
--- linux-2.6.orig/arch/x86/kernel/module.c
+++ linux-2.6/arch/x86/kernel/module.c
@@ -27,6 +27,7 @@
#include <asm/system.h>
#include <asm/page.h>
#include <asm/pgtable.h>
+#include <asm/uaccess.h>

#if 0
#define DEBUGP printk
@@ -60,12 +61,24 @@ void *module_alloc(unsigned long size)
}
#endif

+static void trim_init_extable(struct module *m)
+{
+ /*trim the beginning*/
+ while (m->num_exentries && within_module_init(m->extable[0].insn, m)) {
+ m->extable++;
+ m->num_exentries--;
+ }
+ /*trim the end*/
+ while (m->num_exentries &&
+ within_module_init(m->extable[m->num_exentries-1].insn, m))
+ m->num_exentries--;
+}
+
/* Free memory returned from module_alloc */
void module_free(struct module *mod, void *module_region)
{
vfree(module_region);
- /* FIXME: If module_region == mod->init_region, trim exception
- table entries. */
+ trim_init_extable(mod);
}

/* We don't need anything special. */
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/