Example #1
0
        private List <ClrThread> CreateThreadList()
        {
            IThreadStoreData threadStore = GetThreadStoreData();
            ulong            finalizer   = ulong.MaxValue - 1;

            if (threadStore != null)
            {
                finalizer = threadStore.Finalizer;
            }

            List <ClrThread> threads = new List <ClrThread>();

            ulong       addr   = GetFirstThread();
            IThreadData thread = GetThread(addr);

            // Ensure we don't hit an infinite loop
            HashSet <ulong> seen = new HashSet <ulong> {
                addr
            };

            while (thread != null)
            {
                threads.Add(new DesktopThread(this, thread, addr, addr == finalizer));
                addr = thread.Next;
                if (seen.Contains(addr) || addr == 0)
                {
                    break;
                }

                seen.Add(addr);
                thread = GetThread(addr);
            }

            return(threads);
        }
Example #2
0
        internal Dictionary <ulong, ulong> GetAllocContexts()
        {
            Dictionary <ulong, ulong> ret = new Dictionary <ulong, ulong>();

            // Give a max number of threads to walk to ensure no infinite loops due to data
            // inconsistency.
            int max = 1024;

            IThreadData thread = GetThread(GetFirstThread());

            while (max-- > 0 && thread != null)
            {
                if (thread.AllocPtr != 0)
                {
                    ret[thread.AllocPtr] = thread.AllocLimit;
                }

                if (thread.Next == 0)
                {
                    break;
                }
                thread = GetThread(thread.Next);
            }

            return(ret);
        }
Example #3
0
        private void InitThreads()
        {
            if (_threads == null)
            {
                IThreadStoreData threadStore = GetThreadStoreData();
                ulong            finalizer   = ulong.MaxValue - 1;
                if (threadStore != null)
                {
                    finalizer = threadStore.Finalizer;
                }

                List <ClrThread> threads = new List <ClrThread>();

                // Give a max number of threads to walk to ensure no infinite loops due to data
                // inconsistency.
                int         max    = 4098;
                ulong       addr   = GetFirstThread();
                IThreadData thread = GetThread(addr);

                while (max-- > 0 && thread != null)
                {
                    threads.Add(new DesktopThread(this, thread, addr, addr == finalizer));
                    addr   = thread.Next;
                    thread = GetThread(addr);
                }

                _threads = threads;
            }
        }
Example #4
0
        internal ThreadBase(IThreadData thread, ulong address, bool finalizer)
        {
            _address   = address;
            _finalizer = finalizer;

            Debug.Assert(thread != null);
            if (thread != null)
            {
                _osThreadId      = thread.OSThreadID;
                _managedThreadId = thread.ManagedThreadID;
                _appDomain       = thread.AppDomain;
                _lockCount       = thread.LockCount;
                _teb             = thread.Teb;
                _threadState     = thread.State;
                _exception       = thread.ExceptionPtr;
                _preemptive      = thread.Preemptive;
            }
        }
Example #5
0
        private void InitThreads()
        {
            IThreadStoreData tsData  = GetThreadStoreData();
            List <ClrThread> threads = new List <ClrThread>(tsData.Count);

            ulong       addr   = tsData.FirstThread;
            IThreadData thread = GetThread(tsData.FirstThread);

            for (int i = 0; thread != null; i++)
            {
                threads.Add(new NativeThread(this, thread, addr, tsData.Finalizer == addr));

                addr   = thread.Next;
                thread = GetThread(addr);
            }

            _threads = threads.ToArray();
        }
Example #6
0
        internal DesktopThread(RuntimeBase clr, IThreadData thread, ulong address, bool finalizer)
        {
            m_runtime   = clr;
            m_address   = address;
            m_finalizer = finalizer;

            Debug.Assert(thread != null);
            if (thread != null)
            {
                m_osThreadId      = thread.OSThreadID;
                m_managedThreadId = thread.ManagedThreadID;
                m_appDomain       = thread.AppDomain;
                m_lockCount       = thread.LockCount;
                m_teb             = thread.Teb;
                m_threadState     = thread.State;
                m_exception       = thread.ExceptionPtr;
                m_preemptive      = thread.Preemptive;
            }
        }
Example #7
0
        public ClrmdThread(IThreadData data, ClrRuntime runtime, ClrAppDomain currentDomain)
        {
            if (data is null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            _helpers         = data.Helpers;
            Runtime          = runtime;
            Address          = data.Address;
            IsFinalizer      = data.IsFinalizer;
            OSThreadId       = data.OSThreadID;
            ManagedThreadId  = data.ManagedThreadID;
            CurrentAppDomain = currentDomain;
            LockCount        = data.LockCount;
            _threadState     = data.State;
            _exceptionHandle = data.ExceptionHandle;
            StackBase        = data.StackBase;
            StackLimit       = data.StackLimit;
            GcMode           = data.Preemptive ? GcMode.Preemptive : GcMode.Cooperative;
        }
Example #8
0
 internal DesktopThread(DesktopRuntimeBase clr, IThreadData thread, ulong address, bool finalizer)
     : base(thread, address, finalizer)
 {
     DesktopRuntime = clr;
 }
Example #9
0
        internal DesktopThread(RuntimeBase clr, IThreadData thread, ulong address, bool finalizer)
        {
            _runtime = clr;
            _address = address;
            _finalizer = finalizer;

            Debug.Assert(thread != null);
            if (thread != null)
            {
                _osThreadId = thread.OSThreadID;
                _managedThreadId = thread.ManagedThreadID;
                _appDomain = thread.AppDomain;
                _lockCount = thread.LockCount;
                _teb = thread.Teb;
                _threadState = thread.State;
                _exception = thread.ExceptionPtr;
                _preemptive = thread.Preemptive;
            }
        }
Example #10
0
 internal DesktopThread(DesktopRuntimeBase clr, IThreadData thread, ulong address, bool finalizer)
     : base(thread, address, finalizer)
 {
     _runtime = clr;
 }
Example #11
0
 public NativeThread(NativeRuntime runtime, IThreadData thread, ulong address, bool finalizer) : base(thread, address, finalizer)
 {
     _runtime = runtime;
 }
Example #12
0
 public NativeThread(NativeRuntime runtime, IThreadData thread, ulong address, bool finalizer) : base(thread, address, finalizer)
 {
     _runtime = runtime;
 }