mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-22 11:41:19 +00:00
47690db676
This introduces _experimental_ block execution run by embedded Silkworm API library: - new command-line option `silkworm.path` to enable the feature by specifying the path to the Silkworm library - the Silkworm API shared library is dynamically loaded on-demand - currently requires to build Silkworm library on the target machine - available only on Linux at the moment: macOS has issue with [stack size](https://github.com/golang/go/issues/28024) and Windows would require [TDM-GCC-64](https://jmeubank.github.io/tdm-gcc/), both need dedicated effort for an assessment
36 lines
806 B
Go
36 lines
806 B
Go
package silkworm
|
|
|
|
/*
|
|
#cgo LDFLAGS: -ldl
|
|
#include <dlfcn.h>
|
|
#include <stdlib.h>
|
|
*/
|
|
import "C"
|
|
|
|
import (
|
|
"fmt"
|
|
"unsafe"
|
|
)
|
|
|
|
func OpenLibrary(dllPath string) (unsafe.Pointer, error) {
|
|
cPath := C.CString(dllPath)
|
|
defer C.free(unsafe.Pointer(cPath))
|
|
dllHandle := C.dlopen(cPath, C.RTLD_LAZY)
|
|
if dllHandle == nil {
|
|
err := C.GoString(C.dlerror())
|
|
return nil, fmt.Errorf("failed to load dynamic library %s: %s", dllPath, err)
|
|
}
|
|
return dllHandle, nil
|
|
}
|
|
|
|
func LoadFunction(dllHandle unsafe.Pointer, funcName string) (unsafe.Pointer, error) {
|
|
cName := C.CString(funcName)
|
|
defer C.free(unsafe.Pointer(cName))
|
|
funcPtr := C.dlsym(dllHandle, cName)
|
|
if funcPtr == nil {
|
|
err := C.GoString(C.dlerror())
|
|
return nil, fmt.Errorf("failed to find the %s function: %s", funcName, err)
|
|
}
|
|
return funcPtr, nil
|
|
}
|