Index: /trunk/include/iprt/critsect.h
===================================================================
--- /trunk/include/iprt/critsect.h	(revision 51939)
+++ /trunk/include/iprt/critsect.h	(revision 51940)
@@ -108,8 +108,10 @@
  * might or might not require entering a critical section before access. */
 #define RTCRITSECT_FLAGS_NOP            UINT32_C(0x00000008)
+/** Indicates that this is a ring-0 critical section. */
+#define RTCRITSECT_FLAGS_RING0          UINT32_C(0x00000010)
 /** @} */
 
 
-#ifdef IN_RING3
+#if defined(IN_RING3) || defined(IN_RING0)
 
 /**
@@ -209,4 +211,6 @@
 RTDECL(int) RTCritSectTryEnterDebug(PRTCRITSECT pCritSect, RTHCUINTPTR uId, RT_SRC_POS_DECL);
 
+#ifdef IN_RING3 /* Crazy APIs: ring-3 only. */
+
 /**
  * Enter multiple critical sections.
@@ -248,4 +252,6 @@
 RTDECL(int) RTCritSectEnterMultipleDebug(size_t cCritSects, PRTCRITSECT *papCritSects, RTUINTPTR uId, RT_SRC_POS_DECL);
 
+#endif /* IN_RING3 */
+
 /**
  * Leave a critical section.
@@ -285,5 +291,5 @@
 }
 
-#endif /* IN_RING3 */
+#endif /* IN_RING3 || IN_RING0 */
 
 /**
@@ -455,5 +461,5 @@
 /** @} */
 
-#ifdef IN_RING3
+#if defined(IN_RING3) || defined(IN_RING0)
 
 /**
@@ -701,5 +707,5 @@
 RTDECL(uint32_t) RTCritSectRwGetReadCount(PRTCRITSECTRW pThis);
 
-#endif /* IN_RING3 */
+#endif /* IN_RING3 || IN_RING0 */
 
 /**
Index: /trunk/src/VBox/Runtime/Makefile.kmk
===================================================================
--- /trunk/src/VBox/Runtime/Makefile.kmk	(revision 51939)
+++ /trunk/src/VBox/Runtime/Makefile.kmk	(revision 51940)
@@ -1755,4 +1755,5 @@
 	common/time/timesup.cpp \
 	generic/RTAssertShouldPanic-generic.cpp \
+	generic/critsect-generic.cpp \
 	\
 	$(RuntimeNoCrt_SOURCES)
@@ -1935,4 +1936,5 @@
  	generic/RTSemEventMultiWait-2-ex-generic.cpp \
  	generic/RTSemEventMultiWaitNoResume-2-ex-generic.cpp \
+	generic/critsect-generic.cpp \
 	generic/errvars-generic.cpp \
 	generic/uuid-generic.cpp \
Index: /trunk/src/VBox/Runtime/generic/critsect-generic.cpp
===================================================================
--- /trunk/src/VBox/Runtime/generic/critsect-generic.cpp	(revision 51939)
+++ /trunk/src/VBox/Runtime/generic/critsect-generic.cpp	(revision 51940)
@@ -59,5 +59,9 @@
      */
     pCritSect->u32Magic             = RTCRITSECT_MAGIC;
-    pCritSect->fFlags               = fFlags;
+#ifdef IN_RING0
+    pCritSect->fFlags               = fFlags | RTCRITSECT_FLAGS_RING0;
+#else
+    pCritSect->fFlags               = fFlags & ~RTCRITSECT_FLAGS_RING0;
+#endif
     pCritSect->cNestings            = 0;
     pCritSect->cLockers             = -1;
@@ -87,4 +91,8 @@
     if (RT_SUCCESS(rc))
     {
+#ifdef IN_RING0
+        rc = RTSemEventCreate(&pCritSect->EventSem);
+
+#else
         rc = RTSemEventCreateEx(&pCritSect->EventSem,
                                 fFlags & RTCRITSECT_FLAGS_BOOTSTRAP_HACK
@@ -93,7 +101,10 @@
                                 NIL_RTLOCKVALCLASS,
                                 NULL);
+#endif
         if (RT_SUCCESS(rc))
             return VINF_SUCCESS;
+#ifdef RTCRITSECT_STRICT
         RTLockValidatorRecExclDestroy(&pCritSect->pValidatorRec);
+#endif
     }
 
@@ -108,12 +119,12 @@
 RTDECL(uint32_t) RTCritSectSetSubClass(PRTCRITSECT pCritSect, uint32_t uSubClass)
 {
-#ifdef RTCRITSECT_STRICT
+# ifdef RTCRITSECT_STRICT
     AssertPtrReturn(pCritSect, RTLOCKVAL_SUB_CLASS_INVALID);
     AssertReturn(pCritSect->u32Magic == RTCRITSECT_MAGIC, RTLOCKVAL_SUB_CLASS_INVALID);
     AssertReturn(!(pCritSect->fFlags & RTCRITSECT_FLAGS_NOP), RTLOCKVAL_SUB_CLASS_INVALID);
     return RTLockValidatorRecExclSetSubClass(pCritSect->pValidatorRec, uSubClass);
-#else
+# else
     return RTLOCKVAL_SUB_CLASS_INVALID;
-#endif
+# endif
 }
 
@@ -124,4 +135,9 @@
     Assert(pCritSect->u32Magic == RTCRITSECT_MAGIC);
     /*AssertReturn(pCritSect->u32Magic == RTCRITSECT_MAGIC, VERR_SEM_DESTROYED);*/
+#ifdef IN_RING0
+    Assert(pCritSect->fFlags & RTCRITSECT_FLAGS_RING0);
+#else
+    Assert(!(pCritSect->fFlags & RTCRITSECT_FLAGS_RING0));
+#endif
 
     /*
@@ -196,4 +212,9 @@
     AssertPtr(pCritSect);
     AssertReturn(pCritSect->u32Magic == RTCRITSECT_MAGIC, VERR_SEM_DESTROYED);
+#ifdef IN_RING0
+    Assert(pCritSect->fFlags & RTCRITSECT_FLAGS_RING0);
+#else
+    Assert(!(pCritSect->fFlags & RTCRITSECT_FLAGS_RING0));
+#endif
 
     /*
@@ -267,9 +288,11 @@
                 return rc9;
             }
-#else
+#elif defined(IN_RING3)
             RTThreadBlocking(hThreadSelf, RTTHREADSTATE_CRITSECT, false);
 #endif
             int rc = RTSemEventWait(pCritSect->EventSem, RT_INDEFINITE_WAIT);
+#ifdef IN_RING3
             RTThreadUnblocked(hThreadSelf, RTTHREADSTATE_CRITSECT);
+#endif
 
             if (pCritSect->u32Magic != RTCRITSECT_MAGIC)
@@ -322,4 +345,9 @@
     Assert(pCritSect);
     Assert(pCritSect->u32Magic == RTCRITSECT_MAGIC);
+#ifdef IN_RING0
+    Assert(pCritSect->fFlags & RTCRITSECT_FLAGS_RING0);
+#else
+    Assert(!(pCritSect->fFlags & RTCRITSECT_FLAGS_RING0));
+#endif
     if (pCritSect->fFlags & RTCRITSECT_FLAGS_NOP)
         return VINF_SUCCESS;
@@ -363,5 +391,5 @@
 
 
-
+#ifdef IN_RING3
 
 static int rtCritSectEnterMultiple(size_t cCritSects, PRTCRITSECT *papCritSects, PCRTLOCKVALSRCPOS pSrcPos)
@@ -477,4 +505,7 @@
 RT_EXPORT_SYMBOL(RTCritSectLeaveMultiple);
 
+#endif /* IN_RING3 */
+
+
 
 RTDECL(int) RTCritSectDelete(PRTCRITSECT pCritSect)
@@ -488,4 +519,9 @@
     Assert(pCritSect->cLockers == -1);
     Assert(pCritSect->NativeThreadOwner == NIL_RTNATIVETHREAD);
+#ifdef IN_RING0
+    Assert(pCritSect->fFlags & RTCRITSECT_FLAGS_RING0);
+#else
+    Assert(!(pCritSect->fFlags & RTCRITSECT_FLAGS_RING0));
+#endif
 
     /*
@@ -506,5 +542,7 @@
     AssertRC(rc);
 
+#ifdef RTCRITSECT_STRICT
     RTLockValidatorRecExclDestroy(&pCritSect->pValidatorRec);
+#endif
 
     return rc;
Index: /trunk/src/VBox/VMM/VMMR0/GMMR0.cpp
===================================================================
--- /trunk/src/VBox/VMM/VMMR0/GMMR0.cpp	(revision 51939)
+++ /trunk/src/VBox/VMM/VMMR0/GMMR0.cpp	(revision 51940)
@@ -165,4 +165,5 @@
 # include <iprt/crc.h>
 #endif
+#include <iprt/critsect.h>
 #include <iprt/list.h>
 #include <iprt/mem.h>
@@ -172,4 +173,17 @@
 #include <iprt/string.h>
 #include <iprt/time.h>
+
+
+/*******************************************************************************
+*   Defined Constants And Macros                                               *
+*******************************************************************************/
+/** @def VBOX_USE_CRIT_SECT_FOR_GIANT
+ * Use a critical section instead of a fast mutex for the giant GMM lock.
+ *
+ * @remarks This is primarily a way of avoiding the deadlock checks in the
+ *          windows driver verifier. */
+#if defined(RT_OS_WINDOWS) || defined(DOXYGEN_RUNNING)
+# define VBOX_USE_CRIT_SECT_FOR_GIANT
+#endif
 
 
@@ -476,7 +490,13 @@
     /** The number of threads waiting on the mutex. */
     uint32_t            cMtxContenders;
+#ifdef VBOX_USE_CRIT_SECT_FOR_GIANT
+    /** The critical section protecting the GMM.
+     * More fine grained locking can be implemented later if necessary. */
+    RTCRITSECT          GiantCritSect;
+#else
     /** The fast mutex protecting the GMM.
      * More fine grained locking can be implemented later if necessary. */
     RTSEMFASTMUTEX      hMtx;
+#endif
 #ifdef VBOX_STRICT
     /** The current mutex owner. */
@@ -758,5 +778,9 @@
     ASMBitSet(&pGMM->bmChunkId[0], NIL_GMM_CHUNKID);
 
+#ifdef VBOX_USE_CRIT_SECT_FOR_GIANT
+    int rc = RTCritSectInit(&pGMM->GiantCritSect);
+#else
     int rc = RTSemFastMutexCreate(&pGMM->hMtx);
+#endif
     if (RT_SUCCESS(rc))
     {
@@ -816,5 +840,9 @@
         while (iMtx-- > 0)
             RTSemFastMutexDestroy(pGMM->aChunkMtx[iMtx].hMtx);
+#ifdef VBOX_USE_CRIT_SECT_FOR_GIANT
+        RTCritSectDelete(&pGMM->GiantCritSect);
+#else
         RTSemFastMutexDestroy(pGMM->hMtx);
+#endif
     }
 
@@ -851,6 +879,10 @@
     g_pGMM = NULL;
     pGMM->u32Magic    = ~GMM_MAGIC;
+#ifdef VBOX_USE_CRIT_SECT_FOR_GIANT
+    RTCritSectDelete(&pGMM->GiantCritSect);
+#else
     RTSemFastMutexDestroy(pGMM->hMtx);
     pGMM->hMtx        = NIL_RTSEMFASTMUTEX;
+#endif
 
     /* Free any chunks still hanging around. */
@@ -933,5 +965,9 @@
 {
     ASMAtomicIncU32(&pGMM->cMtxContenders);
+#ifdef VBOX_USE_CRIT_SECT_FOR_GIANT
+    int rc = RTCritSectEnter(&pGMM->GiantCritSect);
+#else
     int rc = RTSemFastMutexRequest(pGMM->hMtx);
+#endif
     ASMAtomicDecU32(&pGMM->cMtxContenders);
     AssertRC(rc);
@@ -954,6 +990,10 @@
     pGMM->hMtxOwner = NIL_RTNATIVETHREAD;
 #endif
+#ifdef VBOX_USE_CRIT_SECT_FOR_GIANT
+    int rc = RTCritSectLeave(&pGMM->GiantCritSect);
+#else
     int rc = RTSemFastMutexRelease(pGMM->hMtx);
     AssertRC(rc);
+#endif
     return rc;
 }
@@ -991,9 +1031,17 @@
 #endif
     ASMAtomicIncU32(&pGMM->cMtxContenders);
+#ifdef VBOX_USE_CRIT_SECT_FOR_GIANT
+    int rc1 = RTCritSectLeave(&pGMM->GiantCritSect); AssertRC(rc1);
+#else
     int rc1 = RTSemFastMutexRelease(pGMM->hMtx); AssertRC(rc1);
+#endif
 
     RTThreadYield();
 
+#ifdef VBOX_USE_CRIT_SECT_FOR_GIANT
+    int rc2 = RTCritSectEnter(&pGMM->GiantCritSect); AssertRC(rc2);
+#else
     int rc2 = RTSemFastMutexRequest(pGMM->hMtx); AssertRC(rc2);
+#endif
     *puLockNanoTS = RTTimeSystemNanoTS();
     ASMAtomicDecU32(&pGMM->cMtxContenders);
