Skip to content

Commit

Permalink
Convert GetCurrentMethod to QCALL
Browse files Browse the repository at this point in the history
This has a similar structure to FailFast as converted in dotnet#98908.

Contributes to dotnet#95695
  • Loading branch information
AustinWise committed Mar 16, 2024
1 parent 52eb3ed commit 538144f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -844,11 +844,13 @@ internal static partial Interop.BOOL IsCAVisibleFromDecoratedType(
QCallTypeHandle sourceTypeHandle,
QCallModule sourceModule);

[MethodImpl(MethodImplOptions.InternalCall)]
private static extern IRuntimeMethodInfo? _GetCurrentMethod(ref StackCrawlMark stackMark);
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "RuntimeMethodHandle_GetCurrentMethod")]
private static partial void _GetCurrentMethod(StackCrawlMarkHandle stackMark, ObjectHandleOnStack retMethod);
internal static IRuntimeMethodInfo? GetCurrentMethod(ref StackCrawlMark stackMark)
{
return _GetCurrentMethod(ref stackMark);
object? retMethod = null;
_GetCurrentMethod(new StackCrawlMarkHandle(ref stackMark), ObjectHandleOnStack.Create(ref retMethod));
return (IRuntimeMethodInfo?)retMethod;
}

[MethodImpl(MethodImplOptions.InternalCall)]
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/vm/ecalllist.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ FCFuncStart(gSignatureNative)
FCFuncEnd()

FCFuncStart(gRuntimeMethodHandle)
FCFuncElement("_GetCurrentMethod", RuntimeMethodHandle::GetCurrentMethod)
FCFuncElement("InvokeMethod", RuntimeMethodHandle::InvokeMethod)
FCFuncElement("ReboxFromNullable", RuntimeMethodHandle::ReboxFromNullable)
FCFuncElement("ReboxToNullable", RuntimeMethodHandle::ReboxToNullable)
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/vm/qcallentrypoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ static const Entry s_QCall[] =
DllImportEntry(RuntimeTypeHandle_AllocateTypeAssociatedMemory)
DllImportEntry(RuntimeTypeHandle_RegisterCollectibleTypeDependency)
DllImportEntry(RuntimeMethodHandle_ConstructInstantiation)
DllImportEntry(RuntimeMethodHandle_GetCurrentMethod)
DllImportEntry(RuntimeMethodHandle_GetFunctionPointer)
DllImportEntry(RuntimeMethodHandle_GetIsCollectible)
DllImportEntry(RuntimeMethodHandle_GetMethodInstantiation)
Expand Down
16 changes: 10 additions & 6 deletions src/coreclr/vm/reflectioninvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -890,11 +890,16 @@ static StackWalkAction SkipMethods(CrawlFrame* frame, VOID* data) {
}

// Return the MethodInfo that represents the current method (two above this one)
FCIMPL1(ReflectMethodObject*, RuntimeMethodHandle::GetCurrentMethod, StackCrawlMark* stackMark) {
FCALL_CONTRACT;
extern "C" void QCALLTYPE RuntimeMethodHandle_GetCurrentMethod(QCall::StackCrawlMarkHandle stackMark, QCall::ObjectHandleOnStack retMethod) {

QCALL_CONTRACT;

BEGIN_QCALL;

GCX_COOP();

REFLECTMETHODREF pRet = NULL;

HELPER_METHOD_FRAME_BEGIN_RET_0();
SkipStruct skip;
skip.pStackMark = stackMark;
skip.pMeth = 0;
Expand All @@ -909,11 +914,10 @@ FCIMPL1(ReflectMethodObject*, RuntimeMethodHandle::GetCurrentMethod, StackCrawlM
else
pRet = NULL;

HELPER_METHOD_FRAME_END();
retMethod.Set(pRet);

return (ReflectMethodObject*)OBJECTREFToObject(pRet);
END_QCALL;
}
FCIMPLEND

static OBJECTREF DirectObjectFieldGet(FieldDesc *pField, TypeHandle fieldType, TypeHandle enclosingType, TypedByRef *pTarget, CLR_BOOL *pIsClassInitialized) {
CONTRACTL
Expand Down
5 changes: 3 additions & 2 deletions src/coreclr/vm/runtimehandles.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,6 @@ extern "C" void QCALLTYPE RuntimeTypeHandle_RegisterCollectibleTypeDependency(QC
class RuntimeMethodHandle {

public:
static FCDECL1(ReflectMethodObject*, GetCurrentMethod, StackCrawlMark* stackMark);

static FCDECL4(Object*, InvokeMethod, Object *target, PVOID* args, SignatureNative* pSig, CLR_BOOL fConstructor);

static FCDECL2(Object*, ReboxToNullable, Object *pBoxedValUNSAFE, ReflectClassBaseObject *pDestUNSAFE);
Expand Down Expand Up @@ -275,6 +273,9 @@ class RuntimeMethodHandle {
static FCDECL1(Object*, GetLoaderAllocator, MethodDesc *pMethod);
};


extern "C" void QCALLTYPE RuntimeMethodHandle_GetCurrentMethod(QCall::StackCrawlMarkHandle stackMark, QCall::ObjectHandleOnStack retMethod);

extern "C" BOOL QCALLTYPE RuntimeMethodHandle_IsCAVisibleFromDecoratedType(
QCall::TypeHandle targetTypeHandle,
MethodDesc * pTargetCtor,
Expand Down

0 comments on commit 538144f

Please sign in to comment.