internal ProviderManifest(byte[] serializedManifest, ManifestEnvelope.ManifestFormats format, byte majorVersion, byte minorVersion)
 {
     this.serializedManifest = serializedManifest;
     this.majorVersion = majorVersion;
     this.minorVersion = minorVersion;
     this.format = format;
 }
Exemplo n.º 2
0
        private unsafe bool SendManifest(byte[] rawManifest)
        {
            bool success = true;

            if (rawManifest.Length == 1)
                throw new ArgumentException(SR.EventSource_NoManifest);  // EventSourceTransformer detected an illegal event method and inserted a 1-length manifest as a sentinel.

            fixed (byte* dataPtr = rawManifest)
            {
                Interop.mincore._EVENT_DESCRIPTOR manifestDescr = new Interop.mincore._EVENT_DESCRIPTOR()
                {
                    Id = 0xFFFE,
                    Version = 1,
                    Opcode = 0xFE,
                    Task = 0xFFFE,
                    Keyword = 0xFFFFFFFFFFFFFFFF
                };
                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 consistency. 
                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;

                while (dataLeft > 0)
                {
                    dataDescrs[1].Size = (uint)Math.Min(dataLeft, ManifestEnvelope.MaxChunkSize);
                    if (m_provider != null)
                    {
                        if (!m_provider.WriteEvent(ref manifestDescr, 2, (IntPtr)dataDescrs))
                        {
                            success = false;
                            if (m_throwOnEventWriteErrors)
                            {
                                throw new EventSourceException();
                            }
                        }
                    }
                    dataLeft -= ManifestEnvelope.MaxChunkSize;
                    dataDescrs[1].Ptr += ManifestEnvelope.MaxChunkSize;
                    envelope.ChunkNumber++;
                }
            }

            return success;
        }
Exemplo n.º 3
0
        private unsafe bool SendManifest(byte[] rawManifest)
        {
            bool success = true;

#if FEATURE_MANAGED_ETW
            fixed (byte* dataPtr = rawManifest)
            {
                var manifestDescr = new System.Diagnostics.Tracing.EventDescriptor(0xFFFE, 1, 0, 0, 0xFE, 0xFFFE, -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;

                int chunkSize = ManifestEnvelope.MaxChunkSize;
            TRY_AGAIN_WITH_SMALLER_CHUNK_SIZE:

                while (dataLeft > 0)
                {
                    dataDescrs[1].Size = (uint)Math.Min(dataLeft, chunkSize);
                    if (m_provider != null)
                    {
                        if (!m_provider.WriteEvent(ref manifestDescr, null, 2, (IntPtr)dataDescrs))
                        {                            
                            // Turns out that if users set the BufferSize to something less than 64K then WriteEvent
                            // can fail.   If we get this failure on the first chunk try again with something smaller
                            // The smallest BufferSize is 1K so if we get to 512, we can give up making it smaller. 
                            if (EventProvider.GetLastWriteEventError() == EventProvider.WriteEventErrorCode.EventTooBig)
                            {
                                chunkSize = chunkSize / 2;
                                if (envelope.ChunkNumber == 0 && chunkSize > 512)
                                    goto TRY_AGAIN_WITH_SMALLER_CHUNK_SIZE;
                            }
                            success = false;
                            if(m_throwOnEventWriteErrors)
                                ThrowEventSourceException();
                            }
                        }
                    dataLeft -= ManifestEnvelope.MaxChunkSize;
                    dataDescrs[1].Ptr += ManifestEnvelope.MaxChunkSize;
                    envelope.ChunkNumber++;
                }
            }
#endif

            return success;
        }