Skip to content

[cDAC] Add Hijack DacDbi API#129764

Merged
rcj1 merged 9 commits into
dotnet:mainfrom
rcj1:hijack2
Jul 1, 2026
Merged

[cDAC] Add Hijack DacDbi API#129764
rcj1 merged 9 commits into
dotnet:mainfrom
rcj1:hijack2

Conversation

@rcj1

@rcj1 rcj1 commented Jun 23, 2026

Copy link
Copy Markdown
Contributor
  • Adds a StackPusher utility to push arbitrary bytes onto the stack with or without alignment
  • Adds an IntegerArgPlacer utility to place integer args according to the native ABI
  • Adds TargetPointer PrepareExceptionHijack(byte[] context, TargetPointer vmThread, byte[]? exceptionRecord, int reason, TargetPointer userData); to the Debugger contract
  • Adds context-write delegate to cDAC
  • Implements Hijack DacDbi API

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @steveisok, @tommcdon, @dotnet/dotnet-diag
See info in area-owners.md if you want to be subscribed.

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

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

Copilot AI review requested due to automatic review settings June 23, 2026 21: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: 38/38 changed files
  • Comments generated: 6

Copilot AI review requested due to automatic review settings June 24, 2026 20:22

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: 37/37 changed files
  • Comments generated: 5

Comment thread src/native/managed/cdac/mscordaccore_universal/Entrypoints.cs
Comment thread src/native/managed/cdac/mscordaccore_universal/Entrypoints.cs

@noahfalk noahfalk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks good to me modulo a few suggestions inline.

Comment thread docs/design/datacontracts/Debugger.md Outdated
Comment thread src/native/managed/cdac/tests/UnitTests/DebuggerTests.cs
Copilot AI review requested due to automatic review settings June 30, 2026 19:16

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: 37/37 changed files
  • Comments generated: 4

Comment thread src/native/managed/cdac/mscordaccore_universal/Entrypoints.cs
Comment thread src/native/managed/cdac/mscordaccore_universal/Entrypoints.cs

@max-charlamb max-charlamb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm mod few comments

Comment thread docs/design/datacontracts/Debugger.md Outdated
Copilot AI review requested due to automatic review settings June 30, 2026 21:23

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 encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@rcj1 rcj1 merged commit 88e2ee6 into dotnet:main Jul 1, 2026
137 of 139 checks passed
@rcj1 rcj1 deleted the hijack2 branch July 1, 2026 15:52
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview7 milestone Jul 2, 2026
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.

4 participants