Skip to content

Special-Case BitMask Parsing#2327

Merged
brianrob merged 2 commits intomicrosoft:mainfrom
brianrob:dev/brianrob/issue707
Nov 7, 2025
Merged

Special-Case BitMask Parsing#2327
brianrob merged 2 commits intomicrosoft:mainfrom
brianrob:dev/brianrob/issue707

Conversation

@brianrob
Copy link
Member

@brianrob brianrob commented Nov 6, 2025

When an event contains a bitmask, it is sometimes described in metadata as an array of pointers. ETW differentiates between input and output types, and so there is a possibility for metadata to specify the input type as an array of UInt64 and the output type as an array of IntPtr. Existing code can't handle this properly, so we must special case it.

The MSNT_SystemTrace/SystemConfig/ProcessorGroup event is an example of one such event.

When an event contains a bitmask, it is sometimes described in metadata
as an array of pointers.  ETW differentiates between input and output
types, and so there is a possibility for metadata to specify the input
type as an array of UInt64 and the output type as an array of IntPtr.
Existing code can't handle this properly, so we must special case it.

The MSNT_SystemTrace/SystemConfig/ProcessorGroup event is an example of
one such event.
@MagicAndre1981
Copy link
Contributor

ok, the InvalidCastException is gone with the artifact build from this PR:

<Event MSec= "42988.4096" PID=  "-1" PName=        "" TID=  "-1" EventName="SystemConfig/ProcessorGroup"
  TimeStamp="11/07/25 10:57:24.957906" ID="Illegal" Version="2" Keywords="0x00000000" TimeStampQPC="2,246,767,051" QPCTime="0.100us"
  Level="Always" ProviderName="MSNT_SystemTrace" ProviderGuid="9e814aad-3204-11d2-9a82-006008a86939" ClassicProvider="True" ProcessorNumber="4"
  Opcode="26" TaskGuid="01853a65-418f-4f36-aefc-dc0f1d2fd235" Channel="0" PointerSize="8"
  CPU="4" EventIndex="9091131" TemplateType="DynamicTraceEventData">
  <PrettyPrint>
    <Event MSec= "42988.4096" PID=  "-1" PName=        "" TID=  "-1" EventName="SystemConfig/ProcessorGroup" ProviderName="MSNT_SystemTrace" Affinity="[255]"/>
  </PrettyPrint>
  <Payload Length="12">
       0:   1  0  0  0 ff  0  0  0 |  0  0  0  0               ........ ....
  </Payload>
</Event>

leculver
leculver previously approved these changes Nov 7, 2025
Copy link
Collaborator

@leculver leculver left a comment

Choose a reason for hiding this comment

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

Small nitpick, otherwise looks fine to me.

// input=Array of ulong
// output=Array of IntPtr
// This is common for bitmasks. To address this, we special case it here.
if (value is ulong && elementType == typeof(IntPtr))
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd combine the unboxing operation with pattern matching.

                    if (elementType == typeof(IntPtr) && value is ulong uintVal)
                    {
                        value = new IntPtr(unchecked((long)uintVal));
                    }

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh yes, I like that a lot better. Pushing that change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

EXCEPTION_DURING_VALUE_LOOKUP InvalidCastException while viewing MSNT_SystemTrace/SystemConfig/ProcessorGroup event

3 participants

Comments