From: Johan Lorensson Date: Mon, 23 Oct 2023 23:48:53 +0000 (+0200) Subject: Handle sessionId as ulong instead of long in EventPipeSession.cs. (#4345) X-Git-Tag: accepted/tizen/unified/riscv/20231226.055542~35^2~1^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6f9f639970a8cb373c8b8b1974d29005d3d33da1;p=platform%2Fcore%2Fdotnet%2Fdiagnostics.git Handle sessionId as ulong instead of long in EventPipeSession.cs. (#4345) Session id is a uint64 in runtime as well as specified as a uint64 in IPC protocol, https://github.com/dotnet/diagnostics/blob/main/documentation/design-docs/ipc-protocol.md#returns-as-an-ipc-message-payload. EventPipeSession.cs however handled it as a long instead of an ulong, currently that doesn't affect release builds since it doesn't do much with the id except passing it back to stop the session, but in debug builds there is an assert that validates that session id > 0. On Android physical devices it is not uncommon to get code and memory allocated at high addresses, including having the high order bit set and when that happens, EventPipeSession.cs will see a negative session id and assert on debug builds. Fix adjust session id as ulong inline with IPC protocol, it also makes sure keyword serialized when starting a session is handled according to IPC specification, but only when serialized into the payload, it will still be typed as long inside EventPipeProvider since it is a public property. --- diff --git a/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsClient/EventPipeSession.cs b/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsClient/EventPipeSession.cs index 041502f6f..d61aace34 100644 --- a/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsClient/EventPipeSession.cs +++ b/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsClient/EventPipeSession.cs @@ -13,13 +13,13 @@ namespace Microsoft.Diagnostics.NETCore.Client { public class EventPipeSession : IDisposable { - private long _sessionId; + private ulong _sessionId; private IpcEndpoint _endpoint; private bool _disposedValue; // To detect redundant calls private bool _stopped; // To detect redundant calls private readonly IpcResponse _response; - private EventPipeSession(IpcEndpoint endpoint, IpcResponse response, long sessionId) + private EventPipeSession(IpcEndpoint endpoint, IpcResponse response, ulong sessionId) { _endpoint = endpoint; _response = response; @@ -93,7 +93,7 @@ namespace Microsoft.Diagnostics.NETCore.Client { DiagnosticsClient.ValidateResponseMessage(response.Value.Message, operationName); - long sessionId = BinaryPrimitives.ReadInt64LittleEndian(new ReadOnlySpan(response.Value.Message.Payload, 0, 8)); + ulong sessionId = BinaryPrimitives.ReadUInt64LittleEndian(new ReadOnlySpan(response.Value.Message.Payload, 0, 8)); EventPipeSession session = new(endpoint, response.Value, sessionId); response = null; diff --git a/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsClient/EventPipeSessionConfiguration.cs b/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsClient/EventPipeSessionConfiguration.cs index 25f813d8f..0e837d908 100644 --- a/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsClient/EventPipeSessionConfiguration.cs +++ b/src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsClient/EventPipeSessionConfiguration.cs @@ -59,7 +59,7 @@ namespace Microsoft.Diagnostics.NETCore.Client writer.Write(Providers.Count); foreach (EventPipeProvider provider in Providers) { - writer.Write(provider.Keywords); + writer.Write(unchecked((ulong)provider.Keywords)); writer.Write((uint)provider.EventLevel); writer.WriteString(provider.Name);