[SuppressUnmanagedCodeSecurityAttribute] // Don't do security checks private static extern int EventWriteTransfer( [In] long registrationHandle, [In] ref EventDescriptor eventDescriptor, [In] Guid *activityId, [In] Guid *relatedActivityId, [In] int userDataCount, [In] EventProvider.EventData *userData );
private static unsafe object EncodeObject(ref object data, ref EventProvider.EventData *dataDescriptor, ref byte *dataBuffer, ref uint totalEventSize) { string str; byte[] numArray; while (true) { dataDescriptor->Reserved = 0U; str = data as string; numArray = (byte[])null; if (str == null) { if ((numArray = data as byte[]) == null) { if (!(data is IntPtr)) { if (!(data is int)) { if (!(data is long)) { if (!(data is uint)) { if (!(data is ulong)) { if (!(data is char)) { if (!(data is byte)) { if (!(data is short)) { if (!(data is sbyte)) { if (!(data is ushort)) { if (!(data is float)) { if (!(data is double)) { if (!(data is bool)) { if (!(data is Guid)) { if (!(data is Decimal)) { if (!(data is DateTime)) { if (data is Enum) { Type underlyingType = Enum.GetUnderlyingType(data.GetType()); if (underlyingType == typeof(int)) { // ISSUE: explicit reference operation // ISSUE: variable of a reference type object& local1 = @data; // ISSUE: explicit reference operation // ISSUE: variable of a boxed type __Boxed <int> local2 = (ValueType)((IConvertible) ^ local1).ToInt32((IFormatProvider)null);
// Write an event. unsafe int IEventProvider.EventWriteTransferWrapper( long registrationHandle, ref EventDescriptor eventDescriptor, Guid *activityId, Guid *relatedActivityId, int userDataCount, EventProvider.EventData *userData) { return(0); }
private unsafe bool SendManifest(byte[] rawManifest, EventProviderDataStream outputStream) { fixed(byte *numRef = rawManifest) { EventDescriptorInternal eventDescriptor = new EventDescriptorInternal(0xfffe, 1, 0, 0, 0xfe, 0, -1L); ManifestEnvelope envelope = new ManifestEnvelope { Format = ManifestEnvelope.ManifestFormats.SimpleXmlFormat, MajorVersion = 1, MinorVersion = 0, Magic = 0x5b }; int length = rawManifest.Length; envelope.TotalChunks = (ushort)((length + 0xfeff) / 0xff00); envelope.ChunkNumber = 0; EventProvider.EventData *dataPtr = (EventProvider.EventData *) stackalloc byte[(((IntPtr)2) * sizeof(EventProvider.EventData))]; dataPtr->Ptr = (ulong)((IntPtr) & envelope); dataPtr->Size = (uint)sizeof(ManifestEnvelope); dataPtr->Reserved = 0; dataPtr[1].Ptr = (ulong)numRef; dataPtr[1].Reserved = 0; bool flag = true; while (length > 0) { dataPtr[1].Size = (uint)Math.Min(length, 0xff00); if (((outputStream == null) && (this.m_provider != null)) && !this.m_provider.WriteEvent(ref eventDescriptor, 2, (IntPtr)dataPtr)) { flag = false; } if (outputStream != null) { byte[] destination = null; byte[] buffer2 = null; if (destination == null) { destination = new byte[dataPtr->Size]; buffer2 = new byte[dataPtr[1].Size]; } Marshal.Copy((IntPtr)dataPtr->Ptr, destination, 0, (int)dataPtr->Size); Marshal.Copy((IntPtr)dataPtr[1].Ptr, buffer2, 0, (int)dataPtr[1].Size); this.m_eventCallbackArgs.EventId = eventDescriptor.EventId; this.m_eventCallbackArgs.Payload = new object[] { destination, buffer2 }; outputStream.m_Callback(this.m_eventCallbackArgs); } length -= 0xff00; envelope.ChunkNumber = (ushort)(envelope.ChunkNumber + 1); } return(flag); } }
/// <summary> /// Call the ETW native API EventWriteTransfer and checks for invalid argument error. /// The implementation of EventWriteTransfer on some older OSes (Windows 2008) does not accept null relatedActivityId. /// So, for these cases we will retry the call with an empty Guid. /// </summary> internal static int EventWriteTransferWrapper(long registrationHandle, ref EventDescriptor eventDescriptor, Guid* activityId, Guid* relatedActivityId, int userDataCount, EventProvider.EventData* userData) { int HResult = EventWriteTransfer(registrationHandle, ref eventDescriptor, activityId, relatedActivityId, userDataCount, userData); if (HResult == ERROR_INVALID_PARAMETER && relatedActivityId == null) { Guid emptyGuid = Guid.Empty; HResult = EventWriteTransfer(registrationHandle, ref eventDescriptor, activityId, &emptyGuid, userDataCount, userData); } return HResult; }
protected unsafe void WriteEvent(int eventId, long value) { if ((this.m_provider != null) && this.m_eventData[eventId].EnabledForETW) { EventProvider.EventData *dataPtr = (EventProvider.EventData *) stackalloc byte[(((IntPtr)1) * sizeof(EventProvider.EventData))]; dataPtr->Ptr = (ulong)((IntPtr) & value); dataPtr->Size = 8; dataPtr->Reserved = 0; this.m_provider.WriteEvent(ref this.m_eventData[eventId].Descriptor, 1, (IntPtr)dataPtr); if (this.m_eventData[eventId].CaptureStack) { this.CaptureStack(); } } if ((this.m_OutputStreams != null) && this.m_eventData[eventId].EnabledForAnyStream) { this.WriteToAllStreams(eventId, new object[] { value }); } }
[SuppressUnmanagedCodeSecurityAttribute] // Don't do security checks private static unsafe int EventWriteTransfer( [In] long registrationHandle, [In] ref EventDescriptor eventDescriptor, [In] Guid* activityId, [In] Guid* relatedActivityId, [In] int userDataCount, [In] EventProvider.EventData* userData ) { IntPtr descripPtr = Marshal.AllocHGlobal(Marshal.SizeOf(eventDescriptor)); Marshal.StructureToPtr(eventDescriptor, descripPtr, false); int status = Interop.Kernel32.EventWriteTransfer((ulong)registrationHandle, (void*)descripPtr, activityId, relatedActivityId, userDataCount, (void*)userData); Marshal.FreeHGlobal(descripPtr); return status; }
// Write an event. unsafe int IEventProvider.EventWriteTransferWrapper( long registrationHandle, ref EventDescriptor eventDescriptor, IntPtr eventHandle, Guid *activityId, Guid *relatedActivityId, int userDataCount, EventProvider.EventData *userData) { uint eventID = (uint)eventDescriptor.EventId; if (eventID != 0 && eventHandle != IntPtr.Zero) { if (userDataCount == 0) { EventPipeInternal.WriteEvent(eventHandle, eventID, null, 0, activityId, relatedActivityId); return(0); } uint length = 0; for (int i = 0; i < userDataCount; i++) { length += userData[i].Size; } byte[] data = new byte[length]; fixed(byte *pData = data) { uint offset = 0; for (int i = 0; i < userDataCount; i++) { byte *singleUserDataPtr = (byte *)(userData[i].Ptr); uint singleUserDataSize = userData[i].Size; WriteToBuffer(pData, length, ref offset, singleUserDataPtr, singleUserDataSize); } EventPipeInternal.WriteEvent(eventHandle, eventID, pData, length, activityId, relatedActivityId); } } return(0); }
protected unsafe void WriteEvent(int eventId, string value1, string value2, string value3) { if ((this.m_provider != null) && this.m_eventData[eventId].EnabledForETW) { fixed(char *str = ((char *)value1)) { char *chPtr = str; fixed(char *str2 = ((char *)value2)) { char *chPtr2 = str2; fixed(char *str3 = ((char *)value3)) { char *chPtr3 = str3; EventProvider.EventData *dataPtr = (EventProvider.EventData *) stackalloc byte[(((IntPtr)3) * sizeof(EventProvider.EventData))]; dataPtr->Ptr = (ulong)chPtr; dataPtr->Size = (uint)((value1.Length + 1) * 2); dataPtr->Reserved = 0; dataPtr[1].Ptr = (ulong)chPtr2; dataPtr[1].Size = (uint)((value2.Length + 1) * 2); dataPtr[1].Reserved = 0; dataPtr[2].Ptr = (ulong)chPtr3; dataPtr[2].Size = (uint)((value3.Length + 1) * 2); dataPtr[2].Reserved = 0; this.m_provider.WriteEvent(ref this.m_eventData[eventId].Descriptor, 3, (IntPtr)dataPtr); if (this.m_eventData[eventId].CaptureStack) { this.CaptureStack(); } } } } } if ((this.m_OutputStreams != null) && this.m_eventData[eventId].EnabledForAnyStream) { this.WriteToAllStreams(eventId, new object[] { value1, value2, value3 }); } }
// Write an event. unsafe int IEventProvider.EventWriteTransferWrapper( long registrationHandle, ref EventDescriptor eventDescriptor, IntPtr eventHandle, Guid *activityId, Guid *relatedActivityId, int userDataCount, EventProvider.EventData *userData) { uint eventID = (uint)eventDescriptor.EventId; if (eventID != 0 && eventHandle != IntPtr.Zero) { if (userDataCount == 0) { EventPipeInternal.WriteEventData(eventHandle, eventID, null, 0, activityId, relatedActivityId); return(0); } EventPipeInternal.WriteEventData(eventHandle, eventID, &userData, (uint)userDataCount, activityId, relatedActivityId); } return(0); }
internal static extern unsafe void WriteEventData(IntPtr eventHandle, EventProvider.EventData *pEventData, uint dataCount, Guid *activityId, Guid *relatedActivityId);
internal static extern unsafe int EventWrite( [In] long registrationHandle, [In] ref EventDescriptor eventDescriptor, [In] int userDataCount, [In] EventProvider.EventData *userData );
internal static extern unsafe uint EventWriteTransfer([In] long registrationHandle, [In] ref EventDescriptorInternal eventDescriptor, [In] ref Guid activityId, [In] ref Guid relatedActivityId, [In] uint userDataCount, [In] EventProvider.EventData *userData);
private unsafe static object EncodeObject(ref object data, ref EventProvider.EventData *dataDescriptor, ref byte *dataBuffer, ref uint totalEventSize) { string text; byte[] array; for (;;) { dataDescriptor.Reserved = 0U; text = (data as string); array = null; if (text != null) { break; } if ((array = (data as byte[])) != null) { goto Block_1; } if (data is IntPtr) { goto Block_2; } if (data is int) { goto Block_3; } if (data is long) { goto Block_4; } if (data is uint) { goto Block_5; } if (data is ulong) { goto Block_6; } if (data is char) { goto Block_7; } if (data is byte) { goto Block_8; } if (data is short) { goto Block_9; } if (data is sbyte) { goto Block_10; } if (data is ushort) { goto Block_11; } if (data is float) { goto Block_12; } if (data is double) { goto Block_13; } if (data is bool) { goto Block_14; } if (data is Guid) { goto Block_16; } if (data is decimal) { goto Block_17; } if (data is DateTime) { goto Block_18; } if (!(data is Enum)) { goto IL_40C; } Type underlyingType = Enum.GetUnderlyingType(data.GetType()); if (underlyingType == typeof(int)) { data = ((IConvertible)data).ToInt32(null); } else { if (!(underlyingType == typeof(long))) { goto IL_40C; } data = ((IConvertible)data).ToInt64(null); } } dataDescriptor.Size = (uint)((text.Length + 1) * 2); goto IL_431; Block_1: *dataBuffer = array.Length; dataDescriptor.Ptr = (ulong)dataBuffer; dataDescriptor.Size = 4U; totalEventSize += dataDescriptor.Size; dataDescriptor += (IntPtr)sizeof(EventProvider.EventData); dataBuffer += 16; dataDescriptor.Size = (uint)array.Length; goto IL_431; Block_2: dataDescriptor.Size = (uint)sizeof(IntPtr); IntPtr *ptr = dataBuffer; *ptr = (IntPtr)data; dataDescriptor.Ptr = ptr; goto IL_431; Block_3: dataDescriptor.Size = 4U; int *ptr2 = dataBuffer; *ptr2 = (int)data; dataDescriptor.Ptr = ptr2; goto IL_431; Block_4: dataDescriptor.Size = 8U; long *ptr3 = dataBuffer; *ptr3 = (long)data; dataDescriptor.Ptr = ptr3; goto IL_431; Block_5: dataDescriptor.Size = 4U; uint *ptr4 = dataBuffer; *ptr4 = (uint)data; dataDescriptor.Ptr = ptr4; goto IL_431; Block_6: dataDescriptor.Size = 8U; ulong *ptr5 = dataBuffer; *ptr5 = (ulong)data; dataDescriptor.Ptr = ptr5; goto IL_431; Block_7: dataDescriptor.Size = 2U; char *ptr6 = dataBuffer; *ptr6 = (char)data; dataDescriptor.Ptr = ptr6; goto IL_431; Block_8: dataDescriptor.Size = 1U; byte *ptr7 = dataBuffer; *ptr7 = (byte)data; dataDescriptor.Ptr = ptr7; goto IL_431; Block_9: dataDescriptor.Size = 2U; short *ptr8 = dataBuffer; *ptr8 = (short)data; dataDescriptor.Ptr = ptr8; goto IL_431; Block_10: dataDescriptor.Size = 1U; sbyte *ptr9 = dataBuffer; *ptr9 = (sbyte)data; dataDescriptor.Ptr = ptr9; goto IL_431; Block_11: dataDescriptor.Size = 2U; ushort *ptr10 = dataBuffer; *ptr10 = (ushort)data; dataDescriptor.Ptr = ptr10; goto IL_431; Block_12: dataDescriptor.Size = 4U; float *ptr11 = dataBuffer; *ptr11 = (float)data; dataDescriptor.Ptr = ptr11; goto IL_431; Block_13: dataDescriptor.Size = 8U; double *ptr12 = dataBuffer; *ptr12 = (double)data; dataDescriptor.Ptr = ptr12; goto IL_431; Block_14: dataDescriptor.Size = 4U; int *ptr13 = dataBuffer; if ((bool)data) { *ptr13 = 1; } else { *ptr13 = 0; } dataDescriptor.Ptr = ptr13; goto IL_431; Block_16: dataDescriptor.Size = (uint)sizeof(Guid); Guid *ptr14 = dataBuffer; *ptr14 = (Guid)data; dataDescriptor.Ptr = ptr14; goto IL_431; Block_17: dataDescriptor.Size = 16U; decimal *ptr15 = dataBuffer; *ptr15 = (decimal)data; dataDescriptor.Ptr = ptr15; goto IL_431; Block_18: long num = 0L; if (((DateTime)data).Ticks > 504911232000000000L) { num = ((DateTime)data).ToFileTimeUtc(); } dataDescriptor.Size = 8U; long *ptr16 = dataBuffer; *ptr16 = num; dataDescriptor.Ptr = ptr16; goto IL_431; IL_40C: if (data == null) { text = ""; } else { text = data.ToString(); } dataDescriptor.Size = (uint)((text.Length + 1) * 2); IL_431: totalEventSize += dataDescriptor.Size; dataDescriptor += (IntPtr)sizeof(EventProvider.EventData); dataBuffer += 16; return(text ?? array); }
internal static unsafe int EventWriteTransferWrapper(long registrationHandle, ref EventDescriptor eventDescriptor, Guid *activityId, Guid *relatedActivityId, int userDataCount, EventProvider.EventData *userData) { int num = UnsafeNativeMethods.ManifestEtw.EventWriteTransfer(registrationHandle, ref eventDescriptor, activityId, relatedActivityId, userDataCount, userData); if (num == 87 && (IntPtr)relatedActivityId == IntPtr.Zero) { Guid guid = Guid.Empty; num = UnsafeNativeMethods.ManifestEtw.EventWriteTransfer(registrationHandle, ref eventDescriptor, activityId, &guid, userDataCount, userData); } return(num); }