From owner-p4-projects@FreeBSD.ORG Mon Jul 3 12:23:19 2006 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 8BAFC16A416; Mon, 3 Jul 2006 12:23:19 +0000 (UTC) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 49EDA16A407 for ; Mon, 3 Jul 2006 12:23:19 +0000 (UTC) (envelope-from jb@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0BF2143D45 for ; Mon, 3 Jul 2006 12:23:19 +0000 (GMT) (envelope-from jb@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.6/8.13.6) with ESMTP id k63CNIbG078308 for ; Mon, 3 Jul 2006 12:23:18 GMT (envelope-from jb@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.6/8.13.4/Submit) id k63CNI5c078305 for perforce@freebsd.org; Mon, 3 Jul 2006 12:23:18 GMT (envelope-from jb@freebsd.org) Date: Mon, 3 Jul 2006 12:23:18 GMT Message-Id: <200607031223.k63CNI5c078305@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to jb@freebsd.org using -f From: John Birrell To: Perforce Change Reviews Cc: Subject: PERFORCE change 100491 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 03 Jul 2006 12:23:19 -0000 http://perforce.freebsd.org/chv.cgi?CH=100491 Change 100491 by jb@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 #include #include -#include #include #include #include @@ -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)); }