Skip to content

Commit

Permalink
Syscall Sysv: Add support for strings in callback arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
jwijenbergh committed Jan 5, 2024
1 parent d36331f commit 439893e
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions syscall_sysv.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"runtime"
"sync"
"unsafe"

"github.com/jwijenbergh/purego/internal/strings"
)

var syscall15XABI0 uintptr
Expand Down Expand Up @@ -81,7 +83,7 @@ func compileCallback(fn interface{}) uintptr {
switch in.Kind() {
case reflect.Struct, reflect.Interface, reflect.Func, reflect.Slice,
reflect.Chan, reflect.Complex64, reflect.Complex128,
reflect.String, reflect.Map, reflect.Invalid:
reflect.Map, reflect.Invalid:
panic("purego: unsupported argument type: " + in.Kind().String())
}
}
Expand Down Expand Up @@ -140,6 +142,16 @@ func callbackWrap(a *callbackArgs) {
stack := numOfIntegerRegisters() + numOfFloats
for i := range args {
var pos int
addInt := func() {
if intsN >= numOfIntegerRegisters() {
pos = stack
stack++
} else {
// the integers begin after the floats in frame
pos = intsN + numOfFloats
}
intsN++
}
switch fnType.In(i).Kind() {
case reflect.Float32, reflect.Float64:
if floatsN >= numOfFloats {
Expand All @@ -149,17 +161,14 @@ func callbackWrap(a *callbackArgs) {
pos = floatsN
}
floatsN++
args[i] = reflect.NewAt(fnType.In(i), unsafe.Pointer(&frame[pos])).Elem()
case reflect.String:
addInt()
args[i] = reflect.ValueOf(strings.GoString(frame[pos]))
default:
if intsN >= numOfIntegerRegisters() {
pos = stack
stack++
} else {
// the integers begin after the floats in frame
pos = intsN + numOfFloats
}
intsN++
addInt()
args[i] = reflect.NewAt(fnType.In(i), unsafe.Pointer(&frame[pos])).Elem()
}
args[i] = reflect.NewAt(fnType.In(i), unsafe.Pointer(&frame[pos])).Elem()
}
ret := fn.Call(args)
if len(ret) > 0 {
Expand Down

0 comments on commit 439893e

Please sign in to comment.