patch-2.4.0-test2 linux/kernel/module.c
Next file: linux/kernel/panic.c
Previous file: linux/kernel/ksyms.c
Back to the patch index
Back to the overall index
- Lines: 52
- Date:
Mon Jun 19 13:45:51 2000
- Orig file:
v2.4.0-test1/linux/kernel/module.c
- Orig date:
Tue Mar 14 19:10:40 2000
diff -u --recursive --new-file v2.4.0-test1/linux/kernel/module.c linux/kernel/module.c
@@ -973,7 +973,9 @@
* Gets the address for a symbol in the given module. If modname is
* NULL, it looks for the name in any registered symbol table. If the
* modname is an empty string, it looks for the symbol in kernel exported
- * symbol tables.
+ * symbol tables. Increase the usage count of the module in which the
+ * symbol was found - it's the only way we can guarantee that it's still
+ * there by the time our caller actually uses it.
*/
unsigned long
get_module_symbol(char *modname, char *symname)
@@ -982,6 +984,7 @@
struct module_symbol *sym;
int i;
+ spin_lock(&unload_lock);
for (mp = module_list; mp; mp = mp->next) {
if (((modname == NULL) || (strcmp(mp->name, modname) == 0)) &&
MOD_CAN_QUERY(mp) &&
@@ -990,12 +993,32 @@
i > 0; --i, ++sym) {
if (strcmp(sym->name, symname) == 0) {
+ __MOD_INC_USE_COUNT(mp);
+ spin_unlock(&unload_lock);
return sym->value;
}
}
}
}
+ spin_unlock(&unload_lock);
return 0;
+}
+
+/* Decrease the use count of the module containing a symbol with the
+ * address passed.
+ */
+void put_module_symbol(unsigned long addr)
+{
+ struct module *mp;
+
+ for (mp = module_list; mp; mp = mp->next) {
+ if (MOD_CAN_QUERY(mp) &&
+ addr >= (unsigned long)mp &&
+ addr < (unsigned long)mp + mp->size) {
+ __MOD_DEC_USE_COUNT(mp);
+ return;
+ }
+ }
}
#else /* CONFIG_MODULES */
FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)