PERFORCE change 100491 for review
John Birrell
jb at FreeBSD.org
Mon Jul 3 12:23:19 UTC 2006
http://perforce.freebsd.org/chv.cgi?CH=100491
Change 100491 by jb at jb_freebsd2 on 2006/07/03 12:22:33
Update to use jhb's changes in current. Re-implement version 2
of kldstat to return the path to the module.
Affected files ...
.. //depot/projects/dtrace/src/sys/kern/kern_linker.c#12 edit
Differences ...
==== //depot/projects/dtrace/src/sys/kern/kern_linker.c#12 (text+ko) ====
@@ -40,7 +40,6 @@
#include <sys/proc.h>
#include <sys/lock.h>
#include <sys/mutex.h>
-#include <sys/sdt.h>
#include <sys/sx.h>
#include <sys/mac.h>
#include <sys/module.h>
@@ -93,12 +92,6 @@
static struct sx kld_sx; /* kernel linker lock */
-/*
- * Load counter used by clients to determine if a linker file has been
- * re-loaded. This counter is incremented for each file load.
- */
-static int loadcnt;
-
static linker_class_list_t classes;
static linker_file_list_t linker_files;
static int next_file_id = 1;
@@ -542,10 +535,8 @@
LINKER_GET_NEXT_FILE_ID(lf->id);
lf->ndeps = 0;
lf->deps = NULL;
- lf->loadcnt = ++loadcnt;
STAILQ_INIT(&lf->common);
TAILQ_INIT(&lf->modules);
- mtx_lock(&kld_mtx);
TAILQ_INSERT_TAIL(&linker_files, lf, link);
return (lf);
}
@@ -686,27 +677,6 @@
}
/*
- * List linker files.
- */
-int
-linker_file_listall(int (*callback_func)(linker_file_t,void *),void *arg)
-{
- linker_file_t lf;
- int error = 0;
-
- sx_xlock(&kld_sx);
-
- TAILQ_FOREACH(lf, &linker_files, link) {
- if ((error = callback_func(lf, arg)) != 0)
- break;
- }
-
- sx_xunlock(&kld_sx);
-
- return (error);
-}
-
-/*
* List all functions in a file.
*/
int
@@ -722,10 +692,13 @@
linker_file_t lf;
c_linker_sym_t sym;
linker_symval_t symval;
+ int locked;
symval.value = 0;
- sx_xlock(&kld_sx);
+ locked = KLD_LOCKED();
+ if (!locked)
+ KLD_LOCK();
TAILQ_FOREACH(lf, &linker_files, link) {
if (LINKER_LOOKUP_SYMBOL(lf, name, &sym) == 0 &&
@@ -733,11 +706,13 @@
break;
}
- sx_xunlock(&kld_sx);
+ if (!locked)
+ KLD_UNLOCK();
return (symval.value);
}
+
caddr_t
linker_file_lookup_symbol(linker_file_t file, const char *name, int deps)
{
@@ -994,10 +969,7 @@
printf("kldunload: attempt to unload file that has"
" DTrace probes enabled\n");
error = EBUSY;
- goto out;
- }
-
- if (lf->userrefs == 0) {
+ } else if (lf->userrefs == 0) {
/*
* XXX: maybe LINKER_UNLOAD_FORCE should override ?
*/
@@ -1129,15 +1101,18 @@
{
struct kld_file_stat stat;
linker_file_t lf;
- int error, namelen;
+ int error, namelen, version, version_num;
/*
* Check the version of the user's structure.
*/
- error = copyin(uap->stat, &stat, sizeof(struct kld_file_stat));
- if (error)
+ if ((error = copyin(&uap->stat->version, &version, sizeof(version))) != 0)
return (error);
- if (stat.version != sizeof(struct kld_file_stat))
+ if (version == sizeof(struct kld_file_stat_1))
+ version_num = 1;
+ else if (version == sizeof(struct kld_file_stat))
+ version_num = 2;
+ else
return (EINVAL);
#ifdef MAC
@@ -1162,21 +1137,18 @@
stat.id = lf->id;
stat.address = lf->address;
stat.size = lf->size;
+ if (version_num > 1) {
+ /* Version 2 fields: */
+ namelen = strlen(lf->pathname) + 1;
+ if (namelen > MAXPATHLEN)
+ namelen = MAXPATHLEN;
+ bcopy(lf->pathname, &stat.pathname[0], namelen);
+ }
KLD_UNLOCK();
- if (version_num < 2)
- goto done;
- /* Version 2 fields: */
- namelen = strlen(lf->pathname) + 1;
- if (namelen > MAXPATHLEN)
- namelen = MAXPATHLEN;
- if ((error = copyout(lf->pathname, &stat->pathname[0], namelen)) != 0)
- goto out;
-
-done:
td->td_retval[0] = 0;
- return (copyout(&stat, uap->stat, sizeof(struct kld_file_stat)));
+ return (copyout(&stat, uap->stat, version));
}
/*
@@ -1964,9 +1936,6 @@
*lfpp = lfdep;
} while (0);
free(pathname, M_LINKER);
-
- SDT_PROBE(kernel, linker_load_module, return, kldname, modname, parent, error, lfpp);
-
return (error);
}
@@ -2089,7 +2058,6 @@
return (error);
}
}
- mtx_unlock(&kld_mtx);
KLD_UNLOCK();
return (SYSCTL_OUT(req, "", 1));
}
More information about the p4-projects
mailing list