1
0
mirror of https://github.com/fumiama/gozel.git synced 2026-06-05 08:20: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) h, err := purego.Dlopen(zeLibraryName, purego.RTLD_LAZY|purego.RTLD_GLOBAL)
if err != nil { if err != nil {
panic(err) libZeLoader = ^uintptr(0)
return
} }
libZeLoader = h libZeLoader = h
} }
// Register a process for calling. For generated init only. Not thread-safe. // Register a process for calling. For generated init only. Not thread-safe.
func Register(name string) error { func Register(name string) error {
if libZeLoader == 0 { if libZeLoader == 0 || ^libZeLoader == 0 {
return ErrZeCallNotInit return ErrZeCallNotInit
} }
sym, err := purego.Dlsym(libZeLoader, name) sym, err := purego.Dlsym(libZeLoader, name)
@@ -45,6 +46,9 @@ func Register(name string) error {
// //
//go:uintptrescapes //go:uintptrescapes
func Syscall(name string, args ...uintptr) (r1, r2 uintptr, err error) { func Syscall(name string, args ...uintptr) (r1, r2 uintptr, err error) {
if libZeLoader == 0 || ^libZeLoader == 0 {
return 0, 0, ErrZeCallNotInit
}
fn, ok := procMap[name] fn, ok := procMap[name]
if !ok { if !ok {
return 0, 0, ErrNoSuchProcess return 0, 0, ErrNoSuchProcess

View File

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