Skip to content

Commit

Permalink
add register cgo symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
pkujhd committed Jul 27, 2024
1 parent b5789c1 commit a26e356
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions registerCgo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package goloader

import (
"github.com/pkujhd/goloader/libdl"
)

func (linker *Linker) RegisterCgoSymbols(symPtr map[string]uintptr) error {
soNameMap := make(map[string]string)
for _, cgoImport := range linker.CgoImportMap {
soNameMap[cgoImport.SoName] = cgoImport.SoName
}

for _, soName := range soNameMap {
_, err := libdl.Open(soName)
if err != nil {
return err
}
}

handle, err := libdl.Open(EmptyString)
if err != nil {
return err
}

for _, cgoImport := range linker.CgoImportMap {
ptr, err := libdl.LookupSymbol(handle, cgoImport.CSymName)
if err != nil {
return err
}
symPtr[cgoImport.GoSymName] = ptr
}
return nil
}

0 comments on commit a26e356

Please sign in to comment.