func (h *libHandle) close() error { C.dlerror() C.dlclose(h.handle) e := C.dlerror() if e != nil { return errwrap.Wrap(fmt.Errorf("error closing %v", h.libname), errors.New(C.GoString(e))) } return nil }
// Close closes a LibHandle. func (l *LibHandle) Close() error { C.dlerror() C.dlclose(l.Handle) e := C.dlerror() if e != nil { return fmt.Errorf("error closing %v: %v", l.Libname, errors.New(C.GoString(e))) } return nil }
// GetSymbolPointer takes a symbol name and returns a pointer to the symbol. func (l *LibHandle) GetSymbolPointer(symbol string) (unsafe.Pointer, error) { sym := C.CString(symbol) defer C.free(unsafe.Pointer(sym)) C.dlerror() p := C.dlsym(l.Handle, sym) e := C.dlerror() if e != nil { return nil, fmt.Errorf("error resolving symbol %q: %v", symbol, errors.New(C.GoString(e))) } return p, nil }
func getSymbolPointer(handle unsafe.Pointer, symbol string) (unsafe.Pointer, error) { sym := C.CString(symbol) defer C.free(unsafe.Pointer(sym)) C.dlerror() p := C.dlsym(handle, sym) e := C.dlerror() if e != nil { return nil, errwrap.Wrap(fmt.Errorf("error resolving symbol %q", symbol), errors.New(C.GoString(e))) } return p, nil }
func loadThySelf(t *testing.T, symbol string) { this_process := C.dlopen(nil, C.RTLD_NOW) if this_process == nil { t.Fatal("dlopen:", C.GoString(C.dlerror())) } defer C.dlclose(this_process) symbol_address := C.dlsym(this_process, C.CString(symbol)) if symbol_address == nil { t.Fatal("dlsym:", C.GoString(C.dlerror())) } else { t.Log(symbol, symbol_address) } }
/* * loadThySelf() * Go doesn't support dynamic linking. However, it supports a C interface that supports * dynamic linking. And it supports symbol export allowing callbacks into go functions * using a C calling convention. So, Go supports dynamic linking. */ func loadThySelf(symbol string) *[0]byte { this_process := C.dlopen(nil, C.RTLD_NOW) if this_process == nil { panic(C.GoString(C.dlerror())) } symbol_address := C.dlsym(this_process, C.CString(symbol)) if symbol_address == nil { panic(C.GoString(C.dlerror())) } C.dlclose(this_process) return (*[0]byte)(unsafe.Pointer(symbol_address)) }
func Close(handle uintptr) error { ret := C.dlclose(unsafe.Pointer(handle)) if ret != 0 { return errors.New(C.GoString(C.dlerror())) } return nil }
func Error() string { err := C.dlerror() if err == nil { return "OK" } return C.GoString(err) }
func loadThySelf(t *testing.T, symbol string) { this_process := C.dlopen(nil, C.RTLD_NOW) if this_process == nil { t.Error("dlopen:", C.GoString(C.dlerror())) return } defer C.dlclose(this_process) symbol_address := C.dlsym(this_process, C.CString(symbol)) if symbol_address == nil { t.Error("dlsym:", C.GoString(C.dlerror())) return } t.Log(symbol, symbol_address) C.call4029(symbol_address) }
func dlerror(ctx string) error { errptr := C.dlerror() if errptr == nil { return nil } return errors.New(ctx + ": " + C.GoString(errptr)) }
// populateFunctions ranges over the library's ftable, initializing each // function inside. Assumes that the caller executes runtime.LockOSThread. func (lib *Lib) populateFunctions() error { libT := reflect.TypeOf(lib.ftable) functionsV := reflect.ValueOf(lib).Elem().FieldByName("ftable") n := libT.NumField() for i := 0; i < n; i++ { // Get the field name, and make sure it's an Fp_. f := libT.FieldByIndex([]int{i}) if !strings.HasPrefix(f.Name, fpPrefix) { return fmt.Errorf( "Unexpected: field %q does not start with %q", f.Name, fpPrefix) } // Resolve the symbol. cfname := C.CString(f.Name[len(fpPrefix):]) v := C.dlsym(lib.handle, cfname) C.free(unsafe.Pointer(cfname)) if v == nil { return fmt.Errorf("%s", C.GoString(C.dlerror())) } // Save the value into the struct functionsV.FieldByIndex([]int{i}).SetPointer(v) } return nil }
func (h Handle) Close() error { o := C.dlclose(h.c) if o != C.int(0) { c_err := C.dlerror() return fmt.Errorf("dl: %s", C.GoString(c_err)) } return nil }
func Open(filename string /*, flag int*/) (uintptr, error) { ptr := C.CString(filename) defer C.free(unsafe.Pointer(ptr)) ret := C.dlopen(ptr /*C.int(flag)*/, C.RTLD_LAZY) if ret != nil { return uintptr(ret), nil } return uintptr(ret), errors.New(C.GoString(C.dlerror())) }
func Sym(handle uintptr, symbol string) (uintptr, error) { ptr := C.CString(symbol) defer C.free(unsafe.Pointer(ptr)) ret := C.dlsym(unsafe.Pointer(handle), ptr) if ret != nil { return uintptr(ret), nil } return uintptr(ret), errors.New(C.GoString(C.dlerror())) }
func dlopen(lib string, flags uint) (uintptr, error) { n := C.CString(lib) defer C.free(unsafe.Pointer(n)) u := C.dlopen(n, (C.int)(flags)) if u == nil { err := errors.New(C.GoString(C.dlerror())) return 0, err } return uintptr(u), nil }
func dlclose(handle uintptr) error { Chandle := unsafe.Pointer(handle) errno, _ := C.dlclose(Chandle) if errno != 0 { CErrString, _ := C.dlerror() return errors.New(C.GoString(CErrString)) } else { return nil } }
func dlsym(handle uintptr, symbol string) (uintptr, error) { Csymbol := C.CString(symbol) defer C.free(unsafe.Pointer(Csymbol)) Chandle := unsafe.Pointer(handle) // First clean preview error _, _ = C.dlerror() // Then call dlsym CSymbolHandle, _ := C.dlsym(Chandle, Csymbol) // Test error now CErrString, _ := C.dlerror() if CErrString == nil { return uintptr(CSymbolHandle), nil } else { return 0, errors.New(C.GoString(CErrString)) } }
func Open(fname string, flags Flags) (Handle, error) { c_str := C.CString(fname) defer C.free(unsafe.Pointer(c_str)) h := C.dlopen(c_str, C.int(flags)) if h == nil { c_err := C.dlerror() return Handle{}, fmt.Errorf("dl: %s", C.GoString(c_err)) } return Handle{h}, nil }
func (h Handle) Symbol(symbol string) (uintptr, error) { c_sym := C.CString(symbol) defer C.free(unsafe.Pointer(c_sym)) c_addr := C.dlsym(h.c, c_sym) if c_addr == nil { c_err := C.dlerror() return 0, fmt.Errorf("dl: %s", C.GoString(c_err)) } return uintptr(c_addr), nil }
func dlopen(filename string, flag int) (uintptr, error) { Cfilename := C.CString(filename) defer C.free(unsafe.Pointer(Cfilename)) Cflag := C.int(flag) Chandle, _ := C.dlopen(Cfilename, Cflag) if Chandle == nil { // error happened CErrString := C.dlerror() return 0, errors.New(C.GoString(CErrString)) } else { return uintptr(Chandle), nil } }
// Load attempts to load a dynamically-linked gssapi library from the path // specified by the supplied Options. func Load(o *Options) (*Lib, error) { if o == nil { o = &Options{} } // We get the error in a separate call, so we need to lock OS thread runtime.LockOSThread() defer runtime.UnlockOSThread() lib := &Lib{ Printers: o.Printers, } if o.Krb5Config != "" { err := os.Setenv("KRB5_CONFIG", o.Krb5Config) if err != nil { return nil, err } } if o.Krb5Ktname != "" { err := os.Setenv("KRB5_KTNAME", o.Krb5Ktname) if err != nil { return nil, err } } path := o.Path() lib.Debug(fmt.Sprintf("Loading %q", path)) lib_cs := C.CString(path) defer C.free(unsafe.Pointer(lib_cs)) // we don't use RTLD_FIRST, it might be the case that the GSSAPI lib // delegates symbols to other libs it links against (eg, Kerberos) lib.handle = C.dlopen(lib_cs, C.RTLD_NOW|C.RTLD_LOCAL) if lib.handle == nil { return nil, fmt.Errorf("%s", C.GoString(C.dlerror())) } err := lib.populateFunctions() if err != nil { lib.Unload() return nil, err } lib.initConstants() return lib, nil }
func initialiseInterpreterFrom(enginePath string) bool { if !core.PathExists(enginePath) { return false } log.Debug("Attempting to load engine from %s", enginePath) cEnginePath := C.CString(enginePath) defer C.free(unsafe.Pointer(cEnginePath)) result := C.InitialiseInterpreter(cEnginePath) if result != 0 { // Low level of logging because it's allowable to fail on libplease_parser_pypy, which we try first. log.Notice("Failed to initialise interpreter from %s: %s", enginePath, C.GoString(C.dlerror())) return false } log.Info("Using parser engine from %s", enginePath) return true }
// Unload closes the handle to the dynamically-linked gssapi library. func (lib *Lib) Unload() error { if lib == nil || lib.handle == nil { return nil } runtime.LockOSThread() defer runtime.UnlockOSThread() i := C.dlclose(lib.handle) if i == -1 { return fmt.Errorf("%s", C.GoString(C.dlerror())) } lib.handle = nil return nil }
func dlerror() error { s := C.dlerror() return errors.New(C.GoString(s)) }
func dlerror() error { return &Error{ Message: C.GoString(C.dlerror()), } }