Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Event source uint fix#19205

Merged
vancem merged 5 commits intodotnet:masterfrom
vancem:EventSourceUIntFix
Aug 29, 2018
Merged

Event source uint fix#19205
vancem merged 5 commits intodotnet:masterfrom
vancem:EventSourceUIntFix

Conversation

@vancem
Copy link

@vancem vancem commented Jul 30, 2018

Fix for https://github.com/dotnet/coreclr/issues/19204.

Need to do some targeted testing before checkin, but wanted to get it out there, so I don't forget it.

@brianrob

// write out each enum value
FieldInfo[] staticFields = enumType.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Static);

// Empty map entries cause Windows to reject the whole manifest. Avoid ths by only writting the
Copy link
Member

Choose a reason for hiding this comment

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

Typo: ths

@vancem vancem changed the title Event source u int fix Event source uint fix Jul 31, 2018
{
if (data is System.Enum)
{
Type underlyingType = Enum.GetUnderlyingType(data.GetType());
Copy link
Author

Choose a reason for hiding this comment

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

The fix in this file was prompted by testing where if you have enums that are not based on int or long, then it will serialize it as a string, but the manifest says it decodes like an enum. This fix basically extends the types recognized to be all the integer types. the 64 bit types are handled specially and all others are cast to int (32 bit case).


// write out each enum value
FieldInfo[] staticFields = enumType.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Static);
bool anyValuesWritten = false;
Copy link
Author

Choose a reason for hiding this comment

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

This fix allows enums with unsigned underlying types. It also insures that if there are no enum values we add one because the windows ETW manifest parser requires it.

@vancem
Copy link
Author

vancem commented Jul 31, 2018

I have done some ad-hoc testing to confirm this works.

}
}

// the OS requrires that bitmaps and valuemaps have at least one value or it reject the whole manifest.
Copy link
Member

Choose a reason for hiding this comment

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

typo: requires

else if (underlyingType == typeof(long))
data = (long)data;
else
data = (int)Convert.ToInt64(data); // This handles all int/uint or below (we treat them like 32 bit ints)
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to modify DecodeObject as well to make sure that data types smaller than 4 bytes are properly handled?

Copy link
Author

Choose a reason for hiding this comment

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

I will look into this.

@vancem vancem merged commit 1eedc35 into dotnet:master Aug 29, 2018
MichalStrehovsky added a commit to MichalStrehovsky/runtime that referenced this pull request Jan 27, 2021
We're getting the marshalling size of an enum underlying type - there are not that many of those. I chose not to treat `char` and `bool`, but we could (the only other remaining options).

Calling into `Marshal.SizeOf` increases the risk that `EventSource` is going call itself recursively - see the comment at the beginning of the method.

This was originally introduced in dotnet/coreclr#19205.
stephentoub pushed a commit to dotnet/runtime that referenced this pull request Jan 29, 2021
* Avoid Marshal.SizeOf in EventSource

We're getting the marshalling size of an enum underlying type - there are not that many of those. I chose not to treat `char` and `bool`, but we could (the only other remaining options).

Calling into `Marshal.SizeOf` increases the risk that `EventSource` is going call itself recursively - see the comment at the beginning of the method.

This was originally introduced in dotnet/coreclr#19205.

* Update src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs

* Update src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs

* Update src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventSource.cs
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.

3 participants