示例#1
0
文件: acl.go 项目: sinfomicien/rkt
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
}
示例#2
0
// 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
}
示例#3
0
// 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
}
示例#4
0
文件: acl.go 项目: sinfomicien/rkt
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
}
示例#5
0
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)
	}
}
示例#6
0
/*
* 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))
}
示例#7
0
文件: dl_unix.go 项目: mattn/go-dl
func Close(handle uintptr) error {
	ret := C.dlclose(unsafe.Pointer(handle))
	if ret != 0 {
		return errors.New(C.GoString(C.dlerror()))
	}
	return nil
}
示例#8
0
func Error() string {
	err := C.dlerror()
	if err == nil {
		return "OK"
	}
	return C.GoString(err)
}
示例#9
0
文件: issue4029.go 项目: 2thetop/go
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)
}
示例#10
0
文件: dlopen.go 项目: cookieo9/goffi
func dlerror(ctx string) error {
	errptr := C.dlerror()
	if errptr == nil {
		return nil
	}
	return errors.New(ctx + ": " + C.GoString(errptr))
}
示例#11
0
文件: lib.go 项目: Xmagicer/origin
// 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
}
示例#12
0
文件: dl.go 项目: sbinet/go-ffi
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
}
示例#13
0
文件: dl_unix.go 项目: mattn/go-dl
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()))
}
示例#14
0
文件: dl_unix.go 项目: mattn/go-dl
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()))
}
示例#15
0
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
}
示例#16
0
文件: dlfcn.go 项目: hamo/godynlib
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
	}
}
示例#17
0
文件: dlfcn.go 项目: hamo/godynlib
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))
	}
}
示例#18
0
文件: dl.go 项目: sbinet/go-ffi
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
}
示例#19
0
文件: dl.go 项目: sbinet/go-ffi
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
}
示例#20
0
文件: dlfcn.go 项目: hamo/godynlib
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
	}
}
示例#21
0
文件: lib.go 项目: Xmagicer/origin
// 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
}
示例#22
0
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
}
示例#23
0
文件: lib.go 项目: Xmagicer/origin
// 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
}
示例#24
0
文件: dl.go 项目: tiborvass/dl
func dlerror() error {
	s := C.dlerror()
	return errors.New(C.GoString(s))
}
示例#25
0
func dlerror() error {
	return &Error{
		Message: C.GoString(C.dlerror()),
	}
}