Index: trunk/src/VBox/VMM/VMMAll/PGMAllPhys.cpp
===================================================================
--- trunk/src/VBox/VMM/VMMAll/PGMAllPhys.cpp	(revision 107192)
+++ trunk/src/VBox/VMM/VMMAll/PGMAllPhys.cpp	(revision 107194)
@@ -2065,4 +2065,5 @@
 }
 
+#ifndef VBOX_WITH_ONLY_PGM_NEM_MODE
 
 /**
@@ -2087,26 +2088,26 @@
      * Do we need to do anything special?
      */
-#ifdef IN_RING3
+# ifdef IN_RING3
     if (pVM->pgm.s.cHandyPages <= RT_MAX(PGM_HANDY_PAGES_SET_FF, PGM_HANDY_PAGES_R3_ALLOC))
-#else
+# else
     if (pVM->pgm.s.cHandyPages <= RT_MAX(PGM_HANDY_PAGES_SET_FF, PGM_HANDY_PAGES_RZ_TO_R3))
-#endif
+# endif
     {
         /*
          * Allocate pages only if we're out of them, or in ring-3, almost out.
          */
-#ifdef IN_RING3
+# ifdef IN_RING3
         if (pVM->pgm.s.cHandyPages <= PGM_HANDY_PAGES_R3_ALLOC)
-#else
+# else
         if (pVM->pgm.s.cHandyPages <= PGM_HANDY_PAGES_RZ_ALLOC)
-#endif
+# endif
         {
             Log(("PGM: cHandyPages=%u out of %u -> allocate more; VM_FF_PGM_NO_MEMORY=%RTbool\n",
                  pVM->pgm.s.cHandyPages, RT_ELEMENTS(pVM->pgm.s.aHandyPages), VM_FF_IS_SET(pVM, VM_FF_PGM_NO_MEMORY) ));
-#ifdef IN_RING3
+# ifdef IN_RING3
             int rc = PGMR3PhysAllocateHandyPages(pVM);
-#else
+# else
             int rc = pgmR0PhysAllocateHandyPages(pVM, VMMGetCpuId(pVM), false /*fRing3*/);
-#endif
+# endif
             if (RT_UNLIKELY(rc != VINF_SUCCESS))
             {
@@ -2121,7 +2122,7 @@
                 Assert(VM_FF_IS_SET(pVM, VM_FF_PGM_NEED_HANDY_PAGES));
                 Assert(VM_FF_IS_SET(pVM, VM_FF_PGM_NO_MEMORY));
-#ifndef IN_RING3
+# ifndef IN_RING3
                 VMCPU_FF_SET(VMMGetCpu(pVM), VMCPU_FF_TO_R3); /* paranoia */
-#endif
+# endif
             }
             AssertMsgReturn(    pVM->pgm.s.cHandyPages > 0
@@ -2134,5 +2135,5 @@
             if (pVM->pgm.s.cHandyPages <= PGM_HANDY_PAGES_SET_FF)
                 VM_FF_SET(pVM, VM_FF_PGM_NEED_HANDY_PAGES);
-#ifndef IN_RING3
+# ifndef IN_RING3
             if (pVM->pgm.s.cHandyPages <= PGM_HANDY_PAGES_RZ_TO_R3)
             {
@@ -2140,5 +2141,5 @@
                 VMCPU_FF_SET(VMMGetCpu(pVM), VMCPU_FF_TO_R3);
             }
-#endif
+# endif
         }
     }
@@ -2331,5 +2332,5 @@
 }
 
-#ifdef PGM_WITH_LARGE_PAGES
+# ifdef PGM_WITH_LARGE_PAGES
 
 /**
@@ -2408,11 +2409,11 @@
              * Do the allocation.
              */
-# ifdef IN_RING3
+#  ifdef IN_RING3
             rc = VMMR3CallR0(pVM, VMMR0_DO_PGM_ALLOCATE_LARGE_PAGE, GCPhysBase, NULL);
-# elif defined(IN_RING0)
+#  elif defined(IN_RING0)
             rc = pgmR0PhysAllocateLargePage(pVM, VMMGetCpuId(pVM), GCPhysBase);
-# else
-#  error "Port me"
-# endif
+#  else
+#   error "Port me"
+#  endif
             if (RT_SUCCESS(rc))
             {
@@ -2496,5 +2497,7 @@
 }
 
-#endif /* PGM_WITH_LARGE_PAGES */
+# endif /* PGM_WITH_LARGE_PAGES */
+#endif /* !VBOX_WITH_ONLY_PGM_NEM_MODE */
+
 
 
@@ -2585,5 +2588,10 @@
             RT_FALL_THRU();
         case PGM_PAGE_STATE_SHARED:
+#ifndef VBOX_WITH_ONLY_PGM_NEM_MODE
             return pgmPhysAllocPage(pVM, pPage, GCPhys);
+#else
+            AssertFailed(); /** @todo not sure if we make use of ZERO pages or not in NEM-mode, but I can't see how pgmPhysAllocPage would work. */
+            return VERR_PGM_NOT_SUPPORTED_FOR_NEM_MODE;
+#endif
 
         /* Not allowed to write to ballooned pages. */
@@ -2593,5 +2601,5 @@
 }
 
-
+#if 0 /* unused */
 /**
  * Internal usage: Map the page specified by its GMM ID.
@@ -2665,5 +2673,5 @@
 #endif
 }
-
+#endif /* unused */
 
 /**
@@ -3078,5 +3086,5 @@
         AssertMsg(rc == VINF_SUCCESS || rc == VINF_PGM_SYNC_CR3 /* not returned */, ("%Rrc\n", rc));
     }
-    Assert(PGM_PAGE_GET_HCPHYS(pPage) != 0);
+    Assert(PGM_PAGE_GET_HCPHYS(pPage) != 0 || PGM_IS_IN_NEM_MODE(pVM));
 
     /*
@@ -3213,5 +3221,5 @@
         AssertMsg(rc == VINF_SUCCESS || rc == VINF_PGM_SYNC_CR3 /* not returned */, ("%Rrc\n", rc));
     }
-    Assert(PGM_PAGE_GET_HCPHYS(pPage) != 0);
+    Assert(PGM_PAGE_GET_HCPHYS(pPage) != 0 || PGM_IS_IN_NEM_MODE(pVM));
 
     /*
@@ -3250,5 +3258,5 @@
     AssertReturn(pPage, VERR_PGM_PHYS_NULL_PAGE_PARAM);
     PGM_LOCK_ASSERT_OWNER(pVM);
-    Assert(PGM_PAGE_GET_HCPHYS(pPage) != 0);
+    Assert(PGM_PAGE_GET_HCPHYS(pPage) != 0 || PGM_IS_IN_NEM_MODE(pVM));
 
     /*
@@ -3736,5 +3744,5 @@
             AssertMsg(rc == VINF_SUCCESS || rc == VINF_PGM_SYNC_CR3 /* not returned */, ("%Rrc\n", rc));
         }
-        Assert(PGM_PAGE_GET_HCPHYS(pPage) != 0);
+        Assert(PGM_PAGE_GET_HCPHYS(pPage) != 0 || PGM_IS_IN_NEM_MODE(pVM));
 
         /*
