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 // Debugger Heap lock is the smallest of the debugger locks.
189 Crst DebuggerHeapLock
190 AcquiredAfter DebuggerFavorLock DebuggerJitInfo DebuggerMutex
191 // Disabled per bug 581892
192 // AcquiredAfter DebuggerController
196 AcquiredBefore DebuggerHeapLock
199 // This is the major debugger lock.
200 // It's the largest of the debugger locks.
202 AcquiredBefore AvailableParamTypes ConnectionNameTable
203 DynamicIL LoaderHeap ModuleLookupTable ThreadStore
205 // Disabled per bug 581892
206 // AcquiredBefore DebuggerController
207 AcquiredBefore DebuggerHeapLock DebuggerJitInfo
211 // This lock is used only for testing data consistency (see code:DataTest::TestDataSafety)
212 // and is released before taking any other lock except for CrstDataTest2
214 AcquiredAfter DebuggerMutex
217 // This lock is used only for testing data consistency (see code:DataTest::TestDataSafety)
218 // and is released before taking any other lockCrst DataTest2
220 AcquiredAfter DataTest1
227 Crst DelegateToFPtrHash
230 Crst DomainLocalBlock
231 AcquiredBefore AppDomainHandleTable IbcProfile LoaderHeap SystemDomainDelayedUnloadList UniqueStack
238 AcquiredBefore IbcProfile
242 AcquiredBefore LoaderHeap
252 AcquiredBefore UniqueStack
255 Crst ExecuteManRangeLock
259 AcquiredBefore LoaderHeap
263 AcquiredBefore LoaderHeap
266 Crst FriendAccessCache
267 AcquiredBefore JumpStubCache UniqueStack
271 AcquiredBefore IbcProfile LoaderHeap UniqueStack CodeFragmentHeap JumpStubCache PatchEntryPoint
275 AcquiredBefore FusionPolicyConfigPool FusionSingleUse FusionAssemblyDownload
278 Crst FusionAssemblyDownload
279 AcquiredBefore FusionDownload UniqueStack
282 Crst FusionBindResult
289 AcquiredBefore FusionBindContext FusionLoadContext FusionAppCtx FusionClosureGraph DomainLocalBlock ModuleFixup
292 Crst FusionClosureGraph
293 AcquiredBefore FusionAppCtx FusionBindContext FusionLoadContext
296 Crst FusionConfigSettings
302 Crst FusionLoadContext
303 AcquiredBefore PEImage
306 Crst FusionBindContext
307 AcquiredBefore PEImage
311 AcquiredBefore IbcProfile UniqueStack
314 Crst FusionWarningLog
315 AcquiredBefore FusionBindContext FusionLoadContext FusionLog
319 AcquiredBefore SystemDomainDelayedUnloadList
322 Crst FusionNgenIndexPool
323 AcquiredBefore SystemDomainDelayedUnloadList
329 Crst FusionPolicyConfigPool
330 AcquiredBefore UniqueStack
334 AcquiredBefore PEImage
337 Crst FusionIsoLibInit
340 Crst NativeBinderInit
344 Crst NativeImageCache
348 Crst GCMemoryPressure
351 Crst GlobalStrLiteralMap
352 AcquiredBefore HandleTable IbcProfile SyncBlockCache SystemDomainDelayedUnloadList ThreadStore UniqueStack
356 SameLevelAs HandleTable
362 Crst HostAssemblyMapAdd
363 AcquiredBefore HostAssemblyMap
370 AcquiredBefore FuncPtrStubs IJWHash LoaderHeap
377 AcquiredBefore DeadlockDetection UniqueStack
380 Crst InstMethodHashTable
381 AcquiredBefore FusionBindContext FusionLoadContext LoaderHeap UniqueStack JumpStubCache
384 Crst InterfaceVTableMap
388 AcquiredBefore AppDomainHandleTable AvailableParamTypes Cer ClassInit DeadlockDetection DomainLocalBlock
389 HandleTable InstMethodHashTable InteropData JitGenericHandleCache LoaderHeap SigConvert
390 StubDispatchCache StubUnwindInfoHeapSegments SyncBlockCache TypeIDMap UnresolvedClassLock
394 AcquiredBefore LoaderHeap UniqueStack
397 Crst IOThreadpoolWorker
398 AcquiredBefore ThreadIdDispenser ThreadStore
404 Crst ISymUnmanagedReader
405 AcquiredBefore PEImagePDBStream UniqueStack JumpStubCache
409 AcquiredBefore DeadlockDetection JumpStubCache
410 SameLevelAs ClassInit
413 Crst JitGenericHandleCache
421 AcquiredBefore ExecuteManRangeLock LoaderHeap SingleUseLock
422 AcquiredAfter AppDomainCache ExecuteManLock FusionAssemblyDownload FusionNgenIndex FusionNgenIndexPool
423 ILStubGen SharedBaseDomain ThreadpoolTimerQueue ThreadpoolWaitThreads
424 TPMethodTable TypeIDMap BaseDomain AssemblyLoader
431 // Leaflock leveling, used for crsts that explicitly want to be a leaf lock
436 AcquiredBefore AppDomainHandleTable HandleTable UniqueStack ThreadStore
437 AcquiredAfter DomainLocalBlock
440 Crst LoaderAllocatorReferences
441 AcquiredBefore LoaderAllocator
442 AcquiredAfter PendingTypeLoadEntry InstMethodHashTable
446 AcquiredAfter LoaderAllocatorReferences ThreadStore AssemblyLoader
460 AcquiredBefore LoaderHeap
467 AcquiredBefore LoaderHeap UniqueStack
471 AcquiredBefore AppDomainHandleTable GlobalStrLiteralMap IbcProfile SyncBlockCache
474 Crst ModuleLookupTable
475 AcquiredBefore LoaderHeap
485 SameLevelAs ObjectList
494 Crst PEFileSecurityManager
498 AcquiredBefore UniqueStack
501 Crst ILFingerprintCache
502 AcquiredBefore PEImage
505 Crst PEImagePDBStream
508 Crst PendingTypeLoadEntry
509 AcquiredBefore AppDomainCache AppDomainHandleTable AssemblyLoader AvailableClass AvailableParamTypes
510 BaseDomain ClassInit DeadlockDetection DebuggerController DebuggerJitInfo DebuggerMutex
511 DomainLocalBlock DynLinkZapItems Exception ExecuteManRangeLock FuncPtrStubs
512 FusionAppCtx FusionAssemblyDownload FusionBindResult FusionClosure FusionDownload
513 FusionBindContext FusionLoadContext FusionNgenIndex FusionNgenIndexPool FusionPcyCache
514 FusionPolicyConfigPool FusionSingleUse GlobalStrLiteralMap HandleTable IbcProfile
515 IJWFixupData IJWHash ISymUnmanagedReader Jit JumpStubCache LoaderHeap ModIntPairList
516 Module ModuleLookupTable PEImage SecurityStackwalkCache SharedAssemblyCreate
517 SharedBaseDomain SigConvert SingleUseLock StubDispatchCache StubUnwindInfoHeapSegments
518 SyncBlockCache SystemDomain ThreadIdDispenser ThreadStore TypeIDMap UnresolvedClassLock
519 SameLevelAs PendingTypeLoadEntry
525 // ProfilerGCRefDataFreeList synchronizes access to the profiler API's list of
526 // free, previously allocated structures that track moved references and
527 // root references during a GC.
528 Crst ProfilerGCRefDataFreeList
531 // ProfilingAPIStatus serializes attempts to transition the global status
532 // from state to state, and access to the ProfilerDetachInfo structure
533 // between the thread executing DetachProfiler(), and the DetachThread
534 // carrying out the evacuation order.
535 Crst ProfilingAPIStatus
538 Crst PublisherCertificate
542 AcquiredBefore IbcProfile LoaderHeap RCWCleanupList
546 AcquiredBefore HandleTable
556 AcquiredBefore LoaderHeap UnresolvedClassLock
559 // Used to synchronize all rejit information stored in a given AppDomain. One of these
560 // crsts exist per domain (except the SharedDomain--see below)
561 Crst ReJITDomainTable
562 AcquiredBefore LoaderHeap SingleUseLock DeadlockDetection JumpStubCache DebuggerController
563 AcquiredAfter ReJITGlobalRequest ThreadStore GlobalStrLiteralMap SystemDomain DebuggerMutex
566 // Same as ReJITDomainTable, but this is for the SharedDomain's ReJitManager. Only
567 // reason we have a special type for the SharedDomain's ReJitManager is so that we can
568 // explicitly level this guy differently from ReJITDomainTable, so that both the
569 // SharedDomain's ReJitManager table lock AND one non-SharedDomain's ReJitManager table
570 // lock may be held simultaneously. This is useful during ETW rundown.
571 Crst ReJITSharedDomainTable
572 AcquiredBefore ReJITDomainTable
573 AcquiredAfter ReJITGlobalRequest ThreadStore GlobalStrLiteralMap SystemDomain DebuggerMutex
576 // Used to synchronize all global requests (which may span multiple AppDomains) which add
577 // new functions to rejit tables, or request Reverts on existing functions in the rejit
578 // tables. One of these crsts exist per runtime.
579 Crst ReJITGlobalRequest
580 AcquiredBefore ThreadStore ReJITSharedDomainTable ReJITDomainTable SystemDomain
583 // ETW infrastructure uses this crst to protect a hash table of TypeHandles which is
584 // used to remember which types have been logged (to avoid duplicate logging of the
587 AcquiredAfter ThreadStore AllowedFiles Cer TPMethodTable
588 AcquiredBefore AvailableParamTypes ConnectionNameTable DeadlockDetection DebuggerController
589 DebuggerHeapLock DebuggerJitInfo DynamicIL ExecuteManRangeLock HandleTable IbcProfile
590 JitGenericHandleCache JumpStubCache LoaderHeap ModuleLookupTable ProfilingAPIStatus
591 ProfilerGCRefDataFreeList RWLock SingleUseLock SyncBlockCache SystemDomainDelayedUnloadList
592 ThreadIdDispenser ThreadStaticDataHashTable
596 AcquiredBefore AppDomainHandleTable AvailableParamTypes Cer ClassInit DeadlockDetection DebuggerController
597 DebuggerHeapLock DebuggerJitInfo DebuggerMutex DomainLocalBlock ExecuteManRangeLock
598 FuncPtrStubs GlobalStrLiteralMap HandleTable InstMethodHashTable Jit JitGenericHandleCache
599 JumpStubCache LoaderHeap StubCache Module ModuleLookupTable SecurityStackwalkCache SigConvert
600 SingleUseLock StubUnwindInfoHeapSegments SyncBlockCache SystemDomainDelayedUnloadList
601 ThreadStore UnresolvedClassLock PendingTypeLoadEntry
607 Crst SavedExceptionInfo
608 AcquiredBefore DebuggerController
611 Crst SaveModuleProfileData
614 Crst SecurityPolicyCache
617 Crst SecurityPolicyInit
618 AcquiredBefore SecurityPolicyCache
621 Crst SecurityStackwalkCache
624 Crst SharedAssemblyCreate
625 AcquiredBefore DeadlockDetection UniqueStack
628 Crst SharedBaseDomain
629 AcquiredBefore UniqueStack
633 AcquiredBefore LoaderHeap
637 AcquiredBefore ExecuteManRangeLock LoaderHeap UniqueStack DebuggerJitInfo
640 Crst UnwindInfoTableLock
641 AcquiredAfter StubUnwindInfoHeapSegments SingleUseLock
642 AcquiredBefore StressLog
655 Crst CodeFragmentHeap
656 AcquiredBefore SingleUseLock
659 Crst StubDispatchCache
662 Crst StubUnwindInfoHeapSegments
663 AcquiredAfter StubCache
667 AcquiredBefore ThreadIdDispenser
673 Crst SystemBaseDomain
677 AcquiredBefore DebuggerMutex HandleTable IbcProfile SaveModuleProfileData SecurityPolicyCache
678 ThreadIdDispenser ThreadStore
681 Crst SystemDomainDelayedUnloadList
684 Crst ThreadIdDispenser
687 Crst ThreadpoolEventCache
690 Crst ThreadpoolTimerQueue
691 AcquiredBefore UniqueStack
694 Crst ThreadpoolWaitThreads
695 AcquiredBefore UniqueStack
698 Crst ThreadpoolWorker
699 AcquiredBefore ThreadIdDispenser ThreadStore
702 Crst ThreadStaticDataHashTable
703 AcquiredBefore SyncBlockCache
707 AcquiredBefore AvailableParamTypes ConnectionNameTable DeadlockDetection DebuggerController
708 DebuggerHeapLock DebuggerJitInfo DynamicIL ExecuteManRangeLock HandleTable IbcProfile
709 JitGenericHandleCache JumpStubCache LoaderHeap ModuleLookupTable ProfilingAPIStatus
710 ProfilerGCRefDataFreeList RWLock SingleUseLock SyncBlockCache SystemDomainDelayedUnloadList
711 ThreadIdDispenser ThreadStaticDataHashTable
715 AcquiredBefore DebuggerHeapLock LoaderHeap UniqueStack AvailableParamTypes
719 AcquiredBefore UniqueStack
722 Crst TypeEquivalenceMap
723 AcquiredBefore LoaderHeap
730 AcquiredBefore LoaderHeap
733 Crst UnresolvedClassLock
734 AcquiredBefore AvailableParamTypes DynLinkZapItems IbcProfile JumpStubCache
738 AcquiredBefore IbcProfile
741 Crst UMEntryThunkCache
742 AcquiredBefore LoaderHeap
745 Crst PinnedByrefValidation
748 Crst AssemblyUsageLog
751 Crst VSDIndirectionCellLock
752 AcquiredBefore LoaderHeap
755 Crst MulticoreJitHash
758 Crst MulticoreJitManager
759 AcquiredBefore MulticoreJitHash ThreadStore
762 Crst WinRTFactoryCache
763 AcquiredBefore HandleTable
772 Crst InlineTrackingMap
773 AcquiredBefore IbcProfile