-
Notifications
You must be signed in to change notification settings - Fork 5k
[cDAC] Fix method table slot lookup #115057
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
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 fixes a critical bug in the pointer arithmetic for method table slot lookup in the cDAC runtime type system.
- Correctly adjusts the pointer arithmetic by multiplying the offset with _target.PointerSize
- Ensures that the calculation accounts for pointer-sized slots
Comments suppressed due to low confidence (1)
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/RuntimeTypeSystem_1.cs:846
- The change correctly applies multiplication by _target.PointerSize to adjust for pointer-sized slots. Ensure that _target.PointerSize is always valid and consistent across different target environments to avoid potential underflow or miscalculation.
return nonVirtualSlotsArray - ((1 + (slotNum - mt.NumVirtuals)) * (ulong)_target.PointerSize);
Tagging subscribers to this area: @tommcdon |
Is this a pattern that occurs in other places? It might be worth considering having a |
@@ -843,7 +843,7 @@ private TargetPointer GetAddressOfSlot(TypeHandle typeHandle, uint slotNum) | |||
TargetPointer auxDataPtr = mt.AuxiliaryData; | |||
Data.MethodTableAuxiliaryData auxData = _target.ProcessedData.GetOrAdd<Data.MethodTableAuxiliaryData>(auxDataPtr); | |||
TargetPointer nonVirtualSlotsArray = auxDataPtr + (ulong)auxData.OffsetToNonVirtualSlots; | |||
return nonVirtualSlotsArray - (1 + (slotNum - mt.NumVirtuals)); | |||
return nonVirtualSlotsArray - ((1 + (slotNum - mt.NumVirtuals)) * (ulong)_target.PointerSize); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to see (1 + (slotNum - mt.NumVirtuals))
in a separate named local that describes what it is, so the index calculation is separated from the machinery of turning an index into an address
This sounds like a good idea, but the current design makes it difficult to implement.
Maybe we could add a method or extension to |
Merging fix for now, will take another look at improving pointer math in the future |
Found this bug while testing
EnumMethodInstancesByAddress
.MethodTable slots are pointer sized. Finding the correct one is done using pointer arithmetic on the native code but has to be done explicitly on the cDAC.