diff --git a/syscall_sysv.go b/syscall_sysv.go index c0860f72..354e7b77 100644 --- a/syscall_sysv.go +++ b/syscall_sysv.go @@ -10,6 +10,8 @@ import ( "runtime" "sync" "unsafe" + + "github.com/jwijenbergh/purego/internal/strings" ) var syscall15XABI0 uintptr @@ -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()) } } @@ -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 { @@ -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 {