Index: /trunk/src/VBox/VMM/VMMR3/PATM.cpp
===================================================================
--- /trunk/src/VBox/VMM/VMMR3/PATM.cpp	(revision 54685)
+++ /trunk/src/VBox/VMM/VMMR3/PATM.cpp	(revision 54686)
@@ -308,12 +308,12 @@
 #endif /* VBOX_WITH_STATISTICS */
 
-    Log(("PATMCallRecord.size           %d\n", PATMCallRecord.size));
-    Log(("PATMCallIndirectRecord.size   %d\n", PATMCallIndirectRecord.size));
-    Log(("PATMRetRecord.size            %d\n", PATMRetRecord.size));
-    Log(("PATMJumpIndirectRecord.size   %d\n", PATMJumpIndirectRecord.size));
-    Log(("PATMPopf32Record.size         %d\n", PATMPopf32Record.size));
-    Log(("PATMIretRecord.size           %d\n", PATMIretRecord.size));
-    Log(("PATMStiRecord.size            %d\n", PATMStiRecord.size));
-    Log(("PATMCheckIFRecord.size        %d\n", PATMCheckIFRecord.size));
+    Log(("PATMCallRecord.cbFunction           %u\n", PATMCallRecord.cbFunction));
+    Log(("PATMCallIndirectRecord.cbFunction   %u\n", PATMCallIndirectRecord.cbFunction));
+    Log(("PATMRetRecord.cbFunction            %u\n", PATMRetRecord.cbFunction));
+    Log(("PATMJumpIndirectRecord.cbFunction   %u\n", PATMJumpIndirectRecord.cbFunction));
+    Log(("PATMPopf32Record.cbFunction         %u\n", PATMPopf32Record.cbFunction));
+    Log(("PATMIretRecord.cbFunction           %u\n", PATMIretRecord.cbFunction));
+    Log(("PATMStiRecord.cbFunction            %u\n", PATMStiRecord.cbFunction));
+    Log(("PATMCheckIFRecord.cbFunction        %u\n", PATMCheckIFRecord.cbFunction));
 
     return rc;
Index: /trunk/src/VBox/VMM/VMMR3/PATMA.asm
===================================================================
--- /trunk/src/VBox/VMM/VMMR3/PATMA.asm	(revision 54685)
+++ /trunk/src/VBox/VMM/VMMR3/PATMA.asm	(revision 54686)
@@ -1912,30 +1912,23 @@
 SECTION .data
 ; Patch record for 'cpuid'
-GLOBALNAME PATMCpuidRecord
-    RTCCPTR_DEF PATMCpuidStart
-    DD      0
-    DD      0
-    DD      0
-    DD      PATMCpuidEnd- PATMCpuidStart
-    DD      9
-    DD      PATM_INTERRUPTFLAG
-    DD      0
-    DD      PATM_CPUID_STD_MAX
-    DD      0
-    DD      PATM_CPUID_EXT_MAX
-    DD      0
-    DD      PATM_CPUID_CENTAUR_MAX
-    DD      0
-    DD      PATM_CPUID_DEF_PTR
-    DD      0
-    DD      PATM_CPUID_STD_PTR
-    DD      0
-    DD      PATM_CPUID_EXT_PTR
-    DD      0
-    DD      PATM_CPUID_CENTAUR_PTR
-    DD      0
-    DD      PATM_INTERRUPTFLAG
-    DD      0
-    DD      0ffffffffh
+GLOBALNAME PATMCpuidRecord 
+    istruc PATCHASMRECORD
+    at PATCHASMRECORD.pbFunction,     RTCCPTR_DEF PATMCpuidStart
+    at PATCHASMRECORD.offJump,        DD          0
+    at PATCHASMRECORD.offRelJump,     DD          0
+    at PATCHASMRECORD.offSizeOverride,DD          0
+    at PATCHASMRECORD.cbFunction,     DD          PATMCpuidEnd- PATMCpuidStart
+    at PATCHASMRECORD.cRelocs,        DD          9
+    iend
+    DD      PATM_INTERRUPTFLAG,     0       ; 0
+    DD      PATM_CPUID_STD_MAX,     0       ; 1
+    DD      PATM_CPUID_EXT_MAX,     0       ; 2
+    DD      PATM_CPUID_CENTAUR_MAX, 0       ; 3
+    DD      PATM_CPUID_DEF_PTR,     0       ; 4
+    DD      PATM_CPUID_STD_PTR,     0       ; 5
+    DD      PATM_CPUID_EXT_PTR,     0       ; 6
+    DD      PATM_CPUID_CENTAUR_PTR, 0       ; 7
+    DD      PATM_INTERRUPTFLAG,     0       ; 8
+    DD      0ffffffffh, 0ffffffffh          ; 9 - for sanity checks
 SECTION .text
 
Index: /trunk/src/VBox/VMM/VMMR3/PATMA.mac
===================================================================
--- /trunk/src/VBox/VMM/VMMR3/PATMA.mac	(revision 54685)
+++ /trunk/src/VBox/VMM/VMMR3/PATMA.mac	(revision 54686)
@@ -1,9 +1,9 @@
 ; $Id$
 ;; @file
-; PATM macros & definitions (identical to PATMA.h!!)
+; PATM macros & definitions (identical to PATMA.h!).
 ;
 
 ;
-; Copyright (C) 2006-2010 Oracle Corporation
+; Copyright (C) 2006-2015 Oracle Corporation
 ;
 ; This file is part of VirtualBox Open Source Edition (OSE), as
@@ -19,53 +19,56 @@
 %define PATM_INT3            int3
 
-%define PATM_VMFLAGS         0xF1ABCD00
+;; @name Patch Fixup Types
+; @{
+%define PATM_VMFLAGS                            0xF1ABCD00
 %ifdef VBOX_WITH_STATISTICS
-%define PATM_ALLPATCHCALLS   0xF1ABCD01
-%define PATM_PERPATCHCALLS   0xF1ABCD02
+ %define PATM_ALLPATCHCALLS                     0xF1ABCD01
+ %define PATM_PERPATCHCALLS                     0xF1ABCD02
 %endif
-%define PATM_JUMPDELTA       0xF1ABCD03
+%define PATM_JUMPDELTA                          0xF1ABCD03
 %ifdef VBOX_WITH_STATISTICS
-%define PATM_IRETEFLAGS      0xF1ABCD04
-%define PATM_IRETCS          0xF1ABCD05
-%define PATM_IRETEIP         0xF1ABCD06
+ %define PATM_IRETEFLAGS                        0xF1ABCD04
+ %define PATM_IRETCS                            0xF1ABCD05
+ %define PATM_IRETEIP                           0xF1ABCD06
 %endif
-%define PATM_FIXUP           0xF1ABCD07
-%define PATM_PENDINGACTION   0xF1ABCD08
-%define PATM_CPUID_STD_PTR   0xF1ABCD09
-%define PATM_CPUID_EXT_PTR   0xF1ABCD0a
-%define PATM_CPUID_DEF_PTR   0xF1ABCD0b
-%define PATM_STACKBASE       0xF1ABCD0c    ;/** Stack to store our private patch return addresses */
-%define PATM_STACKBASE_GUEST 0xF1ABCD0d    ;/** Stack to store guest return addresses */
-%define PATM_STACKPTR        0xF1ABCD0e
-%define PATM_PATCHBASE       0xF1ABCD0f
-%define PATM_INTERRUPTFLAG   0xF1ABCD10
-%define PATM_INHIBITIRQADDR  0xF1ABCD11
-%define PATM_VM_FORCEDACTIONS  0xF1ABCD12
-%define PATM_TEMP_EAX                           0xF1ABCD13      ;/** Location for original EAX register */
-%define PATM_TEMP_ECX                           0xF1ABCD14      ;/** Location for original ECX register */
-%define PATM_TEMP_EDI                           0xF1ABCD15      ;/** Location for original EDI register */
-%define PATM_TEMP_EFLAGS                        0xF1ABCD16      ;/** Location for original eflags */
-%define PATM_TEMP_RESTORE_FLAGS                 0xF1ABCD17      ;/** Which registers to restore */
+%define PATM_FIXUP                              0xF1ABCD07
+%define PATM_PENDINGACTION                      0xF1ABCD08
+%define PATM_CPUID_STD_PTR                      0xF1ABCD09
+%define PATM_CPUID_EXT_PTR                      0xF1ABCD0a
+%define PATM_CPUID_DEF_PTR                      0xF1ABCD0b
+%define PATM_STACKBASE                          0xF1ABCD0c  ;;< Stack to store our private patch return addresses
+%define PATM_STACKBASE_GUEST                    0xF1ABCD0d  ;;< Stack to store guest return addresses 
+%define PATM_STACKPTR                           0xF1ABCD0e
+%define PATM_PATCHBASE                          0xF1ABCD0f
+%define PATM_INTERRUPTFLAG                      0xF1ABCD10
+%define PATM_INHIBITIRQADDR                     0xF1ABCD11
+%define PATM_VM_FORCEDACTIONS                   0xF1ABCD12
+%define PATM_TEMP_EAX                           0xF1ABCD13  ;;< Location for original EAX register
+%define PATM_TEMP_ECX                           0xF1ABCD14  ;;< Location for original ECX register
+%define PATM_TEMP_EDI                           0xF1ABCD15  ;;< Location for original EDI register
+%define PATM_TEMP_EFLAGS                        0xF1ABCD16  ;;< Location for original eflags
+%define PATM_TEMP_RESTORE_FLAGS                 0xF1ABCD17  ;;< Which registers to restore
 %define PATM_CALL_PATCH_TARGET_ADDR             0xF1ABCD18
 %define PATM_CALL_RETURN_ADDR                   0xF1ABCD19
-%define PATM_CPUID_CENTAUR_PTR                  0xF1ABCD1A
+%define PATM_CPUID_CENTAUR_PTR                  0xF1ABCD1a
 
 ;/* Anything larger doesn't require a fixup */
-%define PATM_NO_FIXUP        0xF1ABCE00
-%define PATM_CPUID_STD_MAX   0xF1ABCE00
-%define PATM_CPUID_EXT_MAX   0xF1ABCE01
-%define PATM_RETURNADDR      0xF1ABCE02
-%define PATM_PATCHNEXTBLOCK  0xF1ABCE03
-%define PATM_CALLTARGET      0xF1ABCE04    ; /* relative */
-%define PATM_NEXTINSTRADDR   0xF1ABCE05    ; /* absolute guest address of the next instruction */
-%define PATM_CURINSTRADDR    0xF1ABCE06    ; /* absolute guest address of the current instruction */
-%define PATM_LOOKUP_AND_CALL_FUNCTION           0xF1ABCE07   ; /** Relative address of global PATM lookup and call function. */
-%define PATM_RETURN_FUNCTION                    0xF1ABCE08   ; /** Relative address of global PATM return function. */
-%define PATM_LOOKUP_AND_JUMP_FUNCTION           0xF1ABCE09   ; /** Relative address of global PATM lookup and jump function. */
-%define PATM_IRET_FUNCTION                      0xF1ABCE0A   ; /** Relative address of global PATM iret function. */
+%define PATM_NO_FIXUP                           0xF1ABCE00
+%define PATM_CPUID_STD_MAX                      0xF1ABCE00
+%define PATM_CPUID_EXT_MAX                      0xF1ABCE01
+%define PATM_RETURNADDR                         0xF1ABCE02
+%define PATM_PATCHNEXTBLOCK                     0xF1ABCE03
+%define PATM_CALLTARGET                         0xF1ABCE04  ;;< relative call target 
+%define PATM_NEXTINSTRADDR                      0xF1ABCE05  ;;< absolute guest address of the next instruction 
+%define PATM_CURINSTRADDR                       0xF1ABCE06  ;;< absolute guest address of the current instruction 
+%define PATM_LOOKUP_AND_CALL_FUNCTION           0xF1ABCE07  ;;< Relative address of global PATM lookup and call function. 
+%define PATM_RETURN_FUNCTION                    0xF1ABCE08  ;;< Relative address of global PATM return function. 
+%define PATM_LOOKUP_AND_JUMP_FUNCTION           0xF1ABCE09  ;;< Relative address of global PATM lookup and jump function. 
+%define PATM_IRET_FUNCTION                      0xF1ABCE0A  ;;< Relative address of global PATM iret function. 
 %define PATM_CPUID_CENTAUR_MAX                  0xF1ABCE0B
+;; @}
 
 
-; everything except IOPL, NT, IF, VM, VIF, VIP and RF
+;; Everything except IOPL, NT, IF, VM, VIF, VIP and RF 
 %define PATM_FLAGS_MASK      (X86_EFL_CF|X86_EFL_PF|X86_EFL_AF|X86_EFL_ZF|X86_EFL_SF|X86_EFL_TF|X86_EFL_DF|X86_EFL_OF|X86_EFL_AC|X86_EFL_ID)
 
@@ -73,9 +76,11 @@
 %define PATM_VIRTUAL_FLAGS_MASK (X86_EFL_IF|X86_EFL_IOPL)
 
-; PATM stack size (identical in PATMA.mac!!)
+; PATM stack size (identical in PATMA.h!!)
 %define PATM_STACK_SIZE                    (4096)
-%define PATM_STACK_TOTAL_SIZE              (2*PATM_STACK_SIZE)
+%define PATM_STACK_TOTAL_SIZE              (2 * PATM_STACK_SIZE)
+%define PATM_MAX_STACK                     (PATM_STACK_SIZE / RTRCPTR_CB)
 
-;/* Patch Manager pending actions (in GCSTATE). */
+;; @name Patch Manager pending actions (in GCSTATE).
+;; @{
 %define PATM_ACTION_LOOKUP_ADDRESS              1
 %define PATM_ACTION_DISPATCH_PENDING_IRQ        2
@@ -92,12 +97,46 @@
 %define PATM_ACTION_LOG_CALL                    13
 %define PATM_ACTION_LOG_GATE_ENTRY              14
+;; @}
 
-;/* Magic dword found in ecx for patm pending actions. */
-%define PATM_ACTION_MAGIC          0xABCD4321
+;; Magic dword found in ecx for patm pending actions.
+%define PATM_ACTION_MAGIC                       0xABCD4321
 
+;; @name PATM_TEMP_RESTORE_FLAGS
+;; @{
 %define PATM_RESTORE_EAX                        RT_BIT(0)
 %define PATM_RESTORE_ECX                        RT_BIT(1)
 %define PATM_RESTORE_EDI                        RT_BIT(2)
+;; @}
 
+
+;;
+; Relocation entry for PATCHASMRECORD.
+;
+struc PATCHASMRELOC
+    ;; The relocation type.
+    .uType              resd 1
+    ;; Additional information specific to the relocation type.
+    .uCode              resd 1
+endstruc
+
+;;
+; Assembly patch descriptor record.
+;
+struc PATCHASMRECORD
+    ;; Pointer to the patch code.
+    .pbFunction         RTCCPTR_RES 1
+    ;; Offset of the jump table?
+    .offJump            resd 1
+    ;; Used only by loop/loopz/loopnz. 
+    .offRelJump         resd 1        
+    ;; Size override byte position.
+    .offSizeOverride    resd 1        
+    ;; The size of the patch function.
+    .cbFunction         resd 1
+    ;; The number of relocations in aRelocs.
+    .cRelocs            resd 1
+    ;; Variable sized relocation table. (put after the iend, so no included)
+    ;.aRelocs            resb PATCHASMRELOC_size
+endstruc
 
 ;/* For indirect calls/jump (identical in PATMA.h & PATMA.mac!) */
Index: /trunk/src/VBox/VMM/VMMR3/PATMPatch.cpp
===================================================================
--- /trunk/src/VBox/VMM/VMMR3/PATMPatch.cpp	(revision 54685)
+++ /trunk/src/VBox/VMM/VMMR3/PATMPatch.cpp	(revision 54686)
@@ -117,30 +117,31 @@
 
 
-static uint32_t patmPatchGenCode(PVM pVM, PPATCHINFO pPatch, uint8_t *pPB, PPATCHASMRECORD pAsmRecord, RCPTRTYPE(uint8_t *) pReturnAddrGC, bool fGenJump,
+static uint32_t patmPatchGenCode(PVM pVM, PPATCHINFO pPatch, uint8_t *pPB, PCPATCHASMRECORD pAsmRecord,
+                                 RCPTRTYPE(uint8_t *) pReturnAddrGC, bool fGenJump,
                                  PPATMCALLINFO pCallInfo = 0)
 {
-    uint32_t i, j;
-
     Assert(fGenJump == false || pReturnAddrGC);
     Assert(fGenJump == false || pAsmRecord->offJump);
-    Assert(pAsmRecord && pAsmRecord->size > sizeof(pAsmRecord->uReloc[0]));
+    Assert(pAsmRecord);
+    Assert(pAsmRecord->cbFunction > sizeof(pAsmRecord->aRelocs[0].uType) * pAsmRecord->cRelocs);
 
     // Copy the code block
-    memcpy(pPB, pAsmRecord->pFunction, pAsmRecord->size);
+    memcpy(pPB, pAsmRecord->pbFunction, pAsmRecord->cbFunction);
 
     // Process all fixups
-    for (j=0,i=0;i<pAsmRecord->nrRelocs*2; i+=2)
-    {
-        for (;j<pAsmRecord->size;j++)
+    uint32_t i, j;
+    for (j = 0, i = 0; i < pAsmRecord->cRelocs; i++)
+    {
+        for (; j < pAsmRecord->cbFunction; j++)
         {
-            if (*(uint32_t*)&pPB[j] == pAsmRecord->uReloc[i])
+            if (*(uint32_t*)&pPB[j] == pAsmRecord->aRelocs[i].uType)
             {
                 RCPTRTYPE(uint32_t *) dest;
 
 #ifdef VBOX_STRICT
-                if (pAsmRecord->uReloc[i] == PATM_FIXUP)
-                    Assert(pAsmRecord->uReloc[i+1] != 0);
+                if (pAsmRecord->aRelocs[i].uType == PATM_FIXUP)
+                    Assert(pAsmRecord->aRelocs[i].uInfo != 0);
                 else
-                    Assert(pAsmRecord->uReloc[i+1] == 0);
+                    Assert(pAsmRecord->aRelocs[i].uInfo == 0);
 #endif
 
@@ -149,5 +150,5 @@
                  * A DIFFERENT HYPERVISOR LAYOUT.
                  */
-                switch (pAsmRecord->uReloc[i])
+                switch (pAsmRecord->aRelocs[i].uType)
                 {
                 case PATM_VMFLAGS:
@@ -160,6 +161,7 @@
 
                 case PATM_FIXUP:
-                    /* Offset in uReloc[i+1] is from the base of the function. */
-                    dest = (RTGCUINTPTR32)pVM->patm.s.pPatchMemGC + pAsmRecord->uReloc[i+1] + (RTGCUINTPTR32)(pPB - pVM->patm.s.pPatchMemHC);
+                    /* Offset in aRelocs[i].uInfo is from the base of the function. */
+                    dest = (RTGCUINTPTR32)pVM->patm.s.pPatchMemGC + pAsmRecord->aRelocs[i].uInfo
+                         + (RTGCUINTPTR32)(pPB - pVM->patm.s.pPatchMemHC);
                     break;
 #ifdef VBOX_WITH_STATISTICS
@@ -200,17 +202,17 @@
 
                 case PATM_RETURNADDR:   /* absolute guest address; no fixup required */
-                    Assert(pCallInfo && pAsmRecord->uReloc[i] >= PATM_NO_FIXUP);
+                    Assert(pCallInfo && pAsmRecord->aRelocs[i].uType >= PATM_NO_FIXUP);
                     dest = pCallInfo->pReturnGC;
                     break;
 
                 case PATM_PATCHNEXTBLOCK:  /* relative address of instruction following this block */
-                    Assert(pCallInfo && pAsmRecord->uReloc[i] >= PATM_NO_FIXUP);
+                    Assert(pCallInfo && pAsmRecord->aRelocs[i].uType >= PATM_NO_FIXUP);
 
                     /** @note hardcoded assumption that we must return to the instruction following this block */
-                    dest = (uintptr_t)pPB - (uintptr_t)pVM->patm.s.pPatchMemHC + pAsmRecord->size;
+                    dest = (uintptr_t)pPB - (uintptr_t)pVM->patm.s.pPatchMemHC + pAsmRecord->cbFunction;
                     break;
 
                 case PATM_CALLTARGET:   /* relative to patch address; no fixup required */
-                    Assert(pCallInfo && pAsmRecord->uReloc[i] >= PATM_NO_FIXUP);
+                    Assert(pCallInfo && pAsmRecord->aRelocs[i].uType >= PATM_NO_FIXUP);
 
                     /* Address must be filled in later. (see patmr3SetBranchTargets)  */
@@ -224,20 +226,20 @@
 
                 case PATM_CPUID_STD_PTR:
-                    /* @todo dirty hack when correcting this fixup (state restore) */
+                    /** @todo dirty hack when correcting this fixup (state restore) */
                     dest = CPUMR3GetGuestCpuIdPatmStdRCPtr(pVM);
                     break;
 
                 case PATM_CPUID_EXT_PTR:
-                    /* @todo dirty hack when correcting this fixup (state restore) */
+                    /** @todo dirty hack when correcting this fixup (state restore) */
                     dest = CPUMR3GetGuestCpuIdPatmExtRCPtr(pVM);
                     break;
 
                 case PATM_CPUID_CENTAUR_PTR:
-                    /* @todo dirty hack when correcting this fixup (state restore) */
+                    /** @todo dirty hack when correcting this fixup (state restore) */
                     dest = CPUMR3GetGuestCpuIdPatmCentaurRCPtr(pVM);
                     break;
 
                 case PATM_CPUID_DEF_PTR:
-                    /* @todo dirty hack when correcting this fixup (state restore) */
+                    /** @todo dirty hack when correcting this fixup (state restore) */
                     dest = CPUMR3GetGuestCpuIdPatmDefRCPtr(pVM);
                     break;
@@ -353,5 +355,5 @@
 
                 *(RTRCPTR *)&pPB[j] = dest;
-                if (pAsmRecord->uReloc[i] < PATM_NO_FIXUP)
+                if (pAsmRecord->aRelocs[i].uType < PATM_NO_FIXUP)
                 {
                     patmPatchAddReloc32(pVM, pPatch, &pPB[j], FIXUP_ABSOLUTE);
@@ -360,7 +362,7 @@
             }
         }
-        Assert(j < pAsmRecord->size);
-    }
-    Assert(pAsmRecord->uReloc[i] == 0xffffffff);
+        Assert(j < pAsmRecord->cbFunction);
+    }
+    Assert(pAsmRecord->aRelocs[i].uInfo == 0xffffffff);
 
     /* Add the jump back to guest code (if required) */
@@ -381,11 +383,7 @@
     // Calculate the right size of this patch block
     if ((fGenJump && pAsmRecord->offJump) || (!fGenJump && !pAsmRecord->offJump))
-    {
-        return pAsmRecord->size;
-    }
-    else {
-        // if a jump instruction is present and we don't want one, then subtract SIZEOF_NEARJUMP32
-        return pAsmRecord->size - SIZEOF_NEARJUMP32;
-    }
+        return pAsmRecord->cbFunction;
+    // if a jump instruction is present and we don't want one, then subtract SIZEOF_NEARJUMP32
+    return pAsmRecord->cbFunction - SIZEOF_NEARJUMP32;
 }
 
@@ -531,5 +529,5 @@
 {
     uint32_t size = 0;
-    PPATCHASMRECORD pPatchAsmRec;
+    PCPATCHASMRECORD pPatchAsmRec;
 
     PATCHGEN_PROLOG(pVM, pPatch);
Index: /trunk/src/VBox/VMM/VMMR3/PATMR3Dbg.cpp
===================================================================
--- /trunk/src/VBox/VMM/VMMR3/PATMR3Dbg.cpp	(revision 54685)
+++ /trunk/src/VBox/VMM/VMMR3/PATMR3Dbg.cpp	(revision 54686)
@@ -241,8 +241,8 @@
      * Global functions and a start marker.
      */
-    ADD_FUNC(hDbgMod, pVM->patm.s.pPatchMemGC, pVM->patm.s.pfnHelperCallGC, PATMLookupAndCallRecord.size, "PATMLookupAndCall");
-    ADD_FUNC(hDbgMod, pVM->patm.s.pPatchMemGC, pVM->patm.s.pfnHelperRetGC,  PATMRetFunctionRecord.size,   "PATMRetFunction");
-    ADD_FUNC(hDbgMod, pVM->patm.s.pPatchMemGC, pVM->patm.s.pfnHelperJumpGC, PATMLookupAndJumpRecord.size, "PATMLookupAndJump");
-    ADD_FUNC(hDbgMod, pVM->patm.s.pPatchMemGC, pVM->patm.s.pfnHelperIretGC, PATMIretFunctionRecord.size,  "PATMIretFunction");
+    ADD_FUNC(hDbgMod, pVM->patm.s.pPatchMemGC, pVM->patm.s.pfnHelperCallGC, PATMLookupAndCallRecord.cbFunction, "PATMLookupAndCall");
+    ADD_FUNC(hDbgMod, pVM->patm.s.pPatchMemGC, pVM->patm.s.pfnHelperRetGC,  PATMRetFunctionRecord.cbFunction,   "PATMRetFunction");
+    ADD_FUNC(hDbgMod, pVM->patm.s.pPatchMemGC, pVM->patm.s.pfnHelperJumpGC, PATMLookupAndJumpRecord.cbFunction, "PATMLookupAndJump");
+    ADD_FUNC(hDbgMod, pVM->patm.s.pPatchMemGC, pVM->patm.s.pfnHelperIretGC, PATMIretFunctionRecord.cbFunction,  "PATMIretFunction");
 
     ADD_FUNC(hDbgMod, pVM->patm.s.pPatchMemGC, pVM->patm.s.pPatchMemGC, 0,  "PatchMemStart");
Index: /trunk/src/VBox/VMM/include/PATMA.h
===================================================================
--- /trunk/src/VBox/VMM/include/PATMA.h	(revision 54685)
+++ /trunk/src/VBox/VMM/include/PATMA.h	(revision 54686)
@@ -1,9 +1,9 @@
 /* $Id$ */
 /** @file
- * PATM macros & definitions (identical to PATMA.mac!!)
+ * PATM macros & definitions (identical to PATMA.mac!).
  */
 
 /*
- * Copyright (C) 2006-2012 Oracle Corporation
+ * Copyright (C) 2006-2015 Oracle Corporation
  *
  * This file is part of VirtualBox Open Source Edition (OSE), as
@@ -19,15 +19,16 @@
 #define ___PATMA_H
 
-
+/** @name Patch Fixup Types
+ * @{ */
 #define PATM_VMFLAGS                            0xF1ABCD00
 #ifdef VBOX_WITH_STATISTICS
-#define PATM_ALLPATCHCALLS                      0xF1ABCD01
-#define PATM_PERPATCHCALLS                      0xF1ABCD02
+# define PATM_ALLPATCHCALLS                     0xF1ABCD01
+# define PATM_PERPATCHCALLS                     0xF1ABCD02
 #endif
 #define PATM_JUMPDELTA                          0xF1ABCD03
 #ifdef VBOX_WITH_STATISTICS
-#define PATM_IRETEFLAGS                         0xF1ABCD04
-#define PATM_IRETCS                             0xF1ABCD05
-#define PATM_IRETEIP                            0xF1ABCD06
+# define PATM_IRETEFLAGS                        0xF1ABCD04
+# define PATM_IRETCS                            0xF1ABCD05
+# define PATM_IRETEIP                           0xF1ABCD06
 #endif
 #define PATM_FIXUP                              0xF1ABCD07
@@ -36,6 +37,6 @@
 #define PATM_CPUID_EXT_PTR                      0xF1ABCD0a
 #define PATM_CPUID_DEF_PTR                      0xF1ABCD0b
-#define PATM_STACKBASE                          0xF1ABCD0c    /** Stack to store our private patch return addresses */
-#define PATM_STACKBASE_GUEST                    0xF1ABCD0d    /** Stack to store guest return addresses */
+#define PATM_STACKBASE                          0xF1ABCD0c  /**< Stack to store our private patch return addresses */
+#define PATM_STACKBASE_GUEST                    0xF1ABCD0d  /**< Stack to store guest return addresses */
 #define PATM_STACKPTR                           0xF1ABCD0e
 #define PATM_PATCHBASE                          0xF1ABCD0f
@@ -43,9 +44,9 @@
 #define PATM_INHIBITIRQADDR                     0xF1ABCD11
 #define PATM_VM_FORCEDACTIONS                   0xF1ABCD12
-#define PATM_TEMP_EAX                           0xF1ABCD13      /** Location for original EAX register */
-#define PATM_TEMP_ECX                           0xF1ABCD14      /** Location for original ECX register */
-#define PATM_TEMP_EDI                           0xF1ABCD15      /** Location for original EDI register */
-#define PATM_TEMP_EFLAGS                        0xF1ABCD16      /** Location for original eflags */
-#define PATM_TEMP_RESTORE_FLAGS                 0xF1ABCD17      /** Which registers to restore */
+#define PATM_TEMP_EAX                           0xF1ABCD13  /**< Location for original EAX register */
+#define PATM_TEMP_ECX                           0xF1ABCD14  /**< Location for original ECX register */
+#define PATM_TEMP_EDI                           0xF1ABCD15  /**< Location for original EDI register */
+#define PATM_TEMP_EFLAGS                        0xF1ABCD16  /**< Location for original eflags */
+#define PATM_TEMP_RESTORE_FLAGS                 0xF1ABCD17  /**< Which registers to restore */
 #define PATM_CALL_PATCH_TARGET_ADDR             0xF1ABCD18
 #define PATM_CALL_RETURN_ADDR                   0xF1ABCD19
@@ -58,25 +59,29 @@
 #define PATM_RETURNADDR                         0xF1ABCE02
 #define PATM_PATCHNEXTBLOCK                     0xF1ABCE03
-#define PATM_CALLTARGET                         0xF1ABCE04    /** relative call target */
-#define PATM_NEXTINSTRADDR                      0xF1ABCE05    /** absolute guest address of the next instruction */
-#define PATM_CURINSTRADDR                       0xF1ABCE06    /** absolute guest address of the current instruction */
-#define PATM_LOOKUP_AND_CALL_FUNCTION           0xF1ABCE07    /** Relative address of global PATM lookup and call function. */
-#define PATM_RETURN_FUNCTION                    0xF1ABCE08    /** Relative address of global PATM return function. */
-#define PATM_LOOKUP_AND_JUMP_FUNCTION           0xF1ABCE09    /** Relative address of global PATM lookup and jump function. */
-#define PATM_IRET_FUNCTION                      0xF1ABCE0A    /** Relative address of global PATM iret function. */
+#define PATM_CALLTARGET                         0xF1ABCE04  /**< relative call target */
+#define PATM_NEXTINSTRADDR                      0xF1ABCE05  /**< absolute guest address of the next instruction */
+#define PATM_CURINSTRADDR                       0xF1ABCE06  /**< absolute guest address of the current instruction */
+#define PATM_LOOKUP_AND_CALL_FUNCTION           0xF1ABCE07  /**< Relative address of global PATM lookup and call function. */
+#define PATM_RETURN_FUNCTION                    0xF1ABCE08  /**< Relative address of global PATM return function. */
+#define PATM_LOOKUP_AND_JUMP_FUNCTION           0xF1ABCE09  /**< Relative address of global PATM lookup and jump function. */
+#define PATM_IRET_FUNCTION                      0xF1ABCE0A  /**< Relative address of global PATM iret function. */
 #define PATM_CPUID_CENTAUR_MAX                  0xF1ABCE0B
-
-// everything except IOPL, NT, IF, VM, VIF, VIP and RF
-#define PATM_FLAGS_MASK                         (X86_EFL_CF|X86_EFL_PF|X86_EFL_AF|X86_EFL_ZF|X86_EFL_SF|X86_EFL_TF|X86_EFL_DF|X86_EFL_OF|X86_EFL_AC|X86_EFL_ID)
-
-// currently only IF & IOPL
-#define PATM_VIRTUAL_FLAGS_MASK                 (X86_EFL_IF|X86_EFL_IOPL)
+/** @} */
+
+
+/** Everything except IOPL, NT, IF, VM, VIF, VIP and RF */
+#define PATM_FLAGS_MASK                         (  X86_EFL_CF | X86_EFL_PF | X86_EFL_AF | X86_EFL_ZF | X86_EFL_SF \
+                                                 | X86_EFL_TF | X86_EFL_DF | X86_EFL_OF | X86_EFL_AC | X86_EFL_ID)
+
+/** Flags that PATM virtualizes. Currently only IF & IOPL. */
+#define PATM_VIRTUAL_FLAGS_MASK                 (X86_EFL_IF | X86_EFL_IOPL)
 
 /* PATM stack size (identical in PATMA.mac!!) */
-#define PATM_STACK_SIZE                         (PAGE_SIZE)
-#define PATM_STACK_TOTAL_SIZE                   (2*PATM_STACK_SIZE)
+#define PATM_STACK_SIZE                         (4096)
+#define PATM_STACK_TOTAL_SIZE                   (2 * PATM_STACK_SIZE)
 #define PATM_MAX_STACK                          (PATM_STACK_SIZE/sizeof(RTRCPTR))
 
-/* Patch Manager pending actions (in GCSTATE). */
+/** @name Patch Manager pending actions (in GCSTATE).
+ * @{  */
 #define PATM_ACTION_LOOKUP_ADDRESS              1
 #define PATM_ACTION_DISPATCH_PENDING_IRQ        2
@@ -93,23 +98,49 @@
 #define PATM_ACTION_LOG_CALL                    13
 #define PATM_ACTION_LOG_GATE_ENTRY              14
-
-/* Magic dword found in ecx for patm pending actions. */
+/** @} */
+
+/** Magic dword found in ecx for patm pending actions. */
 #define PATM_ACTION_MAGIC                       0xABCD4321
 
-/** PATM_TEMP_RESTORE_FLAGS */
+/** @name PATM_TEMP_RESTORE_FLAGS
+ * @{ */
 #define PATM_RESTORE_EAX                        RT_BIT(0)
 #define PATM_RESTORE_ECX                        RT_BIT(1)
 #define PATM_RESTORE_EDI                        RT_BIT(2)
-
+/** @} */
+
+/** Relocation entry for PATCHASMRECORD. */
+typedef struct PATCHASMRELOC
+{
+    /** The relocation type. */
+    uint32_t uType;
+    /** Additional information specific to the relocation type. */
+    uint32_t uInfo;
+} PATCHASMRELOC;
+typedef PATCHASMRELOC const *PCPATCHASMRELOC;
+
+/**
+ * Assembly patch descriptor record.
+ */
 typedef struct
 {
-    uint8_t *pFunction;
-    uint32_t offJump;
-    uint32_t offRelJump;        //used only by loop/loopz/loopnz
-    uint32_t offSizeOverride;   //size override byte position
-    uint32_t size;
-    uint32_t nrRelocs;
-    uint32_t uReloc[1];
-} PATCHASMRECORD, *PPATCHASMRECORD;
+    /** Pointer to the patch code. */
+    uint8_t        *pbFunction;
+    /** Offset of the jump table? */
+    uint32_t        offJump;
+    /** Used only by loop/loopz/loopnz. */
+    uint32_t        offRelJump;
+    /** Size override byte position. */
+    uint32_t        offSizeOverride;
+    /** The size of the patch function. */
+    uint32_t        cbFunction;
+    /** The number of relocations in aRelocs. */
+    uint32_t        cRelocs;
+    /** Variable sized relocation table. */
+    PATCHASMRELOC   aRelocs[1];
+} PATCHASMRECORD;
+/** Pointer to a const patch descriptor record. */
+typedef PATCHASMRECORD const *PCPATCHASMRECORD;
+
 
 /* For indirect calls/jump (identical in PATMA.h & PATMA.mac!) */
@@ -137,4 +168,6 @@
 RT_C_DECLS_BEGIN
 
+/** @name Patch Descriptor Records (in PATMA.asm)
+ * @{ */
 extern PATCHASMRECORD PATMCliRecord;
 extern PATCHASMRECORD PATMStiRecord;
@@ -181,4 +214,5 @@
 
 extern PATCHASMRECORD PATMMovFromSSRecord;
+/** @} */
 
 extern const uint32_t PATMInterruptFlag;
