Skip to content
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

Fix ModuleLoadUnloadTraceData.ModuleID cast to be unchecked since its really a ulong member. #4354

Merged
merged 1 commit into from
Oct 23, 2023

Conversation

lateralusX
Copy link
Member

The ModuleLoadUnload events ModuleID is typed as a uint64 in the EventPipe manifest and emitted as a uint64 in the event payload. However, the parsing logic in ModuleLoadUnloadTraceDataevent in trace event:

https://github.com/microsoft/perfview/blob/a6c87911fe1aef8f59c9ce54aa4e16a1be6db91e/src/TraceEvent/Parsers/ClrEtwAll.cs.base#L4963

handles it as a long. Android devices running arm64 can use pointer tagging meaning that high bits can be set in 64-bit addresses and since module id is a memory address, it will be returned as a negative long from ModuleLoadUnload event and since all diagnostic tooling is build with overflow checking enabled by default, casting it to a ulong will trigger and overflow exception when high bit is set.

Fix is to do an unchecked cast in this case since the value should be threated as a ulong in first place.

Fixes #4348.

The ModuleUnload events ModuleID is typed as a uint64 in the
EventPipe manifest and emitted as a uint64 in the event payload.
However, the parsing logic in ModuleLoadUnload event in trace event
https://github.com/microsoft/perfview/blob/a6c87911fe1aef8f59c9ce54aa4e16a1be6db91e/src/TraceEvent/Parsers/ClrEtwAll.cs.base#L4963
handles it as a long. Android devices running arm64 can use pointer
tagging meaning that high bits can be set in 64-bit addresses and since
module id is a memory address, it will be returned as a negative long
from MofuleLoadUnload event and since all diagnostic tooling is build
with overflow checking on by default, casting it to a ulong will trigger
and overflow exception when negative.

Fix is to do an unchecked cast in this case since the value should be
threated as a ulong in first place.
Copy link
Member

@jonathanpeppers jonathanpeppers left a comment

Choose a reason for hiding this comment

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

This seems to work locally:

D:\src\dotnet\diagnostics\src\Tools\dotnet-gcdump [lateralusX/fix-moduleid-cast]> dotnet run -c Release -- collect -p 6432
Writing gcdump to 'D:\src\dotnet\diagnostics\src\Tools\dotnet-gcdump\20231023_105821_6432.gcdump'...
        Finished writing 492293 bytes.

@mikem8361
Copy link
Member

Is this ready to be merged?

@hoyosjs hoyosjs merged commit 093a0ea into dotnet:main Oct 23, 2023
20 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Jan 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error using dotnet-gcdump on Android device
5 participants