Date: Thu, 30 Mar 2006 15:49:23 GMT From: John Baldwin <jhb@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 94304 for review Message-ID: <200603301549.k2UFnNpl048201@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
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);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200603301549.k2UFnNpl048201>