From bb2c01dcccecb1d962a0f27916615b7ec1d5d05b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 13 Apr 2026 04:37:21 +0000 Subject: [PATCH 1/7] Implement DacDbi code version node APIs Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/449a6821-0eb8-4352-815e-7c870d2edaa0 Co-authored-by: rcj1 <77995559+rcj1@users.noreply.github.com> --- .../Dbi/DacDbiImpl.cs | 133 +++++++++++++++++- 1 file changed, 130 insertions(+), 3 deletions(-) diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/DacDbiImpl.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/DacDbiImpl.cs index a480fe86b576b4..eb107f9841ea4a 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/DacDbiImpl.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/DacDbiImpl.cs @@ -1199,13 +1199,140 @@ public int GetMDStructuresVersion(uint* pMDStructuresVersion) } public int GetActiveRejitILCodeVersionNode(ulong vmModule, uint methodTk, ulong* pVmILCodeVersionNode) - => LegacyFallbackHelper.CanFallback() && _legacy is not null ? _legacy.GetActiveRejitILCodeVersionNode(vmModule, methodTk, pVmILCodeVersionNode) : HResults.E_NOTIMPL; + { + int hr = HResults.S_OK; + try + { + if (pVmILCodeVersionNode is null) + throw new ArgumentException("Output pointer cannot be null.", nameof(pVmILCodeVersionNode)); + + *pVmILCodeVersionNode = 0; + + ILoader loader = _target.Contracts.Loader; + Contracts.ModuleHandle module = loader.GetModuleHandleFromModulePtr(new TargetPointer(vmModule)); + ModuleLookupTables lookupTables = loader.GetLookupTables(module); + TargetPointer methodDesc = loader.GetModuleLookupMapElement(lookupTables.MethodDefToDesc, methodTk, out _); + if (methodDesc != TargetPointer.Null) + { + ICodeVersions codeVersions = _target.Contracts.CodeVersions; + ILCodeVersionHandle ilCodeVersion = codeVersions.GetActiveILCodeVersion(methodDesc); + if (ilCodeVersion.IsValid && ilCodeVersion.IsExplicit && _target.Contracts.TryGetContract(out IReJIT rejit) && rejit.GetRejitState(ilCodeVersion) == RejitState.Active) + { + *pVmILCodeVersionNode = ilCodeVersion.ILCodeVersionNode.Value; + } + } + } + catch (System.Exception ex) + { + hr = ex.HResult; + } + +#if DEBUG + if (_legacy is not null) + { + ulong resultLocal; + int hrLocal = _legacy.GetActiveRejitILCodeVersionNode(vmModule, methodTk, &resultLocal); + Debug.ValidateHResult(hr, hrLocal); + if (hr == HResults.S_OK) + Debug.Assert(*pVmILCodeVersionNode == resultLocal, $"cDAC: {*pVmILCodeVersionNode:x}, DAC: {resultLocal:x}"); + } +#endif + + return hr; + } public int GetNativeCodeVersionNode(ulong vmMethod, ulong codeStartAddress, ulong* pVmNativeCodeVersionNode) - => LegacyFallbackHelper.CanFallback() && _legacy is not null ? _legacy.GetNativeCodeVersionNode(vmMethod, codeStartAddress, pVmNativeCodeVersionNode) : HResults.E_NOTIMPL; + { + int hr = HResults.S_OK; + try + { + if (pVmNativeCodeVersionNode is null) + throw new ArgumentException("Output pointer cannot be null.", nameof(pVmNativeCodeVersionNode)); + + *pVmNativeCodeVersionNode = 0; + + TargetPointer methodDesc = new TargetPointer(vmMethod); + TargetCodePointer codeAddress = new TargetCodePointer(codeStartAddress); + ICodeVersions codeVersions = _target.Contracts.CodeVersions; + bool foundMatch = false; + + foreach (ILCodeVersionHandle ilCodeVersion in codeVersions.GetILCodeVersions(methodDesc)) + { + foreach (NativeCodeVersionHandle nativeCodeVersion in codeVersions.GetNativeCodeVersions(methodDesc, ilCodeVersion)) + { + if (codeVersions.GetNativeCode(nativeCodeVersion) == codeAddress) + { + if (nativeCodeVersion.IsExplicit) + { + *pVmNativeCodeVersionNode = nativeCodeVersion.CodeVersionNodeAddress.Value; + } + + foundMatch = true; + break; + } + } + + if (foundMatch) + { + break; + } + } + } + catch (System.Exception ex) + { + hr = ex.HResult; + } + +#if DEBUG + if (_legacy is not null) + { + ulong resultLocal; + int hrLocal = _legacy.GetNativeCodeVersionNode(vmMethod, codeStartAddress, &resultLocal); + Debug.ValidateHResult(hr, hrLocal); + if (hr == HResults.S_OK) + Debug.Assert(*pVmNativeCodeVersionNode == resultLocal, $"cDAC: {*pVmNativeCodeVersionNode:x}, DAC: {resultLocal:x}"); + } +#endif + + return hr; + } public int GetILCodeVersionNode(ulong vmNativeCodeVersionNode, ulong* pVmILCodeVersionNode) - => LegacyFallbackHelper.CanFallback() && _legacy is not null ? _legacy.GetILCodeVersionNode(vmNativeCodeVersionNode, pVmILCodeVersionNode) : HResults.E_NOTIMPL; + { + int hr = HResults.S_OK; + try + { + if (pVmILCodeVersionNode is null) + throw new ArgumentException("Output pointer cannot be null.", nameof(pVmILCodeVersionNode)); + + *pVmILCodeVersionNode = 0; + + ICodeVersions codeVersions = _target.Contracts.CodeVersions; + NativeCodeVersionHandle nativeCodeVersion = NativeCodeVersionHandle.CreateExplicit(new TargetPointer(vmNativeCodeVersionNode)); + ILCodeVersionHandle ilCodeVersion = codeVersions.GetILCodeVersion(nativeCodeVersion); + if (ilCodeVersion.IsValid && ilCodeVersion.IsExplicit) + { + *pVmILCodeVersionNode = ilCodeVersion.ILCodeVersionNode.Value; + } + } + catch (System.Exception ex) + { + hr = ex.HResult; + } + +#if DEBUG + if (_legacy is not null) + { + ulong resultLocal; + int hrLocal = _legacy.GetILCodeVersionNode(vmNativeCodeVersionNode, &resultLocal); + Debug.ValidateHResult(hr, hrLocal); + if (hr == HResults.S_OK) + Debug.Assert(*pVmILCodeVersionNode == resultLocal, $"cDAC: {*pVmILCodeVersionNode:x}, DAC: {resultLocal:x}"); + } +#endif + + return hr; + } public int GetILCodeVersionNodeData(ulong ilCodeVersionNode, DacDbiSharedReJitInfo* pData) => LegacyFallbackHelper.CanFallback() && _legacy is not null ? _legacy.GetILCodeVersionNodeData(ilCodeVersionNode, pData) : HResults.E_NOTIMPL; From c3de1dc76d6bc05020ba00dc21526d4627eccea6 Mon Sep 17 00:00:00 2001 From: rcj1 Date: Fri, 17 Apr 2026 16:14:04 -0700 Subject: [PATCH 2/7] copilot comment --- .../Dbi/DacDbiImpl.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/DacDbiImpl.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/DacDbiImpl.cs index eb107f9841ea4a..02ccf464d6afe2 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/DacDbiImpl.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/DacDbiImpl.cs @@ -1211,7 +1211,15 @@ public int GetActiveRejitILCodeVersionNode(ulong vmModule, uint methodTk, ulong* ILoader loader = _target.Contracts.Loader; Contracts.ModuleHandle module = loader.GetModuleHandleFromModulePtr(new TargetPointer(vmModule)); ModuleLookupTables lookupTables = loader.GetLookupTables(module); - TargetPointer methodDesc = loader.GetModuleLookupMapElement(lookupTables.MethodDefToDesc, methodTk, out _); + TargetPointer methodDesc = TargetPointer.Null; + try + { + methodDesc = loader.GetModuleLookupMapElement(lookupTables.MethodDefToDesc, methodTk, out _); + } + catch (ArgumentOutOfRangeException) + { + // Invalid method token + } if (methodDesc != TargetPointer.Null) { ICodeVersions codeVersions = _target.Contracts.CodeVersions; From 3b36f4dc4a2fe8948af958dd7c9e58a35e8a6e6b Mon Sep 17 00:00:00 2001 From: rcj1 Date: Tue, 21 Apr 2026 10:01:21 -0700 Subject: [PATCH 3/7] code review --- docs/design/datacontracts/CodeVersions.md | 16 +++++++++++++ .../Contracts/ICodeVersions.cs | 1 + .../Contracts/CodeVersions_1.cs | 8 +++++++ .../Dbi/DacDbiImpl.cs | 23 +++---------------- 4 files changed, 28 insertions(+), 20 deletions(-) diff --git a/docs/design/datacontracts/CodeVersions.md b/docs/design/datacontracts/CodeVersions.md index 6961f63478faa7..71943a91f7458a 100644 --- a/docs/design/datacontracts/CodeVersions.md +++ b/docs/design/datacontracts/CodeVersions.md @@ -34,6 +34,8 @@ public virtual IEnumerable GetILCodeVersions(TargetPointer public virtual IEnumerable GetNativeCodeVersions(TargetPointer methodDesc, ILCodeVersionHandle ilCodeVersionHandle); // Return a handle to the version of the native code that includes the given instruction pointer public virtual NativeCodeVersionHandle GetNativeCodeVersionForIP(TargetCodePointer ip); +// Return a handle to the native code version for a specific method descriptor and code start address +public virtual NativeCodeVersionHandle GetSpecificNativeCodeVersion(TargetPointer methodDesc, TargetCodePointer codeAddress); // Return a handle to the active version of the native code for a given method descriptor and IL code version. The IL code version and method descriptor must represent the same method public virtual NativeCodeVersionHandle GetActiveNativeCodeVersionForILCodeVersion(TargetPointer methodDesc, ILCodeVersionHandle ilCodeVersionHandle); @@ -322,6 +324,20 @@ IEnumerable ICodeVersions.GetNativeCodeVersions(TargetP } ``` +### Finding the native code version for a specific method descriptor and code start address + +Given a method descriptor and code start address, find the corresponding native code version. +If the method's first native code matches the given address, the synthetic native code version is returned. +Otherwise, searches the explicit native code version nodes for a match. + +```csharp +NativeCodeVersionHandle ICodeVersions.GetSpecificNativeCodeVersion(TargetPointer methodDesc, TargetCodePointer codeAddress) +{ + IRuntimeTypeSystem rts = _target.Contracts.RuntimeTypeSystem; + MethodDescHandle md = rts.GetMethodDescHandle(methodDesc); + return GetSpecificNativeCodeVersion(md, codeAddress); +} +``` ### Finding the active native code version of an ILCodeVersion for a method descriptor ```csharp diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/ICodeVersions.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/ICodeVersions.cs index 8b31a943fe2a03..77db2d443e91f9 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/ICodeVersions.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/ICodeVersions.cs @@ -19,6 +19,7 @@ public interface ICodeVersions : IContract public virtual IEnumerable GetNativeCodeVersions(TargetPointer methodDesc, ILCodeVersionHandle ilCodeVersionHandle) => throw new NotImplementedException(); public virtual NativeCodeVersionHandle GetNativeCodeVersionForIP(TargetCodePointer ip) => throw new NotImplementedException(); + public virtual NativeCodeVersionHandle GetSpecificNativeCodeVersion(TargetPointer methodDesc, TargetCodePointer codeAddress) => throw new NotImplementedException(); public virtual NativeCodeVersionHandle GetActiveNativeCodeVersionForILCodeVersion(TargetPointer methodDesc, ILCodeVersionHandle ilCodeVersionHandle) => throw new NotImplementedException(); diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/CodeVersions_1.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/CodeVersions_1.cs index 1856cdef05606e..bc2e3d7c996688 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/CodeVersions_1.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/CodeVersions_1.cs @@ -143,6 +143,14 @@ NativeCodeVersionHandle ICodeVersions.GetNativeCodeVersionForIP(TargetCodePointe } } + NativeCodeVersionHandle ICodeVersions.GetSpecificNativeCodeVersion(TargetPointer methodDesc, TargetCodePointer codeAddress) + { + IRuntimeTypeSystem rts = _target.Contracts.RuntimeTypeSystem; + MethodDescHandle md = rts.GetMethodDescHandle(methodDesc); + + return GetSpecificNativeCodeVersion(rts, md, codeAddress); + } + bool ICodeVersions.CodeVersionManagerSupportsMethod(TargetPointer methodDescAddress) { IRuntimeTypeSystem rts = _target.Contracts.RuntimeTypeSystem; diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/DacDbiImpl.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/DacDbiImpl.cs index 02ccf464d6afe2..7b388a9e95b4d2 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/DacDbiImpl.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/DacDbiImpl.cs @@ -1262,28 +1262,11 @@ public int GetNativeCodeVersionNode(ulong vmMethod, ulong codeStartAddress, ulon TargetPointer methodDesc = new TargetPointer(vmMethod); TargetCodePointer codeAddress = new TargetCodePointer(codeStartAddress); ICodeVersions codeVersions = _target.Contracts.CodeVersions; - bool foundMatch = false; - foreach (ILCodeVersionHandle ilCodeVersion in codeVersions.GetILCodeVersions(methodDesc)) + NativeCodeVersionHandle nativeCodeVersion = codeVersions.GetSpecificNativeCodeVersion(methodDesc, codeAddress); + if (nativeCodeVersion.Valid && nativeCodeVersion.IsExplicit) { - foreach (NativeCodeVersionHandle nativeCodeVersion in codeVersions.GetNativeCodeVersions(methodDesc, ilCodeVersion)) - { - if (codeVersions.GetNativeCode(nativeCodeVersion) == codeAddress) - { - if (nativeCodeVersion.IsExplicit) - { - *pVmNativeCodeVersionNode = nativeCodeVersion.CodeVersionNodeAddress.Value; - } - - foundMatch = true; - break; - } - } - - if (foundMatch) - { - break; - } + *pVmNativeCodeVersionNode = nativeCodeVersion.CodeVersionNodeAddress.Value; } } catch (System.Exception ex) From 68ab63275b66b1557d66834eadedc727e4d0e614 Mon Sep 17 00:00:00 2001 From: rcj1 Date: Mon, 27 Apr 2026 11:10:21 -0700 Subject: [PATCH 4/7] code review --- .../Contracts/ICodeVersions.cs | 1 - .../Contracts/CodeVersions_1.cs | 8 -------- .../Dbi/DacDbiImpl.cs | 10 +++++++--- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/ICodeVersions.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/ICodeVersions.cs index 77db2d443e91f9..8b31a943fe2a03 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/ICodeVersions.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/ICodeVersions.cs @@ -19,7 +19,6 @@ public interface ICodeVersions : IContract public virtual IEnumerable GetNativeCodeVersions(TargetPointer methodDesc, ILCodeVersionHandle ilCodeVersionHandle) => throw new NotImplementedException(); public virtual NativeCodeVersionHandle GetNativeCodeVersionForIP(TargetCodePointer ip) => throw new NotImplementedException(); - public virtual NativeCodeVersionHandle GetSpecificNativeCodeVersion(TargetPointer methodDesc, TargetCodePointer codeAddress) => throw new NotImplementedException(); public virtual NativeCodeVersionHandle GetActiveNativeCodeVersionForILCodeVersion(TargetPointer methodDesc, ILCodeVersionHandle ilCodeVersionHandle) => throw new NotImplementedException(); diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/CodeVersions_1.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/CodeVersions_1.cs index bc2e3d7c996688..1856cdef05606e 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/CodeVersions_1.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/CodeVersions_1.cs @@ -143,14 +143,6 @@ NativeCodeVersionHandle ICodeVersions.GetNativeCodeVersionForIP(TargetCodePointe } } - NativeCodeVersionHandle ICodeVersions.GetSpecificNativeCodeVersion(TargetPointer methodDesc, TargetCodePointer codeAddress) - { - IRuntimeTypeSystem rts = _target.Contracts.RuntimeTypeSystem; - MethodDescHandle md = rts.GetMethodDescHandle(methodDesc); - - return GetSpecificNativeCodeVersion(rts, md, codeAddress); - } - bool ICodeVersions.CodeVersionManagerSupportsMethod(TargetPointer methodDescAddress) { IRuntimeTypeSystem rts = _target.Contracts.RuntimeTypeSystem; diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/DacDbiImpl.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/DacDbiImpl.cs index 7b388a9e95b4d2..dbc02d38e702a0 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/DacDbiImpl.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/DacDbiImpl.cs @@ -1208,6 +1208,9 @@ public int GetActiveRejitILCodeVersionNode(ulong vmModule, uint methodTk, ulong* *pVmILCodeVersionNode = 0; + if (!_target.Contracts.TryGetContract(out IReJIT rejit)) + return hr; + ILoader loader = _target.Contracts.Loader; Contracts.ModuleHandle module = loader.GetModuleHandleFromModulePtr(new TargetPointer(vmModule)); ModuleLookupTables lookupTables = loader.GetLookupTables(module); @@ -1224,7 +1227,9 @@ public int GetActiveRejitILCodeVersionNode(ulong vmModule, uint methodTk, ulong* { ICodeVersions codeVersions = _target.Contracts.CodeVersions; ILCodeVersionHandle ilCodeVersion = codeVersions.GetActiveILCodeVersion(methodDesc); - if (ilCodeVersion.IsValid && ilCodeVersion.IsExplicit && _target.Contracts.TryGetContract(out IReJIT rejit) && rejit.GetRejitState(ilCodeVersion) == RejitState.Active) + if (ilCodeVersion.IsValid + && ilCodeVersion.IsExplicit + && rejit.GetRejitState(ilCodeVersion) == RejitState.Active) { *pVmILCodeVersionNode = ilCodeVersion.ILCodeVersionNode.Value; } @@ -1259,11 +1264,10 @@ public int GetNativeCodeVersionNode(ulong vmMethod, ulong codeStartAddress, ulon *pVmNativeCodeVersionNode = 0; - TargetPointer methodDesc = new TargetPointer(vmMethod); TargetCodePointer codeAddress = new TargetCodePointer(codeStartAddress); ICodeVersions codeVersions = _target.Contracts.CodeVersions; - NativeCodeVersionHandle nativeCodeVersion = codeVersions.GetSpecificNativeCodeVersion(methodDesc, codeAddress); + NativeCodeVersionHandle nativeCodeVersion = codeVersions.GetNativeCodeVersionForIP(codeAddress); if (nativeCodeVersion.Valid && nativeCodeVersion.IsExplicit) { *pVmNativeCodeVersionNode = nativeCodeVersion.CodeVersionNodeAddress.Value; From 77fc8b0e2c68abbd161040420dcb286deaabed59 Mon Sep 17 00:00:00 2001 From: Rachel Jarvi Date: Mon, 27 Apr 2026 11:18:46 -0700 Subject: [PATCH 5/7] Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- docs/design/datacontracts/CodeVersions.md | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/docs/design/datacontracts/CodeVersions.md b/docs/design/datacontracts/CodeVersions.md index 71943a91f7458a..4a44fec021c079 100644 --- a/docs/design/datacontracts/CodeVersions.md +++ b/docs/design/datacontracts/CodeVersions.md @@ -34,8 +34,6 @@ public virtual IEnumerable GetILCodeVersions(TargetPointer public virtual IEnumerable GetNativeCodeVersions(TargetPointer methodDesc, ILCodeVersionHandle ilCodeVersionHandle); // Return a handle to the version of the native code that includes the given instruction pointer public virtual NativeCodeVersionHandle GetNativeCodeVersionForIP(TargetCodePointer ip); -// Return a handle to the native code version for a specific method descriptor and code start address -public virtual NativeCodeVersionHandle GetSpecificNativeCodeVersion(TargetPointer methodDesc, TargetCodePointer codeAddress); // Return a handle to the active version of the native code for a given method descriptor and IL code version. The IL code version and method descriptor must represent the same method public virtual NativeCodeVersionHandle GetActiveNativeCodeVersionForILCodeVersion(TargetPointer methodDesc, ILCodeVersionHandle ilCodeVersionHandle); @@ -324,21 +322,6 @@ IEnumerable ICodeVersions.GetNativeCodeVersions(TargetP } ``` -### Finding the native code version for a specific method descriptor and code start address - -Given a method descriptor and code start address, find the corresponding native code version. -If the method's first native code matches the given address, the synthetic native code version is returned. -Otherwise, searches the explicit native code version nodes for a match. - -```csharp -NativeCodeVersionHandle ICodeVersions.GetSpecificNativeCodeVersion(TargetPointer methodDesc, TargetCodePointer codeAddress) -{ - IRuntimeTypeSystem rts = _target.Contracts.RuntimeTypeSystem; - MethodDescHandle md = rts.GetMethodDescHandle(methodDesc); - return GetSpecificNativeCodeVersion(md, codeAddress); -} -``` - ### Finding the active native code version of an ILCodeVersion for a method descriptor ```csharp public virtual NativeCodeVersionHandle GetActiveNativeCodeVersionForILCodeVersion(TargetPointer methodDesc, ILCodeVersionHandle ilCodeVersionHandle); From 7a10c6fac57f7c67217b710c1a53c49aab898b95 Mon Sep 17 00:00:00 2001 From: Rachel Jarvi Date: Mon, 27 Apr 2026 11:19:20 -0700 Subject: [PATCH 6/7] Update CodeVersions.md --- docs/design/datacontracts/CodeVersions.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/design/datacontracts/CodeVersions.md b/docs/design/datacontracts/CodeVersions.md index 4a44fec021c079..6961f63478faa7 100644 --- a/docs/design/datacontracts/CodeVersions.md +++ b/docs/design/datacontracts/CodeVersions.md @@ -322,6 +322,7 @@ IEnumerable ICodeVersions.GetNativeCodeVersions(TargetP } ``` + ### Finding the active native code version of an ILCodeVersion for a method descriptor ```csharp public virtual NativeCodeVersionHandle GetActiveNativeCodeVersionForILCodeVersion(TargetPointer methodDesc, ILCodeVersionHandle ilCodeVersionHandle); From 87f57d67049faa4358a93f8b7f39766464d384c3 Mon Sep 17 00:00:00 2001 From: rcj1 Date: Mon, 27 Apr 2026 14:45:59 -0700 Subject: [PATCH 7/7] copilot --- .../Dbi/DacDbiImpl.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/DacDbiImpl.cs b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/DacDbiImpl.cs index dbc02d38e702a0..70b31ecadcdb6c 100644 --- a/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/DacDbiImpl.cs +++ b/src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/DacDbiImpl.cs @@ -1217,6 +1217,8 @@ public int GetActiveRejitILCodeVersionNode(ulong vmModule, uint methodTk, ulong* TargetPointer methodDesc = TargetPointer.Null; try { + if ((EcmaMetadataUtils.TokenType)(methodTk & EcmaMetadataUtils.TokenTypeMask) != EcmaMetadataUtils.TokenType.mdtMethodDef) + throw new ArgumentException("methodTk must be a MethodDef token.", nameof(methodTk)); methodDesc = loader.GetModuleLookupMapElement(lookupTables.MethodDefToDesc, methodTk, out _); } catch (ArgumentOutOfRangeException)