summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_linker.c
diff options
context:
space:
mode:
authorarr <arr@FreeBSD.org>2002-03-18 07:45:30 +0000
committerarr <arr@FreeBSD.org>2002-03-18 07:45:30 +0000
commit25a6daa8288f53030d945a2021b249fe06e777bb (patch)
treec2eff913b2ef7378688b056e3fde7b549d509901 /sys/kern/kern_linker.c
parenta5aa67ad0898927e353a7f6c1a4d8b3a03bcca39 (diff)
downloadFreeBSD-src-25a6daa8288f53030d945a2021b249fe06e777bb.zip
FreeBSD-src-25a6daa8288f53030d945a2021b249fe06e777bb.tar.gz
- Lock down the ``module'' structure by adding an SX lock that is used by
all the global bits of ``module'' data. This commit adds a few generic macros, MOD_SLOCK, MOD_XLOCK, etc., that are meant to be used as ways of accessing the SX lock. It is also the first step in helping to lock down the kernel linker and module systems. Reviewed by: jhb, jake, smp@
Diffstat (limited to 'sys/kern/kern_linker.c')
-rw-r--r--sys/kern/kern_linker.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/sys/kern/kern_linker.c b/sys/kern/kern_linker.c
index 37c8605..d83e005 100644
--- a/sys/kern/kern_linker.c
+++ b/sys/kern/kern_linker.c
@@ -37,6 +37,7 @@
#include <sys/proc.h>
#include <sys/lock.h>
#include <sys/mutex.h>
+#include <sys/sx.h>
#include <sys/module.h>
#include <sys/linker.h>
#include <sys/fcntl.h>
@@ -45,7 +46,6 @@
#include <sys/vnode.h>
#include <sys/sysctl.h>
-
#include "linker_if.h"
#ifdef KLD_DEBUG
@@ -274,11 +274,6 @@ linker_file_register_modules(linker_file_t lf)
moddata = (*mdp)->md_data;
KLD_DPF(FILE, ("Registering module %s in %s\n",
moddata->name, lf->filename));
- if (module_lookupbyname(moddata->name) != NULL) {
- printf("Warning: module %s already exists\n",
- moddata->name);
- continue; /* or return a error ? */
- }
error = module_register(moddata, lf);
if (error)
printf("Module %s failed to register: %d\n",
@@ -447,8 +442,10 @@ linker_file_unload(linker_file_t file)
/*
* Inform any modules associated with this file.
*/
+ MOD_XLOCK;
for (mod = TAILQ_FIRST(&file->modules); mod; mod = next) {
next = module_getfnext(mod);
+ MOD_XUNLOCK;
/*
* Give the module a chance to veto the unload.
@@ -458,9 +455,11 @@ linker_file_unload(linker_file_t file)
" vetoes unload\n", mod));
lockmgr(&lock, LK_RELEASE, 0, curthread);
goto out;
- }
+ } else
+ MOD_XLOCK;
module_release(mod);
}
+ MOD_XUNLOCK;
}
file->refs--;
if (file->refs > 0) {
@@ -900,11 +899,13 @@ kldfirstmod(struct thread *td, struct kldfirstmod_args *uap)
mtx_lock(&Giant);
lf = linker_find_file_by_id(SCARG(uap, fileid));
if (lf) {
+ MOD_SLOCK;
mp = TAILQ_FIRST(&lf->modules);
if (mp != NULL)
td->td_retval[0] = module_getid(mp);
else
td->td_retval[0] = 0;
+ MOD_SUNLOCK;
} else
error = ENOENT;
mtx_unlock(&Giant);
OpenPOWER on IntegriCloud