From owner-p4-projects@FreeBSD.ORG Thu Mar 30 15:49:24 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 0E1EE16A4D5; Thu, 30 Mar 2006 15:49:24 +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 DF7D116A4D2 for ; Thu, 30 Mar 2006 15:49:23 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 839A443D49 for ; Thu, 30 Mar 2006 15:49:23 +0000 (GMT) (envelope-from jhb@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.1/8.13.1) with ESMTP id k2UFnNNB048205 for ; Thu, 30 Mar 2006 15:49:23 GMT (envelope-from jhb@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.1/8.13.1/Submit) id k2UFnNpl048201 for perforce@freebsd.org; Thu, 30 Mar 2006 15:49:23 GMT (envelope-from jhb@freebsd.org) Date: Thu, 30 Mar 2006 15:49:23 GMT Message-Id: <200603301549.k2UFnNpl048201@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to jhb@freebsd.org using -f From: John Baldwin To: Perforce Change Reviews Cc: Subject: PERFORCE change 94304 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: Thu, 30 Mar 2006 15:49:24 -0000 http://perforce.freebsd.org/chv.cgi?CH=94304 Change 94304 by jhb@jhb_slimer on 2006/03/30 15:48:58 Use sx_xlocked() to handle recursion in the wrapper functions and make the internal functions private to kern_linker.c. Affected files ... .. //depot/projects/smpng/sys/kern/kern_linker.c#51 edit .. //depot/projects/smpng/sys/kern/link_elf.c#37 edit .. //depot/projects/smpng/sys/kern/link_elf_obj.c#12 edit .. //depot/projects/smpng/sys/sys/linker.h#19 edit Differences ... ==== //depot/projects/smpng/sys/kern/kern_linker.c#51 (text+ko) ==== @@ -63,6 +63,7 @@ #define KLD_LOCK() do { sx_xlock(&kld_sx); mtx_lock(&Giant); } while (0) #define KLD_UNLOCK() do { mtx_unlock(&Giant); sx_xunlock(&kld_sx); } while (0) +#define KLD_LOCKED() sx_xlocked(&kld_sx) #define KLD_LOCK_ASSERT() do { if (!cold) sx_assert(&kld_sx, SX_XLOCKED); } while (0) /* @@ -113,6 +114,9 @@ static int linker_file_add_dependency(linker_file_t file, linker_file_t dep); +static caddr_t linker_file_lookup_symbol_internal(linker_file_t file, + const char* name, int deps); +static int linker_file_unload_internal(linker_file_t _file, int flags); static int linker_load_module_internal(const char *kldname, const char *modname, struct linker_file *parent, struct mod_depend *verinfo, struct linker_file **lfpp); @@ -410,19 +414,23 @@ linker_file_t *result) { modlist_t mod; - int error; + int error, locked; - KLD_LOCK(); + locked = KLD_LOCKED(); + if (!locked) + KLD_LOCK(); if ((mod = modlist_lookup2(modname, verinfo)) != NULL) { *result = mod->container; (*result)->refs++; - KLD_UNLOCK(); + if (!locked) + KLD_UNLOCK(); return (0); } error = linker_load_module_internal(NULL, modname, NULL, verinfo, result); - KLD_UNLOCK(); + if (!locked) + KLD_UNLOCK(); return (error); } @@ -488,16 +496,18 @@ int linker_file_unload(linker_file_t file, int flags) { - int error; + int error, locked; - KLD_LOCK(); + locked = KLD_LOCKED(); + if (!locked) + KLD_LOCK(); error = linker_file_unload_internal(file, flags); - KLD_UNLOCK(); + if (!locked) + KLD_UNLOCK(); return (error); } -/* Not static as it is shared with the linker backends. */ -int +static int linker_file_unload_internal(linker_file_t file, int flags) { module_t mod, next; @@ -512,7 +522,7 @@ error = mac_check_kld_unload(curthread->td_ucred); if (error) return (error); -#endif +#endif KLD_LOCK_ASSERT(); KLD_DPF(FILE, ("linker_file_unload: lf->refs=%d\n", file->refs)); @@ -624,9 +634,11 @@ linker_file_lookup_set(linker_file_t file, const char *name, void *firstp, void *lastp, int *countp) { - int error; + int error, locked; - KLD_LOCK(); + locked = KLD_LOCKED(); + if (!locked) + KLD_LOCK(); error = linker_lookup_set(file, name, firstp, lastp, countp); KLD_UNLOCK(); return (error); @@ -636,14 +648,18 @@ linker_file_lookup_symbol(linker_file_t file, const char *name, int deps) { caddr_t sym; + int locked; - KLD_LOCK(); + locked = KLD_LOCKED(); + if (!locked) + KLD_LOCK(); sym = linker_file_lookup_symbol_internal(file, name, deps); - KLD_UNLOCK(); + if (!locked) + KLD_UNLOCK(); return (sym); } -caddr_t +static caddr_t linker_file_lookup_symbol_internal(linker_file_t file, const char *name, int deps) { @@ -1766,12 +1782,14 @@ struct linker_file *parent, struct mod_depend *verinfo, struct linker_file **lfpp) { - int error; + int error, locked; - KLD_LOCK(); + if (!locked) + KLD_LOCK(); error = linker_load_module_internal(kldname, modname, parent, verinfo, lfpp); - KLD_UNLOCK(); + if (!locked) + KLD_UNLOCK(); return (error); } ==== //depot/projects/smpng/sys/kern/link_elf.c#37 (text+ko) ==== @@ -495,7 +495,7 @@ error = parse_dynamic(ef); if (error) { - linker_file_unload_internal(lf, LINKER_UNLOAD_FORCE); + linker_file_unload(lf, LINKER_UNLOAD_FORCE); return error; } link_elf_reloc_local(lf); @@ -855,7 +855,7 @@ out: if (error && lf) - linker_file_unload_internal(lf, LINKER_UNLOAD_FORCE); + linker_file_unload(lf, LINKER_UNLOAD_FORCE); if (shdr) free(shdr, M_LINKER); if (firstpage) @@ -1301,8 +1301,7 @@ if (*symbol == 0) return (0); - return ((Elf_Addr)linker_file_lookup_symbol_internal(lf, symbol, - deps)); + return ((Elf_Addr)linker_file_lookup_symbol(lf, symbol, deps)); } static void ==== //depot/projects/smpng/sys/kern/link_elf_obj.c#12 (text+ko) ==== @@ -349,7 +349,7 @@ out: /* preload not done this way */ - linker_file_unload_internal(lf, LINKER_UNLOAD_FORCE); + linker_file_unload(lf, LINKER_UNLOAD_FORCE); return (error); } @@ -784,7 +784,7 @@ out: if (error && lf) - linker_file_unload_internal(lf, LINKER_UNLOAD_FORCE); + linker_file_unload(lf, LINKER_UNLOAD_FORCE); if (hdr) free(hdr, M_LINKER); VOP_UNLOCK(nd.ni_vp, 0, td); @@ -1101,8 +1101,7 @@ /* Force a lookup failure if the symbol name is bogus. */ if (*symbol == 0) return (0); - ret = ((Elf_Addr)linker_file_lookup_symbol_internal(lf, symbol, - deps)); + ret = ((Elf_Addr)linker_file_lookup_symbol(lf, symbol, deps)); return ret; case STB_WEAK: ==== //depot/projects/smpng/sys/sys/linker.h#19 (text+ko) ==== @@ -146,9 +146,6 @@ * Functions soley for use by the linker class handlers. */ int linker_add_class(linker_class_t _cls); -caddr_t linker_file_lookup_symbol_internal(linker_file_t _file, - const char* _name, int _deps); -int linker_file_unload_internal(linker_file_t _file, int flags); int linker_load_dependencies(linker_file_t _lf); linker_file_t linker_make_file(const char* _filename, linker_class_t _cls);