Skip to content
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
5 changes: 4 additions & 1 deletion src/coreclr/vm/callconvbuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ bool CallConv::TryGetCallingConventionFromUnmanagedCallersOnly(_In_ MethodDesc*

// UnmanagedCallersOnly each
// have optional named arguments.
CaNamedArg namedArgs[2];
CaNamedArg namedArgs[3];

// For the UnmanagedCallersOnly scenario.
CaType caCallConvs;
Expand All @@ -563,6 +563,9 @@ bool CallConv::TryGetCallingConventionFromUnmanagedCallersOnly(_In_ MethodDesc*
CaTypeCtor caEntryPoint(SERIALIZATION_TYPE_STRING);
namedArgs[1].Init("EntryPoint", SERIALIZATION_TYPE_STRING, caEntryPoint);

CaTypeCtor caAssociatedSourceType(SERIALIZATION_TYPE_TYPE);
namedArgs[2].Init("AssociatedSourceType", SERIALIZATION_TYPE_TYPE, caAssociatedSourceType);

InlineFactory<SArray<CaValue>, 4> caValueArrayFactory;
Assembly* assembly = pMD->GetLoaderModule()->GetAssembly();
IfFailThrow(CustomAttribute::ParseArgumentValues(
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/metadata/marshal.c
Original file line number Diff line number Diff line change
Expand Up @@ -3474,7 +3474,7 @@ mono_marshal_set_callconv_from_unmanaged_callers_only_attribute (MonoMethod *met
}

if (attr != NULL) {
MonoDecodeCustomAttr *decoded_args = mono_reflection_create_custom_attr_data_args_noalloc (mono_defaults.corlib, attr->ctor, attr->data, attr->data_size, error);
MonoDecodeCustomAttr *decoded_args = mono_reflection_create_custom_attr_data_args_noalloc (m_class_get_image (method->klass), attr->ctor, attr->data, attr->data_size, error);
mono_error_assert_ok (error);
for (int i = 0; i < decoded_args->named_args_num; ++i) {
if (decoded_args->named_args_info [i].field && !strcmp (decoded_args->named_args_info [i].field->name, "CallConvs")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ public static int ManagedDoubleCallback(int n)
return DoubleImpl(n);
}

[UnmanagedCallersOnly(CallConvs = [typeof(CallConvStdcall)], EntryPoint = "IgnoredEntryPoint", AssociatedSourceType = typeof(UnmanagedCallersOnlyDll))]
public static int ManagedDoubleCallback_AllOptionalParameters(int n)
{
return DoubleImpl(n);
}

[ActiveIssue("https://github.com/dotnet/runtime/issues/64127", typeof(PlatformDetection), nameof(PlatformDetection.PlatformDoesNotSupportNativeTestAssets))]
[ActiveIssue("Needs coreclr build", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoFULLAOT))]
[ActiveIssue("needs triage", TestPlatforms.Android)]
Expand All @@ -60,7 +66,23 @@ public static void TestUnmanagedCallersOnlyValid()
Assert.Equal(expected, UnmanagedCallersOnlyDll.CallManagedProc((IntPtr)(delegate* unmanaged<int, int>)&ManagedDoubleCallback, n));
}

[UnmanagedCallersOnly(CallConvs = [typeof(CallConvStdcall)])]
[ActiveIssue("https://github.com/dotnet/runtime/issues/64127", typeof(PlatformDetection), nameof(PlatformDetection.PlatformDoesNotSupportNativeTestAssets))]
[ActiveIssue("Needs coreclr build", typeof(PlatformDetection), nameof(PlatformDetection.IsMonoFULLAOT))]
[ActiveIssue("needs triage", TestPlatforms.Android)]
[ActiveIssue("needs triage", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)]
[Fact]
public static void TestUnmanagedCallersOnlyValid_AllOptionalParameters()
{
Console.WriteLine($"Running {nameof(TestUnmanagedCallersOnlyValid_AllOptionalParameters)}...");

int n = 12345;
int expected = DoubleImpl(n);
int actual = UnmanagedCallersOnlyDll.CallManagedProc_Stdcall(&ManagedDoubleCallback_AllOptionalParameters, n);

Assert.Equal(expected, actual);
}

[UnmanagedCallersOnly(CallConvs = [typeof(CallConvStdcall)])]
public static int ManagedDoubleCallback_Stdcall(int n)
{
return DoubleImpl(n);
Expand Down
Loading