[cDAC] Include the highest assigned ID in IdToThread lookup#130889
Merged
max-charlamb merged 2 commits intoJul 17, 2026
Merged
[cDAC] Include the highest assigned ID in IdToThread lookup#130889max-charlamb merged 2 commits into
max-charlamb merged 2 commits into
Conversation
The runtime's IdDispenser::IdToThread resolves a thread by ID using an inclusive bound (`if (id <= m_highestId)`). The cDAC IThread.IdToThread implementation used an exclusive `<` comparison, so it failed to resolve the thread occupying the highest assigned ID slot -- an off-by-one that made the highest valid ID always return a null thread pointer. Match the native inclusive bound and add a boundary unit test that verifies the highest ID resolves to the expected thread while the next ID beyond it still returns null. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: f2aa5dc4-0c99-43f0-af14-734143849c4a
|
Azure Pipelines: Successfully started running 5 pipeline(s). 10 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes an off-by-one boundary in the cDAC IThread.IdToThread contract implementation so that the lookup includes the highest assigned thread ID (inclusive upper bound), and adds coverage + updates the Thread contract documentation to reflect the intended behavior.
Changes:
- Update
Thread_1contract implementation to useid <= HighestIdwhen indexingIdToThread. - Add a new unit test validating that
HighestIdresolves whileHighestId + 1returns null. - Update the Thread contract spec pseudocode to use the inclusive bound.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/native/managed/cdac/tests/UnitTests/ThreadTests.cs | Adds a regression test covering IdToThread behavior at HighestId and HighestId + 1. |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/Thread_1.cs | Fixes the IdToThread upper-bound check to be inclusive. |
| docs/design/datacontracts/Thread.md | Updates the spec pseudocode to match the inclusive bound behavior. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
|
Azure Pipelines: Successfully started running 5 pipeline(s). 10 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
rcj1
approved these changes
Jul 16, 2026
|
Azure Pipelines: Successfully started running 4 pipeline(s). 10 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. Some pipeline(s) encountered errors during trigger evaluation. |
Member
Author
|
/ba-g OSX timeout |
Member
Author
|
/ba-g OSX timeout |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
IdDispenser::IdToThreadin the runtime resolves a thread by ID using aninclusive upper bound (
if (id <= m_highestId)). The cDACIThread.IdToThreadimplementation used an exclusive<comparison andtherefore never resolved the thread occupying the highest assigned ID slot --
an off-by-one that returned a null thread pointer for the highest valid ID.
Native semantic parity
IdDispenser::IdToThread(src/coreclr/vm/threads.h):if (id <= m_highestId) result = m_idToThread[id];Thread_1.csnow usesid <= idDispenserObj.HighestId, matching theinclusive bound.
Thread.mdcontract pseudocode is updated to match.This change is limited to the
IdToThreadlookup boundary. Recycleddispenser slot validation (the free-list check in
IdToThreadWithValidation) is intentionally out of scope.Testing
ThreadTests.IdToThread_IncludesHighestId(runs on all fourarchitecture combinations) verifying the highest ID resolves to the
expected thread while
HighestId + 1returns null.Note
This PR was generated with the assistance of GitHub Copilot.