Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mono] Block SIMD types in Swift interop #98429

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/mono/mono/metadata/marshal.c
Original file line number Diff line number Diff line change
Expand Up @@ -3711,9 +3711,9 @@ mono_marshal_get_native_wrapper (MonoMethod *method, gboolean check_exceptions,
swift_error_args++;
} else if (param_klass == swift_self) {
swift_self_args++;
} else if (!m_class_is_blittable (param_klass) && m_class_get_this_arg (param_klass)->type != MONO_TYPE_FNPTR) {
} else if (!m_class_is_blittable (param_klass) || m_class_is_simd_type (param_klass)) {
swift_error_args = swift_self_args = 0;
mono_error_set_generic_error (emitted_error, "System", "InvalidProgramException", "Passing non-primitive value types to a P/Invoke with the Swift calling convention is unsupported.");
mono_error_set_generic_error (emitted_error, "System", "InvalidProgramException", "Passing non-blittable types to a P/Invoke with the Swift calling convention is unsupported.");
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.Swift;
using System.Numerics;
using Xunit;

public class InvalidCallingConvTests
Expand Down Expand Up @@ -36,6 +37,10 @@ public class StringClass
[DllImport(SwiftLib, EntryPoint = "$s20SwiftInvalidCallConv10simpleFuncyyF")]
public static extern void FuncWithNonPrimitiveArg(StringClass arg1);

[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvSwift) })]
[DllImport(SwiftLib, EntryPoint = "$s20SwiftInvalidCallConv10simpleFuncyyF")]
public static extern void FuncWithSIMDArg(Vector4 vec);

[Fact]
public static void TestFuncWithTwoSelfParameters()
{
Expand Down Expand Up @@ -77,4 +82,12 @@ public static void TestFuncWithNonPrimitiveArg()
arg1.value = "fail";
Assert.Throws<InvalidProgramException>(() => FuncWithNonPrimitiveArg(arg1));
}

[Fact]
public static void TestFuncWithSIMDArg()
{
// Invalid due to a SIMD argument.
Vector4 vec = new Vector4(); // Using Vector4 as it is a SIMD type across all architectures for Mono
Assert.Throws<InvalidProgramException>(() => FuncWithSIMDArg(vec));
}
}