@@ -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