1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
6 // This file is used to describe the different types of Crst and their dependencies on other Crst types (in
7 // terms of which types may be legally held while others are acquired).
9 // The CrstTypeTool utility is used to parse this file, verify that there are no logical inconsistencies (such
10 // as a cycle in the dependencies) and generate an enum value and numerical ranking for each type. This
11 // ranking is used by the runtime (in checked builds) to verify that none of the rules described below are
12 // violated (which could lead to a deadlock).
14 // When you add a new Crst type you need to be aware of which Crst types may be already held when your Crst is
15 // acquired and which other types may be subsequently acquired. You can then add a Crst definition to this
16 // file and annotate it with those dependencies. Running CrstTypeTool will check to see if this introduces a
17 // potential deadlock problem and if everything checks out will generate a new version of
18 // file:CrstTypes.h (be sure to check this file out from TFS/SD before running CrstTypeTool).
20 // The format of this file is a very simple language. Comments are introduced with '//' and continue to the
21 // end of the line. Keywords are case insensitive (Crst type names, however, are case sensitive since they'll
22 // be translated directly to C++ enum values). Crst type names are used without the 'Crst' prefix used in C++
23 // code (e.g. CrstAppDomainCache is referred to as AppDomainCache). The following words are reserved keywords
24 // and may not be used as the names of Crst types:
32 // Each Crst type definition has the following format (where [] indicates optional and ... indicates zero or
35 // [AcquiredBefore <type name>...]
36 // [AcquiredAfter <type name>...]
37 // [SameLevelAs <type name>...]
44 // AcquiredAfter Zob Baz
48 // This introduces a new Crst type Foo (CrstFoo inside the runtime). This type may be legally acquired when
49 // the current thread holds Crst instances of type Zob, Bar or even other instances of Foo. While Foo is held
50 // it is legal to acquire Crsts of type Bar. Assuming that this definition does not introduce any dependency
51 // cycles, CrstTypeTool will assign a numeric rank to CrstFoo that maximizes the chance that any other Crst
52 // type interaction you didn't explicitly specify (e.g. holding Foo while taking a Crst of type Wibble) will
53 // generate a ranking violation assert in the checked build.
55 // Note that the following set of definitions:
56 // Crst A AcquiredBefore B End
60 // Crst B AcquiredAfter A End
62 // Crst A AcquiredBefore B End
63 // Crst B AcquiredAfter A End
65 // are all equivalent. You are free to use whichever variant seems clearest to you (CrstTypeTool will tell you
66 // if you introduce conflicting rules). Similarly "A SameLevelAs B" implies "B SameLevelAs A". The initial
67 // contents of this file uses AcquiredBefore in preference to AcquiredAfter purely because it was generated
68 // automatically by a profiling mechanism (the initial rules were seeded from observations of Crst usage while
69 // running our test suites). Feel free to add meaningful comments to existing rules if you feel they can
70 // usefully clarify the reasons for particular dependencies.
72 // CrstTypeTool is a csScript file at file:..\..\bin\CrstTypeTool.csScript. Simply typing "CrstTypeTool" from a
73 // clrenv command window prompt should rebuild file:CrstTypes.h from the current CrstTypes.def (again,
74 // remember to check out CrstTypes.h first).
75 // Note: If you cannot run the script from command line, because of this error:
76 // Script language type is unsupported.
77 // Use /? for more help on usage.
78 // Or because .csscript extension is not associated with anything on your machine,
79 // Then use "csc.exe CrstTypeTool.csscript" from ClrEnv environment and run the resulting executable.
81 // Each Crst type definition is currently in alphabetical order. Please maintain this convention.
85 AcquiredBefore JumpStubCache UniqueStack
89 AcquiredBefore FusionBindContext FusionLoadContext LoaderHeap UniqueStack UnresolvedClassLock
92 Crst AppDomainHandleTable
93 AcquiredBefore AvailableParamTypes HandleTable IbcProfile SyncBlockCache SystemDomainDelayedUnloadList
94 ThreadStore SystemDomain
97 Crst ArgBasedStubCache
100 Crst AssemblyIdentityCache
104 AcquiredBefore DeadlockDetection UniqueStack
108 AcquiredBefore LoaderHeap
111 Crst AssemblyDependencyGraph
114 Crst AvailableParamTypes
115 AcquiredBefore FusionBindContext FusionLoadContext IbcProfile LoaderHeap
119 AcquiredBefore LoaderHeap UniqueStack
127 AcquiredBefore JumpStubCache UniqueStack
130 Crst ClassFactInfoHash
131 AcquiredBefore SyncBlockCache ThreadStore
135 AcquiredBefore DeadlockDetection IbcProfile
143 Crst CrstCLRPrivBinderLocalWinMDPath
146 Crst CLRPrivBinderMaps
149 Crst CLRPrivBinderMapsAdd
150 AcquiredBefore CLRPrivBinderMaps
154 AcquiredBefore HandleTable UniqueStack
157 Crst ConnectionNameTable
161 AcquiredBefore AvailableParamTypes Cer ClassInit DeadlockDetection DomainLocalBlock FuncPtrStubs
162 GlobalStrLiteralMap Jit LoaderHeap ModuleLookupTable RWLock SigConvert SingleUseLock
163 StubUnwindInfoHeapSegments SyncBlockCache TypeIDMap UnresolvedClassLock FusionClosure
166 Crst CoreCLRBinderLog
171 AcquiredBefore JumpStubCache
174 Crst DeadlockDetection
177 Crst DebuggerController
178 // AcquiredBefore DebuggerHeapLock DebuggerJitInfo LoaderHeap
180 // See bug: 581892. This has a conflict with CrstInstMethodHashTableRanking.
181 // The controller logic will be moved to OOP in V3, and so this lock will no longer be necessary.
182 // Fixing this in-proc would be difficult, and it would all be throwaway as we go oop.
186 // This is a leaf debugger lock.
187 Crst DebuggerFavorLock
188 AcquiredAfter DebuggerJitInfo DebuggerMutex
191 // This is the lock used by the DebuggerHeapExecutableMemoryAllocator for allocating/freeing memory.
192 Crst DebuggerHeapExecMemLock
195 // Debugger Heap lock is the smallest of the debugger locks.
196 Crst DebuggerHeapLock
197 AcquiredAfter DebuggerFavorLock DebuggerJitInfo DebuggerMutex
198 // Disabled per bug 581892
199 // AcquiredAfter DebuggerController
203 AcquiredBefore DebuggerHeapLock
206 // This is the major debugger lock.
207 // It's the largest of the debugger locks.
209 AcquiredBefore AvailableParamTypes ConnectionNameTable
210 DynamicIL LoaderHeap ModuleLookupTable ThreadStore
212 // Disabled per bug 581892
213 // AcquiredBefore DebuggerController
214 AcquiredBefore DebuggerHeapLock DebuggerJitInfo
218 // This lock is used only for testing data consistency (see code:DataTest::TestDataSafety)
219 // and is released before taking any other lock except for CrstDataTest2
221 AcquiredAfter DebuggerMutex
224 // This lock is used only for testing data consistency (see code:DataTest::TestDataSafety)
225 // and is released before taking any other lockCrst DataTest2
227 AcquiredAfter DataTest1
234 Crst DelegateToFPtrHash
237 Crst DomainLocalBlock
238 AcquiredBefore AppDomainHandleTable IbcProfile LoaderHeap SystemDomainDelayedUnloadList UniqueStack
245 AcquiredBefore IbcProfile
249 AcquiredBefore LoaderHeap
259 AcquiredBefore UniqueStack
262 Crst ExecuteManRangeLock
266 AcquiredBefore LoaderHeap
270 AcquiredBefore LoaderHeap
273 Crst FriendAccessCache
274 AcquiredBefore JumpStubCache UniqueStack
278 AcquiredBefore IbcProfile LoaderHeap UniqueStack CodeFragmentHeap JumpStubCache PatchEntryPoint
282 AcquiredBefore FusionPolicyConfigPool FusionSingleUse FusionAssemblyDownload
285 Crst FusionAssemblyDownload
286 AcquiredBefore FusionDownload UniqueStack
289 Crst FusionBindResult
296 AcquiredBefore FusionBindContext FusionLoadContext FusionAppCtx FusionClosureGraph DomainLocalBlock ModuleFixup
299 Crst FusionClosureGraph
300 AcquiredBefore FusionAppCtx FusionBindContext FusionLoadContext
303 Crst FusionConfigSettings
309 Crst FusionLoadContext
310 AcquiredBefore PEImage
313 Crst FusionBindContext
314 AcquiredBefore PEImage
318 AcquiredBefore IbcProfile UniqueStack
321 Crst FusionWarningLog
322 AcquiredBefore FusionBindContext FusionLoadContext FusionLog
326 AcquiredBefore SystemDomainDelayedUnloadList
329 Crst FusionNgenIndexPool
330 AcquiredBefore SystemDomainDelayedUnloadList
336 Crst FusionPolicyConfigPool
337 AcquiredBefore UniqueStack
341 AcquiredBefore PEImage
344 Crst FusionIsoLibInit
347 Crst NativeBinderInit
351 Crst NativeImageCache
355 Crst GCMemoryPressure
358 Crst GlobalStrLiteralMap
359 AcquiredBefore HandleTable IbcProfile SyncBlockCache SystemDomainDelayedUnloadList ThreadStore UniqueStack
363 SameLevelAs HandleTable
369 Crst HostAssemblyMapAdd
370 AcquiredBefore HostAssemblyMap
377 AcquiredBefore FuncPtrStubs IJWHash LoaderHeap
384 AcquiredBefore DeadlockDetection UniqueStack
387 Crst InstMethodHashTable
388 AcquiredBefore FusionBindContext FusionLoadContext LoaderHeap UniqueStack JumpStubCache
391 Crst InterfaceVTableMap
395 AcquiredBefore AppDomainHandleTable AvailableParamTypes Cer ClassInit DeadlockDetection DomainLocalBlock
396 HandleTable InstMethodHashTable InteropData JitGenericHandleCache LoaderHeap SigConvert
397 StubDispatchCache StubUnwindInfoHeapSegments SyncBlockCache TypeIDMap UnresolvedClassLock
401 AcquiredBefore LoaderHeap UniqueStack
404 Crst IOThreadpoolWorker
405 AcquiredBefore ThreadIdDispenser ThreadStore
411 Crst ISymUnmanagedReader
412 AcquiredBefore PEImagePDBStream UniqueStack JumpStubCache
416 AcquiredBefore DeadlockDetection JumpStubCache
417 SameLevelAs ClassInit
420 Crst JitGenericHandleCache
428 AcquiredBefore ExecuteManRangeLock LoaderHeap SingleUseLock
429 AcquiredAfter AppDomainCache ExecuteManLock FusionAssemblyDownload FusionNgenIndex FusionNgenIndexPool
430 ILStubGen SharedBaseDomain ThreadpoolTimerQueue ThreadpoolWaitThreads
431 TPMethodTable TypeIDMap BaseDomain AssemblyLoader
438 // Leaflock leveling, used for crsts that explicitly want to be a leaf lock
443 AcquiredBefore AppDomainHandleTable HandleTable UniqueStack ThreadStore
444 AcquiredAfter DomainLocalBlock
447 Crst LoaderAllocatorReferences
448 AcquiredBefore LoaderAllocator
449 AcquiredAfter PendingTypeLoadEntry InstMethodHashTable
453 AcquiredAfter LoaderAllocatorReferences ThreadStore AssemblyLoader
467 AcquiredBefore LoaderHeap
474 AcquiredBefore LoaderHeap UniqueStack
478 AcquiredBefore AppDomainHandleTable GlobalStrLiteralMap IbcProfile SyncBlockCache
481 Crst ModuleLookupTable
482 AcquiredBefore LoaderHeap
492 SameLevelAs ObjectList
501 Crst PEFileSecurityManager
505 AcquiredBefore UniqueStack
508 Crst ILFingerprintCache
509 AcquiredBefore PEImage
512 Crst PEImagePDBStream
515 Crst PendingTypeLoadEntry
516 AcquiredBefore AppDomainCache AppDomainHandleTable AssemblyLoader AvailableClass AvailableParamTypes
517 BaseDomain ClassInit DeadlockDetection DebuggerController DebuggerJitInfo DebuggerMutex
518 DomainLocalBlock DynLinkZapItems Exception ExecuteManRangeLock FuncPtrStubs
519 FusionAppCtx FusionAssemblyDownload FusionBindResult FusionClosure FusionDownload
520 FusionBindContext FusionLoadContext FusionNgenIndex FusionNgenIndexPool FusionPcyCache
521 FusionPolicyConfigPool FusionSingleUse GlobalStrLiteralMap HandleTable IbcProfile
522 IJWFixupData IJWHash ISymUnmanagedReader Jit JumpStubCache LoaderHeap ModIntPairList
523 Module ModuleLookupTable PEImage SecurityStackwalkCache SharedAssemblyCreate
524 SharedBaseDomain SigConvert SingleUseLock StubDispatchCache StubUnwindInfoHeapSegments
525 SyncBlockCache SystemDomain ThreadIdDispenser ThreadStore TypeIDMap UnresolvedClassLock
526 SameLevelAs PendingTypeLoadEntry
532 // ProfilerGCRefDataFreeList synchronizes access to the profiler API's list of
533 // free, previously allocated structures that track moved references and
534 // root references during a GC.
535 Crst ProfilerGCRefDataFreeList
538 // ProfilingAPIStatus serializes attempts to transition the global status
539 // from state to state, and access to the ProfilerDetachInfo structure
540 // between the thread executing DetachProfiler(), and the DetachThread
541 // carrying out the evacuation order.
542 Crst ProfilingAPIStatus
545 Crst PublisherCertificate
549 AcquiredBefore IbcProfile LoaderHeap RCWCleanupList
553 AcquiredBefore HandleTable
563 AcquiredBefore LoaderHeap UnresolvedClassLock
566 // Used to synchronize all rejit information stored in a given AppDomain. One of these
567 // crsts exist per domain (except the SharedDomain--see below)
568 Crst ReJITDomainTable
569 AcquiredBefore LoaderHeap SingleUseLock DeadlockDetection JumpStubCache DebuggerController
570 AcquiredAfter ReJITGlobalRequest ThreadStore GlobalStrLiteralMap SystemDomain DebuggerMutex
573 // Same as ReJITDomainTable, but this is for the SharedDomain's ReJitManager. Only
574 // reason we have a special type for the SharedDomain's ReJitManager is so that we can
575 // explicitly level this guy differently from ReJITDomainTable, so that both the
576 // SharedDomain's ReJitManager table lock AND one non-SharedDomain's ReJitManager table
577 // lock may be held simultaneously. This is useful during ETW rundown.
578 Crst ReJITSharedDomainTable
579 AcquiredBefore ReJITDomainTable
580 AcquiredAfter ReJITGlobalRequest ThreadStore GlobalStrLiteralMap SystemDomain DebuggerMutex
583 // Used to synchronize all global requests (which may span multiple AppDomains) which add
584 // new functions to rejit tables, or request Reverts on existing functions in the rejit
585 // tables. One of these crsts exist per runtime.
586 Crst ReJITGlobalRequest
587 AcquiredBefore ThreadStore ReJITSharedDomainTable ReJITDomainTable SystemDomain
590 // ETW infrastructure uses this crst to protect a hash table of TypeHandles which is
591 // used to remember which types have been logged (to avoid duplicate logging of the
594 AcquiredAfter ThreadStore AllowedFiles Cer TPMethodTable
595 AcquiredBefore AvailableParamTypes ConnectionNameTable DeadlockDetection DebuggerController
596 DebuggerHeapLock DebuggerJitInfo DynamicIL ExecuteManRangeLock HandleTable IbcProfile
597 JitGenericHandleCache JumpStubCache LoaderHeap ModuleLookupTable ProfilingAPIStatus
598 ProfilerGCRefDataFreeList RWLock SingleUseLock SyncBlockCache SystemDomainDelayedUnloadList
599 ThreadIdDispenser ThreadStaticDataHashTable
603 AcquiredBefore AppDomainHandleTable AvailableParamTypes Cer ClassInit DeadlockDetection DebuggerController
604 DebuggerHeapLock DebuggerJitInfo DebuggerMutex DomainLocalBlock ExecuteManRangeLock
605 FuncPtrStubs GlobalStrLiteralMap HandleTable InstMethodHashTable Jit JitGenericHandleCache
606 JumpStubCache LoaderHeap StubCache Module ModuleLookupTable SecurityStackwalkCache SigConvert
607 SingleUseLock StubUnwindInfoHeapSegments SyncBlockCache SystemDomainDelayedUnloadList
608 ThreadStore UnresolvedClassLock PendingTypeLoadEntry
614 Crst SavedExceptionInfo
615 AcquiredBefore DebuggerController
618 Crst SaveModuleProfileData
621 Crst SecurityPolicyCache
624 Crst SecurityPolicyInit
625 AcquiredBefore SecurityPolicyCache
628 Crst SecurityStackwalkCache
631 Crst SharedAssemblyCreate
632 AcquiredBefore DeadlockDetection UniqueStack
635 Crst SharedBaseDomain
636 AcquiredBefore UniqueStack
640 AcquiredBefore LoaderHeap
644 AcquiredBefore ExecuteManRangeLock LoaderHeap UniqueStack DebuggerJitInfo
647 Crst UnwindInfoTableLock
648 AcquiredAfter StubUnwindInfoHeapSegments SingleUseLock
649 AcquiredBefore StressLog
662 Crst CodeFragmentHeap
663 AcquiredBefore SingleUseLock
666 Crst StubDispatchCache
669 Crst StubUnwindInfoHeapSegments
670 AcquiredAfter StubCache
674 AcquiredBefore ThreadIdDispenser
680 Crst SystemBaseDomain
684 AcquiredBefore DebuggerMutex HandleTable IbcProfile SaveModuleProfileData SecurityPolicyCache
685 ThreadIdDispenser ThreadStore
688 Crst SystemDomainDelayedUnloadList
691 Crst ThreadIdDispenser
694 Crst ThreadpoolEventCache
697 Crst ThreadpoolTimerQueue
698 AcquiredBefore UniqueStack
701 Crst ThreadpoolWaitThreads
702 AcquiredBefore UniqueStack
705 Crst ThreadpoolWorker
706 AcquiredBefore ThreadIdDispenser ThreadStore
709 Crst ThreadStaticDataHashTable
710 AcquiredBefore SyncBlockCache
714 AcquiredBefore AvailableParamTypes ConnectionNameTable DeadlockDetection DebuggerController
715 DebuggerHeapLock DebuggerJitInfo DynamicIL ExecuteManRangeLock HandleTable IbcProfile
716 JitGenericHandleCache JumpStubCache LoaderHeap ModuleLookupTable ProfilingAPIStatus
717 ProfilerGCRefDataFreeList RWLock SingleUseLock SyncBlockCache SystemDomainDelayedUnloadList
718 ThreadIdDispenser ThreadStaticDataHashTable
722 AcquiredBefore DebuggerHeapLock LoaderHeap UniqueStack AvailableParamTypes
726 AcquiredBefore UniqueStack
729 Crst TypeEquivalenceMap
730 AcquiredBefore LoaderHeap
737 AcquiredBefore LoaderHeap
740 Crst UnresolvedClassLock
741 AcquiredBefore AvailableParamTypes DynLinkZapItems IbcProfile JumpStubCache
745 AcquiredBefore IbcProfile
748 Crst UMEntryThunkCache
749 AcquiredBefore LoaderHeap
752 Crst PinnedByrefValidation
755 Crst AssemblyUsageLog
758 Crst VSDIndirectionCellLock
759 AcquiredBefore LoaderHeap
762 Crst MulticoreJitHash
765 Crst MulticoreJitManager
766 AcquiredBefore MulticoreJitHash ThreadStore
769 Crst WinRTFactoryCache
770 AcquiredBefore HandleTable
779 Crst InlineTrackingMap
780 AcquiredBefore IbcProfile
784 AcquiredBefore ThreadIdDispenser ThreadStore DomainLocalBlock InstMethodHashTable