public unsafe bool WriteEvent(ref EventDescriptorInternal eventDescriptor, string data) { uint num = 0; if (data == null) { throw new ArgumentNullException("dataString"); } if (this.IsEnabled(eventDescriptor.Level, eventDescriptor.Keywords)) { EventData data2; if (data.Length > 0x7fd4) { s_returnCode = WriteEventErrorCode.EventTooBig; return(false); } data2.Size = (uint)((data.Length + 1) * 2); data2.Reserved = 0; fixed(char *str = ((char *)data)) { char *chPtr = str; data2.Ptr = (ulong)chPtr; num = this.EventWrite(ref eventDescriptor, 1, &data2); } } if (num != 0) { SetLastError((int)num); return(false); } return(true); }
private unsafe uint EventWrite(ref EventDescriptorInternal eventDescriptor, uint userDataCount, EventData* userData) { if (!m_isClassic) return ManifestEtw.EventWrite(m_regHandle, ref eventDescriptor, userDataCount, userData); else return ClassicShimEventWrite(ref eventDescriptor, userDataCount, userData); }
private unsafe uint EventWriteTransfer(ref EventDescriptorInternal eventDescriptor, ref Guid activityId, ref Guid relatedActivityId, uint userDataCount, EventData *userData) { if (!this.m_isClassic) { return(ManifestEtw.EventWriteTransfer(this.m_regHandle, ref eventDescriptor, ref activityId, ref relatedActivityId, userDataCount, userData)); } return(this.ClassicShimEventWriteTransfer(ref eventDescriptor, ref activityId, ref relatedActivityId, userDataCount, userData)); }
private unsafe uint EventWrite(ref EventDescriptorInternal eventDescriptor, uint userDataCount, EventData *userData) { if (!this.m_isClassic) { return(ManifestEtw.EventWrite(this.m_regHandle, ref eventDescriptor, userDataCount, userData)); } return(this.ClassicShimEventWrite(ref eventDescriptor, userDataCount, userData)); }
private unsafe uint EventWriteTransfer(ref EventDescriptorInternal eventDescriptor, ref Guid activityId, ref Guid relatedActivityId, uint userDataCount, EventData* userData) { if (!m_isClassic) return ManifestEtw.EventWriteTransfer(m_regHandle, ref eventDescriptor, ref activityId, ref relatedActivityId, userDataCount, userData); else return ClassicShimEventWriteTransfer(ref eventDescriptor, ref activityId, ref relatedActivityId, userDataCount, userData); }
protected void WriteEvent(ref EventDescriptorInternal descriptor, params object[] args) { if ((this.m_provider != null) && this.m_eventData[descriptor.EventId].EnabledForETW) { this.m_provider.WriteEvent(ref descriptor, args); } if ((this.m_OutputStreams != null) && this.m_eventData[descriptor.EventId].EnabledForAnyStream) { this.WriteToAllStreams(descriptor.EventId, args); } }
protected internal unsafe bool WriteEvent(ref EventDescriptorInternal eventDescriptor, int dataCount, IntPtr data) { uint num = 0; num = this.EventWrite(ref eventDescriptor, (uint)dataCount, (EventData *)data); if (num != 0) { SetLastError((int)num); return(false); } return(true); }
protected unsafe bool WriteTransferEvent(ref EventDescriptorInternal eventDescriptor, Guid relatedActivityId, int dataCount, IntPtr data) { uint num = 0; Guid activityId = GetActivityId(); num = this.EventWriteTransfer(ref eventDescriptor, ref activityId, ref relatedActivityId, (uint)dataCount, (EventData *)data); if (num != 0) { SetLastError((int)num); return(false); } return(true); }
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); } }
private unsafe uint ClassicShimEventWriteString(byte level, long keywords, char *message) { EventDescriptorInternal eventDescriptor = new EventDescriptorInternal(0, 0, 0, 0, 0, 0, 0L); char *chPtr = message; while (chPtr[0] != '\0') { chPtr++; } EventData userData = new EventData { Ptr = (ulong)message, Size = ((uint)((long)((chPtr - message) / 2))) + 1, Reserved = 0 }; return(this.ClassicShimEventWrite(ref eventDescriptor, 1, &userData)); }
private unsafe uint ClassicShimEventWrite(ref EventDescriptorInternal eventDescriptor, uint userDataCount, EventData* userData) { this.m_classicEventHeader.Header.ClientContext = 0; this.m_classicEventHeader.Header.Flags = 0x120000; this.m_classicEventHeader.Header.Guid = GenTaskGuidFromProviderGuid(this.m_providerId, (ushort) eventDescriptor.Task); this.m_classicEventHeader.Header.Level = eventDescriptor.Level; this.m_classicEventHeader.Header.Type = eventDescriptor.Opcode; this.m_classicEventHeader.Header.Version = eventDescriptor.Version; EventData* dataPtr = &this.m_classicEventHeader.Data; if (userDataCount > 0x10) { throw new Exception(); } this.m_classicEventHeader.Header.Size = (ushort) (((ulong) 0x30L) + (userDataCount * sizeof(EventData))); for (int i = 0; i < userDataCount; i++) { dataPtr[i].Ptr = userData[i].Ptr; dataPtr[i].Size = userData[i].Size; } return ClassicEtw.TraceEvent(this.m_classicSessionHandle, this.m_classicEventHeader); }
private unsafe uint ClassicShimEventWrite(ref EventDescriptorInternal eventDescriptor, uint userDataCount, EventData *userData) { this.m_classicEventHeader.Header.ClientContext = 0; this.m_classicEventHeader.Header.Flags = 0x120000; this.m_classicEventHeader.Header.Guid = GenTaskGuidFromProviderGuid(this.m_providerId, (ushort)eventDescriptor.Task); this.m_classicEventHeader.Header.Level = eventDescriptor.Level; this.m_classicEventHeader.Header.Type = eventDescriptor.Opcode; this.m_classicEventHeader.Header.Version = eventDescriptor.Version; EventData *dataPtr = &this.m_classicEventHeader.Data; if (userDataCount > 0x10) { throw new Exception(); } this.m_classicEventHeader.Header.Size = (ushort)(((ulong)0x30L) + (userDataCount * sizeof(EventData))); for (int i = 0; i < userDataCount; i++) { dataPtr[i].Ptr = userData[i].Ptr; dataPtr[i].Size = userData[i].Size; } return(ClassicEtw.TraceEvent(this.m_classicSessionHandle, this.m_classicEventHeader)); }
public unsafe bool WriteTransferEvent(ref EventDescriptorInternal eventDescriptor, Guid relatedActivityId, params object[] eventPayload) { uint num = 0; if (this.IsEnabled(eventDescriptor.Level, eventDescriptor.Keywords)) { Guid activityId = GetActivityId(); if ((eventPayload != null) && (eventPayload.Length != 0)) { int length = eventPayload.Length; if (length > 0x20) { throw new ArgumentOutOfRangeException("eventPayload", SRETW.GetString("ArgumentOutOfRange_MaxArgExceeded", new object[] { 0x20 })); } uint num3 = 0; int index = 0; int[] numArray = new int[8]; string[] strArray = new string[8]; EventData *userData = (EventData *)stackalloc byte[(((IntPtr)length) * sizeof(EventData))]; EventData *dataDescriptor = userData; byte * dataBuffer = stackalloc byte[(IntPtr)(0x10 * length)]; for (int i = 0; i < eventPayload.Length; i++) { if (eventPayload[i] != null) { string str = EncodeObject(ref eventPayload[i], dataDescriptor, dataBuffer); dataBuffer += 0x10; num3 += dataDescriptor->Size; dataDescriptor++; if (str != null) { if (index >= 8) { throw new ArgumentOutOfRangeException("eventPayload", SRETW.GetString("ArgumentOutOfRange_MaxStringsExceeded", new object[] { 8 })); } strArray[index] = str; numArray[index] = i; index++; } } } if (num3 > 0xffca) { s_returnCode = WriteEventErrorCode.EventTooBig; return(false); } fixed(char *str2 = ((char *)strArray[0])) { char *chPtr = str2; fixed(char *str3 = ((char *)strArray[1])) { char *chPtr2 = str3; fixed(char *str4 = ((char *)strArray[2])) { char *chPtr3 = str4; fixed(char *str5 = ((char *)strArray[3])) { char *chPtr4 = str5; fixed(char *str6 = ((char *)strArray[4])) { char *chPtr5 = str6; fixed(char *str7 = ((char *)strArray[5])) { char *chPtr6 = str7; fixed(char *str8 = ((char *)strArray[6])) { char *chPtr7 = str8; fixed(char *str9 = ((char *)strArray[7])) { char *chPtr8 = str9; dataDescriptor = userData; if (strArray[0] != null) { dataDescriptor[numArray[0]].Ptr = (ulong)chPtr; } if (strArray[1] != null) { dataDescriptor[numArray[1]].Ptr = (ulong)chPtr2; } if (strArray[2] != null) { dataDescriptor[numArray[2]].Ptr = (ulong)chPtr3; } if (strArray[3] != null) { dataDescriptor[numArray[3]].Ptr = (ulong)chPtr4; } if (strArray[4] != null) { dataDescriptor[numArray[4]].Ptr = (ulong)chPtr5; } if (strArray[5] != null) { dataDescriptor[numArray[5]].Ptr = (ulong)chPtr6; } if (strArray[6] != null) { dataDescriptor[numArray[6]].Ptr = (ulong)chPtr7; } if (strArray[7] != null) { dataDescriptor[numArray[7]].Ptr = (ulong)chPtr8; } num = this.EventWriteTransfer(ref eventDescriptor, ref activityId, ref relatedActivityId, (uint)length, userData); } } } } } } } } str4 = null; str5 = null; str6 = null; str7 = null; str8 = null; str9 = null; } else { num = this.EventWriteTransfer(ref eventDescriptor, ref activityId, ref relatedActivityId, 0, null); } } if (num != 0) { SetLastError((int)num); return(false); } return(true); }
public bool Equals(EventDescriptorInternal other) { return ((((this.m_id == other.m_id) && (this.m_version == other.m_version)) && ((this.m_channel == other.m_channel) && (this.m_level == other.m_level))) && (((this.m_opcode == other.m_opcode) && (this.m_task == other.m_task)) && (this.m_keywords == other.m_keywords))); }
protected bool WriteTransferEvent(ref EventDescriptorInternal eventDescriptor, Guid relatedActivityId, int dataCount, IntPtr data) { uint status = 0; Guid activityId = GetActivityId(); unsafe { status = EventWriteTransfer( ref eventDescriptor, ref activityId, ref relatedActivityId, (uint)dataCount, (EventData*)data); } if (status != 0) { SetLastError((int)status); return false; } return true; }
public bool WriteEvent(ref EventDescriptorInternal eventDescriptor, params object[] eventPayload) { uint status = 0; if (IsEnabled(eventDescriptor.Level, eventDescriptor.Keywords)) { int argCount = 0; unsafe { if ((eventPayload == null) || (eventPayload.Length == 0) || (eventPayload.Length == 1)) { string dataString = null; EventData userData; byte* dataBuffer = stackalloc byte[s_basicTypeAllocationBufferSize]; // Assume a max of 16 chars for non-string argument userData.Size = 0; if ((eventPayload != null) && (eventPayload.Length != 0)) { // // Figure out the type and fill the data descriptor // dataString = EncodeObject(ref eventPayload[0], &userData, dataBuffer); argCount = 1; } if (userData.Size > s_traceEventMaximumSize) { // // Maximum size of the event payload plus header is 64k // s_returnCode = WriteEventErrorCode.EventTooBig; return false; } if (dataString != null) { fixed (char* pdata = dataString) { userData.Ptr = (ulong)pdata; status = EventWrite(ref eventDescriptor, (uint)argCount, &userData); } } else { if (argCount == 0) { status = EventWrite(ref eventDescriptor, 0, null); } else { status = EventWrite(ref eventDescriptor, (uint)argCount, &userData); } } } else { argCount = eventPayload.Length; if (argCount > s_etwMaxMumberArguments) { // //too many arguments to log // throw new ArgumentOutOfRangeException("eventPayload", SRETW.GetString(SRETW.ArgumentOutOfRange_MaxArgExceeded, s_etwMaxMumberArguments)); } uint totalEventSize = 0; int index; int stringIndex = 0; int[] stringPosition = new int[s_etwAPIMaxStringCount]; string[] dataString = new string[s_etwAPIMaxStringCount]; EventData* userData = stackalloc EventData[argCount]; EventData* userDataPtr = (EventData*)userData; byte* dataBuffer = stackalloc byte[s_basicTypeAllocationBufferSize * argCount]; // Assume 16 chars for non-string argument byte* currentBuffer = dataBuffer; // // The loop below goes through all the arguments and fills in the data // descriptors. For strings save the location in the dataString array. // Caculates the total size of the event by adding the data descriptor // size value set in EncodeObjec method. // for (index = 0; index < eventPayload.Length; index++) { if (eventPayload[index] != null) { string isString; isString = EncodeObject(ref eventPayload[index], userDataPtr, currentBuffer); currentBuffer += s_basicTypeAllocationBufferSize; totalEventSize += userDataPtr->Size; userDataPtr++; if (isString != null) { if (stringIndex < s_etwAPIMaxStringCount) { dataString[stringIndex] = isString; stringPosition[stringIndex] = index; stringIndex++; } else { throw new ArgumentOutOfRangeException("eventPayload", SRETW.GetString(SRETW.ArgumentOutOfRange_MaxStringsExceeded, s_etwAPIMaxStringCount)); } } } } if (totalEventSize > s_traceEventMaximumSize) { s_returnCode = WriteEventErrorCode.EventTooBig; return false; } // // now fix any string arguments and set the pointer on the data descriptor // fixed (char* v0 = dataString[0], v1 = dataString[1], v2 = dataString[2], v3 = dataString[3], v4 = dataString[4], v5 = dataString[5], v6 = dataString[6], v7 = dataString[7]) { userDataPtr = (EventData*)userData; if (dataString[0] != null) { userDataPtr[stringPosition[0]].Ptr = (ulong)v0; } if (dataString[1] != null) { userDataPtr[stringPosition[1]].Ptr = (ulong)v1; } if (dataString[2] != null) { userDataPtr[stringPosition[2]].Ptr = (ulong)v2; } if (dataString[3] != null) { userDataPtr[stringPosition[3]].Ptr = (ulong)v3; } if (dataString[4] != null) { userDataPtr[stringPosition[4]].Ptr = (ulong)v4; } if (dataString[5] != null) { userDataPtr[stringPosition[5]].Ptr = (ulong)v5; } if (dataString[6] != null) { userDataPtr[stringPosition[6]].Ptr = (ulong)v6; } if (dataString[7] != null) { userDataPtr[stringPosition[7]].Ptr = (ulong)v7; } status = EventWrite(ref eventDescriptor, (uint)argCount, userData); } } } } if (status != 0) { SetLastError((int)status); return false; } return true; }
public unsafe bool WriteEvent(ref EventDescriptorInternal eventDescriptor, string data) { uint num = 0; if (data == null) { throw new ArgumentNullException("dataString"); } if (this.IsEnabled(eventDescriptor.Level, eventDescriptor.Keywords)) { EventData data2; if (data.Length > 0x7fd4) { s_returnCode = WriteEventErrorCode.EventTooBig; return false; } data2.Size = (uint) ((data.Length + 1) * 2); data2.Reserved = 0; fixed (char* str = ((char*) data)) { char* chPtr = str; data2.Ptr = (ulong) chPtr; num = this.EventWrite(ref eventDescriptor, 1, &data2); } } if (num != 0) { SetLastError((int) num); return false; } return true; }
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; } }
private unsafe uint ClassicShimEventWriteTransfer(ref EventDescriptorInternal eventDescriptor, ref Guid activityId, ref Guid relatedActivityId, uint userDataCount, EventData* userData) { // throw new NotImplementedException(); }
protected unsafe void WriteEvent(ref EventDescriptorInternal descriptor, params object[] args) { Contract.Assert(m_eventData[descriptor.EventId].Descriptor.EventId != 0); #if ETW_SUPPORTED if (m_provider != null && m_eventData[descriptor.EventId].EnabledForETW) m_provider.WriteEvent(ref descriptor, args); #endif if (m_OutputStreams != null && m_eventData[descriptor.EventId].EnabledForAnyStream) WriteToAllStreams(descriptor.EventId, args); }
protected unsafe bool WriteTransferEvent(ref EventDescriptorInternal eventDescriptor, Guid relatedActivityId, int dataCount, IntPtr data) { uint num = 0; Guid activityId = GetActivityId(); num = this.EventWriteTransfer(ref eventDescriptor, ref activityId, ref relatedActivityId, (uint) dataCount, (EventData*) data); if (num != 0) { SetLastError((int) num); return false; } return true; }
public unsafe bool WriteTransferEvent(ref EventDescriptorInternal eventDescriptor, Guid relatedActivityId, params object[] eventPayload) { uint num = 0; if (this.IsEnabled(eventDescriptor.Level, eventDescriptor.Keywords)) { Guid activityId = GetActivityId(); if ((eventPayload != null) && (eventPayload.Length != 0)) { int length = eventPayload.Length; if (length > 0x20) { throw new ArgumentOutOfRangeException("eventPayload", SRETW.GetString("ArgumentOutOfRange_MaxArgExceeded", new object[] { 0x20 })); } uint num3 = 0; int index = 0; int[] numArray = new int[8]; string[] strArray = new string[8]; EventData* userData = (EventData*) stackalloc byte[(((IntPtr) length) * sizeof(EventData))]; EventData* dataDescriptor = userData; byte* dataBuffer = stackalloc byte[(IntPtr) (0x10 * length)]; for (int i = 0; i < eventPayload.Length; i++) { if (eventPayload[i] != null) { string str = EncodeObject(ref eventPayload[i], dataDescriptor, dataBuffer); dataBuffer += 0x10; num3 += dataDescriptor->Size; dataDescriptor++; if (str != null) { if (index >= 8) { throw new ArgumentOutOfRangeException("eventPayload", SRETW.GetString("ArgumentOutOfRange_MaxStringsExceeded", new object[] { 8 })); } strArray[index] = str; numArray[index] = i; index++; } } } if (num3 > 0xffca) { s_returnCode = WriteEventErrorCode.EventTooBig; return false; } fixed (char* str2 = ((char*) strArray[0])) { char* chPtr = str2; fixed (char* str3 = ((char*) strArray[1])) { char* chPtr2 = str3; fixed (char* str4 = ((char*) strArray[2])) { char* chPtr3 = str4; fixed (char* str5 = ((char*) strArray[3])) { char* chPtr4 = str5; fixed (char* str6 = ((char*) strArray[4])) { char* chPtr5 = str6; fixed (char* str7 = ((char*) strArray[5])) { char* chPtr6 = str7; fixed (char* str8 = ((char*) strArray[6])) { char* chPtr7 = str8; fixed (char* str9 = ((char*) strArray[7])) { char* chPtr8 = str9; dataDescriptor = userData; if (strArray[0] != null) { dataDescriptor[numArray[0]].Ptr = (ulong) chPtr; } if (strArray[1] != null) { dataDescriptor[numArray[1]].Ptr = (ulong) chPtr2; } if (strArray[2] != null) { dataDescriptor[numArray[2]].Ptr = (ulong) chPtr3; } if (strArray[3] != null) { dataDescriptor[numArray[3]].Ptr = (ulong) chPtr4; } if (strArray[4] != null) { dataDescriptor[numArray[4]].Ptr = (ulong) chPtr5; } if (strArray[5] != null) { dataDescriptor[numArray[5]].Ptr = (ulong) chPtr6; } if (strArray[6] != null) { dataDescriptor[numArray[6]].Ptr = (ulong) chPtr7; } if (strArray[7] != null) { dataDescriptor[numArray[7]].Ptr = (ulong) chPtr8; } num = this.EventWriteTransfer(ref eventDescriptor, ref activityId, ref relatedActivityId, (uint) length, userData); } } } } } } } } str4 = null; str5 = null; str6 = null; str7 = null; str8 = null; str9 = null; } else { num = this.EventWriteTransfer(ref eventDescriptor, ref activityId, ref relatedActivityId, 0, null); } } if (num != 0) { SetLastError((int) num); return false; } return true; }
protected internal unsafe bool WriteEvent(ref EventDescriptorInternal eventDescriptor, int dataCount, IntPtr data) { uint num = 0; num = this.EventWrite(ref eventDescriptor, (uint) dataCount, (EventData*) data); if (num != 0) { SetLastError((int) num); return false; } return true; }
public bool WriteTransferEvent(ref EventDescriptorInternal eventDescriptor, Guid relatedActivityId, params object[] eventPayload) { uint status = 0; if (IsEnabled(eventDescriptor.Level, eventDescriptor.Keywords)) { Guid activityId = GetActivityId(); unsafe { if ((eventPayload != null) && (eventPayload.Length != 0)) { int argCount = eventPayload.Length; if (argCount > s_etwMaxMumberArguments) { // //too many arguments to log // throw new ArgumentOutOfRangeException("eventPayload", SRETW.GetString(SRETW.ArgumentOutOfRange_MaxArgExceeded, s_etwMaxMumberArguments)); } uint totalEventSize = 0; int index; int stringIndex = 0; int[] stringPosition = new int[s_etwAPIMaxStringCount]; //used to keep the position of strings in the eventPayload parameter string[] dataString = new string[s_etwAPIMaxStringCount]; // string arrays from the eventPayload parameter EventData* userData = stackalloc EventData[argCount]; // allocation for the data descriptors EventData* userDataPtr = (EventData*)userData; byte* dataBuffer = stackalloc byte[s_basicTypeAllocationBufferSize * argCount]; // 16 byte for unboxing non-string argument byte* currentBuffer = dataBuffer; // // The loop below goes through all the arguments and fills in the data // descriptors. For strings save the location in the dataString array. // Caculates the total size of the event by adding the data descriptor // size value set in EncodeObjec method. // for (index = 0; index < eventPayload.Length; index++) { if (eventPayload[index] != null) { string isString; isString = EncodeObject(ref eventPayload[index], userDataPtr, currentBuffer); currentBuffer += s_basicTypeAllocationBufferSize; totalEventSize += userDataPtr->Size; userDataPtr++; if (isString != null) { if (stringIndex < s_etwAPIMaxStringCount) { dataString[stringIndex] = isString; stringPosition[stringIndex] = index; stringIndex++; } else { throw new ArgumentOutOfRangeException("eventPayload", SRETW.GetString(SRETW.ArgumentOutOfRange_MaxStringsExceeded, s_etwAPIMaxStringCount)); } } } } if (totalEventSize > s_traceEventMaximumSize) { s_returnCode = WriteEventErrorCode.EventTooBig; return false; } fixed (char* v0 = dataString[0], v1 = dataString[1], v2 = dataString[2], v3 = dataString[3], v4 = dataString[4], v5 = dataString[5], v6 = dataString[6], v7 = dataString[7]) { userDataPtr = (EventData*)userData; if (dataString[0] != null) { userDataPtr[stringPosition[0]].Ptr = (ulong)v0; } if (dataString[1] != null) { userDataPtr[stringPosition[1]].Ptr = (ulong)v1; } if (dataString[2] != null) { userDataPtr[stringPosition[2]].Ptr = (ulong)v2; } if (dataString[3] != null) { userDataPtr[stringPosition[3]].Ptr = (ulong)v3; } if (dataString[4] != null) { userDataPtr[stringPosition[4]].Ptr = (ulong)v4; } if (dataString[5] != null) { userDataPtr[stringPosition[5]].Ptr = (ulong)v5; } if (dataString[6] != null) { userDataPtr[stringPosition[6]].Ptr = (ulong)v6; } if (dataString[7] != null) { userDataPtr[stringPosition[7]].Ptr = (ulong)v7; } status = EventWriteTransfer(ref eventDescriptor, ref activityId, ref relatedActivityId, (uint)argCount, userData); } } else { status = EventWriteTransfer(ref eventDescriptor, ref activityId, ref relatedActivityId, 0, null); } } } if (status != 0) { SetLastError((int)status); return false; } return true; }
internal protected bool WriteEvent(ref EventDescriptorInternal eventDescriptor, int dataCount, IntPtr data) { uint status = 0; unsafe { status = EventWrite(ref eventDescriptor, (uint)dataCount, (EventData*)data); } if (status != 0) { SetLastError((int)status); return false; } return true; }
private unsafe uint ClassicShimEventWrite(ref EventDescriptorInternal eventDescriptor, uint userDataCount, EventData* userData) { m_classicEventHeader->Header.ClientContext = 0; m_classicEventHeader->Header.Flags = ClassicEtw.WNODE_FLAG_TRACED_GUID | ClassicEtw.WNODE_FLAG_USE_MOF_PTR; m_classicEventHeader->Header.Guid = GenTaskGuidFromProviderGuid(m_providerId, (ushort)eventDescriptor.Task); m_classicEventHeader->Header.Level = eventDescriptor.Level; m_classicEventHeader->Header.Type = eventDescriptor.Opcode; m_classicEventHeader->Header.Version = eventDescriptor.Version; EventData* eventData = &m_classicEventHeader->Data; if (userDataCount > ClassicEtw.MAX_MOF_FIELDS) throw new Exception(); // m_classicEventHeader->Header.Size = (ushort)(48 + userDataCount * sizeof(EventData)); for (int i = 0; i < userDataCount; i++) { eventData[i].Ptr = userData[i].Ptr; eventData[i].Size = userData[i].Size; } return ClassicEtw.TraceEvent(m_classicSessionHandle, m_classicEventHeader); }
private unsafe uint ClassicShimEventWriteString(byte level, long keywords, char* message) { EventDescriptorInternal eventDescriptor = new EventDescriptorInternal(0, 0, 0, 0, 0, 0, 0L); char* chPtr = message; while (chPtr[0] != '\0') { chPtr++; } EventData userData = new EventData { Ptr = (ulong) message, Size = ((uint) ((long) ((chPtr - message) / 2))) + 1, Reserved = 0 }; return this.ClassicShimEventWrite(ref eventDescriptor, 1, &userData); }
private unsafe uint ClassicShimEventWriteString(byte level, long keywords, char* message) { // EventDescriptorInternal eventDescr = new EventDescriptorInternal(0, 0, 0, 0, 0, 0, 0); char* end = message; while (*end != 0) end++; EventData dataDesc = new EventData(); dataDesc.Ptr = (ulong)message; dataDesc.Size = (uint)(end - message) + 1; dataDesc.Reserved = 0; return ClassicShimEventWrite(ref eventDescr, 1, &dataDesc); }
public bool Equals(EventDescriptorInternal other) { return((((this.m_id == other.m_id) && (this.m_version == other.m_version)) && ((this.m_channel == other.m_channel) && (this.m_level == other.m_level))) && (((this.m_opcode == other.m_opcode) && (this.m_task == other.m_task)) && (this.m_keywords == other.m_keywords))); }
private unsafe uint ClassicShimEventWriteTransfer(ref EventDescriptorInternal eventDescriptor, ref Guid activityId, ref Guid relatedActivityId, uint userDataCount, EventData *userData) { throw new NotImplementedException(); }
public bool WriteEvent(ref EventDescriptorInternal eventDescriptor, string data) { uint status = 0; if (data == null) { throw new ArgumentNullException("dataString"); } if (IsEnabled(eventDescriptor.Level, eventDescriptor.Keywords)) { if (data.Length > s_traceEventMaximumStringSize) { s_returnCode = WriteEventErrorCode.EventTooBig; return false; } EventData userData; userData.Size = (uint)((data.Length + 1) * 2); userData.Reserved = 0; unsafe { fixed (char* pdata = data) { userData.Ptr = (ulong)pdata; status = EventWrite(ref eventDescriptor, 1, &userData); } } } if (status != 0) { SetLastError((int)status); return false; } return true; }
private unsafe bool SendManifest(byte[] rawManifest, EventProviderDataStream outputStream) { fixed (byte* dataPtr = rawManifest) { EventDescriptorInternal manifestDescr = new EventDescriptorInternal(0xFFFE, 1, 0, 0, 0xFE, 0, -1); ManifestEnvelope envelope = new ManifestEnvelope(); envelope.Format = ManifestEnvelope.ManifestFormats.SimpleXmlFormat; envelope.MajorVersion = 1; envelope.MinorVersion = 0; envelope.Magic = 0x5B; // An unusual number that can be checked for consistancy. int dataLeft = rawManifest.Length; envelope.TotalChunks = (ushort)((dataLeft + (ManifestEnvelope.MaxChunkSize - 1)) / ManifestEnvelope.MaxChunkSize); envelope.ChunkNumber = 0; EventProvider.EventData* dataDescrs = stackalloc EventProvider.EventData[2]; dataDescrs[0].Ptr = (ulong)&envelope; dataDescrs[0].Size = (uint)sizeof(ManifestEnvelope); dataDescrs[0].Reserved = 0; dataDescrs[1].Ptr = (ulong)dataPtr; dataDescrs[1].Reserved = 0; bool success = true; while (dataLeft > 0) { dataDescrs[1].Size = (uint)Math.Min(dataLeft, ManifestEnvelope.MaxChunkSize); #if ETW_SUPPORTED if (outputStream == null && m_provider != null && !m_provider.WriteEvent(ref manifestDescr, 2, (IntPtr)dataDescrs)) success = false; #endif if (outputStream != null) { byte[] envelopeBlob = null; byte[] manifestBlob = null; if (envelopeBlob == null) { envelopeBlob = new byte[dataDescrs[0].Size]; manifestBlob = new byte[dataDescrs[1].Size]; } System.Runtime.InteropServices.Marshal.Copy((IntPtr)dataDescrs[0].Ptr, envelopeBlob, 0, (int)dataDescrs[0].Size); System.Runtime.InteropServices.Marshal.Copy((IntPtr)dataDescrs[1].Ptr, manifestBlob, 0, (int)dataDescrs[1].Size); m_eventCallbackArgs.EventId = manifestDescr.EventId; m_eventCallbackArgs.Payload = new object[] { envelopeBlob, manifestBlob }; outputStream.m_Callback(m_eventCallbackArgs); } dataLeft -= ManifestEnvelope.MaxChunkSize; envelope.ChunkNumber++; } return success; } }
internal static extern unsafe uint EventWrite([In] long registrationHandle, [In] ref EventDescriptorInternal eventDescriptor, [In] uint 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);
public bool Equals(EventDescriptorInternal other) { if ((m_id != other.m_id) || (m_version != other.m_version) || (m_channel != other.m_channel) || (m_level != other.m_level) || (m_opcode != other.m_opcode) || (m_task != other.m_task) || (m_keywords != other.m_keywords)) { return false; } return true; }