@@ -292,6 +292,22 @@ func RegisterFunc(fptr interface{}, cfn uintptr) {
292
292
fn .Set (v )
293
293
}
294
294
295
+ func numOfIntegerRegisters () int {
296
+ switch runtime .GOARCH {
297
+ case "arm64" :
298
+ return 8
299
+ case "amd64" :
300
+ return 6
301
+ // TODO: figure out why 386 tests are not working
302
+ /*case "386":
303
+ return 0
304
+ case "arm":
305
+ return 4*/
306
+ default :
307
+ panic ("purego: unknown GOARCH (" + runtime .GOARCH + ")" )
308
+ }
309
+ }
310
+
295
311
// WIP: Less reflection below
296
312
297
313
type syscallStackArm64NoWin [1 + maxArgs + numOfFloats ]uintptr
@@ -562,13 +578,15 @@ func getReturnFunc[T any]() func(r1, r2 uintptr) T {
562
578
return nil
563
579
}
564
580
565
- func argsCheck (ty reflect. Type , cfn uintptr ) {
581
+ func argsCheck (fptr any , cfn uintptr ) {
566
582
if cfn == 0 {
567
583
panic ("purego: cfn is nil" )
568
584
}
569
585
// this code checks how many registers and stack this function will use
570
586
// to avoid crashing with too many arguments
571
587
var ints , floats , stack int
588
+
589
+ ty := reflect .ValueOf (fptr ).Elem ().Type ()
572
590
for i := 0 ; i < ty .NumIn (); i ++ {
573
591
arg := ty .In (i )
574
592
switch arg .Kind () {
@@ -621,9 +639,8 @@ func runtime_call(ss syscallStack, cfn uintptr) (uintptr, uintptr) {
621
639
// No return value
622
640
623
641
func RegisterFunc1_0 [I0 any ](fptr * func (I0 ), cfn uintptr ) {
624
- ty := reflect .ValueOf (fptr ).Elem ().Type ()
625
642
// Prevent too many registers and check func address is okay
626
- argsCheck (ty , cfn )
643
+ argsCheck (fptr , cfn )
627
644
func0 := getAddFunc [I0 ]()
628
645
// Create new function
629
646
* fptr = func (i0 I0 ) {
@@ -637,9 +654,8 @@ func RegisterFunc1_0[I0 any](fptr *func(I0), cfn uintptr) {
637
654
}
638
655
639
656
func RegisterFunc2_0 [I0 , I1 any ](fptr * func (I0 , I1 ), cfn uintptr ) {
640
- ty := reflect .ValueOf (fptr ).Elem ().Type ()
641
657
// Prevent too many registers and check func address is okay
642
- argsCheck (ty , cfn )
658
+ argsCheck (fptr , cfn )
643
659
func0 := getAddFunc [I0 ]()
644
660
func1 := getAddFunc [I1 ]()
645
661
// Create new function
@@ -655,9 +671,8 @@ func RegisterFunc2_0[I0, I1 any](fptr *func(I0, I1), cfn uintptr) {
655
671
}
656
672
657
673
func RegisterFunc3_0 [I0 , I1 , I2 any ](fptr * func (I0 , I1 , I2 ), cfn uintptr ) {
658
- ty := reflect .ValueOf (fptr ).Elem ().Type ()
659
674
// Prevent too many registers and check func address is okay
660
- argsCheck (ty , cfn )
675
+ argsCheck (fptr , cfn )
661
676
func0 := getAddFunc [I0 ]()
662
677
func1 := getAddFunc [I1 ]()
663
678
func2 := getAddFunc [I2 ]()
@@ -675,9 +690,8 @@ func RegisterFunc3_0[I0, I1, I2 any](fptr *func(I0, I1, I2), cfn uintptr) {
675
690
}
676
691
677
692
func RegisterFunc4_0 [I0 , I1 , I2 , I3 any ](fptr * func (I0 , I1 , I2 , I3 ), cfn uintptr ) {
678
- ty := reflect .ValueOf (fptr ).Elem ().Type ()
679
693
// Prevent too many registers and check func address is okay
680
- argsCheck (ty , cfn )
694
+ argsCheck (fptr , cfn )
681
695
func0 := getAddFunc [I0 ]()
682
696
func1 := getAddFunc [I1 ]()
683
697
func2 := getAddFunc [I2 ]()
@@ -697,9 +711,8 @@ func RegisterFunc4_0[I0, I1, I2, I3 any](fptr *func(I0, I1, I2, I3), cfn uintptr
697
711
}
698
712
699
713
func RegisterFunc5_0 [I0 , I1 , I2 , I3 , I4 any ](fptr * func (I0 , I1 , I2 , I3 , I4 ), cfn uintptr ) {
700
- ty := reflect .ValueOf (fptr ).Elem ().Type ()
701
714
// Prevent too many registers and check func address is okay
702
- argsCheck (ty , cfn )
715
+ argsCheck (fptr , cfn )
703
716
func0 := getAddFunc [I0 ]()
704
717
func1 := getAddFunc [I1 ]()
705
718
func2 := getAddFunc [I2 ]()
@@ -725,9 +738,8 @@ func RegisterFunc5_0[I0, I1, I2, I3, I4 any](fptr *func(I0, I1, I2, I3, I4), cfn
725
738
// 1 return value
726
739
727
740
func RegisterFunc1_1 [I0 , O any ](fptr * func (I0 ) O , cfn uintptr ) {
728
- ty := reflect .ValueOf (fptr ).Elem ().Type ()
729
741
// Prevent too many registers and check func address is okay
730
- argsCheck (ty , cfn )
742
+ argsCheck (fptr , cfn )
731
743
returnFunc := getReturnFunc [O ]()
732
744
func0 := getAddFunc [I0 ]()
733
745
// Create new function
@@ -744,9 +756,8 @@ func RegisterFunc1_1[I0, O any](fptr *func(I0) O, cfn uintptr) {
744
756
}
745
757
746
758
func RegisterFunc2_1 [I0 , I1 , O any ](fptr * func (I0 , I1 ) O , cfn uintptr ) {
747
- ty := reflect .ValueOf (fptr ).Elem ().Type ()
748
759
// Prevent too many registers and check func address is okay
749
- argsCheck (ty , cfn )
760
+ argsCheck (fptr , cfn )
750
761
returnFunc := getReturnFunc [O ]()
751
762
func0 := getAddFunc [I0 ]()
752
763
func1 := getAddFunc [I1 ]()
@@ -765,9 +776,8 @@ func RegisterFunc2_1[I0, I1, O any](fptr *func(I0, I1) O, cfn uintptr) {
765
776
}
766
777
767
778
func RegisterFunc3_1 [I0 , I1 , I2 , O any ](fptr * func (I0 , I1 , I2 ) O , cfn uintptr ) {
768
- ty := reflect .ValueOf (fptr ).Elem ().Type ()
769
779
// Prevent too many registers and check func address is okay
770
- argsCheck (ty , cfn )
780
+ argsCheck (fptr , cfn )
771
781
returnFunc := getReturnFunc [O ]()
772
782
func0 := getAddFunc [I0 ]()
773
783
func1 := getAddFunc [I1 ]()
@@ -788,9 +798,8 @@ func RegisterFunc3_1[I0, I1, I2, O any](fptr *func(I0, I1, I2) O, cfn uintptr) {
788
798
}
789
799
790
800
func RegisterFunc4_1 [I0 , I1 , I2 , I3 , O any ](fptr * func (I0 , I1 , I2 , I3 ) O , cfn uintptr ) {
791
- ty := reflect .ValueOf (fptr ).Elem ().Type ()
792
801
// Prevent too many registers and check func address is okay
793
- argsCheck (ty , cfn )
802
+ argsCheck (fptr , cfn )
794
803
returnFunc := getReturnFunc [O ]()
795
804
func0 := getAddFunc [I0 ]()
796
805
func1 := getAddFunc [I1 ]()
@@ -813,9 +822,8 @@ func RegisterFunc4_1[I0, I1, I2, I3, O any](fptr *func(I0, I1, I2, I3) O, cfn ui
813
822
}
814
823
815
824
func RegisterFunc5_1 [I0 , I1 , I2 , I3 , I4 , O any ](fptr * func (I0 , I1 , I2 , I3 , I4 ) O , cfn uintptr ) {
816
- ty := reflect .ValueOf (fptr ).Elem ().Type ()
817
825
// Prevent too many registers and check func address is okay
818
- argsCheck (ty , cfn )
826
+ argsCheck (fptr , cfn )
819
827
returnFunc := getReturnFunc [O ]()
820
828
func0 := getAddFunc [I0 ]()
821
829
func1 := getAddFunc [I1 ]()
@@ -842,9 +850,8 @@ func RegisterFunc5_1[I0, I1, I2, I3, I4, O any](fptr *func(I0, I1, I2, I3, I4) O
842
850
// TODO: missing 6-8
843
851
844
852
func RegisterFunc9_1 [I0 , I1 , I2 , I3 , I4 , I5 , I6 , I7 , I8 , O any ](fptr * func (I0 , I1 , I2 , I3 , I4 , I5 , I6 , I7 , I8 ) O , cfn uintptr ) {
845
- ty := reflect .ValueOf (fptr ).Elem ().Type ()
846
853
// Prevent too many registers and check func address is okay
847
- argsCheck (ty , cfn )
854
+ argsCheck (fptr , cfn )
848
855
returnFunc := getReturnFunc [O ]()
849
856
func0 := getAddFunc [I0 ]()
850
857
func1 := getAddFunc [I1 ]()
@@ -875,19 +882,3 @@ func RegisterFunc9_1[I0, I1, I2, I3, I4, I5, I6, I7, I8, O any](fptr *func(I0, I
875
882
return returnFunc (r1 , r2 )
876
883
}
877
884
}
878
-
879
- func numOfIntegerRegisters () int {
880
- switch runtime .GOARCH {
881
- case "arm64" :
882
- return 8
883
- case "amd64" :
884
- return 6
885
- // TODO: figure out why 386 tests are not working
886
- /*case "386":
887
- return 0
888
- case "arm":
889
- return 4*/
890
- default :
891
- panic ("purego: unknown GOARCH (" + runtime .GOARCH + ")" )
892
- }
893
- }
0 commit comments