Ejemplo n.º 1
0
        unsafe void Initialize(Guid guid)
        {
            controlGuid = guid;
            TraceGuidRegistration guidReg = new TraceGuidRegistration();
            Guid dummyGuid = new Guid("{aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaabbb}");

            etwProc = new EtwTraceCallback(EtwNotificationCallback);

            guidReg.Guid      = &dummyGuid;
            guidReg.RegHandle = null;

            uint status = EtwNativeMethods.RegisterTraceGuids(etwProc,
                                                              null,
                                                              ref controlGuid,
                                                              1,
                                                              ref guidReg,
                                                              null,
                                                              null,
                                                              out registrationHandle);

            if (status != 0)
            {
                throw new Win32Exception((int)status);
            }
            this.isDisposed = false;
        }
Ejemplo n.º 2
0
        public void Dispose(bool disposing)
        {
            if (disposing)
            {
                int result = EtwNativeMethods.UnregisterTraceGuids(this.registrationHandle);
                // PreSharp requires this: ignore result as we can neither trace nor throw
            }

            this.isDisposed = true;
        }
Ejemplo n.º 3
0
        internal unsafe uint Trace(MofEvent *evt)
        {
            bool shouldRedispose = this.isDisposed;

            if (shouldRedispose)
            {
                this.Initialize(this.controlGuid);
            }
            uint retval = EtwNativeMethods.TraceEvent(traceHandle, (char *)evt);

            if (shouldRedispose)
            {
                this.Dispose(true);
            }
            return(retval);
        }
Ejemplo n.º 4
0
        unsafe uint EtwNotificationCallback(uint requestCode, System.IntPtr context, System.IntPtr bufferSize, byte *buffer)
        {
            if (null == buffer)
            {
                //note that the return value will be ignored
                return(uint.MaxValue);
            }

            EventTraceHeader *eventBuffer = (EventTraceHeader *)buffer;

            switch (requestCode)
            {
            case RequestCodes.EnableEvents:
                this.traceHandle = eventBuffer->HistoricalContext;
                int flags = EtwNativeMethods.GetTraceEnableFlags((ulong)this.traceHandle);
                int level = EtwNativeMethods.GetTraceEnableLevel((ulong)this.traceHandle);
                using (Process process = Process.GetCurrentProcess())
                {
                    if (flags == process.Id)
                    {
                        //TODO, vadim, if the listener is private, forward the level
                        //if not, consider using TraceFilter
                        //Level = LevelFromInt(level);
                    }
                }
                break;

            case RequestCodes.DisableEvents:
                this.traceHandle = 0;
                break;

            default:
                this.traceHandle = 0;
                break;
            }

            return(0);
        }