diff --git a/src/coreclr/nativeaot/Runtime/RuntimeInstance.h b/src/coreclr/nativeaot/Runtime/RuntimeInstance.h index e50ddac18dfd40..b8f6b08709cf42 100644 --- a/src/coreclr/nativeaot/Runtime/RuntimeInstance.h +++ b/src/coreclr/nativeaot/Runtime/RuntimeInstance.h @@ -12,6 +12,7 @@ enum GenericVarianceType : uint8_t; #include "forward_declarations.h" #include "ICodeManager.h" +#include "cdacdata.h" extern "C" void PopulateDebugHeaders(); @@ -20,6 +21,7 @@ class RuntimeInstance friend class AsmOffsets; friend class Thread; friend void PopulateDebugHeaders(); + friend struct ::cdac_data; HANDLE m_hPalInstance; // this is the HANDLE passed into DllMain @@ -109,6 +111,13 @@ class RuntimeInstance }; typedef DPTR(RuntimeInstance) PTR_RuntimeInstance; +template<> struct cdac_data +{ + static constexpr size_t OsModuleList = offsetof(RuntimeInstance, m_OsModuleList) + offsetof(SList, m_pHead); + static constexpr size_t TypeManagerList = offsetof(RuntimeInstance, m_TypeManagerList) + offsetof(SList, m_pHead); + static constexpr size_t ManagedCodeStartRange = offsetof(RuntimeInstance, m_pvManagedCodeStartRange); + static constexpr size_t ManagedCodeRangeSize = offsetof(RuntimeInstance, m_cbManagedCodeRange); +}; PTR_RuntimeInstance GetRuntimeInstance(); diff --git a/src/coreclr/nativeaot/Runtime/TypeManager.h b/src/coreclr/nativeaot/Runtime/TypeManager.h index 4429ee4e28cb48..839df96853b609 100644 --- a/src/coreclr/nativeaot/Runtime/TypeManager.h +++ b/src/coreclr/nativeaot/Runtime/TypeManager.h @@ -3,9 +3,12 @@ #pragma once #include "ModuleHeaders.h" #include "ICodeManager.h" +#include "cdacdata.h" class TypeManager { + friend struct ::cdac_data; + // NOTE: Part of this layout is a contract with the managed side in TypeManagerHandle.cs HANDLE m_osModule; ReadyToRunHeader * m_pHeader; @@ -55,3 +58,9 @@ struct TypeManagerHandle TypeManager* AsTypeManager(); }; +template<> struct cdac_data +{ + static constexpr size_t OsModule = offsetof(TypeManager, m_osModule); + static constexpr size_t Header = offsetof(TypeManager, m_pHeader); +}; + diff --git a/src/coreclr/nativeaot/Runtime/datadescriptor/datadescriptor.h b/src/coreclr/nativeaot/Runtime/datadescriptor/datadescriptor.h index 4b5b4e1824f413..985919fb765979 100644 --- a/src/coreclr/nativeaot/Runtime/datadescriptor/datadescriptor.h +++ b/src/coreclr/nativeaot/Runtime/datadescriptor/datadescriptor.h @@ -11,6 +11,7 @@ #include "Pal.h" #include "holder.h" #include "RuntimeInstance.h" +#include "TypeManager.h" #include "regdisplay.h" #include "StackFrameIterator.h" #include "thread.h" @@ -21,6 +22,7 @@ GPTR_DECL(MethodTable, g_pFreeObjectEEType); GPTR_DECL(StressLog, g_pStressLog); +GPTR_DECL(RuntimeInstance, g_pTheRuntimeInstance); // ILC emits a ContractDescriptor named "DotNetManagedContractDescriptor" with // managed type layouts. We take its address so datadescriptor.inc can reference diff --git a/src/coreclr/nativeaot/Runtime/datadescriptor/datadescriptor.inc b/src/coreclr/nativeaot/Runtime/datadescriptor/datadescriptor.inc index 365abce8061d29..9b8d0d69ee2991 100644 --- a/src/coreclr/nativeaot/Runtime/datadescriptor/datadescriptor.inc +++ b/src/coreclr/nativeaot/Runtime/datadescriptor/datadescriptor.inc @@ -38,6 +38,36 @@ CDAC_TYPE_INDETERMINATE(ThreadStore) CDAC_TYPE_FIELD(ThreadStore, T_POINTER, FirstThreadLink, cdac_data::FirstThreadLink) CDAC_TYPE_END(ThreadStore) +// ======================== +// Loader (RuntimeInstance / TypeManager / module entries) +// ======================== + +CDAC_TYPE_BEGIN(RuntimeInstance) +CDAC_TYPE_INDETERMINATE(RuntimeInstance) +CDAC_TYPE_FIELD(RuntimeInstance, T_POINTER, OsModuleList, cdac_data::OsModuleList) +CDAC_TYPE_FIELD(RuntimeInstance, T_POINTER, TypeManagerList, cdac_data::TypeManagerList) +CDAC_TYPE_FIELD(RuntimeInstance, T_POINTER, ManagedCodeStartRange, cdac_data::ManagedCodeStartRange) +CDAC_TYPE_FIELD(RuntimeInstance, T_UINT32, ManagedCodeRangeSize, cdac_data::ManagedCodeRangeSize) +CDAC_TYPE_END(RuntimeInstance) + +CDAC_TYPE_BEGIN(TypeManagerEntry) +CDAC_TYPE_INDETERMINATE(TypeManagerEntry) +CDAC_TYPE_FIELD(TypeManagerEntry, T_POINTER, Next, offsetof(RuntimeInstance::TypeManagerEntry, m_pNext)) +CDAC_TYPE_FIELD(TypeManagerEntry, T_POINTER, TypeManager, offsetof(RuntimeInstance::TypeManagerEntry, m_pTypeManager)) +CDAC_TYPE_END(TypeManagerEntry) + +CDAC_TYPE_BEGIN(OsModuleEntry) +CDAC_TYPE_INDETERMINATE(OsModuleEntry) +CDAC_TYPE_FIELD(OsModuleEntry, T_POINTER, Next, offsetof(RuntimeInstance::OsModuleEntry, m_pNext)) +CDAC_TYPE_FIELD(OsModuleEntry, T_POINTER, OsModule, offsetof(RuntimeInstance::OsModuleEntry, m_osModule)) +CDAC_TYPE_END(OsModuleEntry) + +CDAC_TYPE_BEGIN(TypeManager) +CDAC_TYPE_INDETERMINATE(TypeManager) +CDAC_TYPE_FIELD(TypeManager, T_POINTER, OsModule, cdac_data::OsModule) +CDAC_TYPE_FIELD(TypeManager, T_POINTER, Header, cdac_data::Header) +CDAC_TYPE_END(TypeManager) + // ======================== // Allocation Context // ======================== @@ -94,6 +124,7 @@ CDAC_TYPE_FIELD(StressLog, T_INT32, TotalChunks, offsetof(StressLog, totalChunk) CDAC_TYPE_FIELD(StressLog, T_POINTER, Logs, offsetof(StressLog, logs)) CDAC_TYPE_FIELD(StressLog, T_UINT64, TickFrequency, offsetof(StressLog, tickFrequency)) CDAC_TYPE_FIELD(StressLog, T_UINT64, StartTimestamp, offsetof(StressLog, startTimeStamp)) +CDAC_TYPE_FIELD(StressLog, T_NUINT, ModuleOffset, offsetof(StressLog, moduleOffset)) CDAC_TYPE_END(StressLog) CDAC_TYPE_BEGIN(ThreadStressLog) @@ -136,6 +167,8 @@ CDAC_GLOBALS_BEGIN() CDAC_GLOBAL_POINTER(ThreadStore, &ThreadStore::s_pThreadStore) +CDAC_GLOBAL_POINTER(RuntimeInstance, &g_pTheRuntimeInstance) + CDAC_GLOBAL_POINTER(FreeObjectMethodTable, &g_pFreeObjectEEType) CDAC_GLOBAL_POINTER(GCLowestAddress, &g_lowest_address) @@ -162,9 +195,12 @@ CDAC_GLOBAL(StressLogMaxMessageSize, T_UINT64, (uint64_t)StressMsg::maxMsgSize) // Contracts: declare which contracts this runtime supports CDAC_GLOBAL_CONTRACT(Thread, n1) -CDAC_GLOBAL_CONTRACT(Exception, c1) +CDAC_GLOBAL_CONTRACT(Exception, n1) CDAC_GLOBAL_CONTRACT(RuntimeTypeSystem, n1) CDAC_GLOBAL_CONTRACT(StressLog, c2) +CDAC_GLOBAL_CONTRACT(Loader, n1) +CDAC_GLOBAL_CONTRACT(ExecutionManager, n1) +CDAC_GLOBAL_CONTRACT(Object, n1) // Managed type sub-descriptor: ILC emits a ContractDescriptor with managed type layouts // that the cDAC reader merges as a sub-descriptor. This provides field offsets for managed diff --git a/src/coreclr/nativeaot/Runtime/threadstore.h b/src/coreclr/nativeaot/Runtime/threadstore.h index 5f855dc5b18abd..928f2c8ab4fd86 100644 --- a/src/coreclr/nativeaot/Runtime/threadstore.h +++ b/src/coreclr/nativeaot/Runtime/threadstore.h @@ -74,7 +74,7 @@ typedef DPTR(ThreadStore) PTR_ThreadStore; template<> struct cdac_data { - static constexpr size_t FirstThreadLink = offsetof(ThreadStore, m_ThreadList); + static constexpr size_t FirstThreadLink = offsetof(ThreadStore, m_ThreadList) + offsetof(SList, m_pHead); }; ThreadStore * GetThreadStore(); diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj b/src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj index ffa900b4b08198..bf6295a2001f36 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj @@ -198,7 +198,6 @@ - diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Exception.NativeAot.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Exception.NativeAot.cs index be7b1d2b0da15c..9e8678dd719d6d 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Exception.NativeAot.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Exception.NativeAot.cs @@ -14,6 +14,7 @@ namespace System { + [DataContract] public partial class Exception { public MethodBase? TargetSite @@ -32,15 +33,20 @@ public MethodBase? TargetSite private static string? SerializationWatsonBuckets => null; + [DataContract] internal string? _message; private IDictionary? _data; + [DataContract] private Exception? _innerException; private string? _helpURL; private string? _source; // Mainly used by VB. + [DataContract] private int _HResult; // HResult // To maintain compatibility across runtimes, if this object was deserialized, it will store its stack trace as a string + [DataContract] private string? _stackTraceString; + [DataContract] private string? _remoteStackTraceString; internal IntPtr[] GetStackIPs() @@ -53,7 +59,9 @@ internal IntPtr[] GetStackIPs() return ips; } + [DataContract] private IntPtr[]? _corDbgStackTrace; + [DataContract] private int _idxFirstFreeStackTraceEntry; internal static IntPtr EdiSeparator => (IntPtr)1; // Marks a boundary where an ExceptionDispatchInfo rethrew an exception. diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems index 7e9355d26d52a0..af2e9b739a012a 100644 --- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems +++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems @@ -299,6 +299,7 @@ + diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/Diagnostics/DataContractAttribute.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/DataContractAttribute.cs similarity index 100% rename from src/coreclr/nativeaot/System.Private.CoreLib/src/System/Diagnostics/DataContractAttribute.cs rename to src/libraries/System.Private.CoreLib/src/System/Diagnostics/DataContractAttribute.cs diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs index 5381d2d4418d0c..62faeec7b7506f 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs @@ -111,6 +111,7 @@ public enum TaskStatus /// [DebuggerTypeProxy(typeof(SystemThreadingTasks_TaskDebugView))] [DebuggerDisplay("Id = {Id}, Status = {Status}, Method = {DebuggerDisplayMethodDescription}")] + [DataContract] public class Task : IAsyncResult, IDisposable { [ThreadStatic] @@ -118,14 +119,18 @@ public class Task : IAsyncResult, IDisposable private static int s_taskIdCounter; // static counter used to generate unique task IDs + [DataContract] private int m_taskId; // this task's unique ID. initialized only if it is ever requested // The delegate to invoke for a delegate-backed Task. // This field also may be used by async state machines to cache an Action. + [DataContract] internal Delegate? m_action; + [DataContract] private protected object? m_stateObject; // A state object that can be optionally supplied, passed to action. internal TaskScheduler? m_taskScheduler; // The task scheduler this task runs under. + [DataContract] internal volatile int m_stateFlags; // SOS DumpAsync command depends on this name private Task? ParentForDebugger => m_contingentProperties?.m_parent; // Private property used by a debugger to access this Task's parent @@ -164,6 +169,7 @@ internal enum TaskStateFlags // Can be null, a single continuation, a list of continuations, or s_taskCompletionSentinel, // in that order. The logic arround this object assumes it will never regress to a previous state. + [DataContract] private volatile object? m_continuationObject; // SOS DumpAsync command depends on this name // m_continuationObject is set to this when the task completes.