Skip to content

cDAC: dereference OBJECTHANDLE in collectible thread-statics#129291

Open
leculver wants to merge 4 commits into
dotnet:mainfrom
leculver:cDac-threadstatic-fix
Open

cDAC: dereference OBJECTHANDLE in collectible thread-statics#129291
leculver wants to merge 4 commits into
dotnet:mainfrom
leculver:cDac-threadstatic-fix

Conversation

@leculver

Copy link
Copy Markdown
Contributor

The collectable branch for thread statics currently returns the slot of an object, whereas the NonCollectible branch returns the object itself. Changing this matches the ObjectFromHandleUnchecked in request.cpp (and what clrmd expects on the other end).

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Updates collectible TLS static-base lookup to treat TLS slots as OBJECTHANDLEs and resolve the underlying object rather than treating the slot value as the object pointer.

Changes:

  • Replaces direct pointer read from the collectible TLS array with ObjectHandle dereference via ProcessedData.
  • Adds clarifying comments describing native behavior alignment (ObjectFromHandleUnchecked).
Show a summary per file
File Description
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/Thread_1.cs Adjusts collectible TLS static base resolution to dereference an OBJECTHANDLE via contract processing.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 2

{
TargetPointer collectibleArray = threadLocalData.CollectibleTlsArrayData;
threadLocalStaticBase = _target.ReadPointer(collectibleArray + (ulong)(indexOffset * _target.PointerSize));
// The collectible TLS array slot holds an OBJECTHANDLE. Constructing an

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please delete the comment and update docs/design/datacontracts/Thread.md

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

leculver and others added 3 commits June 12, 2026 13:32
…lution

The cDAC IThread.GetThreadLocalStaticBase collectible-TLS branch returned the
collectible TLS array slot contents directly as the static base. That slot
holds an OBJECTHANDLE, not the object: native GetThreadLocalStaticBaseNoCreate
(threadstatics.cpp) reads the handle from the slot and then calls
ObjectFromHandleUnchecked to get the object. cDAC skipped the dereference, so
collectible (unloadable-ALC) thread-static base resolution returned the handle
cell address instead of the object base, silently mis-resolving every
subsequent field read.

Dereference the handle via the ObjectHandle data type (which reads the handle
then the object, matching ObjectFromHandleUnchecked and the in-flight TLS path
that already uses ObjectHandle.Object). The NonCollectible branch is unchanged:
that array stores direct object refs.

Flows through ISOSDacInterface14::GetThreadStaticBaseAddress, affecting
cDAC-backed SOS thread-static field display and ClrMD
ClrThreadStaticField.GetAddress.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Rename handleAddress -> handleSlotAddress and reword the comment to make
explicit that the value is the address of the TLS array slot containing the
OBJECTHANDLE (not the handle/object), and that ObjectHandle reads the handle
from that slot and dereferences it. No behavior change.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 12, 2026 17:35
@leculver leculver force-pushed the cDac-threadstatic-fix branch from 4314b1a to 67fea10 Compare June 12, 2026 17:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot's findings

  • Files reviewed: 2/2 changed files
  • Comments generated: 2

Comment thread docs/design/datacontracts/Thread.md Outdated
Comment on lines +305 to +307
// The collectible TLS array slot holds an OBJECTHANDLE; dereference the handle to the object
TargetPointer handleSlotAddress = collectibleArray + (ulong)(indexOffset * target.PointerSize);
threadLocalStaticBase = target.ReadPointer(target.ReadPointer(handleSlotAddress));
Comment on lines +219 to +220
TargetPointer handleSlotAddress = collectibleArray + (ulong)(indexOffset * _target.PointerSize);
threadLocalStaticBase = _target.ProcessedData.GetOrAdd<Data.ObjectHandle>(handleSlotAddress).Object;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants