diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2015-10-26 16:16:25 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2015-10-26 16:16:25 -0400 |
commit | 1eb4413f868967283487f73c87e906273bab8b9b (patch) | |
tree | 1eecc8707ac0661fb46ddf56d6607e8065e19dd8 /dl | |
parent | 9a08b2758e86effcb70b92a31548d8368c95a7e6 (diff) |
dlfcn: dlerror requires a global lock anyway
Diffstat (limited to 'dl')
-rw-r--r-- | dl/dlfcn.go | 23 | ||||
-rw-r--r-- | dl/dlsym_reserved.go | 8 |
2 files changed, 17 insertions, 14 deletions
diff --git a/dl/dlfcn.go b/dl/dlfcn.go index eb40794..e240540 100644 --- a/dl/dlfcn.go +++ b/dl/dlfcn.go @@ -58,33 +58,36 @@ const ( type Handle struct { c unsafe.Pointer o int - l sync.RWMutex } +var dllock sync.Mutex + // Open a shared object file, returning a Handle to it, or an error. // If name is an empty string, then the returned handle is the global // symbol table for the current process; if the name contains a slash, // then it is interpretted as a pathname; otherwise, it is // interpretted in an implementation-defined manner. -func Open(name string, flags Flag) (*Handle, error) { +func Open(name string, flags Flag) (Handle, error) { nameC := C.CString(name) defer C.free(unsafe.Pointer(nameC)) if name == "" { nameC = nil } + dllock.Lock() + defer dllock.Unlock() dlerror() ptr := C.dlopen(nameC, C.int(flags)) if ptr == nil { - return &Handle{}, dlerror() + return Handle{}, dlerror() } - return &Handle{c: ptr, o: 1}, nil + return Handle{c: ptr, o: 1}, nil } // Look up a symbol, and return a pointer to it. -func (h *Handle) Sym(symbol string) (unsafe.Pointer, error) { - h.l.RLock() - defer h.l.RUnlock() +func (h Handle) Sym(symbol string) (unsafe.Pointer, error) { + dllock.Lock() + defer dllock.Unlock() if h.o == 0 { return nil, HandleClosedError @@ -104,9 +107,9 @@ func (h *Handle) Sym(symbol string) (unsafe.Pointer, error) { // Close this handle on a shared object; decrementint the reference // count; if the reference count drops below 0, then the object is // unloaded. -func (h *Handle) Close() error { - h.l.Lock() - defer h.l.Unlock() +func (h Handle) Close() error { + dllock.Lock() + defer dllock.Unlock() if h.o == 0 { return HandleClosedError diff --git a/dl/dlsym_reserved.go b/dl/dlsym_reserved.go index cfa0dca..081e012 100644 --- a/dl/dlsym_reserved.go +++ b/dl/dlsym_reserved.go @@ -44,7 +44,7 @@ var ( // the executable and its dependencies, as well as symbols in // shared objects that were dynamically loaded with the // RTLD_GLOBAL flag. - RTLD_DEFAULT *Handle + RTLD_DEFAULT Handle // This Handle represents the shared object search order after // the current object. This allows one to provide a wrapper @@ -54,10 +54,10 @@ var ( // "real" function provided in another shared object (or for // that matter, the "next" definition of the function in cases // where there are multiple layers of preloading). - RTLD_NEXT *Handle + RTLD_NEXT Handle ) func init() { - RTLD_DEFAULT = &Handle{c: unsafe.Pointer(uintptr(C.rtld_default)), o: 2} - RTLD_DEFAULT = &Handle{c: unsafe.Pointer(uintptr(C.rtld_next)), o: 2} + RTLD_DEFAULT = Handle{c: unsafe.Pointer(uintptr(C.rtld_default)), o: 2} + RTLD_DEFAULT = Handle{c: unsafe.Pointer(uintptr(C.rtld_next)), o: 2} } |