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
139 Crst CrstCLRPrivBinderLocalWinMDPath
142 Crst CLRPrivBinderMaps
145 Crst CLRPrivBinderMapsAdd
146 AcquiredBefore CLRPrivBinderMaps
150 AcquiredBefore HandleTable UniqueStack
153 Crst ConnectionNameTable
157 AcquiredBefore AvailableParamTypes Cer ClassInit DeadlockDetection DomainLocalBlock FuncPtrStubs
158 GlobalStrLiteralMap Jit LoaderHeap ModuleLookupTable RWLock SigConvert SingleUseLock
159 StubUnwindInfoHeapSegments SyncBlockCache TypeIDMap UnresolvedClassLock FusionClosure
162 Crst CoreCLRBinderLog
167 AcquiredBefore JumpStubCache
170 Crst DeadlockDetection
173 Crst DebuggerController
174 // AcquiredBefore DebuggerHeapLock DebuggerJitInfo LoaderHeap
176 // See bug: 581892. This has a conflict with CrstInstMethodHashTableRanking.
177 // The controller logic will be moved to OOP in V3, and so this lock will no longer be necessary.
178 // Fixing this in-proc would be difficult, and it would all be throwaway as we go oop.
182 // This is a leaf debugger lock.
183 Crst DebuggerFavorLock
184 AcquiredAfter DebuggerJitInfo DebuggerMutex
187 // This is the lock used by the DebuggerHeapExecutableMemoryAllocator for allocating/freeing memory.
188 Crst DebuggerHeapExecMemLock
191 // Debugger Heap lock is the smallest of the debugger locks.
192 Crst DebuggerHeapLock
193 AcquiredAfter DebuggerFavorLock DebuggerJitInfo DebuggerMutex
194 // Disabled per bug 581892
195 // AcquiredAfter DebuggerController
199 AcquiredBefore DebuggerHeapLock
202 // This is the major debugger lock.
203 // It's the largest of the debugger locks.
205 AcquiredBefore AvailableParamTypes ConnectionNameTable
206 DynamicIL LoaderHeap ModuleLookupTable ThreadStore
208 // Disabled per bug 581892
209 // AcquiredBefore DebuggerController
210 AcquiredBefore DebuggerHeapLock DebuggerJitInfo
214 // This lock is used only for testing data consistency (see code:DataTest::TestDataSafety)
215 // and is released before taking any other lock except for CrstDataTest2
217 AcquiredAfter DebuggerMutex
220 // This lock is used only for testing data consistency (see code:DataTest::TestDataSafety)
221 // and is released before taking any other lockCrst DataTest2
223 AcquiredAfter DataTest1
230 Crst DelegateToFPtrHash
233 Crst DomainLocalBlock
234 AcquiredBefore AppDomainHandleTable IbcProfile LoaderHeap SystemDomainDelayedUnloadList UniqueStack
241 AcquiredBefore IbcProfile
245 AcquiredBefore LoaderHeap
255 AcquiredBefore UniqueStack
258 Crst ExecuteManRangeLock
262 AcquiredBefore LoaderHeap
266 AcquiredBefore LoaderHeap
269 Crst FriendAccessCache
270 AcquiredBefore JumpStubCache UniqueStack
274 AcquiredBefore IbcProfile LoaderHeap UniqueStack CodeFragmentHeap JumpStubCache PatchEntryPoint
278 AcquiredBefore FusionPolicyConfigPool FusionSingleUse FusionAssemblyDownload
281 Crst FusionAssemblyDownload
282 AcquiredBefore FusionDownload UniqueStack
285 Crst FusionBindResult
292 AcquiredBefore FusionBindContext FusionLoadContext FusionAppCtx FusionClosureGraph DomainLocalBlock ModuleFixup
295 Crst FusionClosureGraph
296 AcquiredBefore FusionAppCtx FusionBindContext FusionLoadContext
299 Crst FusionConfigSettings
305 Crst FusionLoadContext
306 AcquiredBefore PEImage
309 Crst FusionBindContext
310 AcquiredBefore PEImage
314 AcquiredBefore IbcProfile UniqueStack
317 Crst FusionWarningLog
318 AcquiredBefore FusionBindContext FusionLoadContext FusionLog
322 AcquiredBefore SystemDomainDelayedUnloadList
325 Crst FusionNgenIndexPool
326 AcquiredBefore SystemDomainDelayedUnloadList
332 Crst FusionPolicyConfigPool
333 AcquiredBefore UniqueStack
337 AcquiredBefore PEImage
340 Crst FusionIsoLibInit
343 Crst NativeBinderInit
347 Crst NativeImageCache
351 Crst GCMemoryPressure
354 Crst GlobalStrLiteralMap
355 AcquiredBefore HandleTable IbcProfile SyncBlockCache SystemDomainDelayedUnloadList ThreadStore UniqueStack
359 SameLevelAs HandleTable
365 Crst HostAssemblyMapAdd
366 AcquiredBefore HostAssemblyMap
373 AcquiredBefore FuncPtrStubs IJWHash LoaderHeap
380 AcquiredBefore DeadlockDetection UniqueStack
383 Crst InstMethodHashTable
384 AcquiredBefore FusionBindContext FusionLoadContext LoaderHeap UniqueStack JumpStubCache
387 Crst InterfaceVTableMap
391 AcquiredBefore AppDomainHandleTable AvailableParamTypes Cer ClassInit DeadlockDetection DomainLocalBlock
392 HandleTable InstMethodHashTable InteropData JitGenericHandleCache LoaderHeap SigConvert
393 StubDispatchCache StubUnwindInfoHeapSegments SyncBlockCache TypeIDMap UnresolvedClassLock
397 AcquiredBefore LoaderHeap UniqueStack
400 Crst IOThreadpoolWorker
401 AcquiredBefore ThreadIdDispenser ThreadStore
407 Crst ISymUnmanagedReader
408 AcquiredBefore PEImagePDBStream UniqueStack JumpStubCache
412 AcquiredBefore DeadlockDetection JumpStubCache
413 SameLevelAs ClassInit
416 Crst JitGenericHandleCache
424 AcquiredBefore ExecuteManRangeLock LoaderHeap SingleUseLock
425 AcquiredAfter AppDomainCache ExecuteManLock FusionAssemblyDownload FusionNgenIndex FusionNgenIndexPool
426 ILStubGen SharedBaseDomain ThreadpoolTimerQueue ThreadpoolWaitThreads
427 TPMethodTable TypeIDMap BaseDomain AssemblyLoader
434 // Leaflock leveling, used for crsts that explicitly want to be a leaf lock
439 AcquiredBefore AppDomainHandleTable HandleTable UniqueStack ThreadStore
440 AcquiredAfter DomainLocalBlock
443 Crst LoaderAllocatorReferences
444 AcquiredBefore LoaderAllocator
445 AcquiredAfter PendingTypeLoadEntry InstMethodHashTable
449 AcquiredAfter LoaderAllocatorReferences ThreadStore AssemblyLoader
463 AcquiredBefore LoaderHeap
470 AcquiredBefore LoaderHeap UniqueStack
474 AcquiredBefore AppDomainHandleTable GlobalStrLiteralMap IbcProfile SyncBlockCache
477 Crst ModuleLookupTable
478 AcquiredBefore LoaderHeap
488 SameLevelAs ObjectList
497 Crst PEFileSecurityManager
501 AcquiredBefore UniqueStack
504 Crst ILFingerprintCache
505 AcquiredBefore PEImage
508 Crst PEImagePDBStream
511 Crst PendingTypeLoadEntry
512 AcquiredBefore AppDomainCache AppDomainHandleTable AssemblyLoader AvailableClass AvailableParamTypes
513 BaseDomain ClassInit DeadlockDetection DebuggerController DebuggerJitInfo DebuggerMutex
514 DomainLocalBlock DynLinkZapItems Exception ExecuteManRangeLock FuncPtrStubs
515 FusionAppCtx FusionAssemblyDownload FusionBindResult FusionClosure FusionDownload
516 FusionBindContext FusionLoadContext FusionNgenIndex FusionNgenIndexPool FusionPcyCache
517 FusionPolicyConfigPool FusionSingleUse GlobalStrLiteralMap HandleTable IbcProfile
518 IJWFixupData IJWHash ISymUnmanagedReader Jit JumpStubCache LoaderHeap ModIntPairList
519 Module ModuleLookupTable PEImage SecurityStackwalkCache SharedAssemblyCreate
520 SharedBaseDomain SigConvert SingleUseLock StubDispatchCache StubUnwindInfoHeapSegments
521 SyncBlockCache SystemDomain ThreadIdDispenser ThreadStore TypeIDMap UnresolvedClassLock
522 SameLevelAs PendingTypeLoadEntry
528 // ProfilerGCRefDataFreeList synchronizes access to the profiler API's list of
529 // free, previously allocated structures that track moved references and
530 // root references during a GC.
531 Crst ProfilerGCRefDataFreeList
534 // ProfilingAPIStatus serializes attempts to transition the global status
535 // from state to state, and access to the ProfilerDetachInfo structure
536 // between the thread executing DetachProfiler(), and the DetachThread
537 // carrying out the evacuation order.
538 Crst ProfilingAPIStatus
541 Crst PublisherCertificate
545 AcquiredBefore IbcProfile LoaderHeap RCWCleanupList
549 AcquiredBefore HandleTable
559 AcquiredBefore LoaderHeap UnresolvedClassLock
562 // Used to synchronize all rejit information stored in a given AppDomain. One of these
563 // crsts exist per domain (except the SharedDomain--see below)
564 Crst ReJITDomainTable
565 AcquiredBefore LoaderHeap SingleUseLock DeadlockDetection JumpStubCache DebuggerController
566 AcquiredAfter ReJITGlobalRequest ThreadStore GlobalStrLiteralMap SystemDomain DebuggerMutex
569 // Same as ReJITDomainTable, but this is for the SharedDomain's ReJitManager. Only
570 // reason we have a special type for the SharedDomain's ReJitManager is so that we can
571 // explicitly level this guy differently from ReJITDomainTable, so that both the
572 // SharedDomain's ReJitManager table lock AND one non-SharedDomain's ReJitManager table
573 // lock may be held simultaneously. This is useful during ETW rundown.
574 Crst ReJITSharedDomainTable
575 AcquiredBefore ReJITDomainTable
576 AcquiredAfter ReJITGlobalRequest ThreadStore GlobalStrLiteralMap SystemDomain DebuggerMutex
579 // Used to synchronize all global requests (which may span multiple AppDomains) which add
580 // new functions to rejit tables, or request Reverts on existing functions in the rejit
581 // tables. One of these crsts exist per runtime.
582 Crst ReJITGlobalRequest
583 AcquiredBefore ThreadStore ReJITSharedDomainTable ReJITDomainTable SystemDomain
586 // ETW infrastructure uses this crst to protect a hash table of TypeHandles which is
587 // used to remember which types have been logged (to avoid duplicate logging of the
590 AcquiredAfter ThreadStore AllowedFiles Cer TPMethodTable
591 AcquiredBefore AvailableParamTypes ConnectionNameTable DeadlockDetection DebuggerController
592 DebuggerHeapLock DebuggerJitInfo DynamicIL ExecuteManRangeLock HandleTable IbcProfile
593 JitGenericHandleCache JumpStubCache LoaderHeap ModuleLookupTable ProfilingAPIStatus
594 ProfilerGCRefDataFreeList RWLock SingleUseLock SyncBlockCache SystemDomainDelayedUnloadList
595 ThreadIdDispenser ThreadStaticDataHashTable
599 AcquiredBefore AppDomainHandleTable AvailableParamTypes Cer ClassInit DeadlockDetection DebuggerController
600 DebuggerHeapLock DebuggerJitInfo DebuggerMutex DomainLocalBlock ExecuteManRangeLock
601 FuncPtrStubs GlobalStrLiteralMap HandleTable InstMethodHashTable Jit JitGenericHandleCache
602 JumpStubCache LoaderHeap StubCache Module ModuleLookupTable SecurityStackwalkCache SigConvert
603 SingleUseLock StubUnwindInfoHeapSegments SyncBlockCache SystemDomainDelayedUnloadList
604 ThreadStore UnresolvedClassLock PendingTypeLoadEntry
610 Crst SavedExceptionInfo
611 AcquiredBefore DebuggerController
614 Crst SaveModuleProfileData
617 Crst SecurityPolicyCache
620 Crst SecurityPolicyInit
621 AcquiredBefore SecurityPolicyCache
624 Crst SecurityStackwalkCache
627 Crst SharedAssemblyCreate
628 AcquiredBefore DeadlockDetection UniqueStack
631 Crst SharedBaseDomain
632 AcquiredBefore UniqueStack
636 AcquiredBefore LoaderHeap
640 AcquiredBefore ExecuteManRangeLock LoaderHeap UniqueStack DebuggerJitInfo
643 Crst UnwindInfoTableLock
644 AcquiredAfter StubUnwindInfoHeapSegments SingleUseLock
645 AcquiredBefore StressLog
658 Crst CodeFragmentHeap
659 AcquiredBefore SingleUseLock
662 Crst StubDispatchCache
665 Crst StubUnwindInfoHeapSegments
666 AcquiredAfter StubCache
670 AcquiredBefore ThreadIdDispenser
676 Crst SystemBaseDomain
680 AcquiredBefore DebuggerMutex HandleTable IbcProfile SaveModuleProfileData SecurityPolicyCache
681 ThreadIdDispenser ThreadStore
684 Crst SystemDomainDelayedUnloadList
687 Crst ThreadIdDispenser
690 Crst ThreadpoolEventCache
693 Crst ThreadpoolTimerQueue
694 AcquiredBefore UniqueStack
697 Crst ThreadpoolWaitThreads
698 AcquiredBefore UniqueStack
701 Crst ThreadpoolWorker
702 AcquiredBefore ThreadIdDispenser ThreadStore
705 Crst ThreadStaticDataHashTable
706 AcquiredBefore SyncBlockCache
710 AcquiredBefore AvailableParamTypes ConnectionNameTable DeadlockDetection DebuggerController
711 DebuggerHeapLock DebuggerJitInfo DynamicIL ExecuteManRangeLock HandleTable IbcProfile
712 JitGenericHandleCache JumpStubCache LoaderHeap ModuleLookupTable ProfilingAPIStatus
713 ProfilerGCRefDataFreeList RWLock SingleUseLock SyncBlockCache SystemDomainDelayedUnloadList
714 ThreadIdDispenser ThreadStaticDataHashTable
718 AcquiredBefore DebuggerHeapLock LoaderHeap UniqueStack AvailableParamTypes
722 AcquiredBefore UniqueStack
725 Crst TypeEquivalenceMap
726 AcquiredBefore LoaderHeap
733 AcquiredBefore LoaderHeap
736 Crst UnresolvedClassLock
737 AcquiredBefore AvailableParamTypes DynLinkZapItems IbcProfile JumpStubCache
741 AcquiredBefore IbcProfile
744 Crst UMEntryThunkCache
745 AcquiredBefore LoaderHeap
748 Crst PinnedByrefValidation
751 Crst AssemblyUsageLog
754 Crst VSDIndirectionCellLock
755 AcquiredBefore LoaderHeap
758 Crst MulticoreJitHash
761 Crst MulticoreJitManager
762 AcquiredBefore MulticoreJitHash ThreadStore
765 Crst WinRTFactoryCache
766 AcquiredBefore HandleTable
775 Crst InlineTrackingMap
776 AcquiredBefore IbcProfile