Index: /trunk/include/VBox/VMMDev.h
===================================================================
--- /trunk/include/VBox/VMMDev.h	(revision 21644)
+++ /trunk/include/VBox/VMMDev.h	(revision 21645)
@@ -131,6 +131,6 @@
     VMMDevReq_GetHypervisorInfo          = 20,
     VMMDevReq_SetHypervisorInfo          = 21,
-    VMMDevReq_SetPatchMemory             = 22,
-    VMMDevReq_ClearPatchMemory           = 23,
+    VMMDevReq_RegisterPatchMemory             = 22,
+    VMMDevReq_DeregisterPatchMemory           = 23,
     VMMDevReq_SetPowerStatus             = 30,
     VMMDevReq_AcknowledgeEvents          = 41,
@@ -462,5 +462,5 @@
 
 /** @name Default patch memory size .
- * Used by VMMDevReq_SetPatchMemory and VMMDevReq_ClearPatchMemory.
+ * Used by VMMDevReq_RegisterPatchMemory and VMMDevReq_DeregisterPatchMemory.
  * @{ */
 #define VMMDEV_GUEST_DEFAULT_PATCHMEM_SIZE          8192
@@ -470,5 +470,5 @@
  * Patching memory structure. (locked executable & read-only page from the guest's perspective)
  *
- * Used by VMMDevReq_SetPatchMemory and VMMDevReq_ClearPatchMemory
+ * Used by VMMDevReq_RegisterPatchMemory and VMMDevReq_DeregisterPatchMemory
  */
 typedef struct
@@ -1404,6 +1404,6 @@
         case VMMDevReq_SetHypervisorInfo:
             return sizeof(VMMDevReqHypervisorInfo);
-        case VMMDevReq_SetPatchMemory:
-        case VMMDevReq_ClearPatchMemory:
+        case VMMDevReq_RegisterPatchMemory:
+        case VMMDevReq_DeregisterPatchMemory:
             return sizeof(VMMDevReqPatchMemory);
         case VMMDevReq_SetPowerStatus:
Index: /trunk/include/VBox/hwaccm.h
===================================================================
--- /trunk/include/VBox/hwaccm.h	(revision 21644)
+++ /trunk/include/VBox/hwaccm.h	(revision 21645)
@@ -141,4 +141,6 @@
 VMMR3DECL(int)  HWACCMR3EmulateIoBlock(PVM pVM, PCPUMCTX pCtx);
 VMMR3DECL(int)  HWACCMR3RestartPendingIOInstr(PVM pVM, PVMCPU pVCpu, PCPUMCTX pCtx);
+VMMR3DECL(int)  HWACMMR3EnablePatching(PVM pVM);
+VMMR3DECL(int)  HWACMMR3DisablePatching(PVM pVM);
 
 /** @} */
Index: /trunk/include/VBox/vmm.h
===================================================================
--- /trunk/include/VBox/vmm.h	(revision 21644)
+++ /trunk/include/VBox/vmm.h	(revision 21645)
@@ -192,6 +192,6 @@
 VMMR3DECL(void)     VMMR3SendSipi(PVM pVM, VMCPUID idCpu, uint32_t uVector);
 VMMR3DECL(void)     VMMR3SendInitIpi(PVM pVM, VMCPUID idCpu);
-VMMR3DECL(int)      VMMR3SetPatchMemory(PVM pVM, RTGCPTR pPatchMem, unsigned cbPatchMem);
-VMMR3DECL(int)      VMMR3ClearPatchMemory(PVM pVM, RTGCPTR pPatchMem, unsigned cbPatchMem);
+VMMR3DECL(int)      VMMR3RegisterPatchMemory(PVM pVM, RTGCPTR pPatchMem, unsigned cbPatchMem);
+VMMR3DECL(int)      VMMR3DeregisterPatchMemory(PVM pVM, RTGCPTR pPatchMem, unsigned cbPatchMem);
 VMMR3DECL(int)      VMMR3AtomicExecuteHandler(PVM pVM, PFNATOMICHANDLER pfnHandler, void *pvUser);
 VMMR3DECL(int)      VMMR3EmtRendezvous(PVM pVM, uint32_t fFlags, PFNVMMEMTRENDEZVOUS pfnRendezvous, void *pvUser);
Index: /trunk/src/VBox/Additions/WINNT/VBoxGuest/VBoxGuest.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/VBoxGuest/VBoxGuest.cpp	(revision 21644)
+++ /trunk/src/VBox/Additions/WINNT/VBoxGuest/VBoxGuest.cpp	(revision 21645)
@@ -1743,5 +1743,5 @@
     {
         VMMDevReqPatchMemory *req = NULL;
-        int rc = VbglGRAlloc ((VMMDevRequestHeader **)&req, sizeof (VMMDevReqPatchMemory), VMMDevReq_SetPatchMemory);
+        int rc = VbglGRAlloc ((VMMDevRequestHeader **)&req, sizeof (VMMDevReqPatchMemory), VMMDevReq_RegisterPatchMemory);
         if (RT_SUCCESS(rc))
         {
@@ -1756,5 +1756,5 @@
                 if (RT_FAILURE(rc) || RT_FAILURE(req->header.rc))
                 {
-                    dprintf(("VBoxGuest::reserveHypervisorMemory: VMMDevReq_SetPatchMemory error!"
+                    dprintf(("VBoxGuest::reserveHypervisorMemory: VMMDevReq_RegisterPatchMemory error!"
                                 "rc = %d, VMMDev rc = %Rrc\n", rc, req->header.rc));
                     RTR0MemObjFree(pDevExt->PatchMemObj, true);
@@ -1783,5 +1783,5 @@
     {
         VMMDevReqPatchMemory *req = NULL;
-        int rc = VbglGRAlloc ((VMMDevRequestHeader **)&req, sizeof (VMMDevReqPatchMemory), VMMDevReq_ClearPatchMemory);
+        int rc = VbglGRAlloc ((VMMDevRequestHeader **)&req, sizeof (VMMDevReqPatchMemory), VMMDevReq_DeregisterPatchMemory);
         if (RT_SUCCESS(rc))
         {
@@ -1792,5 +1792,5 @@
             if (RT_FAILURE(rc) || RT_FAILURE(req->header.rc))
             {
-                dprintf(("VBoxGuest::reserveHypervisorMemory: VMMDevReq_ClearPatchMemory error!"
+                dprintf(("VBoxGuest::reserveHypervisorMemory: VMMDevReq_DeregisterPatchMemory error!"
                             "rc = %d, VMMDev rc = %Rrc\n", rc, req->header.rc));
                 /* We intentially leak the memory object here as there still could 
Index: /trunk/src/VBox/Devices/VMMDev/VMMDev.cpp
===================================================================
--- /trunk/src/VBox/Devices/VMMDev/VMMDev.cpp	(revision 21644)
+++ /trunk/src/VBox/Devices/VMMDev/VMMDev.cpp	(revision 21645)
@@ -811,9 +811,9 @@
         }
 
-        case VMMDevReq_SetPatchMemory:
+        case VMMDevReq_RegisterPatchMemory:
         {
             if (pRequestHeader->size != sizeof(VMMDevReqPatchMemory))
             {
-                AssertMsgFailed(("VMMDevReq_SetPatchMemory structure has invalid size!\n"));
+                AssertMsgFailed(("VMMDevReq_RegisterPatchMemory structure has invalid size!\n"));
                 pRequestHeader->rc = VERR_INVALID_PARAMETER;
             }
@@ -822,14 +822,14 @@
                 VMMDevReqPatchMemory *pPatchRequest = (VMMDevReqPatchMemory*)pRequestHeader;
 
-                pRequestHeader->rc = VMMR3SetPatchMemory(PDMDevHlpGetVM(pDevIns), pPatchRequest->pPatchMem, pPatchRequest->cbPatchMem);
-            }
-            break;
-        }
-
-        case VMMDevReq_ClearPatchMemory:
+                pRequestHeader->rc = VMMR3RegisterPatchMemory(PDMDevHlpGetVM(pDevIns), pPatchRequest->pPatchMem, pPatchRequest->cbPatchMem);
+            }
+            break;
+        }
+
+        case VMMDevReq_DeregisterPatchMemory:
         {
             if (pRequestHeader->size != sizeof(VMMDevReqPatchMemory))
             {
-                AssertMsgFailed(("VMMDevReq_ClearPatchMemory structure has invalid size!\n"));
+                AssertMsgFailed(("VMMDevReq_DeregisterPatchMemory structure has invalid size!\n"));
                 pRequestHeader->rc = VERR_INVALID_PARAMETER;
             }
@@ -838,5 +838,5 @@
                 VMMDevReqPatchMemory *pPatchRequest = (VMMDevReqPatchMemory*)pRequestHeader;
 
-                pRequestHeader->rc = VMMR3ClearPatchMemory(PDMDevHlpGetVM(pDevIns), pPatchRequest->pPatchMem, pPatchRequest->cbPatchMem);
+                pRequestHeader->rc = VMMR3DeregisterPatchMemory(PDMDevHlpGetVM(pDevIns), pPatchRequest->pPatchMem, pPatchRequest->cbPatchMem);
             }
             break;
Index: /trunk/src/VBox/VMM/HWACCM.cpp
===================================================================
--- /trunk/src/VBox/VMM/HWACCM.cpp	(revision 21644)
+++ /trunk/src/VBox/VMM/HWACCM.cpp	(revision 21645)
@@ -1383,4 +1383,26 @@
 
 /**
+ * Enable patching in a VT-x/AMD-V guest
+ *
+ * @returns VBox status code.
+ * @param   pVM         The VM to operate on.
+ */
+VMMR3DECL(int)  HWACMMR3EnablePatching(PVM pVM)
+{
+    return VINF_SUCCESS;
+}
+
+/**
+ * Disable patching in a VT-x/AMD-V guest
+ *
+ * @returns VBox status code.
+ * @param   pVM         The VM to operate on.
+ */
+VMMR3DECL(int)  HWACMMR3DisablePatching(PVM pVM)
+{
+    return VINF_SUCCESS;
+}
+
+/**
  * Force execution of the current IO code in the recompiler
  *
Index: /trunk/src/VBox/VMM/VMM.cpp
===================================================================
--- /trunk/src/VBox/VMM/VMM.cpp	(revision 21644)
+++ /trunk/src/VBox/VMM/VMM.cpp	(revision 21645)
@@ -1305,24 +1305,36 @@
 
 /**
- * Sets the guest memory range that can be used for patching
- *
+ * Registers the guest memory range that can be used for patching
+ *
+ * @returns VBox status code.
  * @param   pVM         The VM to operate on.
  * @param   pPatchMem   Patch memory range
  * @param   cbPatchMem  Size of the memory range
  */
-VMMR3DECL(int) VMMR3SetPatchMemory(PVM pVM, RTGCPTR pPatchPage, unsigned cbPatch)
-{
+VMMR3DECL(int) VMMR3RegisterPatchMemory(PVM pVM, RTGCPTR pPatchMem, unsigned cbPatchMem)
+{
+    if (HWACCMIsEnabled(pVM))
+        HWACMMR3EnablePatching(pVM);
+
     return VERR_ACCESS_DENIED;
 }
 
 /**
- * Clears the guest memory range that can be used for patching
- *
+ * Deregisters the guest memory range that can be used for patching
+ *
+ * @returns VBox status code.
  * @param   pVM         The VM to operate on.
  * @param   pPatchMem   Patch memory range
  * @param   cbPatchMem  Size of the memory range
  */
-VMMR3DECL(int) VMMR3ClearPatchMemory(PVM pVM, RTGCPTR pPatchPage, unsigned cbPatch)
-{
+VMMR3DECL(int) VMMR3DeregisterPatchMemory(PVM pVM, RTGCPTR pPatchMem, unsigned cbPatchMem)
+{
+    if (HWACCMIsEnabled(pVM))
+    {
+        int rc = HWACMMR3DisablePatching(pVM);
+        if (VBOX_FAILURE(rc))
+            return rc;
+    }
+
     return VINF_SUCCESS;
 }
