Beispiel #1
0
        /// <summary>
        /// Gets WCT information for the specified thread.
        /// </summary>
        public ThreadWCTInfo GetBlockingObjects(uint osThreadId)
        {
            IntPtr wctSession = IntPtr.Zero;
            try
            {
                wctSession = OpenThreadWaitChainSession((int)WCT_SESSION_OPEN_FLAGS.WCT_SYNC_OPEN_FLAG, 0);
                if (wctSession == IntPtr.Zero)
                    return null;

                WAITCHAIN_NODE_INFO[] nodes = new WAITCHAIN_NODE_INFO[WCT_MAX_NODE_COUNT];
                int isCycle = 0;
                int count = nodes.Length;
                if (GetThreadWaitChain(wctSession, IntPtr.Zero, WCTP_GETINFO_ALL_FLAGS,
                                       osThreadId, ref count, nodes, out isCycle))
                {
                    return new ThreadWCTInfo(isCycle == 1, osThreadId, nodes.Take(count).ToArray());
                }
            }
            finally
            {
                if (wctSession != IntPtr.Zero)
                    CloseThreadWaitChainSession(wctSession);
            }

            return null;
        }
Beispiel #2
0
        /// <summary>
        /// Gets WCT information for the specified thread.
        /// </summary>
        public ThreadWCTInfo GetBlockingObjects(uint osThreadId)
        {
            IntPtr wctSession = IntPtr.Zero;

            try
            {
                wctSession = OpenThreadWaitChainSession((int)WCT_SESSION_OPEN_FLAGS.WCT_SYNC_OPEN_FLAG, 0);
                if (wctSession == IntPtr.Zero)
                {
                    return(null);
                }

                WAITCHAIN_NODE_INFO[] nodes = new WAITCHAIN_NODE_INFO[WCT_MAX_NODE_COUNT];
                int isCycle = 0;
                int count   = nodes.Length;
                if (GetThreadWaitChain(wctSession, IntPtr.Zero, WCTP_GETINFO_ALL_FLAGS,
                                       osThreadId, ref count, nodes, out isCycle))
                {
                    return(new ThreadWCTInfo(isCycle == 1, osThreadId, nodes.Take(count).ToArray()));
                }
            }
            finally
            {
                if (wctSession != IntPtr.Zero)
                {
                    CloseThreadWaitChainSession(wctSession);
                }
            }

            return(null);
        }
Beispiel #3
0
 public void ThreadWaitChainSessionTest()
 {
     RegisterWaitChainCOMCallback();
     using (new ElevPriv("SeDebugPrivilege"))
         using (var hWct = OpenThreadWaitChainSession(WaitChainSessionType.WCT_SYNC_OPEN_FLAG))
         {
             Assert.That(hWct, ResultIs.ValidHandle);
             var  nodes   = new WAITCHAIN_NODE_INFO[WCT_MAX_NODE_COUNT];
             uint nodeCnt = (uint)nodes.Length;
             Assert.That(GetThreadWaitChain(hWct, default, WaitChainRetrievalOptions.WCTP_GETINFO_ALL_FLAGS, Kernel32.GetCurrentThreadId(),
Beispiel #4
0
        public WaitChainInfoObject(WAITCHAIN_NODE_INFO item)
        {
            ObjectStatus = item.ObjectStatus;
            ObjectType   = item.ObjectType;

            TimeOut   = item.Union.LockObject.Timeout;
            Alertable = item.Union.LockObject.Alertable;

            if (item.ObjectType == WCT_OBJECT_TYPE.WctThreadType)
            {
                OSThreadId      = item.Union.ThreadObject.ThreadId;
                OSProcessId     = item.Union.ThreadObject.ProcessId;
                ContextSwitches = item.Union.ThreadObject.ContextSwitches;
                WaitTime        = item.Union.ThreadObject.WaitTime;
            }
            else
            {
                unsafe
                {
                    ObjectName = Marshal.PtrToStringUni((IntPtr)item.Union.LockObject.ObjectName);
                }
            }
        }
Beispiel #5
0
        public WaitChainInfoObject(WAITCHAIN_NODE_INFO item)
        {
            ObjectStatus = item.ObjectStatus;
            ObjectType = item.ObjectType;

            TimeOut = item.Union.LockObject.Timeout;
            Alertable = item.Union.LockObject.Alertable;

            if (item.ObjectType == WCT_OBJECT_TYPE.WctThreadType)
            {
                OSThreadId = item.Union.ThreadObject.ThreadId;
                OSProcessId = item.Union.ThreadObject.ProcessId;
                ContextSwitches = item.Union.ThreadObject.ContextSwitches;
                WaitTime = item.Union.ThreadObject.WaitTime;
            }
            else
            {
                unsafe
                {
                    ObjectName = Marshal.PtrToStringUni((IntPtr)item.Union.LockObject.ObjectName);
                }
            }

        }
 public static bool GetThreadWaitChain(SafeWaitChainHandle chainHandle, int threadId, ref int NodeCount, WAITCHAIN_NODE_INFO[] NodeInfoArray, out int IsCycle)
 {
     return RealGetThreadWaitChain(chainHandle, IntPtr.Zero, WCT_FLAGS.All, threadId, ref NodeCount, NodeInfoArray, out IsCycle);
 }
Beispiel #7
0
 public ThreadWCTInfo(bool isDeadLock, uint threadId, WAITCHAIN_NODE_INFO[] info)
 {
     IsDeadlocked = isDeadLock;
     OSThreadId = threadId;
     WaitChain.AddRange(info.Select(i => new WaitChainInfoObject(i)));
 }