diff options
author | Jan Kotas <jkotas@microsoft.com> | 2017-05-22 07:39:31 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-22 07:39:31 +0300 |
commit | 3075191e58a0543d8ef3cd42da97e268da3d5741 (patch) | |
tree | 83da5ba5a7de511a15ad6e6bb7a1c6cda2b3bee1 /src | |
parent | a80c986dd46eb4ccaa05310d10c606570900b944 (diff) | |
parent | 8f97aa5874ca56d1bff719f0271067dbe3c8e6b7 (diff) |
Merge pull request #3668 from dotnet/nmirror
Merge nmirror to master
Diffstat (limited to 'src')
8 files changed, 112 insertions, 21 deletions
diff --git a/src/Native/Runtime/DebuggerHook.cpp b/src/Native/Runtime/DebuggerHook.cpp index 26ca90497..08da25213 100644 --- a/src/Native/Runtime/DebuggerHook.cpp +++ b/src/Native/Runtime/DebuggerHook.cpp @@ -4,6 +4,7 @@ #include "common.h" #include "CommonTypes.h" +#include "CommonMacros.h" #include "DebuggerHook.h" #include "DebugEventSource.h" #include "Debug.h" @@ -14,6 +15,10 @@ GVAL_IMPL_INIT(UInt32, g_numGcProtectionRequests, 0); /* static */ DebuggerProtectedBufferList* DebuggerHook::s_debuggerProtectedBuffers = nullptr; +/* static */ DebuggerOwnedHandleList* DebuggerHook::s_debuggerOwnedHandleList = nullptr; + +/* static */ UInt32 DebuggerHook::s_debuggeeInitiatedHandleIdentifier = 2; + /* static */ void DebuggerHook::OnBeforeGcCollection() { if (g_numGcProtectionRequests > 0) @@ -109,4 +114,27 @@ GVAL_IMPL_INIT(UInt32, g_numGcProtectionRequests, 0); } } +/* static */ UInt32 DebuggerHook::RecordDebuggeeInitiatedHandle(void* objectHandle) +{ + DebuggerOwnedHandleList* head = new (nothrow) DebuggerOwnedHandleList(); + if (head == nullptr) + { + return 0; + } + + head->handle = objectHandle; + head->identifier = DebuggerHook::s_debuggeeInitiatedHandleIdentifier; + head->next = s_debuggerOwnedHandleList; + s_debuggerOwnedHandleList = head; + + s_debuggeeInitiatedHandleIdentifier += 2; + + return head->identifier; +} + +EXTERN_C REDHAWK_API UInt32 __cdecl RhpRecordDebuggeeInitiatedHandle(void* objectHandle) +{ + return DebuggerHook::RecordDebuggeeInitiatedHandle(objectHandle); +} + #endif // !DACCESS_COMPILE
\ No newline at end of file diff --git a/src/Native/Runtime/DebuggerHook.h b/src/Native/Runtime/DebuggerHook.h index feb1d3e24..bc6c87ded 100644 --- a/src/Native/Runtime/DebuggerHook.h +++ b/src/Native/Runtime/DebuggerHook.h @@ -25,11 +25,21 @@ struct DebuggerProtectedBufferList struct DebuggerProtectedBufferList* next; }; +struct DebuggerOwnedHandleList +{ + void* handle; + UInt32 identifier; + struct DebuggerOwnedHandleList* next; +}; + class DebuggerHook { public: static void OnBeforeGcCollection(); + static UInt32 RecordDebuggeeInitiatedHandle(void* handle); static DebuggerProtectedBufferList* s_debuggerProtectedBuffers; + static DebuggerOwnedHandleList* s_debuggerOwnedHandleList; + static UInt32 s_debuggeeInitiatedHandleIdentifier; }; #endif //!DACCESS_COMPILE diff --git a/src/System.Private.CoreLib/src/Internal/Runtime/Augments/RuntimeAugments.cs b/src/System.Private.CoreLib/src/Internal/Runtime/Augments/RuntimeAugments.cs index ce2131230..63f21775c 100644 --- a/src/System.Private.CoreLib/src/Internal/Runtime/Augments/RuntimeAugments.cs +++ b/src/System.Private.CoreLib/src/Internal/Runtime/Augments/RuntimeAugments.cs @@ -1054,6 +1054,53 @@ namespace Internal.Runtime.Augments { return typeHandle.LastResortToString; } + + public static void RhpSetHighLevelDebugFuncEvalHelper(IntPtr highLevelDebugFuncEvalHelper) + { + RuntimeImports.RhpSetHighLevelDebugFuncEvalHelper(highLevelDebugFuncEvalHelper); + } + + public static void RhpSendCustomEventToDebugger(IntPtr payload, int length) + { + RuntimeImports.RhpSendCustomEventToDebugger(payload, length); + } + + public static IntPtr RhpGetFuncEvalTargetAddress() + { + return RuntimeImports.RhpGetFuncEvalTargetAddress(); + } + + [CLSCompliant(false)] + public static uint RhpGetFuncEvalParameterBufferSize() + { + return RuntimeImports.RhpGetFuncEvalParameterBufferSize(); + } + + [CLSCompliant(false)] + public static unsafe uint RhpRecordDebuggeeInitiatedHandle(IntPtr objectHandle) + { + return RuntimeImports.RhpRecordDebuggeeInitiatedHandle((void*)objectHandle); + } + + public static unsafe object RhBoxAny(IntPtr pData, IntPtr pEEType) + { + return RuntimeImports.RhBoxAny((void*)pData, new EETypePtr(pEEType)); + } + + public static IntPtr RhHandleAlloc(Object value, GCHandleType type) + { + return RuntimeImports.RhHandleAlloc(value, type); + } + + public static void RhHandleFree(IntPtr handle) + { + RuntimeImports.RhHandleFree(handle); + } + + public static IntPtr RhGetOSModuleForMrt() + { + return RuntimeImports.RhGetOSModuleForMrt(); + } } } diff --git a/src/System.Private.CoreLib/src/MembersMustExist.AnalyzerData b/src/System.Private.CoreLib/src/MembersMustExist.AnalyzerData index c798ffe66..e321c569a 100644 --- a/src/System.Private.CoreLib/src/MembersMustExist.AnalyzerData +++ b/src/System.Private.CoreLib/src/MembersMustExist.AnalyzerData @@ -120,11 +120,11 @@ internal static extern System.IntPtr System.Runtime.RuntimeImports.RhGetRuntimeH internal static extern System.IntPtr System.Runtime.RuntimeImports.RhGetThreadLocalStorageForDynamicType(int index, int tlsStorageSize, int numTlsCells) internal static extern byte* System.Runtime.RuntimeImports.RhGetThreadStaticFieldAddress(System.EETypePtr pEEType, System.IntPtr fieldCookie) internal static extern System.IntPtr System.Runtime.RuntimeImports.RhGetUniversalTransitionThunk() -public static System.IntPtr System.Runtime.RuntimeImports.RhHandleAlloc(object value, System.Runtime.InteropServices.GCHandleType type) +internal static System.IntPtr System.Runtime.RuntimeImports.RhHandleAlloc(object value, System.Runtime.InteropServices.GCHandleType type) internal static System.IntPtr System.Runtime.RuntimeImports.RhHandleAllocDependent(object primary, object secondary) internal static System.IntPtr System.Runtime.RuntimeImports.RhHandleAllocVariable(object value, uint type) internal static extern uint System.Runtime.RuntimeImports.RhHandleCompareExchangeVariableType(System.IntPtr handle, uint oldType, uint newType) -public static extern void System.Runtime.RuntimeImports.RhHandleFree(System.IntPtr handle) +internal static extern void System.Runtime.RuntimeImports.RhHandleFree(System.IntPtr handle) internal static extern object System.Runtime.RuntimeImports.RhHandleGet(System.IntPtr handle) internal static extern object System.Runtime.RuntimeImports.RhHandleGetDependent(System.IntPtr handle, out object secondary) internal static extern uint System.Runtime.RuntimeImports.RhHandleGetVariableType(System.IntPtr handle) diff --git a/src/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs b/src/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs index 330580c99..4a9c71d98 100644 --- a/src/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs +++ b/src/System.Private.CoreLib/src/System/Runtime/RuntimeImports.cs @@ -31,18 +31,20 @@ namespace System.Runtime [MethodImpl(MethodImplOptions.InternalCall)] [RuntimeImport(RuntimeLibrary, "RhpSetHighLevelDebugFuncEvalHelper")] - public static extern void RhpSetHighLevelDebugFuncEvalHelper(IntPtr highLevelDebugFuncEvalHelper); + internal static extern void RhpSetHighLevelDebugFuncEvalHelper(IntPtr highLevelDebugFuncEvalHelper); [MethodImpl(MethodImplOptions.InternalCall)] [RuntimeImport(RuntimeLibrary, "RhpSendCustomEventToDebugger")] - public static extern void RhpSendCustomEventToDebugger(IntPtr payload, int length); + internal static extern void RhpSendCustomEventToDebugger(IntPtr payload, int length); [DllImport(RuntimeLibrary, ExactSpelling = true)] - public static extern IntPtr RhpGetFuncEvalTargetAddress(); + internal static extern IntPtr RhpGetFuncEvalTargetAddress(); [DllImport(RuntimeLibrary, ExactSpelling = true)] - [CLSCompliant(false)] - public static extern uint RhpGetFuncEvalParameterBufferSize(); + internal static extern uint RhpGetFuncEvalParameterBufferSize(); + + [DllImport(RuntimeLibrary, ExactSpelling = true)] + internal static extern unsafe uint RhpRecordDebuggeeInitiatedHandle(void* objectHandle); // // calls to GC @@ -187,7 +189,7 @@ namespace System.Runtime [RuntimeImport(RuntimeLibrary, "RhpHandleAlloc")] private static extern IntPtr RhpHandleAlloc(Object value, GCHandleType type); - public static IntPtr RhHandleAlloc(Object value, GCHandleType type) + internal static IntPtr RhHandleAlloc(Object value, GCHandleType type) { IntPtr h = RhpHandleAlloc(value, type); if (h == IntPtr.Zero) @@ -224,7 +226,7 @@ namespace System.Runtime // Free handle. [MethodImpl(MethodImplOptions.InternalCall)] [RuntimeImport(RuntimeLibrary, "RhHandleFree")] - public static extern void RhHandleFree(IntPtr handle); + internal static extern void RhHandleFree(IntPtr handle); // Get object reference from handle. [MethodImpl(MethodImplOptions.InternalCall)] @@ -298,7 +300,7 @@ namespace System.Runtime // [MethodImpl(MethodImplOptions.InternalCall)] [RuntimeImport(RuntimeLibrary, "RhBoxAny")] - public static extern unsafe object RhBoxAny(IntPtr pData, IntPtr pEEType); + internal static extern unsafe object RhBoxAny(void* pData, EETypePtr pEEType); [MethodImpl(MethodImplOptions.InternalCall)] [RuntimeImport(RuntimeLibrary, "RhNewObject")] @@ -540,7 +542,7 @@ namespace System.Runtime [MethodImplAttribute(MethodImplOptions.InternalCall)] [RuntimeImport(RuntimeLibrary, "RhGetOSModuleForMrt")] - public static extern IntPtr RhGetOSModuleForMrt(); + internal static extern IntPtr RhGetOSModuleForMrt(); [MethodImplAttribute(MethodImplOptions.InternalCall)] [RuntimeImport(RuntimeLibrary, "RhGetThreadStaticFieldAddress")] diff --git a/src/System.Private.Jit/src/Internal/Runtime/JitSupport/RyuJitExecutionStrategy.cs b/src/System.Private.Jit/src/Internal/Runtime/JitSupport/RyuJitExecutionStrategy.cs index 078258ef8..e67b3b8c4 100644 --- a/src/System.Private.Jit/src/Internal/Runtime/JitSupport/RyuJitExecutionStrategy.cs +++ b/src/System.Private.Jit/src/Internal/Runtime/JitSupport/RyuJitExecutionStrategy.cs @@ -8,6 +8,7 @@ using System.Collections.Generic; using System.Runtime.InteropServices; using Internal.JitInterface; +using Internal.Runtime.Augments; using Internal.Runtime.TypeLoader; using Internal.TypeSystem; @@ -62,7 +63,7 @@ namespace Internal.Runtime.JitSupport { if (_corInfoImpl == null) { - InitJitCodeManager(RuntimeImports.RhGetOSModuleForMrt ()); + InitJitCodeManager(RuntimeAugments.RhGetOSModuleForMrt ()); // TODO: Recycle jit interface object and TypeSystemContext _context = TypeSystemContextFactory.Create(); diff --git a/src/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/DebugFuncEval.cs b/src/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/DebugFuncEval.cs index 1e6790327..d3d1162be 100644 --- a/src/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/DebugFuncEval.cs +++ b/src/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/DebugFuncEval.cs @@ -8,6 +8,7 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using Internal.NativeFormat; +using Internal.Runtime.Augments; using Internal.Runtime.CallInterceptor; using Internal.Runtime.CompilerServices; using Internal.TypeSystem; @@ -31,7 +32,7 @@ namespace Internal.Runtime.TypeLoader } // Obtain the target method address from the runtime - IntPtr targetAddress = RuntimeImports.RhpGetFuncEvalTargetAddress(); + IntPtr targetAddress = RuntimeAugments.RhpGetFuncEvalTargetAddress(); LocalVariableType[] returnAndArgumentTypes = new LocalVariableType[param.types.Length]; for (int i = 0; i < returnAndArgumentTypes.Length; i++) @@ -49,15 +50,17 @@ namespace Internal.Runtime.TypeLoader { // Box the return IntPtr input = arguments.GetAddressOfVarData(0); - object returnValue = RuntimeImports.RhBoxAny(input, (IntPtr)param.types[0].ToEETypePtr()); + object returnValue = RuntimeAugments.RhBoxAny(input, (IntPtr)param.types[0].ToEETypePtr()); GCHandle returnValueHandle = GCHandle.Alloc(returnValue); + IntPtr returnValueHandlePointer = GCHandle.ToIntPtr(returnValueHandle); + uint identifier = RuntimeAugments.RhpRecordDebuggeeInitiatedHandle(returnValueHandlePointer); // Signal to the debugger the func eval completes FuncEvalCompleteCommand* funcEvalCompleteCommand = stackalloc FuncEvalCompleteCommand[1]; funcEvalCompleteCommand->commandCode = 0; - funcEvalCompleteCommand->returnAddress = (long)GCHandle.ToIntPtr(returnValueHandle); + funcEvalCompleteCommand->returnAddress = (long)returnValueHandlePointer; IntPtr funcEvalCompleteCommandPointer = new IntPtr(funcEvalCompleteCommand); - RuntimeImports.RhpSendCustomEventToDebugger(funcEvalCompleteCommandPointer, Unsafe.SizeOf<FuncEvalCompleteCommand>()); + RuntimeAugments.RhpSendCustomEventToDebugger(funcEvalCompleteCommandPointer, Unsafe.SizeOf<FuncEvalCompleteCommand>()); } // debugger magic will make sure this function never returns, instead control will be transferred back to the point where the FuncEval begins @@ -94,7 +97,7 @@ namespace Internal.Runtime.TypeLoader private static void HighLevelDebugFuncEvalHelper() { - uint parameterBufferSize = RuntimeImports.RhpGetFuncEvalParameterBufferSize(); + uint parameterBufferSize = RuntimeAugments.RhpGetFuncEvalParameterBufferSize(); IntPtr writeParameterCommandPointer; IntPtr debuggerBufferPointer; @@ -111,7 +114,7 @@ namespace Internal.Runtime.TypeLoader writeParameterCommandPointer = new IntPtr(&writeParameterCommand); - RuntimeImports.RhpSendCustomEventToDebugger(writeParameterCommandPointer, Unsafe.SizeOf<WriteParameterCommand>()); + RuntimeAugments.RhpSendCustomEventToDebugger(writeParameterCommandPointer, Unsafe.SizeOf<WriteParameterCommand>()); // .. debugger magic ... the debuggerBuffer will be filled with parameter data @@ -198,7 +201,7 @@ namespace Internal.Runtime.TypeLoader public static void Initialize() { // We needed this function only because the McgIntrinsics attribute cannot be applied on the static constructor - RuntimeImports.RhpSetHighLevelDebugFuncEvalHelper(AddrofIntrinsics.AddrOf<Action>(HighLevelDebugFuncEvalHelper)); + RuntimeAugments.RhpSetHighLevelDebugFuncEvalHelper(AddrofIntrinsics.AddrOf<Action>(HighLevelDebugFuncEvalHelper)); } } } diff --git a/src/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/EETypeCreator.cs b/src/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/EETypeCreator.cs index 5fe35d570..5ca8d36b0 100644 --- a/src/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/EETypeCreator.cs +++ b/src/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/EETypeCreator.cs @@ -626,7 +626,7 @@ namespace Internal.Runtime.TypeLoader { // CoreRT Abi uses managed heap-allocated GC statics object obj = RuntimeAugments.NewObject(((EEType*)state.GcStaticEEType)->ToRuntimeTypeHandle()); - gcStaticData = RuntimeImports.RhHandleAlloc(obj, GCHandleType.Normal); + gcStaticData = RuntimeAugments.RhHandleAlloc(obj, GCHandleType.Normal); // CoreRT references statics through an extra level of indirection (a table in the image). gcStaticsIndirection = MemoryHelpers.AllocateMemory(IntPtr.Size); @@ -708,7 +708,7 @@ namespace Internal.Runtime.TypeLoader if (state.AllocatedThreadStaticGCDesc) MemoryHelpers.FreeMemory(state.ThreadStaticDesc); if (gcStaticData != IntPtr.Zero) - RuntimeImports.RhHandleFree(gcStaticData); + RuntimeAugments.RhHandleFree(gcStaticData); if (gcStaticsIndirection != IntPtr.Zero) MemoryHelpers.FreeMemory(gcStaticsIndirection); } |