Skip to content

Add cDAC ObjectiveCMarshal contract and IsTrackedReferenceWithFinalizer API#125895

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/add-cdac-apis
Draft

Add cDAC ObjectiveCMarshal contract and IsTrackedReferenceWithFinalizer API#125895
Copilot wants to merge 3 commits intomainfrom
copilot/add-cdac-apis

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 21, 2026

Summary

Implements cDAC APIs for Objective-C interop diagnostics as a new ObjectiveCMarshal contract, plus adds IsTrackedReferenceWithFinalizer to the RuntimeTypeSystem contract. Based on draft PR #118250, adjusted per review feedback (contract renamed, TargetNUInt instead of nuint, APIs in dedicated contract).

Note

This PR was generated with GitHub Copilot.

Changes

New ObjectiveCMarshal cDAC Contract

  • IObjectiveCMarshal (Abstractions/Contracts/IObjectiveCMarshal.cs): Interface with a single API:

    TargetPointer GetTaggedMemory(TargetPointer address, out TargetNUInt size);

    Returns the tagged memory pointer for an Objective-C tracked reference object (or TargetPointer.Null if none). Sets size to 2 * pointerSize bytes only on success.

  • ObjectiveCMarshal_1 (Contracts/ObjectiveCMarshal_1.cs): Version 1 implementation — reads the sync block from the object header, then extracts InteropSyncBlockInfo.TaggedMemory.

  • ObjectiveCMarshalFactory (Contracts/ObjectiveCMarshalFactory.cs): Contract factory.

  • Registered in ContractRegistry and CachingContractRegistry.

  • datadescriptor.inc: Added TaggedMemory field to InteropSyncBlockInfo type (under #ifdef FEATURE_OBJCMARSHAL) and CDAC_GLOBAL_CONTRACT(ObjectiveCMarshal, 1) (also guarded).

  • syncblk.h: Added TaggedMemory offset to cdac_data<InteropSyncBlockInfo> under #ifdef FEATURE_OBJCMARSHAL.

  • InteropSyncBlockInfo.cs (Data class): Added TaggedMemory property using TryGetValue to handle the optional FEATURE_OBJCMARSHAL field.

IsTrackedReferenceWithFinalizer on RuntimeTypeSystem

  • Added IsTrackedReferenceWithFinalizer = 0x04000000 to WFLAGS_HIGH enum in MethodTableFlags_1.cs, plus a convenience property bool IsTrackedReferenceWithFinalizer.

  • Added IsTrackedReferenceWithFinalizer(TypeHandle) to IRuntimeTypeSystem.cs and implemented it in RuntimeTypeSystem_1.cs.

SOSDacImpl.csISOSDacInterface11

Replaced the stub implementations of IsTrackedType and GetTaggedMemory with full cDAC implementations:

  • IsTrackedType: uses IRuntimeTypeSystem.IsTrackedReferenceWithFinalizer and IObjectiveCMarshal.GetTaggedMemory; returns S_OK if tracked, S_FALSE if not, E_INVALIDARG for null inputs.
  • GetTaggedMemory: uses IObjectiveCMarshal.GetTaggedMemory; returns S_OK with address and size if tagged memory exists, S_FALSE otherwise.

Both methods include #if DEBUG assertions against the legacy DAC implementation for validation.

Documentation

  • docs/design/datacontracts/ObjectiveCMarshal.md: New contract documentation.
  • docs/design/datacontracts/RuntimeTypeSystem.md: Added IsTrackedReferenceWithFinalizer to API listing and pseudocode.

Testing

All 1322 existing cDAC unit tests pass. The new contract will be exercised when running on an Apple platform with FEATURE_OBJCMARSHAL enabled.

@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.

Collectible = 0x00200000, // GC depends on this bit.

ContainsGCPointers = 0x01000000,
IsTrackedReferenceWithFinalizer = 0x04000000,
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.

We need to add this to the RuntimeTypeSystem.md markdown file.

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