Alternative: Introduce TargetPointer type for cross-bitness pointer values#1422
Closed
max-charlamb wants to merge 3 commits intomicrosoft:mainfrom
Closed
Alternative: Introduce TargetPointer type for cross-bitness pointer values#1422max-charlamb wants to merge 3 commits intomicrosoft:mainfrom
max-charlamb wants to merge 3 commits intomicrosoft:mainfrom
Conversation
…erSize Replace ~50 uses of IntPtr.Size (host pointer size) with the target process's PointerSize so that dumps from a different architecture can be read correctly (e.g. reading ARM64 dumps from an x64 host). Changes across 14 files: - ClrArray: array length offset, multi-dim detection, rank, element addressing - ClrObject: boxed value header offset - ClrInstanceField: field address calculation - ClrField: GetSize accepts optional pointerSize parameter - ClrException: all offset methods + stack trace parsing - ClrHeap: string offsets, alignment, min object size, GC ref scanning, finalize queue walking, MemoryCache.ReadPointer - ClrDacType: GC descriptor reading, array element type, base array offset - ClrTypeFactory: string type StaticSize - GCDesc: new constructor overload with explicit pointerSize; all internal methods converted - DacHeap: frozen segment committed start - DacThreadHelpers: IP/SP reads - CommonMemoryReader: fix ReadPointer calling AsPointer(pointerSize) which bound to the 2-arg overload treating pointerSize as offset instead of size - SpanExtensions: new 3-arg AsPointer overload (pointerSize, offset) - SigParser: pointerSize field for PeekElemTypeSize Bug fix: CommonMemoryReader.ReadPointer was calling AsPointer(pointerSize) which resolved to the 2-arg overload (span, offset), treating the pointer size as an offset. Changed to AsPointer(pointerSize, 0) to use the correct 3-arg overload. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…zed reads Per review feedback from @leculver: - SpanExtensions: Remove 0-arg and 1-arg AsPointer overloads that defaulted to IntPtr.Size. The ulong-offset overload now requires explicit pointerSize. - SigParser: Remove 2-arg constructor defaulting to IntPtr.Size. All callers (ClrEnum, ClrField, MetadataImport) now pass explicit pointer size. - GCDesc: Remove 1-arg constructor defaulting to IntPtr.Size. - ClrField.GetSize: Remove pointerSize=0 fallback to IntPtr.Size; parameter is now required. Updated ClrPrimitiveType caller. Additional fixes for host-sized target reads: - ClrDelegate: Replace Read<UIntPtr> with ReadPointer (target-pointer-aware). Replace ReadValues<UIntPtr> loop with GetObjectValue iteration. - ClrObject.AsRuntimeType: Replace ReadField<nint> with ReadPointer for m_handle/m_ptr fields. - ClrArray.GetObjectValue: Replace ReadValue<nuint> with ReadPointer to read target-sized object references. - ClrEnum: Replace *(nint*) and *(nuint*) with pointer-size-conditional reads using target PointerSize. - ClrInstanceField: Add ReadPointer method for target-pointer-aware reads. - MetadataImport: Accept pointerSize in constructors, pass to SigParser. - SigParserBoundsTests: Updated to pass explicit pointer size. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add readonly struct TargetPointer wrapping ulong with implicit conversions to make it clear at the type level when a value is a target pointer vs an arbitrary integer. Updated IMemoryReader.ReadPointer, SpanExtensions.AsPointer, and all internal callers to use TargetPointer. Public API surface stays source-compatible via implicit conversions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
abf8557 to
c54713c
Compare
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.
Alternative approach: TargetPointer type for cross-bitness support
This branch builds on #1421 and introduces a
TargetPointerreadonly struct (inspired by the cDAC'sTargetPointer) to make it clear at the type level when a value represents a target process pointer vs an arbitrary integer.What's different from #1421
TargetPointerreadonly struct wrappingulongwith implicit conversionsIMemoryReader.ReadPointerreturnsTargetPointerinstead ofulongSpanExtensions.AsPointerreturnsTargetPointerinstead ofulongTargetPointerulong<->TargetPointerconversionsBenefits
TargetPointervsulongmakes intent clearTest results