Index: trunk/src/VBox/VMM/VMMAll/PGMAll.cpp
===================================================================
--- trunk/src/VBox/VMM/VMMAll/PGMAll.cpp	(revision 80163)
+++ trunk/src/VBox/VMM/VMMAll/PGMAll.cpp	(revision 80167)
@@ -52,8 +52,6 @@
 DECLINLINE(int) pgmShwGetLongModePDPtr(PVMCPU pVCpu, RTGCPTR64 GCPtr, PX86PML4E *ppPml4e, PX86PDPT *ppPdpt, PX86PDPAE *ppPD);
 DECLINLINE(int) pgmShwGetPaePoolPagePD(PVMCPU pVCpu, RTGCPTR GCPtr, PPGMPOOLPAGE *ppShwPde);
-#ifndef IN_RC
 static int pgmShwSyncLongModePDPtr(PVMCPU pVCpu, RTGCPTR64 GCPtr, X86PGPAEUINT uGstPml4e, X86PGPAEUINT uGstPdpe, PX86PDPAE *ppPD);
 static int pgmShwGetEPTPDPtr(PVMCPU pVCpu, RTGCPTR64 GCPtr, PEPTPDPT *ppPdpt, PEPTPD *ppPD);
-#endif
 
 
@@ -190,21 +188,38 @@
 
 
-#ifndef IN_RC /* AMD64 implies VT-x/AMD-V */
 /*
  * Shadow - AMD64 mode
  */
-# define PGM_SHW_TYPE               PGM_TYPE_AMD64
-# define PGM_SHW_NAME(name)         PGM_SHW_NAME_AMD64(name)
-# include "PGMAllShw.h"
+#define PGM_SHW_TYPE               PGM_TYPE_AMD64
+#define PGM_SHW_NAME(name)         PGM_SHW_NAME_AMD64(name)
+#include "PGMAllShw.h"
 
 /* Guest - protected mode (only used for AMD-V nested paging in 64 bits mode) */
 /** @todo retire this hack. */
-# define PGM_GST_TYPE               PGM_TYPE_PROT
-# define PGM_GST_NAME(name)         PGM_GST_NAME_PROT(name)
-# define PGM_BTH_NAME(name)         PGM_BTH_NAME_AMD64_PROT(name)
-# define BTH_PGMPOOLKIND_PT_FOR_PT  PGMPOOLKIND_PAE_PT_FOR_PHYS
-# define BTH_PGMPOOLKIND_ROOT       PGMPOOLKIND_PAE_PD_PHYS
+#define PGM_GST_TYPE               PGM_TYPE_PROT
+#define PGM_GST_NAME(name)         PGM_GST_NAME_PROT(name)
+#define PGM_BTH_NAME(name)         PGM_BTH_NAME_AMD64_PROT(name)
+#define BTH_PGMPOOLKIND_PT_FOR_PT  PGMPOOLKIND_PAE_PT_FOR_PHYS
+#define BTH_PGMPOOLKIND_ROOT       PGMPOOLKIND_PAE_PD_PHYS
+#include "PGMGstDefs.h"
+#include "PGMAllBth.h"
+#undef BTH_PGMPOOLKIND_PT_FOR_PT
+#undef BTH_PGMPOOLKIND_ROOT
+#undef PGM_BTH_NAME
+#undef PGM_GST_TYPE
+#undef PGM_GST_NAME
+
+#ifdef VBOX_WITH_64_BITS_GUESTS
+/* Guest - AMD64 mode */
+# define PGM_GST_TYPE              PGM_TYPE_AMD64
+# define PGM_GST_NAME(name)        PGM_GST_NAME_AMD64(name)
+# define PGM_BTH_NAME(name)        PGM_BTH_NAME_AMD64_AMD64(name)
+# define BTH_PGMPOOLKIND_PT_FOR_PT PGMPOOLKIND_PAE_PT_FOR_PAE_PT
+# define BTH_PGMPOOLKIND_PT_FOR_BIG PGMPOOLKIND_PAE_PT_FOR_PAE_2MB
+# define BTH_PGMPOOLKIND_ROOT      PGMPOOLKIND_64BIT_PML4
 # include "PGMGstDefs.h"
+# include "PGMAllGst.h"
 # include "PGMAllBth.h"
+# undef BTH_PGMPOOLKIND_PT_FOR_BIG
 # undef BTH_PGMPOOLKIND_PT_FOR_PT
 # undef BTH_PGMPOOLKIND_ROOT
@@ -212,26 +227,8 @@
 # undef PGM_GST_TYPE
 # undef PGM_GST_NAME
-
-# ifdef VBOX_WITH_64_BITS_GUESTS
-/* Guest - AMD64 mode */
-#  define PGM_GST_TYPE              PGM_TYPE_AMD64
-#  define PGM_GST_NAME(name)        PGM_GST_NAME_AMD64(name)
-#  define PGM_BTH_NAME(name)        PGM_BTH_NAME_AMD64_AMD64(name)
-#  define BTH_PGMPOOLKIND_PT_FOR_PT PGMPOOLKIND_PAE_PT_FOR_PAE_PT
-#  define BTH_PGMPOOLKIND_PT_FOR_BIG PGMPOOLKIND_PAE_PT_FOR_PAE_2MB
-#  define BTH_PGMPOOLKIND_ROOT      PGMPOOLKIND_64BIT_PML4
-#  include "PGMGstDefs.h"
-#  include "PGMAllGst.h"
-#  include "PGMAllBth.h"
-#  undef BTH_PGMPOOLKIND_PT_FOR_BIG
-#  undef BTH_PGMPOOLKIND_PT_FOR_PT
-#  undef BTH_PGMPOOLKIND_ROOT
-#  undef PGM_BTH_NAME
-#  undef PGM_GST_TYPE
-#  undef PGM_GST_NAME
-# endif /* VBOX_WITH_64_BITS_GUESTS */
-
-# undef PGM_SHW_TYPE
-# undef PGM_SHW_NAME
+#endif /* VBOX_WITH_64_BITS_GUESTS */
+
+#undef PGM_SHW_TYPE
+#undef PGM_SHW_NAME
 
 
@@ -239,12 +236,53 @@
  * Shadow - 32-bit nested paging mode.
  */
-# define PGM_SHW_TYPE               PGM_TYPE_NESTED_32BIT
-# define PGM_SHW_NAME(name)         PGM_SHW_NAME_NESTED_32BIT(name)
-# include "PGMAllShw.h"
+#define PGM_SHW_TYPE                PGM_TYPE_NESTED_32BIT
+#define PGM_SHW_NAME(name)          PGM_SHW_NAME_NESTED_32BIT(name)
+#include "PGMAllShw.h"
 
 /* Guest - real mode */
-# define PGM_GST_TYPE               PGM_TYPE_REAL
-# define PGM_GST_NAME(name)         PGM_GST_NAME_REAL(name)
-# define PGM_BTH_NAME(name)         PGM_BTH_NAME_NESTED_32BIT_REAL(name)
+#define PGM_GST_TYPE                PGM_TYPE_REAL
+#define PGM_GST_NAME(name)          PGM_GST_NAME_REAL(name)
+#define PGM_BTH_NAME(name)          PGM_BTH_NAME_NESTED_32BIT_REAL(name)
+#include "PGMGstDefs.h"
+#include "PGMAllBth.h"
+#undef PGM_BTH_NAME
+#undef PGM_GST_TYPE
+#undef PGM_GST_NAME
+
+/* Guest - protected mode */
+#define PGM_GST_TYPE                PGM_TYPE_PROT
+#define PGM_GST_NAME(name)          PGM_GST_NAME_PROT(name)
+#define PGM_BTH_NAME(name)          PGM_BTH_NAME_NESTED_32BIT_PROT(name)
+#include "PGMGstDefs.h"
+#include "PGMAllBth.h"
+#undef PGM_BTH_NAME
+#undef PGM_GST_TYPE
+#undef PGM_GST_NAME
+
+/* Guest - 32-bit mode */
+#define PGM_GST_TYPE                PGM_TYPE_32BIT
+#define PGM_GST_NAME(name)          PGM_GST_NAME_32BIT(name)
+#define PGM_BTH_NAME(name)          PGM_BTH_NAME_NESTED_32BIT_32BIT(name)
+#include "PGMGstDefs.h"
+#include "PGMAllBth.h"
+#undef PGM_BTH_NAME
+#undef PGM_GST_TYPE
+#undef PGM_GST_NAME
+
+/* Guest - PAE mode */
+#define PGM_GST_TYPE                PGM_TYPE_PAE
+#define PGM_GST_NAME(name)          PGM_GST_NAME_PAE(name)
+#define PGM_BTH_NAME(name)          PGM_BTH_NAME_NESTED_32BIT_PAE(name)
+#include "PGMGstDefs.h"
+#include "PGMAllBth.h"
+#undef PGM_BTH_NAME
+#undef PGM_GST_TYPE
+#undef PGM_GST_NAME
+
+#ifdef VBOX_WITH_64_BITS_GUESTS
+/* Guest - AMD64 mode */
+# define PGM_GST_TYPE               PGM_TYPE_AMD64
+# define PGM_GST_NAME(name)         PGM_GST_NAME_AMD64(name)
+# define PGM_BTH_NAME(name)         PGM_BTH_NAME_NESTED_32BIT_AMD64(name)
 # include "PGMGstDefs.h"
 # include "PGMAllBth.h"
@@ -252,9 +290,62 @@
 # undef PGM_GST_TYPE
 # undef PGM_GST_NAME
+#endif /* VBOX_WITH_64_BITS_GUESTS */
+
+#undef PGM_SHW_TYPE
+#undef PGM_SHW_NAME
+
+
+/*
+ * Shadow - PAE nested paging mode.
+ */
+#define PGM_SHW_TYPE                PGM_TYPE_NESTED_PAE
+#define PGM_SHW_NAME(name)          PGM_SHW_NAME_NESTED_PAE(name)
+#include "PGMAllShw.h"
+
+/* Guest - real mode */
+#define PGM_GST_TYPE                PGM_TYPE_REAL
+#define PGM_GST_NAME(name)          PGM_GST_NAME_REAL(name)
+#define PGM_BTH_NAME(name)          PGM_BTH_NAME_NESTED_PAE_REAL(name)
+#include "PGMGstDefs.h"
+#include "PGMAllBth.h"
+#undef PGM_BTH_NAME
+#undef PGM_GST_TYPE
+#undef PGM_GST_NAME
 
 /* Guest - protected mode */
-# define PGM_GST_TYPE               PGM_TYPE_PROT
-# define PGM_GST_NAME(name)         PGM_GST_NAME_PROT(name)
-# define PGM_BTH_NAME(name)         PGM_BTH_NAME_NESTED_32BIT_PROT(name)
+#define PGM_GST_TYPE                PGM_TYPE_PROT
+#define PGM_GST_NAME(name)          PGM_GST_NAME_PROT(name)
+#define PGM_BTH_NAME(name)          PGM_BTH_NAME_NESTED_PAE_PROT(name)
+#include "PGMGstDefs.h"
+#include "PGMAllBth.h"
+#undef PGM_BTH_NAME
+#undef PGM_GST_TYPE
+#undef PGM_GST_NAME
+
+/* Guest - 32-bit mode */
+#define PGM_GST_TYPE                PGM_TYPE_32BIT
+#define PGM_GST_NAME(name)          PGM_GST_NAME_32BIT(name)
+#define PGM_BTH_NAME(name)          PGM_BTH_NAME_NESTED_PAE_32BIT(name)
+#include "PGMGstDefs.h"
+#include "PGMAllBth.h"
+#undef PGM_BTH_NAME
+#undef PGM_GST_TYPE
+#undef PGM_GST_NAME
+
+/* Guest - PAE mode */
+#define PGM_GST_TYPE                PGM_TYPE_PAE
+#define PGM_GST_NAME(name)          PGM_GST_NAME_PAE(name)
+#define PGM_BTH_NAME(name)          PGM_BTH_NAME_NESTED_PAE_PAE(name)
+#include "PGMGstDefs.h"
+#include "PGMAllBth.h"
+#undef PGM_BTH_NAME
+#undef PGM_GST_TYPE
+#undef PGM_GST_NAME
+
+#ifdef VBOX_WITH_64_BITS_GUESTS
+/* Guest - AMD64 mode */
+# define PGM_GST_TYPE               PGM_TYPE_AMD64
+# define PGM_GST_NAME(name)         PGM_GST_NAME_AMD64(name)
+# define PGM_BTH_NAME(name)         PGM_BTH_NAME_NESTED_PAE_AMD64(name)
 # include "PGMGstDefs.h"
 # include "PGMAllBth.h"
@@ -262,9 +353,62 @@
 # undef PGM_GST_TYPE
 # undef PGM_GST_NAME
+#endif /* VBOX_WITH_64_BITS_GUESTS */
+
+#undef PGM_SHW_TYPE
+#undef PGM_SHW_NAME
+
+
+/*
+ * Shadow - AMD64 nested paging mode.
+ */
+#define PGM_SHW_TYPE                PGM_TYPE_NESTED_AMD64
+#define PGM_SHW_NAME(name)          PGM_SHW_NAME_NESTED_AMD64(name)
+#include "PGMAllShw.h"
+
+/* Guest - real mode */
+#define PGM_GST_TYPE                PGM_TYPE_REAL
+#define PGM_GST_NAME(name)          PGM_GST_NAME_REAL(name)
+#define PGM_BTH_NAME(name)          PGM_BTH_NAME_NESTED_AMD64_REAL(name)
+#include "PGMGstDefs.h"
+#include "PGMAllBth.h"
+#undef PGM_BTH_NAME
+#undef PGM_GST_TYPE
+#undef PGM_GST_NAME
+
+/* Guest - protected mode */
+#define PGM_GST_TYPE                PGM_TYPE_PROT
+#define PGM_GST_NAME(name)          PGM_GST_NAME_PROT(name)
+#define PGM_BTH_NAME(name)          PGM_BTH_NAME_NESTED_AMD64_PROT(name)
+#include "PGMGstDefs.h"
+#include "PGMAllBth.h"
+#undef PGM_BTH_NAME
+#undef PGM_GST_TYPE
+#undef PGM_GST_NAME
 
 /* Guest - 32-bit mode */
-# define PGM_GST_TYPE               PGM_TYPE_32BIT
-# define PGM_GST_NAME(name)         PGM_GST_NAME_32BIT(name)
-# define PGM_BTH_NAME(name)         PGM_BTH_NAME_NESTED_32BIT_32BIT(name)
+#define PGM_GST_TYPE                PGM_TYPE_32BIT
+#define PGM_GST_NAME(name)          PGM_GST_NAME_32BIT(name)
+#define PGM_BTH_NAME(name)          PGM_BTH_NAME_NESTED_AMD64_32BIT(name)
+#include "PGMGstDefs.h"
+#include "PGMAllBth.h"
+#undef PGM_BTH_NAME
+#undef PGM_GST_TYPE
+#undef PGM_GST_NAME
+
+/* Guest - PAE mode */
+#define PGM_GST_TYPE                PGM_TYPE_PAE
+#define PGM_GST_NAME(name)          PGM_GST_NAME_PAE(name)
+#define PGM_BTH_NAME(name)          PGM_BTH_NAME_NESTED_AMD64_PAE(name)
+#include "PGMGstDefs.h"
+#include "PGMAllBth.h"
+#undef PGM_BTH_NAME
+#undef PGM_GST_TYPE
+#undef PGM_GST_NAME
+
+#ifdef VBOX_WITH_64_BITS_GUESTS
+/* Guest - AMD64 mode */
+# define PGM_GST_TYPE               PGM_TYPE_AMD64
+# define PGM_GST_NAME(name)         PGM_GST_NAME_AMD64(name)
+# define PGM_BTH_NAME(name)         PGM_BTH_NAME_NESTED_AMD64_AMD64(name)
 # include "PGMGstDefs.h"
 # include "PGMAllBth.h"
@@ -272,155 +416,8 @@
 # undef PGM_GST_TYPE
 # undef PGM_GST_NAME
-
-/* Guest - PAE mode */
-# define PGM_GST_TYPE               PGM_TYPE_PAE
-# define PGM_GST_NAME(name)         PGM_GST_NAME_PAE(name)
-# define PGM_BTH_NAME(name)         PGM_BTH_NAME_NESTED_32BIT_PAE(name)
-# include "PGMGstDefs.h"
-# include "PGMAllBth.h"
-# undef PGM_BTH_NAME
-# undef PGM_GST_TYPE
-# undef PGM_GST_NAME
-
-# ifdef VBOX_WITH_64_BITS_GUESTS
-/* Guest - AMD64 mode */
-#  define PGM_GST_TYPE              PGM_TYPE_AMD64
-#  define PGM_GST_NAME(name)        PGM_GST_NAME_AMD64(name)
-#  define PGM_BTH_NAME(name)        PGM_BTH_NAME_NESTED_32BIT_AMD64(name)
-#  include "PGMGstDefs.h"
-#  include "PGMAllBth.h"
-#  undef PGM_BTH_NAME
-#  undef PGM_GST_TYPE
-#  undef PGM_GST_NAME
-# endif /* VBOX_WITH_64_BITS_GUESTS */
-
-# undef PGM_SHW_TYPE
-# undef PGM_SHW_NAME
-
-
-/*
- * Shadow - PAE nested paging mode.
- */
-# define PGM_SHW_TYPE               PGM_TYPE_NESTED_PAE
-# define PGM_SHW_NAME(name)         PGM_SHW_NAME_NESTED_PAE(name)
-# include "PGMAllShw.h"
-
-/* Guest - real mode */
-# define PGM_GST_TYPE               PGM_TYPE_REAL
-# define PGM_GST_NAME(name)         PGM_GST_NAME_REAL(name)
-# define PGM_BTH_NAME(name)         PGM_BTH_NAME_NESTED_PAE_REAL(name)
-# include "PGMGstDefs.h"
-# include "PGMAllBth.h"
-# undef PGM_BTH_NAME
-# undef PGM_GST_TYPE
-# undef PGM_GST_NAME
-
-/* Guest - protected mode */
-# define PGM_GST_TYPE               PGM_TYPE_PROT
-# define PGM_GST_NAME(name)         PGM_GST_NAME_PROT(name)
-# define PGM_BTH_NAME(name)         PGM_BTH_NAME_NESTED_PAE_PROT(name)
-# include "PGMGstDefs.h"
-# include "PGMAllBth.h"
-# undef PGM_BTH_NAME
-# undef PGM_GST_TYPE
-# undef PGM_GST_NAME
-
-/* Guest - 32-bit mode */
-# define PGM_GST_TYPE               PGM_TYPE_32BIT
-# define PGM_GST_NAME(name)         PGM_GST_NAME_32BIT(name)
-# define PGM_BTH_NAME(name)         PGM_BTH_NAME_NESTED_PAE_32BIT(name)
-# include "PGMGstDefs.h"
-# include "PGMAllBth.h"
-# undef PGM_BTH_NAME
-# undef PGM_GST_TYPE
-# undef PGM_GST_NAME
-
-/* Guest - PAE mode */
-# define PGM_GST_TYPE               PGM_TYPE_PAE
-# define PGM_GST_NAME(name)         PGM_GST_NAME_PAE(name)
-# define PGM_BTH_NAME(name)         PGM_BTH_NAME_NESTED_PAE_PAE(name)
-# include "PGMGstDefs.h"
-# include "PGMAllBth.h"
-# undef PGM_BTH_NAME
-# undef PGM_GST_TYPE
-# undef PGM_GST_NAME
-
-# ifdef VBOX_WITH_64_BITS_GUESTS
-/* Guest - AMD64 mode */
-#  define PGM_GST_TYPE              PGM_TYPE_AMD64
-#  define PGM_GST_NAME(name)        PGM_GST_NAME_AMD64(name)
-#  define PGM_BTH_NAME(name)        PGM_BTH_NAME_NESTED_PAE_AMD64(name)
-#  include "PGMGstDefs.h"
-#  include "PGMAllBth.h"
-#  undef PGM_BTH_NAME
-#  undef PGM_GST_TYPE
-#  undef PGM_GST_NAME
-# endif /* VBOX_WITH_64_BITS_GUESTS */
-
-# undef PGM_SHW_TYPE
-# undef PGM_SHW_NAME
-
-
-/*
- * Shadow - AMD64 nested paging mode.
- */
-# define PGM_SHW_TYPE               PGM_TYPE_NESTED_AMD64
-# define PGM_SHW_NAME(name)         PGM_SHW_NAME_NESTED_AMD64(name)
-# include "PGMAllShw.h"
-
-/* Guest - real mode */
-# define PGM_GST_TYPE               PGM_TYPE_REAL
-# define PGM_GST_NAME(name)         PGM_GST_NAME_REAL(name)
-# define PGM_BTH_NAME(name)         PGM_BTH_NAME_NESTED_AMD64_REAL(name)
-# include "PGMGstDefs.h"
-# include "PGMAllBth.h"
-# undef PGM_BTH_NAME
-# undef PGM_GST_TYPE
-# undef PGM_GST_NAME
-
-/* Guest - protected mode */
-# define PGM_GST_TYPE               PGM_TYPE_PROT
-# define PGM_GST_NAME(name)         PGM_GST_NAME_PROT(name)
-# define PGM_BTH_NAME(name)         PGM_BTH_NAME_NESTED_AMD64_PROT(name)
-# include "PGMGstDefs.h"
-# include "PGMAllBth.h"
-# undef PGM_BTH_NAME
-# undef PGM_GST_TYPE
-# undef PGM_GST_NAME
-
-/* Guest - 32-bit mode */
-# define PGM_GST_TYPE               PGM_TYPE_32BIT
-# define PGM_GST_NAME(name)         PGM_GST_NAME_32BIT(name)
-# define PGM_BTH_NAME(name)         PGM_BTH_NAME_NESTED_AMD64_32BIT(name)
-# include "PGMGstDefs.h"
-# include "PGMAllBth.h"
-# undef PGM_BTH_NAME
-# undef PGM_GST_TYPE
-# undef PGM_GST_NAME
-
-/* Guest - PAE mode */
-# define PGM_GST_TYPE               PGM_TYPE_PAE
-# define PGM_GST_NAME(name)         PGM_GST_NAME_PAE(name)
-# define PGM_BTH_NAME(name)         PGM_BTH_NAME_NESTED_AMD64_PAE(name)
-# include "PGMGstDefs.h"
-# include "PGMAllBth.h"
-# undef PGM_BTH_NAME
-# undef PGM_GST_TYPE
-# undef PGM_GST_NAME
-
-# ifdef VBOX_WITH_64_BITS_GUESTS
-/* Guest - AMD64 mode */
-#  define PGM_GST_TYPE              PGM_TYPE_AMD64
-#  define PGM_GST_NAME(name)        PGM_GST_NAME_AMD64(name)
-#  define PGM_BTH_NAME(name)        PGM_BTH_NAME_NESTED_AMD64_AMD64(name)
-#  include "PGMGstDefs.h"
-#  include "PGMAllBth.h"
-#  undef PGM_BTH_NAME
-#  undef PGM_GST_TYPE
-#  undef PGM_GST_NAME
-# endif /* VBOX_WITH_64_BITS_GUESTS */
-
-# undef PGM_SHW_TYPE
-# undef PGM_SHW_NAME
+#endif /* VBOX_WITH_64_BITS_GUESTS */
+
+#undef PGM_SHW_TYPE
+#undef PGM_SHW_NAME
 
 
@@ -428,12 +425,61 @@
  * Shadow - EPT.
  */
-# define PGM_SHW_TYPE               PGM_TYPE_EPT
-# define PGM_SHW_NAME(name)         PGM_SHW_NAME_EPT(name)
-# include "PGMAllShw.h"
+#define PGM_SHW_TYPE                PGM_TYPE_EPT
+#define PGM_SHW_NAME(name)          PGM_SHW_NAME_EPT(name)
+#include "PGMAllShw.h"
 
 /* Guest - real mode */
-# define PGM_GST_TYPE               PGM_TYPE_REAL
-# define PGM_GST_NAME(name)         PGM_GST_NAME_REAL(name)
-# define PGM_BTH_NAME(name)         PGM_BTH_NAME_EPT_REAL(name)
+#define PGM_GST_TYPE                PGM_TYPE_REAL
+#define PGM_GST_NAME(name)          PGM_GST_NAME_REAL(name)
+#define PGM_BTH_NAME(name)          PGM_BTH_NAME_EPT_REAL(name)
+#define BTH_PGMPOOLKIND_PT_FOR_PT   PGMPOOLKIND_EPT_PT_FOR_PHYS
+#include "PGMGstDefs.h"
+#include "PGMAllBth.h"
+#undef BTH_PGMPOOLKIND_PT_FOR_PT
+#undef PGM_BTH_NAME
+#undef PGM_GST_TYPE
+#undef PGM_GST_NAME
+
+/* Guest - protected mode */
+#define PGM_GST_TYPE                PGM_TYPE_PROT
+#define PGM_GST_NAME(name)          PGM_GST_NAME_PROT(name)
+#define PGM_BTH_NAME(name)          PGM_BTH_NAME_EPT_PROT(name)
+#define BTH_PGMPOOLKIND_PT_FOR_PT   PGMPOOLKIND_EPT_PT_FOR_PHYS
+#include "PGMGstDefs.h"
+#include "PGMAllBth.h"
+#undef BTH_PGMPOOLKIND_PT_FOR_PT
+#undef PGM_BTH_NAME
+#undef PGM_GST_TYPE
+#undef PGM_GST_NAME
+
+/* Guest - 32-bit mode */
+#define PGM_GST_TYPE                PGM_TYPE_32BIT
+#define PGM_GST_NAME(name)          PGM_GST_NAME_32BIT(name)
+#define PGM_BTH_NAME(name)          PGM_BTH_NAME_EPT_32BIT(name)
+#define BTH_PGMPOOLKIND_PT_FOR_PT   PGMPOOLKIND_EPT_PT_FOR_PHYS
+#include "PGMGstDefs.h"
+#include "PGMAllBth.h"
+#undef BTH_PGMPOOLKIND_PT_FOR_PT
+#undef PGM_BTH_NAME
+#undef PGM_GST_TYPE
+#undef PGM_GST_NAME
+
+/* Guest - PAE mode */
+#define PGM_GST_TYPE                PGM_TYPE_PAE
+#define PGM_GST_NAME(name)          PGM_GST_NAME_PAE(name)
+#define PGM_BTH_NAME(name)          PGM_BTH_NAME_EPT_PAE(name)
+#define BTH_PGMPOOLKIND_PT_FOR_PT   PGMPOOLKIND_EPT_PT_FOR_PHYS
+#include "PGMGstDefs.h"
+#include "PGMAllBth.h"
+#undef BTH_PGMPOOLKIND_PT_FOR_PT
+#undef PGM_BTH_NAME
+#undef PGM_GST_TYPE
+#undef PGM_GST_NAME
+
+#ifdef VBOX_WITH_64_BITS_GUESTS
+/* Guest - AMD64 mode */
+# define PGM_GST_TYPE               PGM_TYPE_AMD64
+# define PGM_GST_NAME(name)         PGM_GST_NAME_AMD64(name)
+# define PGM_BTH_NAME(name)         PGM_BTH_NAME_EPT_AMD64(name)
 # define BTH_PGMPOOLKIND_PT_FOR_PT  PGMPOOLKIND_EPT_PT_FOR_PHYS
 # include "PGMGstDefs.h"
@@ -443,57 +489,8 @@
 # undef PGM_GST_TYPE
 # undef PGM_GST_NAME
-
-/* Guest - protected mode */
-# define PGM_GST_TYPE               PGM_TYPE_PROT
-# define PGM_GST_NAME(name)         PGM_GST_NAME_PROT(name)
-# define PGM_BTH_NAME(name)         PGM_BTH_NAME_EPT_PROT(name)
-# define BTH_PGMPOOLKIND_PT_FOR_PT  PGMPOOLKIND_EPT_PT_FOR_PHYS
-# include "PGMGstDefs.h"
-# include "PGMAllBth.h"
-# undef BTH_PGMPOOLKIND_PT_FOR_PT
-# undef PGM_BTH_NAME
-# undef PGM_GST_TYPE
-# undef PGM_GST_NAME
-
-/* Guest - 32-bit mode */
-# define PGM_GST_TYPE               PGM_TYPE_32BIT
-# define PGM_GST_NAME(name)         PGM_GST_NAME_32BIT(name)
-# define PGM_BTH_NAME(name)         PGM_BTH_NAME_EPT_32BIT(name)
-# define BTH_PGMPOOLKIND_PT_FOR_PT  PGMPOOLKIND_EPT_PT_FOR_PHYS
-# include "PGMGstDefs.h"
-# include "PGMAllBth.h"
-# undef BTH_PGMPOOLKIND_PT_FOR_PT
-# undef PGM_BTH_NAME
-# undef PGM_GST_TYPE
-# undef PGM_GST_NAME
-
-/* Guest - PAE mode */
-# define PGM_GST_TYPE               PGM_TYPE_PAE
-# define PGM_GST_NAME(name)         PGM_GST_NAME_PAE(name)
-# define PGM_BTH_NAME(name)         PGM_BTH_NAME_EPT_PAE(name)
-# define BTH_PGMPOOLKIND_PT_FOR_PT  PGMPOOLKIND_EPT_PT_FOR_PHYS
-# include "PGMGstDefs.h"
-# include "PGMAllBth.h"
-# undef BTH_PGMPOOLKIND_PT_FOR_PT
-# undef PGM_BTH_NAME
-# undef PGM_GST_TYPE
-# undef PGM_GST_NAME
-
-# ifdef VBOX_WITH_64_BITS_GUESTS
-/* Guest - AMD64 mode */
-#  define PGM_GST_TYPE              PGM_TYPE_AMD64
-#  define PGM_GST_NAME(name)        PGM_GST_NAME_AMD64(name)
-#  define PGM_BTH_NAME(name)        PGM_BTH_NAME_EPT_AMD64(name)
-#  define BTH_PGMPOOLKIND_PT_FOR_PT PGMPOOLKIND_EPT_PT_FOR_PHYS
-#  include "PGMGstDefs.h"
-#  include "PGMAllBth.h"
-#  undef BTH_PGMPOOLKIND_PT_FOR_PT
-#  undef PGM_BTH_NAME
-#  undef PGM_GST_TYPE
-#  undef PGM_GST_NAME
-# endif /* VBOX_WITH_64_BITS_GUESTS */
-
-# undef PGM_SHW_TYPE
-# undef PGM_SHW_NAME
+#endif /* VBOX_WITH_64_BITS_GUESTS */
+
+#undef PGM_SHW_TYPE
+#undef PGM_SHW_NAME
 
 
@@ -501,12 +498,53 @@
  * Shadow - NEM / None.
  */
-# define PGM_SHW_TYPE               PGM_TYPE_NONE
-# define PGM_SHW_NAME(name)         PGM_SHW_NAME_NONE(name)
-# include "PGMAllShw.h"
+#define PGM_SHW_TYPE                PGM_TYPE_NONE
+#define PGM_SHW_NAME(name)          PGM_SHW_NAME_NONE(name)
+#include "PGMAllShw.h"
 
 /* Guest - real mode */
-# define PGM_GST_TYPE               PGM_TYPE_REAL
-# define PGM_GST_NAME(name)         PGM_GST_NAME_REAL(name)
-# define PGM_BTH_NAME(name)         PGM_BTH_NAME_NONE_REAL(name)
+#define PGM_GST_TYPE                PGM_TYPE_REAL
+#define PGM_GST_NAME(name)          PGM_GST_NAME_REAL(name)
+#define PGM_BTH_NAME(name)          PGM_BTH_NAME_NONE_REAL(name)
+#include "PGMGstDefs.h"
+#include "PGMAllBth.h"
+#undef PGM_BTH_NAME
+#undef PGM_GST_TYPE
+#undef PGM_GST_NAME
+
+/* Guest - protected mode */
+#define PGM_GST_TYPE                PGM_TYPE_PROT
+#define PGM_GST_NAME(name)          PGM_GST_NAME_PROT(name)
+#define PGM_BTH_NAME(name)          PGM_BTH_NAME_NONE_PROT(name)
+#include "PGMGstDefs.h"
+#include "PGMAllBth.h"
+#undef PGM_BTH_NAME
+#undef PGM_GST_TYPE
+#undef PGM_GST_NAME
+
+/* Guest - 32-bit mode */
+#define PGM_GST_TYPE                PGM_TYPE_32BIT
+#define PGM_GST_NAME(name)          PGM_GST_NAME_32BIT(name)
+#define PGM_BTH_NAME(name)          PGM_BTH_NAME_NONE_32BIT(name)
+#include "PGMGstDefs.h"
+#include "PGMAllBth.h"
+#undef PGM_BTH_NAME
+#undef PGM_GST_TYPE
+#undef PGM_GST_NAME
+
+/* Guest - PAE mode */
+#define PGM_GST_TYPE               PGM_TYPE_PAE
+#define PGM_GST_NAME(name)         PGM_GST_NAME_PAE(name)
+#define PGM_BTH_NAME(name)         PGM_BTH_NAME_NONE_PAE(name)
+#include "PGMGstDefs.h"
+#include "PGMAllBth.h"
+#undef PGM_BTH_NAME
+#undef PGM_GST_TYPE
+#undef PGM_GST_NAME
+
+#ifdef VBOX_WITH_64_BITS_GUESTS
+/* Guest - AMD64 mode */
+# define PGM_GST_TYPE               PGM_TYPE_AMD64
+# define PGM_GST_NAME(name)         PGM_GST_NAME_AMD64(name)
+# define PGM_BTH_NAME(name)         PGM_BTH_NAME_NONE_AMD64(name)
 # include "PGMGstDefs.h"
 # include "PGMAllBth.h"
@@ -514,51 +552,9 @@
 # undef PGM_GST_TYPE
 # undef PGM_GST_NAME
-
-/* Guest - protected mode */
-# define PGM_GST_TYPE               PGM_TYPE_PROT
-# define PGM_GST_NAME(name)         PGM_GST_NAME_PROT(name)
-# define PGM_BTH_NAME(name)         PGM_BTH_NAME_NONE_PROT(name)
-# include "PGMGstDefs.h"
-# include "PGMAllBth.h"
-# undef PGM_BTH_NAME
-# undef PGM_GST_TYPE
-# undef PGM_GST_NAME
-
-/* Guest - 32-bit mode */
-# define PGM_GST_TYPE               PGM_TYPE_32BIT
-# define PGM_GST_NAME(name)         PGM_GST_NAME_32BIT(name)
-# define PGM_BTH_NAME(name)         PGM_BTH_NAME_NONE_32BIT(name)
-# include "PGMGstDefs.h"
-# include "PGMAllBth.h"
-# undef PGM_BTH_NAME
-# undef PGM_GST_TYPE
-# undef PGM_GST_NAME
-
-/* Guest - PAE mode */
-# define PGM_GST_TYPE               PGM_TYPE_PAE
-# define PGM_GST_NAME(name)         PGM_GST_NAME_PAE(name)
-# define PGM_BTH_NAME(name)         PGM_BTH_NAME_NONE_PAE(name)
-# include "PGMGstDefs.h"
-# include "PGMAllBth.h"
-# undef PGM_BTH_NAME
-# undef PGM_GST_TYPE
-# undef PGM_GST_NAME
-
-# ifdef VBOX_WITH_64_BITS_GUESTS
-/* Guest - AMD64 mode */
-#  define PGM_GST_TYPE              PGM_TYPE_AMD64
-#  define PGM_GST_NAME(name)        PGM_GST_NAME_AMD64(name)
-#  define PGM_BTH_NAME(name)        PGM_BTH_NAME_NONE_AMD64(name)
-#  include "PGMGstDefs.h"
-#  include "PGMAllBth.h"
-#  undef PGM_BTH_NAME
-#  undef PGM_GST_TYPE
-#  undef PGM_GST_NAME
-# endif /* VBOX_WITH_64_BITS_GUESTS */
-
-# undef PGM_SHW_TYPE
-# undef PGM_SHW_NAME
-
-#endif /* !IN_RC */
+#endif /* VBOX_WITH_64_BITS_GUESTS */
+
+#undef PGM_SHW_TYPE
+#undef PGM_SHW_NAME
+
 
 
@@ -613,5 +609,5 @@
 #endif
     },
-#if defined(VBOX_WITH_64_BITS_GUESTS) && !defined(IN_RC)
+#ifdef VBOX_WITH_64_BITS_GUESTS
     {
         PGM_TYPE_AMD64,
@@ -657,5 +653,4 @@
 #endif
     },
-#ifndef IN_RC
     {
         PGM_TYPE_AMD64,
@@ -664,7 +659,7 @@
         PGM_SHW_NAME_AMD64(Enter),
         PGM_SHW_NAME_AMD64(Exit),
-# ifdef IN_RING3
+#ifdef IN_RING3
         PGM_SHW_NAME_AMD64(Relocate),
-# endif
+#endif
     },
     {
@@ -674,7 +669,7 @@
         PGM_SHW_NAME_NESTED_32BIT(Enter),
         PGM_SHW_NAME_NESTED_32BIT(Exit),
-# ifdef IN_RING3
+#ifdef IN_RING3
         PGM_SHW_NAME_NESTED_32BIT(Relocate),
-# endif
+#endif
     },
     {
@@ -684,7 +679,7 @@
         PGM_SHW_NAME_NESTED_PAE(Enter),
         PGM_SHW_NAME_NESTED_PAE(Exit),
-# ifdef IN_RING3
+#ifdef IN_RING3
         PGM_SHW_NAME_NESTED_PAE(Relocate),
-# endif
+#endif
     },
     {
@@ -694,7 +689,7 @@
         PGM_SHW_NAME_NESTED_AMD64(Enter),
         PGM_SHW_NAME_NESTED_AMD64(Exit),
-# ifdef IN_RING3
+#ifdef IN_RING3
         PGM_SHW_NAME_NESTED_AMD64(Relocate),
-# endif
+#endif
     },
     {
@@ -704,7 +699,7 @@
         PGM_SHW_NAME_EPT(Enter),
         PGM_SHW_NAME_EPT(Exit),
-# ifdef IN_RING3
+#ifdef IN_RING3
         PGM_SHW_NAME_EPT(Relocate),
-# endif
+#endif
     },
     {
@@ -714,9 +709,8 @@
         PGM_SHW_NAME_NONE(Enter),
         PGM_SHW_NAME_NONE(Exit),
-# ifdef IN_RING3
+#ifdef IN_RING3
         PGM_SHW_NAME_NONE(Relocate),
-# endif
+#endif
     },
-#endif /* IN_RC */
 };
 
@@ -777,5 +771,4 @@
     PGMMODEDATABTH_NULL_ENTRY(), /* PGM_TYPE_PAE, PGM_TYPE_NONE         - illegal */
 
-#ifndef IN_RC
     /* AMD64 shadow paging mode: */
     PGMMODEDATABTH_NULL_ENTRY(), /* 0 */
@@ -784,9 +777,9 @@
     PGMMODEDATABTH_NULL_ENTRY(), //PGMMODEDATABTH_ENTRY(PGM_TYPE_AMD64, PGM_TYPE_32BIT, PGM_BTH_NAME_AMD64_32BIT),
     PGMMODEDATABTH_NULL_ENTRY(), //PGMMODEDATABTH_ENTRY(PGM_TYPE_AMD64, PGM_TYPE_PAE,   PGM_BTH_NAME_AMD64_PAE),
-# ifdef VBOX_WITH_64_BITS_GUESTS
+#ifdef VBOX_WITH_64_BITS_GUESTS
     PGMMODEDATABTH_ENTRY(PGM_TYPE_AMD64, PGM_TYPE_AMD64, PGM_BTH_NAME_AMD64_AMD64),
-# else
+#else
     PGMMODEDATABTH_NULL_ENTRY(), /* PGM_TYPE_AMD64, PGM_TYPE_AMD64        - illegal */
-# endif
+#endif
     PGMMODEDATABTH_NULL_ENTRY(), /* PGM_TYPE_AMD64, PGM_TYPE_NESTED_32BIT - illegal */
     PGMMODEDATABTH_NULL_ENTRY(), /* PGM_TYPE_AMD64, PGM_TYPE_NESTED_PAE   - illegal */
@@ -801,9 +794,9 @@
     PGMMODEDATABTH_ENTRY(PGM_TYPE_NESTED_32BIT, PGM_TYPE_32BIT, PGM_BTH_NAME_NESTED_32BIT_32BIT),
     PGMMODEDATABTH_ENTRY(PGM_TYPE_NESTED_32BIT, PGM_TYPE_PAE,   PGM_BTH_NAME_NESTED_32BIT_PAE),
-# ifdef VBOX_WITH_64_BITS_GUESTS
+#ifdef VBOX_WITH_64_BITS_GUESTS
     PGMMODEDATABTH_ENTRY(PGM_TYPE_NESTED_32BIT, PGM_TYPE_AMD64, PGM_BTH_NAME_NESTED_32BIT_AMD64),
-# else
+#else
     PGMMODEDATABTH_NULL_ENTRY(), /* PGM_TYPE_NESTED_32BIT, PGM_TYPE_AMD64        - illegal */
-# endif
+#endif
     PGMMODEDATABTH_NULL_ENTRY(), /* PGM_TYPE_NESTED_32BIT, PGM_TYPE_NESTED_32BIT - illegal */
     PGMMODEDATABTH_NULL_ENTRY(), /* PGM_TYPE_NESTED_32BIT, PGM_TYPE_NESTED_PAE   - illegal */
@@ -818,9 +811,9 @@
     PGMMODEDATABTH_ENTRY(PGM_TYPE_NESTED_PAE, PGM_TYPE_32BIT, PGM_BTH_NAME_NESTED_PAE_32BIT),
     PGMMODEDATABTH_ENTRY(PGM_TYPE_NESTED_PAE, PGM_TYPE_PAE,   PGM_BTH_NAME_NESTED_PAE_PAE),
-# ifdef VBOX_WITH_64_BITS_GUESTS
+#ifdef VBOX_WITH_64_BITS_GUESTS
     PGMMODEDATABTH_ENTRY(PGM_TYPE_NESTED_PAE, PGM_TYPE_AMD64, PGM_BTH_NAME_NESTED_PAE_AMD64),
-# else
+#else
     PGMMODEDATABTH_NULL_ENTRY(), /* PGM_TYPE_NESTED_PAE, PGM_TYPE_AMD64        - illegal */
-# endif
+#endif
     PGMMODEDATABTH_NULL_ENTRY(), /* PGM_TYPE_NESTED_PAE, PGM_TYPE_NESTED_32BIT - illegal */
     PGMMODEDATABTH_NULL_ENTRY(), /* PGM_TYPE_NESTED_PAE, PGM_TYPE_NESTED_PAE   - illegal */
@@ -835,9 +828,9 @@
     PGMMODEDATABTH_ENTRY(PGM_TYPE_NESTED_AMD64, PGM_TYPE_32BIT, PGM_BTH_NAME_NESTED_AMD64_32BIT),
     PGMMODEDATABTH_ENTRY(PGM_TYPE_NESTED_AMD64, PGM_TYPE_PAE,   PGM_BTH_NAME_NESTED_AMD64_PAE),
-# ifdef VBOX_WITH_64_BITS_GUESTS
+#ifdef VBOX_WITH_64_BITS_GUESTS
     PGMMODEDATABTH_ENTRY(PGM_TYPE_NESTED_AMD64, PGM_TYPE_AMD64, PGM_BTH_NAME_NESTED_AMD64_AMD64),
-# else
+#else
     PGMMODEDATABTH_NULL_ENTRY(), /* PGM_TYPE_NESTED_AMD64, PGM_TYPE_AMD64        - illegal */
-# endif
+#endif
     PGMMODEDATABTH_NULL_ENTRY(), /* PGM_TYPE_NESTED_AMD64, PGM_TYPE_NESTED_32BIT - illegal */
     PGMMODEDATABTH_NULL_ENTRY(), /* PGM_TYPE_NESTED_AMD64, PGM_TYPE_NESTED_PAE   - illegal */
@@ -852,9 +845,9 @@
     PGMMODEDATABTH_ENTRY(PGM_TYPE_EPT, PGM_TYPE_32BIT, PGM_BTH_NAME_EPT_32BIT),
     PGMMODEDATABTH_ENTRY(PGM_TYPE_EPT, PGM_TYPE_PAE,   PGM_BTH_NAME_EPT_PAE),
-# ifdef VBOX_WITH_64_BITS_GUESTS
+#ifdef VBOX_WITH_64_BITS_GUESTS
     PGMMODEDATABTH_ENTRY(PGM_TYPE_EPT, PGM_TYPE_AMD64, PGM_BTH_NAME_EPT_AMD64),
-# else
+#else
     PGMMODEDATABTH_NULL_ENTRY(), /* PGM_TYPE_EPT, PGM_TYPE_AMD64        - illegal */
-# endif
+#endif
     PGMMODEDATABTH_NULL_ENTRY(), /* PGM_TYPE_EPT, PGM_TYPE_NESTED_32BIT - illegal */
     PGMMODEDATABTH_NULL_ENTRY(), /* PGM_TYPE_EPT, PGM_TYPE_NESTED_PAE   - illegal */
@@ -869,9 +862,9 @@
     PGMMODEDATABTH_ENTRY(PGM_TYPE_NONE, PGM_TYPE_32BIT, PGM_BTH_NAME_EPT_32BIT),
     PGMMODEDATABTH_ENTRY(PGM_TYPE_NONE, PGM_TYPE_PAE,   PGM_BTH_NAME_EPT_PAE),
-# ifdef VBOX_WITH_64_BITS_GUESTS
+#ifdef VBOX_WITH_64_BITS_GUESTS
     PGMMODEDATABTH_ENTRY(PGM_TYPE_NONE, PGM_TYPE_AMD64, PGM_BTH_NAME_EPT_AMD64),
-# else
+#else
     PGMMODEDATABTH_NULL_ENTRY(), /* PGM_TYPE_NONE, PGM_TYPE_AMD64        - illegal */
-# endif
+#endif
     PGMMODEDATABTH_NULL_ENTRY(), /* PGM_TYPE_NONE, PGM_TYPE_NESTED_32BIT - illegal */
     PGMMODEDATABTH_NULL_ENTRY(), /* PGM_TYPE_NONE, PGM_TYPE_NESTED_PAE   - illegal */
@@ -880,5 +873,4 @@
     PGMMODEDATABTH_NULL_ENTRY(), /* PGM_TYPE_NONE, PGM_TYPE_NONE         - illegal */
 
-#endif /* IN_RC */
 
 #undef PGMMODEDATABTH_ENTRY
@@ -887,5 +879,5 @@
 
 
-#ifndef IN_RING3
+#ifdef IN_RING0
 /**
  * #PF Handler.
@@ -906,5 +898,5 @@
 
 
-#ifdef VBOX_WITH_STATISTICS
+# ifdef VBOX_WITH_STATISTICS
     /*
      * Error code stats.
@@ -944,5 +936,5 @@
             STAM_COUNTER_INC(&pVCpu->pgm.s.CTX_SUFF(pStats)->StatRZTrap0eSVReserved);
     }
-#endif /* VBOX_WITH_STATISTICS */
+# endif /* VBOX_WITH_STATISTICS */
 
     /*
@@ -969,5 +961,4 @@
             rc = VINF_SUCCESS;
 
-# ifdef IN_RING0
         /* Note: hack alert for difficult to reproduce problem. */
         if (    rc == VERR_PAGE_NOT_PRESENT                 /* SMP only ; disassembly might fail. */
@@ -980,5 +971,4 @@
             rc = VINF_SUCCESS;
         }
-# endif
     }
 
@@ -989,5 +979,5 @@
     return rc;
 }
-#endif /* !IN_RING3 */
+#endif /* IN_RING0 */
 
 
@@ -1236,31 +1226,6 @@
      */
     REMNotifyInvalidatePage(pVM, GCPtrPage);
-#endif /* !IN_RING3 */
+#endif
     IEMTlbInvalidatePage(pVCpu, GCPtrPage);
-
-
-#ifdef IN_RC
-    /*
-     * Check for conflicts and pending CR3 monitoring updates.
-     */
-    if (pgmMapAreMappingsFloating(pVM))
-    {
-        if (    pgmGetMapping(pVM, GCPtrPage)
-            &&  PGMGstGetPage(pVCpu, GCPtrPage, NULL, NULL) != VERR_PAGE_TABLE_NOT_PRESENT)
-        {
-            LogFlow(("PGMGCInvalidatePage: Conflict!\n"));
-            VMCPU_FF_SET(pVCpu, VMCPU_FF_PGM_SYNC_CR3);
-            STAM_COUNTER_INC(&pVM->pgm.s.CTX_SUFF(pStats)->StatRCInvlPgConflict);
-            return VINF_PGM_SYNC_CR3;
-        }
-
-        if (pVCpu->pgm.s.fSyncFlags & PGM_SYNC_MONITOR_CR3)
-        {
-            LogFlow(("PGMGCInvalidatePage: PGM_SYNC_MONITOR_CR3 -> reinterpret instruction in R3\n"));
-            STAM_COUNTER_INC(&pVM->pgm.s.CTX_SUFF(pStats)->StatRCInvlPgSyncMonCR3);
-            return VINF_EM_RAW_EMULATE_INSTR;
-        }
-    }
-#endif /* IN_RC */
 
     /*
@@ -1288,14 +1253,4 @@
         Assert(!pVM->pgm.s.fMappingsFixed); Assert(pgmMapAreMappingsEnabled(pVM));
     }
-
-# ifdef VBOX_WITH_RAW_MODE
-    /*
-     * Inform CSAM about the flush
-     *
-     * Note: This is to check if monitored pages have been changed; when we implement
-     *       callbacks for virtual handlers, this is no longer required.
-     */
-    CSAMR3FlushPage(pVM, GCPtrPage);
-# endif
 #endif /* IN_RING3 */
 
@@ -1563,13 +1518,4 @@
         /* The PD was cached or created; hook it up now. */
         pPdpe->u |= pShwPage->Core.Key | (uGstPdpe & (X86_PDPE_P | X86_PDPE_A));
-
-# if defined(IN_RC)
-        /*
-         * In 32 bits PAE mode we *must* invalidate the TLB when changing a
-         * PDPT entry; the CPU fetches them only during cr3 load, so any
-         * non-present PDPT will continue to cause page faults.
-         */
-        ASMReloadCR3();
-# endif
         PGM_DYNMAP_UNUSED_HINT(pVCpu, pPdpe);
     }
@@ -1619,5 +1565,4 @@
 }
 
-#ifndef IN_RC
 
 /**
@@ -1859,5 +1804,4 @@
 }
 
-#endif /* IN_RC */
 
 #ifdef IN_RING0
@@ -1975,10 +1919,8 @@
             return PGM_GST_NAME_PAE(Walk)(pVCpu, GCPtr, &pWalk->u.Pae);
 
-#if !defined(IN_RC)
         case PGMMODE_AMD64:
         case PGMMODE_AMD64_NX:
             pWalk->enmType = PGMPTWALKGSTTYPE_AMD64;
             return PGM_GST_NAME_AMD64(Walk)(pVCpu, GCPtr, &pWalk->u.Amd64);
-#endif
 
         case PGMMODE_REAL:
@@ -1987,8 +1929,4 @@
             return VERR_PGM_NOT_USED_IN_MODE;
 
-#if defined(IN_RC)
-        case PGMMODE_AMD64:
-        case PGMMODE_AMD64_NX:
-#endif
         case PGMMODE_NESTED_32BIT:
         case PGMMODE_NESTED_PAE:
@@ -2316,8 +2254,8 @@
         RTRCPTR     RCPtr       = NIL_RTRCPTR;
         RTHCPTR     HCPtr       = NIL_RTHCPTR;
-#if !defined(IN_RC) && !defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0)
+# ifndef VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0
         rc = pgmPhysGCPhys2CCPtrInternalDepr(pVM, pPage, GCPhys, &HCPtr);
         AssertRC(rc);
-#endif
+# endif
         if (RT_SUCCESS(rc))
         {
@@ -2350,6 +2288,5 @@
 }
 
-#endif /* !VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0 */
-#if !defined(IN_RC) && !defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0)
+
 /**
  * Performs the lazy mapping of the 32-bit guest PD.
@@ -2376,7 +2313,7 @@
         {
             pVCpu->pgm.s.pGstAmd64Pml4R3 = (R3PTRTYPE(PX86PML4))HCPtrGuestCR3;
-#  ifndef VBOX_WITH_2X_4GB_ADDR_SPACE
+# ifndef VBOX_WITH_2X_4GB_ADDR_SPACE
             pVCpu->pgm.s.pGstAmd64Pml4R0 = (R0PTRTYPE(PX86PML4))HCPtrGuestCR3;
-#  endif
+# endif
             *ppPml4 = (PX86PML4)HCPtrGuestCR3;
 
@@ -2390,5 +2327,6 @@
     return rc;
 }
-#endif
+
+#endif /* !VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0 */
 
 
@@ -2436,7 +2374,7 @@
             /* Force lazy remapping if it changed in any way. */
             pVCpu->pgm.s.apGstPaePDsR3[i]     = 0;
-#  ifndef VBOX_WITH_2X_4GB_ADDR_SPACE
+#ifndef VBOX_WITH_2X_4GB_ADDR_SPACE
             pVCpu->pgm.s.apGstPaePDsR0[i]     = 0;
-#  endif
+#endif
             pVCpu->pgm.s.apGstPaePDsRC[i]     = 0;
             pVCpu->pgm.s.aGCPhysGstPaePDs[i]  = NIL_RTGCPHYS;
@@ -2541,5 +2479,5 @@
     else
     {
-# ifdef PGMPOOL_WITH_OPTIMIZED_DIRTY_PT
+#ifdef PGMPOOL_WITH_OPTIMIZED_DIRTY_PT
         PPGMPOOL pPool = pVM->pgm.s.CTX_SUFF(pPool);
         if (pPool->cDirtyPages)
@@ -2549,5 +2487,5 @@
             pgmUnlock(pVM);
         }
-# endif
+#endif
         /*
          * Check if we have a pending update of the CR3 monitoring.
@@ -2850,14 +2788,7 @@
     /* Flush the TLB */
     PGM_INVL_VCPU_TLBS(pVCpu);
-
-#ifndef IN_RC
     return PGMHCChangeMode(pVCpu->CTX_SUFF(pVM), pVCpu, enmGuestMode);
-#else
-    LogFlow(("PGMChangeMode: returns VINF_PGM_CHANGE_MODE.\n"));
-    return VINF_PGM_CHANGE_MODE;
-#endif
-}
-
-#ifndef IN_RC
+}
+
 
 /**
@@ -3067,5 +2998,4 @@
                             break;
 
-#if HC_ARCH_BITS == 64 || defined(RT_OS_DARWIN)
                         case SUPPAGINGMODE_AMD64:
                         case SUPPAGINGMODE_AMD64_GLOBAL:
@@ -3074,5 +3004,5 @@
                             enmShadowMode = PGMMODE_NESTED_AMD64;
                             break;
-#endif
+
                         default:
                             AssertLogRelMsgFailedReturn(("enmHostMode=%d\n", pVM->pgm.s.enmHostMode), PGMMODE_INVALID);
@@ -3251,5 +3181,4 @@
 }
 
-#endif /* !IN_RC */
 
 /**
@@ -3502,5 +3431,5 @@
     int rc = PDMCritSectEnter(&pVM->pgm.s.CritSectX, VERR_SEM_BUSY);
 #endif
-#if defined(IN_RC) || defined(IN_RING0)
+#ifdef IN_RING0
     if (rc == VERR_SEM_BUSY)
         rc = VMMRZCallRing3NoCpu(pVM, VMMCALLRING3_PGM_LOCK, 0);
@@ -3526,5 +3455,5 @@
 }
 
-#if defined(IN_RC) || defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0)
+#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0
 
 /**
@@ -3571,5 +3500,5 @@
 }
 
-#endif /* IN_RC || VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0 */
+#endif /* VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0 */
 #if !defined(IN_R0) || defined(LOG_ENABLED)
 
@@ -3593,5 +3522,5 @@
         szTmp[cch++] = s_achPageStates[PGM_PAGE_GET_STATE_NA(pPage)];
 
-#define IS_PART_INCLUDED(lvl) ( !(fFlags & RTSTR_F_PRECISION) || cchPrecision == (lvl) || cchPrecision >= (lvl)+10 )
+# define IS_PART_INCLUDED(lvl) ( !(fFlags & RTSTR_F_PRECISION) || cchPrecision == (lvl) || cchPrecision >= (lvl)+10 )
         if (IS_PART_INCLUDED(5))
         {
@@ -3630,5 +3559,5 @@
             cch += RTStrFormatNumber(&szTmp[cch], PGM_PAGE_GET_TD_IDX_NA(pPage), 16, 4, 0, RTSTR_F_ZEROPAD | RTSTR_F_16BIT);
         }
-#undef IS_PART_INCLUDED
+# undef IS_PART_INCLUDED
 
         cch = pfnOutput(pvArgOutput, szTmp, cch);
@@ -3764,5 +3693,5 @@
     return cErrors;
 }
-# endif
+# endif /* !PGM_WITHOUT_MAPPINGS */
 
 
Index: trunk/src/VBox/VMM/VMMAll/PGMAllBth.h
===================================================================
--- trunk/src/VBox/VMM/VMMAll/PGMAllBth.h	(revision 80163)
+++ trunk/src/VBox/VMM/VMMAll/PGMAllBth.h	(revision 80167)
@@ -42,7 +42,7 @@
 static int PGM_BTH_NAME(CheckDirtyPageFault)(PVMCPU pVCpu, uint32_t uErr, PSHWPDE pPdeDst, GSTPDE const *pPdeSrc, RTGCPTR GCPtrPage);
 static int PGM_BTH_NAME(SyncPT)(PVMCPU pVCpu, unsigned iPD, PGSTPD pPDSrc, RTGCPTR GCPtrPage);
-# if PGM_WITH_PAGING(PGM_GST_TYPE, PGM_SHW_TYPE)
+#if PGM_WITH_PAGING(PGM_GST_TYPE, PGM_SHW_TYPE)
 static void PGM_BTH_NAME(SyncPageWorker)(PVMCPU pVCpu, PSHWPTE pPteDst, GSTPDE PdeSrc, GSTPTE PteSrc, PPGMPOOLPAGE pShwPage, unsigned iPTDst);
-# else
+#else
 static void PGM_BTH_NAME(SyncPageWorker)(PVMCPU pVCpu, PSHWPTE pPteDst, RTGCPHYS GCPhysPage, PPGMPOOLPAGE pShwPage, unsigned iPTDst);
 #endif
@@ -686,32 +686,4 @@
 
                 /*
-                 * Check if the fault address is in a virtual page access handler range.
-                 */
-                PPGMVIRTHANDLER pCur = (PPGMVIRTHANDLER)RTAvlroGCPtrRangeGet(&pVM->pgm.s.CTX_SUFF(pTrees)->HyperVirtHandlers,
-                                                                             pvFault);
-                if (    pCur
-                    &&  pvFault - pCur->Core.Key < pCur->cb
-                    &&  uErr & X86_TRAP_PF_RW)
-                {
-                    VBOXSTRICTRC rcStrict;
-#   ifdef IN_RC
-                    STAM_PROFILE_START(&pCur->Stat, h);
-                    PPGMVIRTHANDLERTYPEINT pCurType = PGMVIRTANDLER_GET_TYPE(pVM, pCur);
-                    void *pvUser = pCur->CTX_SUFF(pvUser);
-                    pgmUnlock(pVM);
-                    rcStrict = pCurType->CTX_SUFF(pfnPfHandler)(pVM, pVCpu, uErr, pRegFrame, pvFault, pCur->Core.Key,
-                                                                pvFault - pCur->Core.Key, pvUser);
-                    pgmLock(pVM);
-                    STAM_PROFILE_STOP(&pCur->Stat, h);
-#   else
-                    AssertFailed();
-                    rcStrict = VINF_EM_RAW_EMULATE_INSTR; /* can't happen with VMX */
-#   endif
-                    STAM_COUNTER_INC(&pVCpu->pgm.s.CTX_SUFF(pStats)->StatRZTrap0eHandlersMapping);
-                    STAM_STATS({ pVCpu->pgm.s.CTX_SUFF(pStatTrap0eAttribution) = &pVCpu->pgm.s.CTX_SUFF(pStats)->StatRZTrap0eTime2Mapping; });
-                    return VBOXSTRICTRC_TODO(rcStrict);
-                }
-
-                /*
                  * Pretend we're not here and let the guest handle the trap.
                  */
@@ -765,48 +737,4 @@
 # endif
 
-#  if PGM_WITH_PAGING(PGM_GST_TYPE, PGM_SHW_TYPE) && !defined(IN_RING0)
-    if (uErr & X86_TRAP_PF_P)
-    {
-        /*
-         * The page isn't marked, but it might still be monitored by a virtual page access handler.
-         * (ASSUMES no temporary disabling of virtual handlers.)
-         */
-        /** @todo r=bird: Since the purpose is to catch out of sync pages with virtual handler(s) here,
-         * we should correct both the shadow page table and physical memory flags, and not only check for
-         * accesses within the handler region but for access to pages with virtual handlers. */
-        PPGMVIRTHANDLER pCur = (PPGMVIRTHANDLER)RTAvlroGCPtrRangeGet(&pVM->pgm.s.CTX_SUFF(pTrees)->VirtHandlers, pvFault);
-        if (pCur)
-        {
-            PPGMVIRTHANDLERTYPEINT pCurType = PGMVIRTANDLER_GET_TYPE(pVM, pCur);
-            AssertMsg(   !(pvFault - pCur->Core.Key < pCur->cb)
-                      || (    pCurType->enmKind != PGMVIRTHANDLERKIND_WRITE
-                           || !(uErr & X86_TRAP_PF_P)
-                           || (pCurType->enmKind == PGMVIRTHANDLERKIND_WRITE && (uErr & X86_TRAP_PF_RW))),
-                      ("Unexpected trap for virtual handler: %08X (phys=%08x) %R[pgmpage] uErr=%X, enumKind=%d\n",
-                       pvFault, GCPhys, pPage, uErr, pCurType->enmKind));
-
-            if (    pvFault - pCur->Core.Key < pCur->cb
-                &&  (    uErr & X86_TRAP_PF_RW
-                     ||  pCurType->enmKind != PGMVIRTHANDLERKIND_WRITE ) )
-            {
-                VBOXSTRICTRC rcStrict;
-#   ifdef IN_RC
-                STAM_PROFILE_START(&pCur->Stat, h);
-                void *pvUser = pCur->CTX_SUFF(pvUser);
-                pgmUnlock(pVM);
-                rcStrict = pCurType->CTX_SUFF(pfnPfHandler)(pVM, pVCpu, uErr, pRegFrame, pvFault, pCur->Core.Key,
-                                                            pvFault - pCur->Core.Key, pvUser);
-                pgmLock(pVM);
-                STAM_PROFILE_STOP(&pCur->Stat, h);
-#   else
-                rcStrict = VINF_EM_RAW_EMULATE_INSTR; /** @todo for VMX */
-#   endif
-                STAM_STATS({ pVCpu->pgm.s.CTX_SUFF(pStatTrap0eAttribution) = &pVCpu->pgm.s.CTX_SUFF(pStats)->StatRZTrap0eTime2HndVirt; });
-                return VBOXSTRICTRC_TODO(rcStrict);
-            }
-        }
-    }
-#  endif /* PGM_WITH_PAGING(PGM_GST_TYPE, PGM_SHW_TYPE) */
-
     /*
      * We are here only if page is present in Guest page tables and
@@ -837,5 +765,5 @@
         }
 
-#   if defined(LOG_ENABLED) && !defined(IN_RING0)
+#   if defined(LOG_ENABLED) && 0
         RTGCPHYS   GCPhys2;
         uint64_t   fPageGst2;
@@ -850,70 +778,4 @@
 #   endif /* LOG_ENABLED */
 
-#   if PGM_WITH_PAGING(PGM_GST_TYPE, PGM_SHW_TYPE) && !defined(IN_RING0)
-        if (   !GstWalk.Core.fEffectiveUS
-            && CSAMIsEnabled(pVM)
-            && CPUMGetGuestCPL(pVCpu) == 0)
-        {
-            /* Note: Can't check for X86_TRAP_ID bit, because that requires execute disable support on the CPU. */
-            if (    pvFault == (RTGCPTR)pRegFrame->eip
-                ||  pvFault - pRegFrame->eip < 8    /* instruction crossing a page boundary */
-#    ifdef CSAM_DETECT_NEW_CODE_PAGES
-                ||  (   !PATMIsPatchGCAddr(pVM, pRegFrame->eip)
-                     && CSAMDoesPageNeedScanning(pVM, pRegFrame->eip))   /* any new code we encounter here */
-#    endif /* CSAM_DETECT_NEW_CODE_PAGES */
-               )
-            {
-                LogFlow(("CSAMExecFault %RX32\n", pRegFrame->eip));
-                rc = CSAMExecFault(pVM, (RTRCPTR)pRegFrame->eip);
-                if (rc != VINF_SUCCESS)
-                {
-                    /*
-                     * CSAM needs to perform a job in ring 3.
-                     *
-                     * Sync the page before going to the host context; otherwise we'll end up in a loop if
-                     * CSAM fails (e.g. instruction crosses a page boundary and the next page is not present)
-                     */
-                    LogFlow(("CSAM ring 3 job\n"));
-                    int rc2 = PGM_BTH_NAME(SyncPage)(pVCpu, GstWalk.Pde, pvFault, 1, uErr);
-                    AssertRC(rc2);
-
-                    STAM_STATS({ pVCpu->pgm.s.CTX_SUFF(pStatTrap0eAttribution) = &pVCpu->pgm.s.CTX_SUFF(pStats)->StatRZTrap0eTime2CSAM; });
-                    return rc;
-                }
-            }
-#    ifdef CSAM_DETECT_NEW_CODE_PAGES
-            else if (    uErr == X86_TRAP_PF_RW
-                     &&  pRegFrame->ecx >= 0x100         /* early check for movswd count */
-                     &&  pRegFrame->ecx < 0x10000)
-            {
-                /* In case of a write to a non-present supervisor shadow page, we'll take special precautions
-                 * to detect loading of new code pages.
-                 */
-
-                /*
-                 * Decode the instruction.
-                 */
-                PDISCPUSTATE pDis = &pVCpu->pgm.s.DisState;
-                uint32_t     cbOp;
-                rc = EMInterpretDisasCurrent(pVM, pVCpu, pDis, &cbOp);
-
-                /* For now we'll restrict this to rep movsw/d instructions */
-                if (    rc == VINF_SUCCESS
-                    &&  pDis->pCurInstr->opcode == OP_MOVSWD
-                    &&  (pDis->prefix & DISPREFIX_REP))
-                {
-                    CSAMMarkPossibleCodePage(pVM, pvFault);
-                }
-            }
-#    endif  /* CSAM_DETECT_NEW_CODE_PAGES */
-
-            /*
-             * Mark this page as safe.
-             */
-            /** @todo not correct for pages that contain both code and data!! */
-            Log2(("CSAMMarkPage %RGv; scanned=%d\n", pvFault, true));
-            CSAMMarkPage(pVM, pvFault, true);
-        }
-#   endif /* PGM_WITH_PAGING(PGM_GST_TYPE, PGM_SHW_TYPE) && !defined(IN_RING0) */
 #   if PGM_WITH_PAGING(PGM_GST_TYPE, PGM_SHW_TYPE)
         rc = PGM_BTH_NAME(SyncPage)(pVCpu, GstWalk.Pde, pvFault, PGM_SYNC_NR_PAGES, uErr);
@@ -1159,4 +1021,5 @@
 # endif
 }
+
 #endif /* !IN_RING3 */
 
@@ -1184,5 +1047,5 @@
 PGM_BTH_DECL(int, InvalidatePage)(PVMCPU pVCpu, RTGCPTR GCPtrPage)
 {
-#if    PGM_WITH_PAGING(PGM_GST_TYPE, PGM_SHW_TYPE)   \
+#if    PGM_WITH_PAGING(PGM_GST_TYPE, PGM_SHW_TYPE) \
     && !PGM_TYPE_IS_NESTED_OR_EPT(PGM_SHW_TYPE) \
     && PGM_SHW_TYPE != PGM_TYPE_NONE
@@ -2072,19 +1935,5 @@
                                 RTGCPTR GCPtrCurPage = (GCPtrPage & ~(RTGCPTR)(GST_PT_MASK << GST_PT_SHIFT)) | ((offPTSrc + iPTDst) << PAGE_SHIFT);
                                 NOREF(GCPtrCurPage);
-#   ifdef VBOX_WITH_RAW_MODE_NOT_R0
-                                /*
-                                 * Assuming kernel code will be marked as supervisor - and not as user level
-                                 * and executed using a conforming code selector - And marked as readonly.
-                                 * Also assume that if we're monitoring a page, it's of no interest to CSAM.
-                                 */
-                                PPGMPAGE pPage;
-                                if (    ((PdeSrc.u & pPteSrc->u) & (X86_PTE_RW | X86_PTE_US))
-                                    ||  iPTDst == ((GCPtrPage >> SHW_PT_SHIFT) & SHW_PT_MASK)   /* always sync GCPtrPage */
-                                    ||  !CSAMDoesPageNeedScanning(pVM, GCPtrCurPage)
-                                    ||  (   (pPage = pgmPhysGetPage(pVM, pPteSrc->u & GST_PTE_PG_MASK))
-                                         && PGM_PAGE_HAS_ACTIVE_HANDLERS(pPage))
-                                   )
-#   endif /* else: CSAM not active */
-                                   PGM_BTH_NAME(SyncPageWorker)(pVCpu, &pPTDst->a[iPTDst], PdeSrc, *pPteSrc, pShwPage, iPTDst);
+                                PGM_BTH_NAME(SyncPageWorker)(pVCpu, &pPTDst->a[iPTDst], PdeSrc, *pPteSrc, pShwPage, iPTDst);
                                 Log2(("SyncPage: 4K+ %RGv PteSrc:{P=%d RW=%d U=%d raw=%08llx} PteDst=%08llx%s\n",
                                       GCPtrCurPage, pPteSrc->n.u1Present,
@@ -2249,6 +2098,5 @@
 # elif (PGM_GST_TYPE == PGM_TYPE_REAL || PGM_GST_TYPE == PGM_TYPE_PROT) \
     && !PGM_TYPE_IS_NESTED(PGM_SHW_TYPE) \
-    && (PGM_SHW_TYPE != PGM_TYPE_EPT || PGM_GST_TYPE == PGM_TYPE_PROT) \
-    && !defined(IN_RC)
+    && (PGM_SHW_TYPE != PGM_TYPE_EPT || PGM_GST_TYPE == PGM_TYPE_PROT)
     NOREF(PdeSrc);
 
@@ -2528,15 +2376,4 @@
         const GSTPTE   PteSrc  = *pPteSrc;
 
-#ifdef VBOX_WITH_RAW_MODE_NOT_R0
-        /* Bail out here as pgmPoolGetPage will return NULL and we'll crash below.
-         * Our individual shadow handlers will provide more information and force a fatal exit.
-         */
-        if (   VM_IS_RAW_MODE_ENABLED(pVM)
-            && MMHyperIsInsideArea(pVM, (RTGCPTR)GCPtrPage))
-        {
-            LogRel(("CheckPageFault: write to hypervisor region %RGv\n", GCPtrPage));
-            return VINF_PGM_NO_DIRTY_BIT_TRACKING;
-        }
-#endif
         /*
          * Map shadow page table.
@@ -3039,14 +2876,4 @@
                         else if (PGM_PAGE_IS_BALLOONED(pPage))
                             SHW_PTE_SET(PteDst, 0); /* Handle ballooned pages at #PF time. */
-# ifdef VBOX_WITH_RAW_MODE_NOT_R0
-                        /*
-                         * Assuming kernel code will be marked as supervisor and not as user level and executed
-                         * using a conforming code selector. Don't check for readonly, as that implies the whole
-                         * 4MB can be code or readonly data. Linux enables write access for its large pages.
-                         */
-                        else if (    !PdeSrc.n.u1User
-                                 &&  CSAMDoesPageNeedScanning(pVM, GCPtr | (iPTDst << SHW_PT_SHIFT)))
-                            SHW_PTE_SET(PteDst, 0);
-# endif
                         else
                             SHW_PTE_SET(PteDst, PGM_PAGE_GET_HCPHYS(pPage) | SHW_PTE_GET_U(PteDstBase));
@@ -3117,6 +2944,5 @@
     && !PGM_TYPE_IS_NESTED(PGM_SHW_TYPE) \
     && (PGM_SHW_TYPE != PGM_TYPE_EPT || PGM_GST_TYPE == PGM_TYPE_PROT) \
-    && PGM_SHW_TYPE != PGM_TYPE_NONE \
-    && !defined(IN_RC)
+    && PGM_SHW_TYPE != PGM_TYPE_NONE
     NOREF(iPDSrc); NOREF(pPDSrc);
 
@@ -3263,5 +3089,5 @@
         }
     }
-# endif /* HC_ARCH_BITS == 64 */
+# endif /* defined(PGM_WITH_LARGE_PAGES) && PGM_SHW_TYPE != PGM_TYPE_32BIT && PGM_SHW_TYPE != PGM_TYPE_PAE */
 
     /*
@@ -3752,8 +3578,4 @@
 
 #ifdef VBOX_STRICT
-# ifdef IN_RC
-#  undef AssertMsgFailed
-#  define AssertMsgFailed Log
-# endif
 
 /**
@@ -4547,5 +4369,5 @@
     AssertReturn(pPageCR3, VERR_PGM_INVALID_CR3_ADDR);
     /** @todo this needs some reworking wrt. locking?  */
-# if defined(IN_RC) || defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0)
+# ifdef VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0
     HCPtrGuestCR3 = NIL_RTHCPTR;
     int rc = VINF_SUCCESS;
@@ -4582,5 +4404,5 @@
                 PPGMPAGE    pPage  = pgmPhysGetPage(pVM, GCPhys);
                 AssertReturn(pPage, VERR_PGM_INVALID_PDPE_ADDR);
-#  if defined(IN_RC) || defined(VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0)
+#  ifdef VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0
                 HCPtr = NIL_RTHCPTR;
                 int rc2 = VINF_SUCCESS;
@@ -4607,7 +4429,4 @@
             pVCpu->pgm.s.apGstPaePDsRC[i]     = 0;
             pVCpu->pgm.s.aGCPhysGstPaePDs[i]  = NIL_RTGCPHYS;
-#  ifdef IN_RC
-            PGM_INVL_PG(pVCpu, GCPtr); /** @todo this shouldn't be necessary? */
-#  endif
         }
 
@@ -4659,23 +4478,8 @@
     rc = VINF_SUCCESS;
 
-#  ifdef IN_RC
-    /*
-     * WARNING! We can't deal with jumps to ring 3 in the code below as the
-     *          state will be inconsistent! Flush important things now while
-     *          we still can and then make sure there are no ring-3 calls.
-     */
-#   ifdef VBOX_WITH_REM
-    REMNotifyHandlerPhysicalFlushIfAlmostFull(pVM, pVCpu);
-#   endif
-    VMMRZCallRing3Disable(pVCpu);
-#  endif
-
     pVCpu->pgm.s.CTX_SUFF(pShwPageCR3) = pNewShwPageCR3;
 #  ifdef IN_RING0
     pVCpu->pgm.s.pShwPageCR3R3 = MMHyperCCToR3(pVM, pVCpu->pgm.s.CTX_SUFF(pShwPageCR3));
     pVCpu->pgm.s.pShwPageCR3RC = MMHyperCCToRC(pVM, pVCpu->pgm.s.CTX_SUFF(pShwPageCR3));
-#  elif defined(IN_RC)
-    pVCpu->pgm.s.pShwPageCR3R3 = MMHyperCCToR3(pVM, pVCpu->pgm.s.CTX_SUFF(pShwPageCR3));
-    pVCpu->pgm.s.pShwPageCR3R0 = MMHyperCCToR0(pVM, pVCpu->pgm.s.CTX_SUFF(pShwPageCR3));
 #  else
     pVCpu->pgm.s.pShwPageCR3R0 = MMHyperCCToR0(pVM, pVCpu->pgm.s.CTX_SUFF(pShwPageCR3));
@@ -4698,9 +4502,4 @@
     /* Set the current hypervisor CR3. */
     CPUMSetHyperCR3(pVCpu, PGMGetHyperCR3(pVCpu));
-
-#  ifdef IN_RC
-    /* NOTE: The state is consistent again. */
-    VMMRZCallRing3Enable(pVCpu);
-#  endif
 
     /* Clean up the old CR3 root. */
@@ -4775,16 +4574,13 @@
 #endif
 
-#if !defined(IN_RC) /* In RC we rely on MapCR3 to do the shadow part for us at a safe time */
     /*
      * Update shadow paging info.
      */
-# if  (   (   PGM_SHW_TYPE == PGM_TYPE_32BIT  \
-           || PGM_SHW_TYPE == PGM_TYPE_PAE    \
-           || PGM_SHW_TYPE == PGM_TYPE_AMD64))
-
-#  if PGM_GST_TYPE != PGM_TYPE_REAL
+#if  (   (   PGM_SHW_TYPE == PGM_TYPE_32BIT \
+          || PGM_SHW_TYPE == PGM_TYPE_PAE \
+          || PGM_SHW_TYPE == PGM_TYPE_AMD64))
+# if PGM_GST_TYPE != PGM_TYPE_REAL
     Assert(!pVM->pgm.s.fNestedPaging);
-#  endif
-
+# endif
     pgmLock(pVM);
 
@@ -4812,7 +4608,7 @@
         pVCpu->pgm.s.pShwPageCR3RC = 0;
     }
+
     pgmUnlock(pVM);
-# endif
-#endif /* !IN_RC*/
+#endif
 
     return rc;
