[cDAC] Add Hijack DacDbi API#129764
Merged
Merged
Conversation
Contributor
|
Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends the cDAC stack-walking/debugger plumbing to support thread-context writes (SetThreadContext), exposes hijack function address via the Debugger contract, surfaces OS exception record/context pointers through the Thread contract, and implements the managed DacDbi Hijack path using new stack/ABI helper utilities.
Changes:
- Add a thread-context write callback/delegate across the cDAC initialization surface (native header, native host glue, managed entrypoints, and
Target/ContractDescriptorTarget). - Extend Thread/Debugger contracts and data descriptors to expose OS exception record/context pointers and to return the hijack function address.
- Implement managed DacDbi
Hijack, plus new helper utilities (StackPusher,IntegerArgPlacer) and add/adjust unit tests + design docs.
Show a summary per file
| File | Description |
|---|---|
| src/tools/StressLogAnalyzer/src/Program.cs | Plumbs new SetThreadContext delegate slot (not implemented for this tool). |
| src/native/managed/cdac/tests/UnitTests/ThreadTests.cs | Adds coverage for OS exception record/context exposure via ThreadData. |
| src/native/managed/cdac/tests/UnitTests/PlatformContextTests.cs | Adds coverage for UnsetSingleStepFlag behavior across architectures. |
| src/native/managed/cdac/tests/UnitTests/MockDescriptors/MockDescriptors.Thread.cs | Extends mock ExceptionInfo layout with OS record/context pointer fields. |
| src/native/managed/cdac/tests/UnitTests/DebuggerTests.cs | Adds tests for GetHijackAddress() behavior. |
| src/native/managed/cdac/tests/UnitTests/ClrDataExceptionStateTests.cs | Updates ThreadData construction for new fields. |
| src/native/managed/cdac/tests/TestInfrastructure/TestPlaceholderTarget.cs | Adds stub override for new TrySetThreadContext. |
| src/native/managed/cdac/tests/TestInfrastructure/DumpTestBase.cs | Wires SetThreadContext delegate for dump test target creation. |
| src/native/managed/cdac/tests/TestInfrastructure/ContractDescriptor/ContractDescriptorBuilder.cs | Updates ContractDescriptorTarget.TryCreate call with SetThreadContext delegate. |
| src/native/managed/cdac/tests/DataGenerator/TestTarget.cs | Adds stub override for new TrySetThreadContext. |
| src/native/managed/cdac/scripts/DumpHelpers.cs | Updates script helper target creation signature for SetThreadContext. |
| src/native/managed/cdac/mscordaccore_universal/Entrypoints.cs | Adds unmanaged callback for writing thread context and forwards into ContractDescriptorTarget. |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader/ContractDescriptorTarget.cs | Adds SetThreadContext delegate support and implements TrySetThreadContext. |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Legacy/Dbi/DacDbiImpl.cs | Implements managed Hijack and adds helpers for EXCEPTION_RECORD sizing/writes. |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/ExceptionInfo.cs | Adds fields for OS EXCEPTION_RECORD/CONTEXT pointers. |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/Thread_1.cs | Populates new ThreadData fields from ExceptionInfo. |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/Debugger_1.cs | Implements IDebugger.GetHijackAddress(). |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/StackWalk/Context/IPlatformContext.cs | Adds UnsetSingleStepFlag() API to platform contexts. |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/StackWalk/Context/IPlatformAgnosticContext.cs | Adds UnsetSingleStepFlag() API + dispatch. |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/StackWalk/Context/ContextHolder.cs | Forwards UnsetSingleStepFlag() to the held context. |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/StackWalk/Context/X86Context.cs | Implements UnsetSingleStepFlag() for x86. |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/StackWalk/Context/AMD64Context.cs | Implements UnsetSingleStepFlag() for x64. |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/StackWalk/Context/ARM64Context.cs | Implements UnsetSingleStepFlag() for arm64. |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/StackWalk/Context/ARMContext.cs | Throws for UnsetSingleStepFlag() (emulated single-step). |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/StackWalk/Context/RISCV64Context.cs | Throws for UnsetSingleStepFlag() (emulated single-step). |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/StackWalk/Context/LoongArch64Context.cs | Throws for UnsetSingleStepFlag() (emulated single-step). |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/StackPusher.cs | New helper for stack writes with optional ABI alignment. |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/IntegerArgPlacer.cs | New helper for placing integer arguments per ABI (regs/stack). |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Target.cs | Adds TrySetThreadContext API to the target abstraction. |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/IThread.cs | Extends ThreadData with exception-in-progress + OS record pointers. |
| src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/IDebugger.cs | Adds GetHijackAddress() API to debugger contract. |
| src/native/managed/cdac/inc/cdac_reader.h | Extends native init signature with optional write_thread_context callback. |
| src/coreclr/vm/exinfo.h | Adds cDAC offsets for ExInfo’s OS exception record/context pointers. |
| src/coreclr/vm/datadescriptor/datadescriptor.inc | Adds ExceptionInfo fields for OS exception record/context pointers. |
| src/coreclr/vm/cdacstress.cpp | Updates in-proc stress init call signature for new callback parameter. |
| src/coreclr/debug/daccess/cdac.cpp | Wires ICorDebugMutableDataTarget::SetThreadContext into cDAC init. |
| docs/design/datacontracts/Thread.md | Documents new ThreadData fields and descriptor dependencies. |
| docs/design/datacontracts/Debugger.md | Documents new GetHijackAddress() API. |
Copilot's findings
- Files reviewed: 38/38 changed files
- Comments generated: 7
This was referenced Jun 25, 2026
Open
noahfalk
approved these changes
Jun 27, 2026
noahfalk
left a comment
Member
There was a problem hiding this comment.
This looks good to me modulo a few suggestions inline.
max-charlamb
approved these changes
Jun 30, 2026
max-charlamb
approved these changes
Jul 1, 2026
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.
TargetPointer PrepareExceptionHijack(byte[] context, TargetPointer vmThread, byte[]? exceptionRecord, int reason, TargetPointer userData);to the Debugger contract