2 // Copyright (c) Microsoft. All rights reserved.
3 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
7 // This file is used to describe the different types of Crst and their dependencies on other Crst types (in
8 // terms of which types may be legally held while others are acquired).
10 // The CrstTypeTool utility is used to parse this file, verify that there are no logical inconsistencies (such
11 // as a cycle in the dependencies) and generate an enum value and numerical ranking for each type. This
12 // ranking is used by the runtime (in checked builds) to verify that none of the rules described below are
13 // violated (which could lead to a deadlock).
15 // When you add a new Crst type you need to be aware of which Crst types may be already held when your Crst is
16 // acquired and which other types may be subsequently acquired. You can then add a Crst definition to this
17 // file and annotate it with those dependencies. Running CrstTypeTool will check to see if this introduces a
18 // potential deadlock problem and if everything checks out will generate a new version of
19 // file:CrstTypes.h (be sure to check this file out from TFS/SD before running CrstTypeTool).
21 // The format of this file is a very simple language. Comments are introduced with '//' and continue to the
22 // end of the line. Keywords are case insensitive (Crst type names, however, are case sensitive since they'll
23 // be translated directly to C++ enum values). Crst type names are used without the 'Crst' prefix used in C++
24 // code (e.g. CrstAppDomainCache is referred to as AppDomainCache). The following words are reserved keywords
25 // and may not be used as the names of Crst types:
33 // Each Crst type definition has the following format (where [] indicates optional and ... indicates zero or
36 // [AcquiredBefore <type name>...]
37 // [AcquiredAfter <type name>...]
38 // [SameLevelAs <type name>...]
45 // AcquiredAfter Zob Baz
49 // This introduces a new Crst type Foo (CrstFoo inside the runtime). This type may be legally acquired when
50 // the current thread holds Crst instances of type Zob, Bar or even other instances of Foo. While Foo is held
51 // it is legal to acquire Crsts of type Bar. Assuming that this definition does not introduce any dependency
52 // cycles, CrstTypeTool will assign a numeric rank to CrstFoo that maximizes the chance that any other Crst
53 // type interaction you didn't explicitly specify (e.g. holding Foo while taking a Crst of type Wibble) will
54 // generate a ranking violation assert in the checked build.
56 // Note that the following set of definitions:
57 // Crst A AcquiredBefore B End
61 // Crst B AcquiredAfter A End
63 // Crst A AcquiredBefore B End
64 // Crst B AcquiredAfter A End
66 // are all equivalent. You are free to use whichever variant seems clearest to you (CrstTypeTool will tell you
67 // if you introduce conflicting rules). Similarly "A SameLevelAs B" implies "B SameLevelAs A". The initial
68 // contents of this file uses AcquiredBefore in preference to AcquiredAfter purely because it was generated
69 // automatically by a profiling mechanism (the initial rules were seeded from observations of Crst usage while
70 // running our test suites). Feel free to add meaningful comments to existing rules if you feel they can
71 // usefully clarify the reasons for particular dependencies.
73 // CrstTypeTool is a csScript file at file:..\..\bin\CrstTypeTool.csScript. Simply typing "CrstTypeTool" from a
74 // clrenv command window prompt should rebuild file:CrstTypes.h from the current CrstTypes.def (again,
75 // remember to check out CrstTypes.h first).
76 // Note: If you cannot run the script from command line, because of this error:
77 // Script language type is unsupported.
78 // Use /? for more help on usage.
79 // Or because .csscript extension is not associated with anything on your machine,
80 // Then use "csc.exe CrstTypeTool.csscript" from ClrEnv environment and run the resulting executable.
82 // Each Crst type definition is currently in alphabetical order. Please maintain this convention.
86 AcquiredBefore JumpStubCache UniqueStack
90 AcquiredBefore FusionBindContext FusionLoadContext LoaderHeap UniqueStack UnresolvedClassLock
93 Crst AppDomainHandleTable
94 AcquiredBefore AvailableParamTypes HandleTable IbcProfile SyncBlockCache SystemDomainDelayedUnloadList
95 ThreadStore SystemDomain
98 Crst ArgBasedStubCache
101 Crst AssemblyIdentityCache
105 AcquiredBefore DeadlockDetection UniqueStack
109 AcquiredBefore LoaderHeap
112 Crst AssemblyDependencyGraph
115 Crst AvailableParamTypes
116 AcquiredBefore FusionBindContext FusionLoadContext IbcProfile LoaderHeap
120 AcquiredBefore LoaderHeap UniqueStack
128 AcquiredBefore JumpStubCache UniqueStack
131 Crst ClassFactInfoHash
132 AcquiredBefore SyncBlockCache ThreadStore
136 AcquiredBefore DeadlockDetection IbcProfile
140 Crst CrstCLRPrivBinderLocalWinMDPath
143 Crst CLRPrivBinderMaps
146 Crst CLRPrivBinderMapsAdd
147 AcquiredBefore CLRPrivBinderMaps
151 AcquiredBefore HandleTable UniqueStack
154 Crst ConnectionNameTable
158 AcquiredBefore AvailableParamTypes Cer ClassInit DeadlockDetection DomainLocalBlock FuncPtrStubs
159 GlobalStrLiteralMap Jit LoaderHeap ModuleLookupTable RWLock SigConvert SingleUseLock
160 StubUnwindInfoHeapSegments SyncBlockCache TypeIDMap UnresolvedClassLock FusionClosure
163 Crst CoreCLRBinderLog
168 AcquiredBefore JumpStubCache
171 Crst DeadlockDetection
174 Crst DebuggerController
175 // AcquiredBefore DebuggerHeapLock DebuggerJitInfo LoaderHeap
177 // See bug: 581892. This has a conflict with CrstInstMethodHashTableRanking.
178 // The controller logic will be moved to OOP in V3, and so this lock will no longer be necessary.
179 // Fixing this in-proc would be difficult, and it would all be throwaway as we go oop.
183 // This is a leaf debugger lock.
184 Crst DebuggerFavorLock
185 AcquiredAfter DebuggerJitInfo DebuggerMutex
188 // This is the lock used by the DebuggerHeapExecutableMemoryAllocator for allocating/freeing memory.
189 Crst DebuggerHeapExecMemLock
192 // Debugger Heap lock is the smallest of the debugger locks.
193 Crst DebuggerHeapLock
194 AcquiredAfter DebuggerFavorLock DebuggerJitInfo DebuggerMutex
195 // Disabled per bug 581892
196 // AcquiredAfter DebuggerController
200 AcquiredBefore DebuggerHeapLock
203 // This is the major debugger lock.
204 // It's the largest of the debugger locks.
206 AcquiredBefore AvailableParamTypes ConnectionNameTable
207 DynamicIL LoaderHeap ModuleLookupTable ThreadStore
209 // Disabled per bug 581892
210 // AcquiredBefore DebuggerController
211 AcquiredBefore DebuggerHeapLock DebuggerJitInfo
215 // This lock is used only for testing data consistency (see code:DataTest::TestDataSafety)
216 // and is released before taking any other lock except for CrstDataTest2
218 AcquiredAfter DebuggerMutex
221 // This lock is used only for testing data consistency (see code:DataTest::TestDataSafety)
222 // and is released before taking any other lockCrst DataTest2
224 AcquiredAfter DataTest1
231 Crst DelegateToFPtrHash
234 Crst DomainLocalBlock
235 AcquiredBefore AppDomainHandleTable IbcProfile LoaderHeap SystemDomainDelayedUnloadList UniqueStack
242 AcquiredBefore IbcProfile
246 AcquiredBefore LoaderHeap
256 AcquiredBefore UniqueStack
259 Crst ExecuteManRangeLock
263 AcquiredBefore LoaderHeap
267 AcquiredBefore LoaderHeap
270 Crst FriendAccessCache
271 AcquiredBefore JumpStubCache UniqueStack
275 AcquiredBefore IbcProfile LoaderHeap UniqueStack CodeFragmentHeap JumpStubCache PatchEntryPoint
279 AcquiredBefore FusionPolicyConfigPool FusionSingleUse FusionAssemblyDownload
282 Crst FusionAssemblyDownload
283 AcquiredBefore FusionDownload UniqueStack
286 Crst FusionBindResult
293 AcquiredBefore FusionBindContext FusionLoadContext FusionAppCtx FusionClosureGraph DomainLocalBlock ModuleFixup
296 Crst FusionClosureGraph
297 AcquiredBefore FusionAppCtx FusionBindContext FusionLoadContext
300 Crst FusionConfigSettings
306 Crst FusionLoadContext
307 AcquiredBefore PEImage
310 Crst FusionBindContext
311 AcquiredBefore PEImage
315 AcquiredBefore IbcProfile UniqueStack
318 Crst FusionWarningLog
319 AcquiredBefore FusionBindContext FusionLoadContext FusionLog
323 AcquiredBefore SystemDomainDelayedUnloadList
326 Crst FusionNgenIndexPool
327 AcquiredBefore SystemDomainDelayedUnloadList
333 Crst FusionPolicyConfigPool
334 AcquiredBefore UniqueStack
338 AcquiredBefore PEImage
341 Crst FusionIsoLibInit
344 Crst NativeBinderInit
348 Crst NativeImageCache
352 Crst GCMemoryPressure
355 Crst GlobalStrLiteralMap
356 AcquiredBefore HandleTable IbcProfile SyncBlockCache SystemDomainDelayedUnloadList ThreadStore UniqueStack
360 SameLevelAs HandleTable
366 Crst HostAssemblyMapAdd
367 AcquiredBefore HostAssemblyMap
374 AcquiredBefore FuncPtrStubs IJWHash LoaderHeap
381 AcquiredBefore DeadlockDetection UniqueStack
384 Crst InstMethodHashTable
385 AcquiredBefore FusionBindContext FusionLoadContext LoaderHeap UniqueStack JumpStubCache
388 Crst InterfaceVTableMap
392 AcquiredBefore AppDomainHandleTable AvailableParamTypes Cer ClassInit DeadlockDetection DomainLocalBlock
393 HandleTable InstMethodHashTable InteropData JitGenericHandleCache LoaderHeap SigConvert
394 StubDispatchCache StubUnwindInfoHeapSegments SyncBlockCache TypeIDMap UnresolvedClassLock
398 AcquiredBefore LoaderHeap UniqueStack
401 Crst IOThreadpoolWorker
402 AcquiredBefore ThreadIdDispenser ThreadStore
408 Crst ISymUnmanagedReader
409 AcquiredBefore PEImagePDBStream UniqueStack JumpStubCache
413 AcquiredBefore DeadlockDetection JumpStubCache
414 SameLevelAs ClassInit
417 Crst JitGenericHandleCache
425 AcquiredBefore ExecuteManRangeLock LoaderHeap SingleUseLock
426 AcquiredAfter AppDomainCache ExecuteManLock FusionAssemblyDownload FusionNgenIndex FusionNgenIndexPool
427 ILStubGen SharedBaseDomain ThreadpoolTimerQueue ThreadpoolWaitThreads
428 TPMethodTable TypeIDMap BaseDomain AssemblyLoader
435 // Leaflock leveling, used for crsts that explicitly want to be a leaf lock
440 AcquiredBefore AppDomainHandleTable HandleTable UniqueStack ThreadStore
441 AcquiredAfter DomainLocalBlock
444 Crst LoaderAllocatorReferences
445 AcquiredBefore LoaderAllocator
446 AcquiredAfter PendingTypeLoadEntry InstMethodHashTable
450 AcquiredAfter LoaderAllocatorReferences ThreadStore AssemblyLoader
464 AcquiredBefore LoaderHeap
471 AcquiredBefore LoaderHeap UniqueStack
475 AcquiredBefore AppDomainHandleTable GlobalStrLiteralMap IbcProfile SyncBlockCache
478 Crst ModuleLookupTable
479 AcquiredBefore LoaderHeap
489 SameLevelAs ObjectList
498 Crst PEFileSecurityManager
502 AcquiredBefore UniqueStack
505 Crst ILFingerprintCache
506 AcquiredBefore PEImage
509 Crst PEImagePDBStream
512 Crst PendingTypeLoadEntry
513 AcquiredBefore AppDomainCache AppDomainHandleTable AssemblyLoader AvailableClass AvailableParamTypes
514 BaseDomain ClassInit DeadlockDetection DebuggerController DebuggerJitInfo DebuggerMutex
515 DomainLocalBlock DynLinkZapItems Exception ExecuteManRangeLock FuncPtrStubs
516 FusionAppCtx FusionAssemblyDownload FusionBindResult FusionClosure FusionDownload
517 FusionBindContext FusionLoadContext FusionNgenIndex FusionNgenIndexPool FusionPcyCache
518 FusionPolicyConfigPool FusionSingleUse GlobalStrLiteralMap HandleTable IbcProfile
519 IJWFixupData IJWHash ISymUnmanagedReader Jit JumpStubCache LoaderHeap ModIntPairList
520 Module ModuleLookupTable PEImage SecurityStackwalkCache SharedAssemblyCreate
521 SharedBaseDomain SigConvert SingleUseLock StubDispatchCache StubUnwindInfoHeapSegments
522 SyncBlockCache SystemDomain ThreadIdDispenser ThreadStore TypeIDMap UnresolvedClassLock
523 SameLevelAs PendingTypeLoadEntry
529 // ProfilerGCRefDataFreeList synchronizes access to the profiler API's list of
530 // free, previously allocated structures that track moved references and
531 // root references during a GC.
532 Crst ProfilerGCRefDataFreeList
535 // ProfilingAPIStatus serializes attempts to transition the global status
536 // from state to state, and access to the ProfilerDetachInfo structure
537 // between the thread executing DetachProfiler(), and the DetachThread
538 // carrying out the evacuation order.
539 Crst ProfilingAPIStatus
542 Crst PublisherCertificate
546 AcquiredBefore IbcProfile LoaderHeap RCWCleanupList
550 AcquiredBefore HandleTable
560 AcquiredBefore LoaderHeap UnresolvedClassLock
563 // Used to synchronize all rejit information stored in a given AppDomain. One of these
564 // crsts exist per domain (except the SharedDomain--see below)
565 Crst ReJITDomainTable
566 AcquiredBefore LoaderHeap SingleUseLock DeadlockDetection JumpStubCache DebuggerController
567 AcquiredAfter ReJITGlobalRequest ThreadStore GlobalStrLiteralMap SystemDomain DebuggerMutex
570 // Same as ReJITDomainTable, but this is for the SharedDomain's ReJitManager. Only
571 // reason we have a special type for the SharedDomain's ReJitManager is so that we can
572 // explicitly level this guy differently from ReJITDomainTable, so that both the
573 // SharedDomain's ReJitManager table lock AND one non-SharedDomain's ReJitManager table
574 // lock may be held simultaneously. This is useful during ETW rundown.
575 Crst ReJITSharedDomainTable
576 AcquiredBefore ReJITDomainTable
577 AcquiredAfter ReJITGlobalRequest ThreadStore GlobalStrLiteralMap SystemDomain DebuggerMutex
580 // Used to synchronize all global requests (which may span multiple AppDomains) which add
581 // new functions to rejit tables, or request Reverts on existing functions in the rejit
582 // tables. One of these crsts exist per runtime.
583 Crst ReJITGlobalRequest
584 AcquiredBefore ThreadStore ReJITSharedDomainTable ReJITDomainTable SystemDomain
587 // ETW infrastructure uses this crst to protect a hash table of TypeHandles which is
588 // used to remember which types have been logged (to avoid duplicate logging of the
591 AcquiredAfter ThreadStore AllowedFiles Cer TPMethodTable
592 AcquiredBefore AvailableParamTypes ConnectionNameTable DeadlockDetection DebuggerController
593 DebuggerHeapLock DebuggerJitInfo DynamicIL ExecuteManRangeLock HandleTable IbcProfile
594 JitGenericHandleCache JumpStubCache LoaderHeap ModuleLookupTable ProfilingAPIStatus
595 ProfilerGCRefDataFreeList RWLock SingleUseLock SyncBlockCache SystemDomainDelayedUnloadList
596 ThreadIdDispenser ThreadStaticDataHashTable
600 AcquiredBefore AppDomainHandleTable AvailableParamTypes Cer ClassInit DeadlockDetection DebuggerController
601 DebuggerHeapLock DebuggerJitInfo DebuggerMutex DomainLocalBlock ExecuteManRangeLock
602 FuncPtrStubs GlobalStrLiteralMap HandleTable InstMethodHashTable Jit JitGenericHandleCache
603 JumpStubCache LoaderHeap StubCache Module ModuleLookupTable SecurityStackwalkCache SigConvert
604 SingleUseLock StubUnwindInfoHeapSegments SyncBlockCache SystemDomainDelayedUnloadList
605 ThreadStore UnresolvedClassLock PendingTypeLoadEntry
611 Crst SavedExceptionInfo
612 AcquiredBefore DebuggerController
615 Crst SaveModuleProfileData
618 Crst SecurityPolicyCache
621 Crst SecurityPolicyInit
622 AcquiredBefore SecurityPolicyCache
625 Crst SecurityStackwalkCache
628 Crst SharedAssemblyCreate
629 AcquiredBefore DeadlockDetection UniqueStack
632 Crst SharedBaseDomain
633 AcquiredBefore UniqueStack
637 AcquiredBefore LoaderHeap
641 AcquiredBefore ExecuteManRangeLock LoaderHeap UniqueStack DebuggerJitInfo
644 Crst UnwindInfoTableLock
645 AcquiredAfter StubUnwindInfoHeapSegments SingleUseLock
646 AcquiredBefore StressLog
659 Crst CodeFragmentHeap
660 AcquiredBefore SingleUseLock
663 Crst StubDispatchCache
666 Crst StubUnwindInfoHeapSegments
667 AcquiredAfter StubCache
671 AcquiredBefore ThreadIdDispenser
677 Crst SystemBaseDomain
681 AcquiredBefore DebuggerMutex HandleTable IbcProfile SaveModuleProfileData SecurityPolicyCache
682 ThreadIdDispenser ThreadStore
685 Crst SystemDomainDelayedUnloadList
688 Crst ThreadIdDispenser
691 Crst ThreadpoolEventCache
694 Crst ThreadpoolTimerQueue
695 AcquiredBefore UniqueStack
698 Crst ThreadpoolWaitThreads
699 AcquiredBefore UniqueStack
702 Crst ThreadpoolWorker
703 AcquiredBefore ThreadIdDispenser ThreadStore
706 Crst ThreadStaticDataHashTable
707 AcquiredBefore SyncBlockCache
711 AcquiredBefore AvailableParamTypes ConnectionNameTable DeadlockDetection DebuggerController
712 DebuggerHeapLock DebuggerJitInfo DynamicIL ExecuteManRangeLock HandleTable IbcProfile
713 JitGenericHandleCache JumpStubCache LoaderHeap ModuleLookupTable ProfilingAPIStatus
714 ProfilerGCRefDataFreeList RWLock SingleUseLock SyncBlockCache SystemDomainDelayedUnloadList
715 ThreadIdDispenser ThreadStaticDataHashTable
719 AcquiredBefore DebuggerHeapLock LoaderHeap UniqueStack AvailableParamTypes
723 AcquiredBefore UniqueStack
726 Crst TypeEquivalenceMap
727 AcquiredBefore LoaderHeap
734 AcquiredBefore LoaderHeap
737 Crst UnresolvedClassLock
738 AcquiredBefore AvailableParamTypes DynLinkZapItems IbcProfile JumpStubCache
742 AcquiredBefore IbcProfile
745 Crst UMEntryThunkCache
746 AcquiredBefore LoaderHeap
749 Crst PinnedByrefValidation
752 Crst AssemblyUsageLog
755 Crst VSDIndirectionCellLock
756 AcquiredBefore LoaderHeap
759 Crst MulticoreJitHash
762 Crst MulticoreJitManager
763 AcquiredBefore MulticoreJitHash ThreadStore
766 Crst WinRTFactoryCache
767 AcquiredBefore HandleTable
776 Crst InlineTrackingMap
777 AcquiredBefore IbcProfile