Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
7 changes: 0 additions & 7 deletions src/coreclr/vm/comdelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2793,13 +2793,6 @@ MethodDesc* COMDelegate::GetDelegateCtor(TypeHandle delegateType, MethodDesc *pT
// associated with the instantiation.
BOOL fMaybeCollectibleAndStatic = FALSE;

// Do not allow static methods with [UnmanagedCallersOnlyAttribute] to be a delegate target.
// A method marked UnmanagedCallersOnly is special and allowing it to be delegate target will destabilize the runtime.
if (pTargetMethod->HasUnmanagedCallersOnlyAttribute())
{
COMPlusThrow(kNotSupportedException, W("NotSupported_UnmanagedCallersOnlyTarget"));
}

if (isStatic)
{
// When this method is called and the method being considered is shared, we typically
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3092,9 +3092,6 @@
<data name="NotSupported_MustBeModuleBuilder" xml:space="preserve">
<value>Module argument must be a ModuleBuilder.</value>
</data>
<data name="NotSupported_UnmanagedCallersOnlyTarget" xml:space="preserve">
<value>Methods with UnmanagedCallersOnlyAttribute cannot be used as delegate target.</value>
</data>
<data name="NotSupported_NoCodepageData" xml:space="preserve">
<value>No data is available for encoding {0}. For information on defining a custom encoding, see the documentation for the Encoding.RegisterProvider method.</value>
</data>
Expand Down
41 changes: 0 additions & 41 deletions src/tests/Interop/UnmanagedCallersOnly/InvalidCallbacks.il
Original file line number Diff line number Diff line change
Expand Up @@ -101,47 +101,6 @@
ret
}

.method public hidebysig static
int32 ManagedDoubleCallback (
int32 n
) cil managed
{
.custom instance void [System.Runtime.InteropServices]System.Runtime.InteropServices.UnmanagedCallersOnlyAttribute::.ctor() = (
01 00 00 00
)
.maxstack 1

nop
ldarg.0
call int32 InvalidCSharp.CallingUnmanagedCallersOnlyDirectly::DoubleImpl(int32)
ret
}

.method private hidebysig static
int32 DoubleImpl (
int32 n
) cil managed
{
.maxstack 2

nop
ldc.i4.2
ldarg.0
mul
ret
}

.method public hidebysig static
class [System.Runtime]System.Func`2<int32, int32> GetDoubleDelegate () cil managed
{
.maxstack 8

ldnull
ldftn int32 InvalidCSharp.CallingUnmanagedCallersOnlyDirectly::ManagedDoubleCallback(int32)
newobj instance void class [System.Runtime]System.Func`2<int32, int32>::.ctor(object, native int)
ret
}

.method public hidebysig static pinvokeimpl("UnmanagedCallersOnlyDll" as "DoesntExist" winapi)
int32 PInvokeMarkedWithUnmanagedCallersOnly (
int32 n
Expand Down
16 changes: 0 additions & 16 deletions src/tests/Interop/UnmanagedCallersOnly/UnmanagedCallersOnlyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,6 @@ public static void TestUnmanagedCallersOnlyValid_ThrowException()
Assert.Equal(-1, UnmanagedCallersOnlyDll.CallManagedProcCatchException((IntPtr)(delegate* unmanaged<int, int>)&CallbackThrows, n));
}

[Fact]
public static void NegativeTest_ViaDelegate()
{
Console.WriteLine($"Running {nameof(NegativeTest_ViaDelegate)}...");

// Try invoking method directly
Assert.Throws<NotSupportedException>(() => { CallAsDelegate(); });

// Local function to delay exception thrown during JIT
void CallAsDelegate()
{
Func<int, int> invoker = CallingUnmanagedCallersOnlyDirectly.GetDoubleDelegate();
invoker(0);
}
}

[Fact]
public static void NegativeTest_NonStaticMethod()
{
Expand Down
Loading