Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
0e18368
General cleanup
AaronRobinsonMSFT May 26, 2023
292da73
Prototype for UnsafeAccessorAttribute
AaronRobinsonMSFT May 26, 2023
40111fa
Remove IsUnsafeAccessor flag from MethodDesc
AaronRobinsonMSFT May 27, 2023
0191e0d
Cleanup memory managment confusion
AaronRobinsonMSFT May 27, 2023
ef239fb
Fix non-standard C++
AaronRobinsonMSFT May 29, 2023
a396e04
Add UnsafeAccessorAttribute API
AaronRobinsonMSFT May 29, 2023
6437420
C++ clean-up
AaronRobinsonMSFT May 29, 2023
b24717a
Return missing(field/method) HRESULT when
AaronRobinsonMSFT May 29, 2023
edd7fb7
Implement IL generation for all accessor paths
AaronRobinsonMSFT May 30, 2023
03a9ef3
Implement static/instance field lookup
AaronRobinsonMSFT May 30, 2023
d771f04
Implement static/instance method lookup
AaronRobinsonMSFT May 30, 2023
02267ff
Alter member names for clarity.
AaronRobinsonMSFT May 30, 2023
e911d3a
Add libraries tests
AaronRobinsonMSFT May 31, 2023
c6dbb50
Remove CORINFO_MODULE_ALLACCESS scope
AaronRobinsonMSFT May 31, 2023
9864b45
Fix message buffer
AaronRobinsonMSFT May 31, 2023
60c38dd
Throw exceptions instead of returning HRESULT.
AaronRobinsonMSFT May 31, 2023
10b9c75
Update visibility check API
AaronRobinsonMSFT May 31, 2023
3e9ee12
Remove enum METHOD_TYPE.
AaronRobinsonMSFT May 31, 2023
62f9e81
Disable tests on Mono
AaronRobinsonMSFT May 31, 2023
a506601
Missing virtual destructor
AaronRobinsonMSFT May 31, 2023
b8c94bf
Apply suggestions from code review
AaronRobinsonMSFT Jun 1, 2023
636e616
Apply suggestions from code review
AaronRobinsonMSFT Jun 1, 2023
72bc7f5
Add error message for invalid UnsafeAccessor use
AaronRobinsonMSFT Jun 5, 2023
2859b6e
Debugger logging updates
AaronRobinsonMSFT Jun 5, 2023
331f4cc
Update BOTR on TypeDesc
AaronRobinsonMSFT Jun 5, 2023
c01080e
Fix type used in message
AaronRobinsonMSFT Jun 5, 2023
1d5c1ab
Support UnsafeAccessor in NativeAOT
AaronRobinsonMSFT Jun 5, 2023
34ada73
Review feedback
AaronRobinsonMSFT Jun 6, 2023
a56bc40
Additional test for ctor
AaronRobinsonMSFT Jun 6, 2023
a43b3cc
Remove ctor special case lookup
AaronRobinsonMSFT Jun 6, 2023
3da55de
Remove usage of MetaSig
AaronRobinsonMSFT Jun 6, 2023
bbe820c
Collect custom modifiers counts
AaronRobinsonMSFT Jun 7, 2023
18a2749
Convert all tests to be runtime tests.
AaronRobinsonMSFT Jun 8, 2023
d5ff647
Defined ambiguity logic with respect to
AaronRobinsonMSFT Jun 8, 2023
924cf37
Address ambiguity in NativeAOT
AaronRobinsonMSFT Jun 8, 2023
305aeff
Add all previous tests in libraries into runtime
AaronRobinsonMSFT Jun 8, 2023
c169969
Use AmbiguousMatchException
AaronRobinsonMSFT Jun 8, 2023
3b3691f
Move tests to be Pri0 since they are all we have.
AaronRobinsonMSFT Jun 8, 2023
f0756b7
Add support in ILAsm
AaronRobinsonMSFT Jun 9, 2023
c51e986
Use xplat ARRAY_SIZE.
AaronRobinsonMSFT Jun 9, 2023
12ba472
Remove special handling of empty method in ILASM
AaronRobinsonMSFT Jun 9, 2023
efb27a4
Generate accessors that throw specific failures.
AaronRobinsonMSFT Jun 9, 2023
d3b0726
NativeAOT error handling was throwing asserts.
AaronRobinsonMSFT Jun 9, 2023
56d733e
Remove catch all for any exception. This code
AaronRobinsonMSFT Jun 10, 2023
facc48e
Use declaration method as owner for stubs
AaronRobinsonMSFT Jun 10, 2023
8d92e7e
Review feedback
AaronRobinsonMSFT Jun 10, 2023
b446a20
Improve MissingMethodException
AaronRobinsonMSFT Jun 12, 2023
5b67d04
Missed fallback name lookup on NativeAOT.
AaronRobinsonMSFT Jun 12, 2023
3663bad
Tests for calling convention bits on NativeAOT.
AaronRobinsonMSFT Jun 12, 2023
c2be6fc
Remove block of doc text for generics. Will add
AaronRobinsonMSFT Jun 12, 2023
63f975c
Treat signature calling convention bits like we treat
AaronRobinsonMSFT Jun 13, 2023
869a5f0
Managed and unmanaged function pointers never
AaronRobinsonMSFT Jun 13, 2023
c03dc9e
Feedback for throwing exceptions on NativeAOT
AaronRobinsonMSFT Jun 13, 2023
a309b06
Merge remote-tracking branch 'upstream/main' into runtime_86161
AaronRobinsonMSFT Jun 14, 2023
b957416
Missing NAOT version of error string
AaronRobinsonMSFT Jun 14, 2023
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
Prev Previous commit
Next Next commit
Managed and unmanaged function pointers never
signature match.
  • Loading branch information
AaronRobinsonMSFT committed Jun 13, 2023
commit 869a5f07cc4cc50e1edef2828223d975a23c405a
55 changes: 34 additions & 21 deletions src/coreclr/vm/siginfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,30 @@ TypeHandle SigPointer::GetTypeHandleNT(Module* pModule,

#endif // #ifndef DACCESS_COMPILE

// Normalizing function pointer calling convention means
// simply treating it as either "managed" or "unmanaged".
static uint32_t NormalizeFnPtrCallingConvention(uint32_t callConv)
{
LIMITED_METHOD_CONTRACT;

// Only have an unmanaged\managed status, and not the unmanaged CALLCONV_ value.
switch (callConv & IMAGE_CEE_CS_CALLCONV_MASK)
{
case IMAGE_CEE_CS_CALLCONV_C:
case IMAGE_CEE_CS_CALLCONV_STDCALL:
case IMAGE_CEE_CS_CALLCONV_THISCALL:
case IMAGE_CEE_CS_CALLCONV_FASTCALL:
// Strip the calling convention.
callConv &= ~IMAGE_CEE_CS_CALLCONV_MASK;
// Normalize to unmanaged.
callConv |= IMAGE_CEE_CS_CALLCONV_UNMANAGED;
break;
default:
break;
}

return callConv;
}

#ifdef _PREFAST_
#pragma warning(push)
Expand Down Expand Up @@ -1739,7 +1763,7 @@ TypeHandle SigPointer::GetTypeHandleThrowing(
TypeHandle *retAndArgTypes = (TypeHandle*) _alloca(cAllocaSize);
bool fReturnTypeOrParameterNotLoaded = false;

for (unsigned i = 0; i <= cArgs; i++)
for (uint32_t i = 0; i <= cArgs; i++)
{
// Lookup type handle.
retAndArgTypes[i] = psig.GetTypeHandleThrowing(pOrigModule,
Expand All @@ -1765,18 +1789,7 @@ TypeHandle SigPointer::GetTypeHandleThrowing(
break;
}

// Only have an unmanaged\managed status, and not the unmanaged CALLCONV_ value.
switch (uCallConv & IMAGE_CEE_CS_CALLCONV_MASK)
{
case IMAGE_CEE_CS_CALLCONV_C:
case IMAGE_CEE_CS_CALLCONV_STDCALL:
case IMAGE_CEE_CS_CALLCONV_THISCALL:
case IMAGE_CEE_CS_CALLCONV_FASTCALL:
// Strip the calling convention.
uCallConv &= ~IMAGE_CEE_CS_CALLCONV_MASK;
// Normalize to unmanaged.
uCallConv |= IMAGE_CEE_CS_CALLCONV_UNMANAGED;
}
uCallConv = NormalizeFnPtrCallingConvention(uCallConv);

// Find an existing function pointer or make a new one
thRet = ClassLoader::LoadFnptrTypeThrowing((BYTE) uCallConv, cArgs, retAndArgTypes, fLoadTypes, level);
Expand Down Expand Up @@ -3929,15 +3942,15 @@ MetaSig::CompareElementType(
IfFailThrow(CorSigUncompressElementType_EndPtr(pSig2, pEndSig2, &callingConvention2));

// Calling conventions are generally treated as custom modifiers.
// When callers request calling conventions to be ignored, we also ignore
// calling conventions and this is okay. It is okay because calling conventions,
// when more than one is defined (for example, SuppressGCTransition), all
// become encoded as custom modifiers.
if (!state->IgnoreCustomModifiers
&& callingConvention1 != callingConvention2)
{
// When callers request custom modifiers to be ignored, we also ignore
// specific unmanaged calling conventions and this is okay. It is okay
// because unmanaged calling conventions, when more than one is defined
// (for example, SuppressGCTransition), all become encoded as custom modifiers.
bool callConvMismatch = state->IgnoreCustomModifiers
? NormalizeFnPtrCallingConvention(callingConvention1) != NormalizeFnPtrCallingConvention(callingConvention2)
: callingConvention1 != callingConvention2;
if (callConvMismatch)
return FALSE;
}

DWORD argCnt1;
IfFailThrow(CorSigUncompressData_EndPtr(pSig1, pEndSig1, &argCnt1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class UserDataClass
public const string MethodPointerName = nameof(_Pointer);
public const string MethodCdeclCallConvBitName = nameof(_CdeclCallConvBit);
public const string MethodStdcallCallConvBitName = nameof(_StdcallCallConvBit);
public const string MethodManagedCallConvBitName = nameof(_ManagedCallConvBit);

private static string _F = PrivateStatic;
private string _f;
Expand All @@ -51,10 +52,11 @@ private void _mvv() {}
// Used to validate pointer values.
private static string _Pointer(void* ptr) => "void*";

// Used to validate the embedded callconv bits (non-unmanaged bit) in
// Used to validate the embedded callconv bits in
// ECMA-335 signatures for methods.
private string _CdeclCallConvBit(delegate* unmanaged[Cdecl]<void> fptr) => nameof(CallConvCdecl);
private string _StdcallCallConvBit(delegate* unmanaged[Stdcall]<void> fptr) => nameof(CallConvStdcall);
private string _ManagedCallConvBit(delegate* <void> fptr) => "Managed";
}

[StructLayout(LayoutKind.Sequential)]
Expand Down Expand Up @@ -330,9 +332,9 @@ public static void Verify_PreciseMatchCustomModifier()

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/86040", TestRuntimes.Mono)]
public static void Verify_CallConvBitsAreTreatedAsCustomModifiersAndIgnored()
public static void Verify_UnmanagedCallConvBitAreTreatedAsCustomModifiersAndIgnored()
{
Console.WriteLine($"Running {nameof(Verify_CallConvBitsAreTreatedAsCustomModifiersAndIgnored)}");
Console.WriteLine($"Running {nameof(Verify_UnmanagedCallConvBitAreTreatedAsCustomModifiersAndIgnored)}");

var ud = CallPrivateConstructorClass();
Assert.Equal(nameof(CallConvCdecl), CallCdeclMethod(ud, null));
Expand All @@ -350,6 +352,25 @@ public static void Verify_CallConvBitsAreTreatedAsCustomModifiersAndIgnored()
extern static string CallStdcallMethod(UserDataClass d, delegate* unmanaged[Cdecl]<void> fptr);
}

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/86040", TestRuntimes.Mono)]
public static void Verify_ManagedUnmanagedFunctionPointersDontMatch()
{
Console.WriteLine($"Running {nameof(Verify_ManagedUnmanagedFunctionPointersDontMatch)}");

var ud = CallPrivateConstructorClass();
Assert.Throws<MissingMethodException>(() => CallCdeclMethod(ud, null));
Assert.Throws<MissingMethodException>(() => CallManagedMethod(ud, null));

// Managed calling conventions don't match on unmanaged function pointers
[UnsafeAccessor(UnsafeAccessorKind.Method, Name=UserDataClass.MethodCdeclCallConvBitName)]
extern static string CallCdeclMethod(UserDataClass d, delegate* <void> fptr);

// Unmanaged calling conventions don't match on managed function pointers
[UnsafeAccessor(UnsafeAccessorKind.Method, Name=UserDataClass.MethodManagedCallConvBitName)]
extern static string CallManagedMethod(UserDataClass d, delegate* unmanaged[Cdecl]<void> fptr);
}

[Fact]
[ActiveIssue("https://github.com/dotnet/runtime/issues/86040", TestRuntimes.Mono)]
public static void Verify_InvalidTargetUnsafeAccessor()
Expand Down