1
0
mirror of https://github.com/fumiama/gozel.git synced 2026-06-05 00:10:24 +08:00

fix: panic on non-ze system

This commit is contained in:
源文雨
2026-03-29 18:52:05 +08:00
parent 9e4a4aa9c1
commit a95fde5243
2 changed files with 13 additions and 4 deletions

View File

@@ -21,14 +21,15 @@ func init() {
}
h, err := purego.Dlopen(zeLibraryName, purego.RTLD_LAZY|purego.RTLD_GLOBAL)
if err != nil {
panic(err)
libZeLoader = ^uintptr(0)
return
}
libZeLoader = h
}
// Register a process for calling. For generated init only. Not thread-safe.
func Register(name string) error {
if libZeLoader == 0 {
if libZeLoader == 0 || ^libZeLoader == 0 {
return ErrZeCallNotInit
}
sym, err := purego.Dlsym(libZeLoader, name)
@@ -45,6 +46,9 @@ func Register(name string) error {
//
//go:uintptrescapes
func Syscall(name string, args ...uintptr) (r1, r2 uintptr, err error) {
if libZeLoader == 0 || ^libZeLoader == 0 {
return 0, 0, ErrZeCallNotInit
}
fn, ok := procMap[name]
if !ok {
return 0, 0, ErrNoSuchProcess

View File

@@ -10,6 +10,7 @@ const (
var (
libZeLoader *syscall.DLL
noZeLib = false
procMap = map[string]*syscall.Proc{}
)
@@ -19,14 +20,15 @@ func init() {
}
h, err := syscall.LoadLibrary(zeLibraryName)
if err != nil {
panic(err)
noZeLib = true
return
}
libZeLoader = &syscall.DLL{Handle: h, Name: zeLibraryName}
}
// Register a process for calling. For generated init only. Not thread-safe.
func Register(name string) error {
if libZeLoader == nil {
if libZeLoader == nil || noZeLib {
return ErrZeCallNotInit
}
proc, err := libZeLoader.FindProc(name)
@@ -43,6 +45,9 @@ func Register(name string) error {
//
//go:uintptrescapes
func Syscall(name string, args ...uintptr) (r1, r2 uintptr, err error) {
if libZeLoader == nil || noZeLib {
return 0, 0, ErrZeCallNotInit
}
fn, ok := procMap[name]
if !ok {
return 0, 0, ErrNoSuchProcess