Skip to content

Commit 823d323

Browse files
committed
Properly handle struct return in AArch64 FFI
1 parent 6660765 commit 823d323

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

BeefLibs/corlib/src/Reflection/MethodInfo.bf

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,10 +543,21 @@ namespace System.Reflection
543543
FFIType* ffiRetType = null;
544544
if (retType.IsStruct)
545545
{
546+
#if BF_MACHINE_AARCH64
547+
let ffiRetElements = scope:: List<FFIType*>(8);
548+
for (let fi in retType.GetFields(.Instance | .DeclaredOnly))
549+
{
550+
let ffiType = GetFFIType!::(fi.FieldType);
551+
ffiRetElements.Add(ffiType);
552+
}
553+
ffiRetElements.Add(null);
554+
ffiRetType = scope::FFIType(Math.Max(24, retType.Size), retType.Align, .Struct, ffiRetElements.Ptr); // Force use of indirect return
555+
#else
546556
ffiRetType = &FFIType.Void;
547557
ffiParamList.Add(&FFIType.Pointer);
548558
ffiArgList.Add(&variantData);
549559
retData = &unusedRetVal;
560+
#endif
550561
}
551562
else
552563
ffiRetType = GetFFIType!::(retType);
@@ -947,10 +958,21 @@ namespace System.Reflection
947958
FFIType* ffiRetType = null;
948959
if (retType.IsStruct)
949960
{
961+
#if BF_MACHINE_AARCH64
962+
let ffiRetElements = scope:: List<FFIType*>(8);
963+
for (let fi in retType.GetFields(.Instance | .DeclaredOnly))
964+
{
965+
let ffiType = GetFFIType!::(fi.FieldType);
966+
ffiRetElements.Add(ffiType);
967+
}
968+
ffiRetElements.Add(null);
969+
ffiRetType = scope::FFIType(Math.Max(24, retType.Size), retType.Align, .Struct, ffiRetElements.Ptr); // Force use of indirect return
970+
#else
950971
ffiRetType = &FFIType.Void;
951972
ffiParamList.Add(&FFIType.Pointer);
952973
ffiArgList.Add(&variantData);
953974
retData = &unusedRetVal;
975+
#endif
954976
}
955977
else
956978
ffiRetType = GetFFIType!::(retType);

0 commit comments

Comments
 (0)