Index: /trunk/include/VBox/HGSMI/HGSMI.h
===================================================================
--- /trunk/include/VBox/HGSMI/HGSMI.h	(revision 55420)
+++ /trunk/include/VBox/HGSMI/HGSMI.h	(revision 55421)
@@ -72,22 +72,9 @@
  */
 
-/* Heap types. */
-#define HGSMI_HEAP_TYPE_NULL    0 /* Heap not initialized. */
-#define HGSMI_HEAP_TYPE_POINTER 1 /* Deprecated. RTHEAPSIMPLE. */
-#define HGSMI_HEAP_TYPE_OFFSET  2 /* Deprecated. RTHEAPOFFSET. */
-#define HGSMI_HEAP_TYPE_MA      3 /* Memory allocator. */
-
 #pragma pack(1)
 typedef struct HGSMIHEAP
 {
-    union
-    {
-        HGSMIMADATA   ma;           /* Memory Allocator */
-        RTHEAPSIMPLE  hPtr;         /* Pointer based heap. */
-        RTHEAPOFFSET  hOff;         /* Offset based heap. */
-    } u;
-    HGSMIAREA     area;             /* Description. */
-    int           cRefs;            /* Number of heap allocations. */
-    uint32_t      u32HeapType;      /* HGSMI_HEAP_TYPE_* */
+    HGSMIAREA area; /* Description. */
+    HGSMIMADATA ma; /* Memory allocator */
 } HGSMIHEAP;
 #pragma pack()
@@ -180,11 +167,16 @@
 }
 
-DECLINLINE(uint8_t *) HGSMIBufferDataFromOffset (const HGSMIAREA *pArea, HGSMIOFFSET offBuffer)
-{
-    HGSMIBUFFERHEADER *pHeader = (HGSMIBUFFERHEADER *)HGSMIOffsetToPointer(pArea, offBuffer);
-    Assert(pHeader);
-    if(pHeader)
-        return HGSMIBufferData(pHeader);
-    return NULL;
+DECLINLINE(uint8_t *) HGSMIBufferDataFromOffset(const HGSMIAREA *pArea,
+                                                HGSMIOFFSET offBuffer)
+{
+    void *pvBuffer = HGSMIOffsetToPointer(pArea, offBuffer);
+    return HGSMIBufferDataFromPtr(pvBuffer);
+}
+
+DECLINLINE(HGSMIOFFSET) HGSMIBufferOffsetFromData(const HGSMIAREA *pArea,
+                                                  void *pvData)
+{
+    HGSMIBUFFERHEADER *pHeader = HGSMIBufferHeaderFromData(pvData);
+    return HGSMIPointerToOffset(pArea, pHeader);
 }
 
@@ -228,6 +220,10 @@
                                          uint16_t u16ChannelInfo);
 
+DECLINLINE(const HGSMIAREA *) HGSMIHeapArea(HGSMIHEAP *pHeap)
+{
+    return &pHeap->area;
+}
+
 int HGSMIHeapSetup (HGSMIHEAP *pHeap,
-                    uint32_t u32HeapType,
                     void *pvBase,
                     HGSMISIZE cbArea,
@@ -235,23 +231,4 @@
                     const HGSMIENV *pEnv);
 
-int HGSMIHeapRelocate (HGSMIHEAP *pHeap,
-                       uint32_t u32HeapType,
-                       void *pvBase,
-                       uint32_t offHeapHandle,
-                       uintptr_t offDelta,
-                       HGSMISIZE cbArea,
-                       HGSMIOFFSET offBase);
-
-int HGSMIHeapRestoreMA(HGSMIHEAP *pHeap,
-                       void *pvBase,
-                       HGSMISIZE cbArea,
-                       HGSMIOFFSET offBase,
-                       uint32_t cBlocks,
-                       HGSMIOFFSET *paDescriptors,
-                       HGSMISIZE cbMaxBlock,
-                       HGSMIENV *pEnv);
-
-void HGSMIHeapSetupUninitialized (HGSMIHEAP *pHeap);
-
 void HGSMIHeapDestroy (HGSMIHEAP *pHeap);
 
@@ -267,6 +244,8 @@
                       uint16_t u16ChannelInfo);
 
-HGSMIOFFSET HGSMIHeapBufferOffset (HGSMIHEAP *pHeap,
-                                   void *pvData);
+DECLINLINE(HGSMIOFFSET) HGSMIHeapBufferOffset(HGSMIHEAP *pHeap, void *pvData)
+{
+    return HGSMIBufferOffsetFromData(HGSMIHeapArea(pHeap), pvData);
+}
 
 void HGSMIHeapFree (HGSMIHEAP *pHeap,
@@ -275,31 +254,10 @@
 DECLINLINE(HGSMIOFFSET) HGSMIHeapOffset(HGSMIHEAP *pHeap)
 {
-    return pHeap->area.offBase;
-}
-
-#ifdef IN_RING3
-/* Needed for heap relocation: offset of the heap handle relative to the start of heap area. */
-DECLINLINE(HGSMIOFFSET) HGSMIHeapHandleLocationOffset(HGSMIHEAP *pHeap)
-{
-    HGSMIOFFSET offHeapHandle;
-    if (pHeap->u32HeapType == HGSMI_HEAP_TYPE_POINTER)
-    {
-        offHeapHandle = (HGSMIOFFSET)((uintptr_t)pHeap->u.hPtr - (uintptr_t)pHeap->area.pu8Base);
-    }
-    else if (pHeap->u32HeapType == HGSMI_HEAP_TYPE_OFFSET)
-    {
-        offHeapHandle = (HGSMIOFFSET)((uintptr_t)pHeap->u.hOff - (uintptr_t)pHeap->area.pu8Base);
-    }
-    else
-    {
-        offHeapHandle = HGSMIOFFSET_VOID;
-    }
-    return offHeapHandle;
-}
-#endif /* IN_RING3 */
+    return HGSMIHeapArea(pHeap)->offBase;
+}
 
 DECLINLINE(HGSMISIZE) HGSMIHeapSize(HGSMIHEAP *pHeap)
 {
-    return pHeap->area.cbArea;
+    return HGSMIHeapArea(pHeap)->cbArea;
 }
 
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/xpdm/VBoxDispVBVA.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/xpdm/VBoxDispVBVA.cpp	(revision 55420)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/xpdm/VBoxDispVBVA.cpp	(revision 55421)
@@ -425,5 +425,4 @@
 
         rc = HGSMIHeapSetup(&pDev->hgsmi.ctx.heapCtx,
-                            HGSMI_HEAP_TYPE_MA,
                             (uint8_t *)pDev->memInfo.VideoRamBase+pDev->layout.offDisplayInfo+sizeof(HGSMIHOSTFLAGS),
                             pDev->layout.cbDisplayInfo-sizeof(HGSMIHOSTFLAGS),
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPShgsmi.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPShgsmi.cpp	(revision 55420)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPShgsmi.cpp	(revision 55421)
@@ -186,9 +186,9 @@
 }
 
-int VBoxSHGSMIInit(PVBOXSHGSMI pHeap, uint32_t u32HeapType, void *pvBase, HGSMISIZE cbArea, HGSMIOFFSET offBase,
+int VBoxSHGSMIInit(PVBOXSHGSMI pHeap, void *pvBase, HGSMISIZE cbArea, HGSMIOFFSET offBase,
                    const HGSMIENV *pEnv)
 {
     KeInitializeSpinLock(&pHeap->HeapLock);
-    return HGSMIHeapSetup(&pHeap->Heap, u32HeapType, pvBase, cbArea, offBase, pEnv);
+    return HGSMIHeapSetup(&pHeap->Heap, pvBase, cbArea, offBase, pEnv);
 }
 
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPShgsmi.h
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPShgsmi.h	(revision 55420)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPShgsmi.h	(revision 55421)
@@ -60,5 +60,5 @@
 }
 
-int VBoxSHGSMIInit(PVBOXSHGSMI pHeap, uint32_t u32HeapType, void *pvBase, HGSMISIZE cbArea, HGSMIOFFSET offBase, const HGSMIENV *pEnv);
+int VBoxSHGSMIInit(PVBOXSHGSMI pHeap, void *pvBase, HGSMISIZE cbArea, HGSMIOFFSET offBase, const HGSMIENV *pEnv);
 void VBoxSHGSMITerm(PVBOXSHGSMI pHeap);
 void* VBoxSHGSMIHeapAlloc(PVBOXSHGSMI pHeap, HGSMISIZE cbData, uint8_t u8Channel, uint16_t u16ChannelInfo);
Index: /trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPVdma.cpp
===================================================================
--- /trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPVdma.cpp	(revision 55420)
+++ /trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPVdma.cpp	(revision 55421)
@@ -1628,5 +1628,4 @@
         /* Setup a HGSMI heap within the adapter information area. */
         rc = VBoxSHGSMIInit(&pInfo->CmdHeap,
-                             HGSMI_HEAP_TYPE_MA,
                              pvBuffer,
                              cbBuffer,
Index: /trunk/src/VBox/Additions/common/VBoxVideo/HGSMIBase.cpp
===================================================================
--- /trunk/src/VBox/Additions/common/VBoxVideo/HGSMIBase.cpp	(revision 55420)
+++ /trunk/src/VBox/Additions/common/VBoxVideo/HGSMIBase.cpp	(revision 55421)
@@ -341,8 +341,8 @@
     pCtx->port = (RTIOPORT)VGA_PORT_HGSMI_GUEST;
 #ifdef VBOX_WDDM_MINIPORT
-    return VBoxSHGSMIInit(&pCtx->heapCtx, HGSMI_HEAP_TYPE_MA, pvGuestHeapMemory,
+    return VBoxSHGSMIInit(&pCtx->heapCtx, pvGuestHeapMemory,
                           cbGuestHeapMemory, offVRAMGuestHeapMemory, pEnv);
 #else
-    return HGSMIHeapSetup(&pCtx->heapCtx, HGSMI_HEAP_TYPE_MA, pvGuestHeapMemory,
+    return HGSMIHeapSetup(&pCtx->heapCtx, pvGuestHeapMemory,
                           cbGuestHeapMemory, offVRAMGuestHeapMemory, pEnv);
 #endif
Index: /trunk/src/VBox/Devices/Graphics/DevVGA_VBVA.cpp
===================================================================
--- /trunk/src/VBox/Devices/Graphics/DevVGA_VBVA.cpp	(revision 55420)
+++ /trunk/src/VBox/Devices/Graphics/DevVGA_VBVA.cpp	(revision 55421)
@@ -2273,5 +2273,5 @@
                          pHeap->u32HeapOffset, pHeap->u32HeapSize));
 
-            rc = HGSMISetupHostHeap (pIns, pHeap->u32HeapOffset, pHeap->u32HeapSize);
+            rc = HGSMIHostHeapSetup(pIns, pHeap->u32HeapOffset, pHeap->u32HeapSize);
         } break;
 
Index: /trunk/src/VBox/Devices/Graphics/HGSMI/HGSMIHost.cpp
===================================================================
--- /trunk/src/VBox/Devices/Graphics/HGSMI/HGSMIHost.cpp	(revision 55420)
+++ /trunk/src/VBox/Devices/Graphics/HGSMI/HGSMIHost.cpp	(revision 55421)
@@ -67,5 +67,5 @@
 
 #include <VBox/err.h>
-#define LOG_GROUP LOG_GROUP_DEV_VGA
+#define LOG_GROUP LOG_GROUP_HGSMI
 #include <VBox/log.h>
 #include <VBox/vmm/ssm.h>
@@ -133,4 +133,29 @@
 
 
+/* Host heap types. */
+#define HGSMI_HEAP_TYPE_NULL    0 /* Heap not initialized. */
+#define HGSMI_HEAP_TYPE_POINTER 1 /* Deprecated, used only for old saved states. RTHEAPSIMPLE. */
+#define HGSMI_HEAP_TYPE_OFFSET  2 /* Deprecated, used only for old saved states. RTHEAPOFFSET. */
+#define HGSMI_HEAP_TYPE_MA      3 /* Memory allocator. */
+
+typedef struct HGSMIHOSTHEAP
+{
+    uint32_t u32HeapType;   /* HGSMI_HEAP_TYPE_* */
+    int32_t volatile cRefs; /* How many blocks allocated. */
+    HGSMIAREA area;         /* Host heap location. */
+    union
+    {
+        HGSMIMADATA ma;     /* Memory allocator for the default host heap implementation. */
+        struct              /* Legacy heap implementations. For old saved states. */
+        {
+            union
+            {
+                RTHEAPSIMPLE hPtr;  /* Pointer based heap. */
+                RTHEAPOFFSET hOff;  /* Offset based heap. */
+            } u;
+        } legacy;
+    } u;
+} HGSMIHOSTHEAP;
+
 typedef struct HGSMIINSTANCE
 {
@@ -142,5 +167,5 @@
 
     HGSMIAREA area; /* The shared memory description. */
-    HGSMIHEAP hostHeap;                /* Host heap instance. */
+    HGSMIHOSTHEAP hostHeap;            /* Host heap instance. */
     RTCRITSECT    hostHeapCritSect;    /* Heap serialization lock. */
 
@@ -182,5 +207,6 @@
     volatile uint32_t fl;              /* Status flags of the entry. */
 
-    HGSMIOFFSET offBuffer;             /* Offset in the memory region of the entry data. */
+    HGSMIOFFSET offBuffer;             /* Offset of the HGSMI buffer header in the HGSMI host heap:
+                                        * [pIns->hostHeap.area.offBase .. offLast]. */
 
 #if 0
@@ -510,4 +536,180 @@
 }
 
+static HGSMIOFFSET hgsmiHostHeapOffset(HGSMIHOSTHEAP *pHeap)
+{
+    return pHeap->area.offBase;
+}
+
+static HGSMISIZE hgsmiHostHeapSize(HGSMIHOSTHEAP *pHeap)
+{
+    return pHeap->area.cbArea;
+}
+
+static void *hgsmiHostHeapBufferAlloc(HGSMIHOSTHEAP *pHeap,
+                                      HGSMISIZE cbBuffer)
+{
+    void *pvBuf = NULL;
+
+    if (pHeap->u32HeapType == HGSMI_HEAP_TYPE_MA)
+    {
+        pvBuf = HGSMIMAAlloc(&pHeap->u.ma, cbBuffer);
+    }
+    else if (pHeap->u32HeapType == HGSMI_HEAP_TYPE_POINTER)
+    {
+        pvBuf = RTHeapSimpleAlloc(pHeap->u.legacy.u.hPtr, cbBuffer, 0);
+    }
+    else if (pHeap->u32HeapType == HGSMI_HEAP_TYPE_OFFSET)
+    {
+        pvBuf = RTHeapOffsetAlloc(pHeap->u.legacy.u.hOff, cbBuffer, 0);
+    }
+
+    if (pvBuf)
+    {
+        ++pHeap->cRefs;
+    }
+
+    return pvBuf;
+}
+
+static void hgsmiHostHeapBufferFree(HGSMIHOSTHEAP *pHeap,
+                                    void *pvBuf)
+{
+    if (pHeap->u32HeapType == HGSMI_HEAP_TYPE_MA)
+    {
+        HGSMIMAFree(&pHeap->u.ma, pvBuf);
+    }
+    else if (pHeap->u32HeapType == HGSMI_HEAP_TYPE_POINTER)
+    {
+        RTHeapSimpleFree(pHeap->u.legacy.u.hPtr, pvBuf);
+    }
+    else if (pHeap->u32HeapType == HGSMI_HEAP_TYPE_OFFSET)
+    {
+        RTHeapOffsetFree(pHeap->u.legacy.u.hOff, pvBuf);
+    }
+    --pHeap->cRefs;
+}
+
+static void *hgsmiHostHeapDataAlloc(HGSMIHOSTHEAP *pHeap,
+                                    HGSMISIZE cbData,
+                                    uint8_t u8Channel,
+                                    uint16_t u16ChannelInfo)
+{
+    HGSMISIZE cbAlloc = HGSMIBufferRequiredSize(cbData);
+    HGSMIBUFFERHEADER *pHeader = (HGSMIBUFFERHEADER *)hgsmiHostHeapBufferAlloc(pHeap, cbAlloc);
+    if (!pHeader)
+        return NULL;
+
+    HGSMIBufferInitializeSingle(&pHeap->area, pHeader, cbAlloc, u8Channel, u16ChannelInfo);
+
+    return HGSMIBufferDataFromPtr(pHeader);
+}
+
+static void hgsmiHostHeapDataFree(HGSMIHOSTHEAP *pHeap,
+                                  void *pvData)
+{
+    if (   pvData
+        && pHeap->u32HeapType != HGSMI_HEAP_TYPE_NULL)
+    {
+        HGSMIBUFFERHEADER *pHeader = HGSMIBufferHeaderFromData(pvData);
+        hgsmiHostHeapBufferFree(pHeap, pHeader);
+    }
+}
+
+/* Needed for heap relocation: offset of the heap handle relative to the start of heap area. */
+static HGSMIOFFSET hgsmiHostHeapHandleLocationOffset(HGSMIHOSTHEAP *pHeap)
+{
+    HGSMIOFFSET offHeapHandle;
+    if (pHeap->u32HeapType == HGSMI_HEAP_TYPE_POINTER)
+    {
+        offHeapHandle = (HGSMIOFFSET)((uintptr_t)pHeap->u.legacy.u.hPtr - (uintptr_t)pHeap->area.pu8Base);
+    }
+    else if (pHeap->u32HeapType == HGSMI_HEAP_TYPE_OFFSET)
+    {
+        offHeapHandle = (HGSMIOFFSET)((uintptr_t)pHeap->u.legacy.u.hOff - (uintptr_t)pHeap->area.pu8Base);
+    }
+    else
+    {
+        offHeapHandle = HGSMIOFFSET_VOID;
+    }
+    return offHeapHandle;
+}
+
+static int hgsmiHostHeapRelocate(HGSMIHOSTHEAP *pHeap,
+                                 uint32_t u32HeapType,
+                                 void *pvBase,
+                                 uint32_t offHeapHandle,
+                                 uintptr_t offDelta,
+                                 HGSMISIZE cbArea,
+                                 HGSMIOFFSET offBase)
+{
+    int rc = HGSMIAreaInitialize(&pHeap->area, pvBase, cbArea, offBase);
+    if (RT_SUCCESS(rc))
+    {
+        if (u32HeapType == HGSMI_HEAP_TYPE_OFFSET)
+        {
+            pHeap->u.legacy.u.hOff = (RTHEAPOFFSET)((uint8_t *)pvBase + offHeapHandle);
+        }
+        else if (u32HeapType == HGSMI_HEAP_TYPE_POINTER)
+        {
+            pHeap->u.legacy.u.hPtr = (RTHEAPSIMPLE)((uint8_t *)pvBase + offHeapHandle);
+            rc = RTHeapSimpleRelocate(pHeap->u.legacy.u.hPtr, offDelta); AssertRC(rc);
+        }
+        else
+        {
+            /* HGSMI_HEAP_TYPE_MA does not need the relocation. */
+            rc = VERR_NOT_SUPPORTED;
+        }
+
+        if (RT_SUCCESS(rc))
+        {
+            pHeap->u32HeapType = u32HeapType;
+        }
+        else
+        {
+            HGSMIAreaClear(&pHeap->area);
+        }
+    }
+
+    return rc;
+}
+
+static int hgsmiHostHeapRestoreMA(HGSMIHOSTHEAP *pHeap,
+                                  void *pvBase,
+                                  HGSMISIZE cbArea,
+                                  HGSMIOFFSET offBase,
+                                  uint32_t cBlocks,
+                                  HGSMIOFFSET *paDescriptors,
+                                  HGSMISIZE cbMaxBlock,
+                                  HGSMIENV *pEnv)
+{
+    int rc = HGSMIAreaInitialize(&pHeap->area, pvBase, cbArea, offBase);
+    if (RT_SUCCESS(rc))
+    {
+        rc = HGSMIMAInit(&pHeap->u.ma, &pHeap->area, paDescriptors, cBlocks, cbMaxBlock, pEnv);
+
+        if (RT_FAILURE(rc))
+        {
+            HGSMIAreaClear(&pHeap->area);
+        }
+    }
+
+    return rc;
+}
+
+static void hgsmiHostHeapSetupUninitialized(HGSMIHOSTHEAP *pHeap)
+{
+    RT_ZERO(*pHeap);
+    pHeap->u32HeapType = HGSMI_HEAP_TYPE_NULL;
+}
+
+static void hgsmiHostHeapDestroy(HGSMIHOSTHEAP *pHeap)
+{
+    if (pHeap->u32HeapType == HGSMI_HEAP_TYPE_MA)
+    {
+        HGSMIMAUninit(&pHeap->u.ma);
+    }
+    hgsmiHostHeapSetupUninitialized(pHeap);
+}
+
 static int hgsmiHostFIFOAlloc (HGSMIINSTANCE *pIns, HGSMIHOSTFIFOENTRY **ppEntry)
 {
@@ -557,4 +759,6 @@
 static int hgsmiHostCommandFreeByEntry (HGSMIHOSTFIFOENTRY *pEntry)
 {
+    LogFlowFunc(("offBuffer 0x%08X\n", pEntry->offBuffer));
+
     HGSMIINSTANCE *pIns = pEntry->pIns;
     int rc = hgsmiFIFOLock (pIns);
@@ -564,5 +768,5 @@
         hgsmiFIFOUnlock (pIns);
 
-        void *pvMem = HGSMIBufferDataFromOffset(&pIns->area, pEntry->offBuffer);
+        void *pvData = HGSMIBufferDataFromOffset(&pIns->hostHeap.area, pEntry->offBuffer);
 
         rc = hgsmiHostHeapLock (pIns);
@@ -570,5 +774,5 @@
         {
             /* Deallocate the host heap memory. */
-            HGSMIHeapFree (&pIns->hostHeap, pvMem);
+            hgsmiHostHeapDataFree(&pIns->hostHeap, pvData);
 
             hgsmiHostHeapUnlock(pIns);
@@ -577,20 +781,22 @@
         hgsmiHostFIFOFree (pIns, pEntry);
     }
+
+    LogFlowFunc(("%Rrc\n", rc));
     return rc;
 }
 
 static int hgsmiHostCommandFree (HGSMIINSTANCE *pIns,
-                                                void *pvMem)
-{
-    HGSMIOFFSET offMem = HGSMIHeapBufferOffset (&pIns->hostHeap, pvMem);
+                                                void *pvData)
+{
     int rc = VINF_SUCCESS;
-    if (offMem != HGSMIOFFSET_VOID)
-    {
+    if (HGSMIAreaContainsPointer(&pIns->hostHeap.area, pvData))
+    {
+        HGSMIHOSTFIFOENTRY *pEntry = NULL;
+        HGSMIOFFSET offBuffer = HGSMIBufferOffsetFromData(&pIns->hostHeap.area, pvData);
+
         rc = hgsmiFIFOLock (pIns);
         if(RT_SUCCESS(rc))
         {
-            /* Search the Processed list for the given offMem. */
-            HGSMIHOSTFIFOENTRY *pEntry = NULL;
-
+            /* Search the Processed list for the given offBuffer. */
             HGSMIHOSTFIFOENTRY *pIter;
             RTListForEach(&pIns->hostFIFOProcessed, pIter, HGSMIHOSTFIFOENTRY, nodeEntry)
@@ -598,5 +804,5 @@
                 Assert(pIter->fl == (HGSMI_F_HOST_FIFO_ALLOCATED | HGSMI_F_HOST_FIFO_PROCESSED));
 
-                if (pIter->offBuffer == offMem)
+                if (pIter->offBuffer == offBuffer)
                 {
                     pEntry = pIter;
@@ -611,6 +817,6 @@
             else
             {
-                LogRel(("HGSMI[%s]: the host frees unprocessed FIFO entry: 0x%08X\n", pIns->pszName, offMem));
-                AssertFailed ();
+                AssertLogRelMsgFailed(("HGSMI[%s]: the host frees unprocessed FIFO entry: 0x%08X\n",
+                                       pIns->pszName, offBuffer));
             }
 
@@ -621,5 +827,5 @@
             {
                 /* Deallocate the host heap memory. */
-                HGSMIHeapFree (&pIns->hostHeap, pvMem);
+                hgsmiHostHeapDataFree(&pIns->hostHeap, pvData);
 
                 hgsmiHostHeapUnlock(pIns);
@@ -636,7 +842,7 @@
     else
     {
+        AssertLogRelMsgFailed(("HGSMI[%s]: the host frees invalid FIFO entry: %p\n",
+                               pIns->pszName, pvData));
         rc = VERR_INVALID_POINTER;
-        LogRel(("HGSMI[%s]: the host frees invalid FIFO entry: %p\n", pIns->pszName, pvMem));
-        AssertFailed ();
     }
     return rc;
@@ -776,40 +982,44 @@
 #endif
 /**
- * Allocate a shared memory block. The host can write command/data to the memory.
- *
- * @param pIns   Pointer to HGSMI instance,
- * @param ppvMem Where to store the allocated memory pointer to data.
- * @param cbMem  How many bytes of data to allocate.
+ * Allocate a shared memory buffer. The host can write command/data to the memory.
+ * The allocated buffer contains the 'header', 'data' and the 'tail', but *ppvData
+ * will point to the 'data'.
+ *
+ * @return VBox status code. Pointer to the payload data in *ppvData.
+ * @param pIns           HGSMI instance,
+ * @param ppvData        Where to store the allocated memory pointer to data.
+ * @param cbData         How many bytes of data to allocate.
+ * @param u8Channel      HGSMI channel.
+ * @param u16ChannelInfo Command parameter.
  */
 int HGSMIHostCommandAlloc (HGSMIINSTANCE *pIns,
-                           void **ppvMem,
-                           HGSMISIZE cbMem,
+                           void **ppvData,
+                           HGSMISIZE cbData,
                            uint8_t u8Channel,
                            uint16_t u16ChannelInfo)
 {
-    LogFlowFunc (("pIns = %p, cbMem = 0x%08X(%d)\n", pIns, cbMem, cbMem));
+    LogFlowFunc (("pIns = %p, cbData = 0x%08X(%d)\n", pIns, cbData, cbData));
 
     int rc = hgsmiHostHeapLock (pIns);
     if(RT_SUCCESS(rc))
     {
-        void *pvMem = HGSMIHeapAlloc (&pIns->hostHeap,
-                                  cbMem,
-                                  u8Channel,
-                                  u16ChannelInfo);
+        void *pvData = hgsmiHostHeapDataAlloc(&pIns->hostHeap,
+                                              cbData,
+                                              u8Channel,
+                                              u16ChannelInfo);
         hgsmiHostHeapUnlock(pIns);
 
-        if (pvMem)
-        {
-            *ppvMem = pvMem;
+        if (pvData)
+        {
+            *ppvData = pvData;
         }
         else
         {
-            LogRel((0, "HGSMIHeapAlloc: HGSMIHeapAlloc failed\n"));
-            rc = VERR_GENERAL_FAILURE;
-        }
-    }
-
-    LogFlowFunc (("rc = %Rrc, pvMem = %p\n", rc, *ppvMem));
-
+            LogRel(("HGSMI[%s]: host heap allocation failed %dbytes\n", pIns->pszName, cbData));
+            rc = VERR_NO_MEMORY;
+        }
+    }
+
+    LogFlowFunc(("%Rrc, pvData = %p\n", rc, *ppvData));
     return rc;
 }
@@ -819,17 +1029,18 @@
  * and make it freed on completion.
  * The caller does not get notified in any way on command completion,
- * on success return the pvMem buffer can not be used after being passed to this function
- *
- * @param pIns  Pointer to HGSMI instance,
- * @param pvMem The pointer returned by 'HGSMIHostCommandAlloc'.
- * @param bDoIrq specifies whether the guest interrupt should be generated,
- * i.e. in case the command is not urgent(e.g. some guest command completion notification that does not require post-processing)
- * the command could be posted without raising an irq.
+ * on successful return the pvData buffer can not be used after being passed to this function.
+ *
+ * @param pIns   HGSMI instance,
+ * @param pvData The pointer returned by 'HGSMIHostCommandAlloc'.
+ * @param bDoIrq Specifies whether the guest interrupt should be generated.
+ *               In case the command is not urgent (e.g. some guest command
+ *               completion notification that does not require post-processing)
+ *               the command could be posted without raising an irq.
  */
 int HGSMIHostCommandProcessAndFreeAsynch (PHGSMIINSTANCE pIns,
-                             void *pvMem,
+                             void *pvData,
                              bool bDoIrq)
 {
-    LogFlowFunc(("pIns = %p, pvMem = %p\n", pIns, pvMem));
+    LogFlowFunc(("pIns = %p, pvData = %p\n", pIns, pvData));
 
 #if 0
@@ -837,5 +1048,5 @@
 #endif
 
-    HGSMIOFFSET offBuffer = HGSMIHeapBufferOffset (&pIns->hostHeap, pvMem);
+    HGSMIOFFSET offBuffer = HGSMIBufferOffsetFromData(&pIns->hostHeap.area, pvData);
 
     int rc = hgsmiHostCommandProcess (pIns, offBuffer,
@@ -925,7 +1136,7 @@
 };
 
-int HGSMISetupHostHeap (PHGSMIINSTANCE pIns,
-                        HGSMIOFFSET    offHeap,
-                        HGSMISIZE      cbHeap)
+int HGSMIHostHeapSetup(PHGSMIINSTANCE pIns,
+                       HGSMIOFFSET    offHeap,
+                       HGSMISIZE      cbHeap)
 {
     LogFlowFunc(("pIns %p, offHeap 0x%08X, cbHeap = 0x%08X\n", pIns, offHeap, cbHeap));
@@ -933,13 +1144,15 @@
     int rc = VINF_SUCCESS;
 
-    Assert (pIns);
-
-//    if (   offHeap >= pIns->cbMem
-//        || cbHeap > pIns->cbMem
-//        || offHeap + cbHeap > pIns->cbMem)
-//    {
-//        rc = VERR_INVALID_PARAMETER;
-//    }
-//    else
+    AssertPtrReturn(pIns, VERR_INVALID_PARAMETER);
+
+    if (   offHeap >= pIns->area.cbArea
+        || cbHeap > pIns->area.cbArea
+        || offHeap > pIns->area.cbArea - cbHeap)
+    {
+        AssertLogRelMsgFailed(("offHeap 0x%08X, cbHeap = 0x%08X, pIns->area.cbArea 0x%08X\n",
+                               offHeap, cbHeap, pIns->area.cbArea));
+        rc = VERR_INVALID_PARAMETER;
+    }
+    else
     {
         rc = hgsmiHostHeapLock (pIns);
@@ -949,5 +1162,6 @@
             if (pIns->hostHeap.cRefs)
             {
-                AssertFailed();
+                AssertLogRelMsgFailed(("HGSMI[%s]: host heap setup ignored. %d allocated.\n",
+                                       pIns->pszName, pIns->hostHeap.cRefs));
                 /* It is possible to change the heap only if there is no pending allocations. */
                 rc = VERR_ACCESS_DENIED;
@@ -955,10 +1169,18 @@
             else
             {
-                rc = HGSMIHeapSetup (&pIns->hostHeap,
-                                     HGSMI_HEAP_TYPE_MA,
-                                     pIns->area.pu8Base+offHeap,
-                                     cbHeap,
-                                     offHeap,
-                                     &g_hgsmiEnv);
+                rc = HGSMIAreaInitialize(&pIns->hostHeap.area, pIns->area.pu8Base + offHeap, cbHeap, offHeap);
+                if (RT_SUCCESS(rc))
+                {
+                    rc = HGSMIMAInit(&pIns->hostHeap.u.ma, &pIns->hostHeap.area, NULL, 0, 0, &g_hgsmiEnv);
+                }
+
+                if (RT_SUCCESS(rc))
+                {
+                    pIns->hostHeap.u32HeapType = HGSMI_HEAP_TYPE_MA;
+                }
+                else
+                {
+                    HGSMIAreaClear(&pIns->hostHeap.area);
+                }
             }
 
@@ -1205,10 +1427,10 @@
     off = pIns->hostHeap.u32HeapType == HGSMI_HEAP_TYPE_MA?
               0:
-              HGSMIHeapHandleLocationOffset(&pIns->hostHeap);
+              hgsmiHostHeapHandleLocationOffset(&pIns->hostHeap);
     rc = SSMR3PutU32 (pSSM, off);
     if(off != HGSMIOFFSET_VOID)
     {
-        SSMR3PutU32 (pSSM, HGSMIHeapOffset(&pIns->hostHeap));
-        SSMR3PutU32 (pSSM, HGSMIHeapSize(&pIns->hostHeap));
+        SSMR3PutU32 (pSSM, hgsmiHostHeapOffset(&pIns->hostHeap));
+        SSMR3PutU32 (pSSM, hgsmiHostHeapSize(&pIns->hostHeap));
         /* need save mem pointer to calculate offset on restore */
         SSMR3PutU64 (pSSM, (uint64_t)(uintptr_t)pIns->area.pu8Base);
@@ -1261,5 +1483,5 @@
     pIns->pHGFlags = (off != HGSMIOFFSET_VOID) ? (HGSMIHOSTFLAGS*)HGSMIOffsetToPointer (&pIns->area, off) : NULL;
 
-    HGSMIHEAP hHeap = pIns->hostHeap;
+    HGSMIHOSTHEAP hHeap = pIns->hostHeap;
     rc = SSMR3GetU32(pSSM, &off);
     AssertRCReturn(rc, rc);
@@ -1311,12 +1533,12 @@
                 if (RT_SUCCESS(rc))
                 {
-                    rc = HGSMIHeapRestoreMA(&pIns->hostHeap,
-                                            pIns->area.pu8Base+offHeap,
-                                            cbHeap,
-                                            offHeap,
-                                            cBlocks,
-                                            paDescriptors,
-                                            cbMaxBlock,
-                                            &g_hgsmiEnv);
+                    rc = hgsmiHostHeapRestoreMA(&pIns->hostHeap,
+                                                pIns->area.pu8Base+offHeap,
+                                                cbHeap,
+                                                offHeap,
+                                                cBlocks,
+                                                paDescriptors,
+                                                cbMaxBlock,
+                                                &g_hgsmiEnv);
 
                     RTMemFree(paDescriptors);
@@ -1332,11 +1554,11 @@
                     pIns->hostHeap.cRefs = 0;
 
-                    rc = HGSMIHeapRelocate(&pIns->hostHeap,
-                                           u32HeapType,
-                                           pIns->area.pu8Base+offHeap,
-                                           off,
-                                           uintptr_t(pIns->area.pu8Base) - uintptr_t(oldMem),
-                                           cbHeap,
-                                           offHeap);
+                    rc = hgsmiHostHeapRelocate(&pIns->hostHeap,
+                                               u32HeapType,
+                                               pIns->area.pu8Base+offHeap,
+                                               off,
+                                               uintptr_t(pIns->area.pu8Base) - uintptr_t(oldMem),
+                                               cbHeap,
+                                               offHeap);
 
                     hgsmiHostHeapUnlock (pIns);
@@ -1534,9 +1756,10 @@
                  size_t         cbContext)
 {
-    LogFlowFunc(("ppIns = %p, pVM = %p, pszName = [%s], pu8MemBase = %p, cbMem = 0x%08X, offMemBase = 0x%08X, "
+    LogFlowFunc(("ppIns = %p, pVM = %p, pszName = [%s], offBase = 0x%08X, pu8MemBase = %p, cbMem = 0x%08X, "
                  "pfnNotifyGuest = %p, pvNotifyGuest = %p, cbContext = %d\n",
                  ppIns,
                  pVM,
                  pszName,
+                 offBase,
                  pu8MemBase,
                  cbMem,
@@ -1585,5 +1808,5 @@
         pIns->pszName        = VALID_PTR(pszName)? pszName: "";
 
-        HGSMIHeapSetupUninitialized(&pIns->hostHeap);
+        hgsmiHostHeapSetupUninitialized(&pIns->hostHeap);
 
         pIns->pfnNotifyGuest = pfnNotifyGuest;
@@ -1634,7 +1857,5 @@
 #endif
 
-    HGSMIHeapDestroy(&pIns->hostHeap);
-
-    HGSMIHeapSetupUninitialized(&pIns->hostHeap);
+    hgsmiHostHeapDestroy(&pIns->hostHeap);
 
     return flags;
@@ -1647,5 +1868,5 @@
     if (pIns)
     {
-        HGSMIHeapDestroy(&pIns->hostHeap);
+        hgsmiHostHeapDestroy(&pIns->hostHeap);
 
         if (RTCritSectIsInitialized (&pIns->hostHeapCritSect))
Index: /trunk/src/VBox/Devices/Graphics/HGSMI/HGSMIHost.h
===================================================================
--- /trunk/src/VBox/Devices/Graphics/HGSMI/HGSMIHost.h	(revision 55420)
+++ /trunk/src/VBox/Devices/Graphics/HGSMI/HGSMIHost.h	(revision 55421)
@@ -69,7 +69,7 @@
                               uint8_t *pu8Channel);
 
-int HGSMISetupHostHeap (PHGSMIINSTANCE pIns,
-                        HGSMIOFFSET    offHeap,
-                        HGSMISIZE      cbHeap);
+int HGSMIHostHeapSetup(PHGSMIINSTANCE pIns,
+                       HGSMIOFFSET    offHeap,
+                       HGSMISIZE      cbHeap);
 
 int HGSMISaveStateExec (PHGSMIINSTANCE pIns, PSSMHANDLE pSSM);
@@ -107,6 +107,6 @@
 /* Allocate a buffer in the host heap. */
 int HGSMIHostCommandAlloc (PHGSMIINSTANCE pIns,
-                           void **ppvMem,
-                           HGSMISIZE cbMem,
+                           void **ppvData,
+                           HGSMISIZE cbData,
                            uint8_t u8Channel,
                            uint16_t u16ChannelInfo);
@@ -116,5 +116,5 @@
 
 int HGSMIHostCommandProcessAndFreeAsynch (PHGSMIINSTANCE pIns,
-                             void *pvMem,
+                             void *pvData,
                              bool bDoIrq);
 
Index: /trunk/src/VBox/GuestHost/HGSMI/HGSMICommon.cpp
===================================================================
--- /trunk/src/VBox/GuestHost/HGSMI/HGSMICommon.cpp	(revision 55420)
+++ /trunk/src/VBox/GuestHost/HGSMI/HGSMICommon.cpp	(revision 55421)
@@ -101,12 +101,45 @@
 }
 
-static HGSMIOFFSET hgsmiBufferInitializeSingle (const HGSMIAREA *pArea,
-                                                HGSMIBUFFERHEADER *pHeader,
-                                                uint32_t u32DataSize,
-                                                uint8_t u8Channel,
-                                                uint16_t u16ChannelInfo)
+int HGSMIAreaInitialize (HGSMIAREA *pArea, void *pvBase, HGSMISIZE cbArea, HGSMIOFFSET offBase)
+{
+    uint8_t *pu8Base = (uint8_t *)pvBase;
+
+    if (  !pArea                                   /* Check that the area: */
+        || cbArea < HGSMIBufferMinimumSize ()      /* Large enough. */
+        || pu8Base + cbArea < pu8Base              /* No address space wrap. */
+        || offBase > UINT32_C(0xFFFFFFFF) - cbArea /* Area within the 32 bit space: offBase + cbMem <= 0xFFFFFFFF */
+       )
+    {
+        return VERR_INVALID_PARAMETER;
+    }
+
+    pArea->pu8Base = pu8Base;
+    pArea->offBase = offBase;
+    pArea->offLast = cbArea - HGSMIBufferMinimumSize () + offBase;
+    pArea->cbArea = cbArea;
+
+    return VINF_SUCCESS;
+}
+
+void HGSMIAreaClear (HGSMIAREA *pArea)
+{
+    if (pArea)
+    {
+        memset (pArea, 0, sizeof (HGSMIAREA));
+    }
+}
+
+/* Initialize the memory buffer including its checksum.
+ * No changes alloed to the header and the tail after that.
+ */
+HGSMIOFFSET HGSMIBufferInitializeSingle(const HGSMIAREA *pArea,
+                                        HGSMIBUFFERHEADER *pHeader,
+                                        HGSMISIZE cbBuffer,
+                                        uint8_t u8Channel,
+                                        uint16_t u16ChannelInfo)
 {
     if (   !pArea
-        || !pHeader)
+        || !pHeader
+        || cbBuffer < HGSMIBufferMinimumSize())
     {
         return HGSMIOFFSET_VOID;
@@ -119,4 +152,5 @@
      */
     HGSMISIZE cbMaximumDataSize = pArea->offLast - pArea->offBase;
+    uint32_t u32DataSize = cbBuffer - HGSMIBufferMinimumSize();
 
     if (   u32DataSize > cbMaximumDataSize
@@ -143,134 +177,5 @@
 }
 
-int HGSMIAreaInitialize (HGSMIAREA *pArea, void *pvBase, HGSMISIZE cbArea, HGSMIOFFSET offBase)
-{
-    uint8_t *pu8Base = (uint8_t *)pvBase;
-
-    if (  !pArea                                   /* Check that the area: */
-        || cbArea < HGSMIBufferMinimumSize ()      /* Large enough. */
-        || pu8Base + cbArea < pu8Base              /* No address space wrap. */
-        || offBase > UINT32_C(0xFFFFFFFF) - cbArea /* Area within the 32 bit space: offBase + cbMem <= 0xFFFFFFFF */
-       )
-    {
-        return VERR_INVALID_PARAMETER;
-    }
-
-    pArea->pu8Base = pu8Base;
-    pArea->offBase = offBase;
-    pArea->offLast = cbArea - HGSMIBufferMinimumSize () + offBase;
-    pArea->cbArea = cbArea;
-
-    return VINF_SUCCESS;
-}
-
-void HGSMIAreaClear (HGSMIAREA *pArea)
-{
-    if (pArea)
-    {
-        memset (pArea, 0, sizeof (HGSMIAREA));
-    }
-}
-
-/* Initialize the memory buffer including its checksum.
- * No changes alloed to the header and the tail after that.
- */
-HGSMIOFFSET HGSMIBufferInitializeSingle (const HGSMIAREA *pArea,
-                                         HGSMIBUFFERHEADER *pHeader,
-                                         HGSMISIZE cbBuffer,
-                                         uint8_t u8Channel,
-                                         uint16_t u16ChannelInfo)
-{
-    if (cbBuffer < HGSMIBufferMinimumSize ())
-    {
-        return HGSMIOFFSET_VOID;
-    }
-
-    return hgsmiBufferInitializeSingle (pArea, pHeader, cbBuffer - HGSMIBufferMinimumSize (), u8Channel, u16ChannelInfo);
-}
-
-void HGSMIHeapSetupUninitialized(HGSMIHEAP *pHeap)
-{
-    RT_ZERO(*pHeap);
-    pHeap->u32HeapType = HGSMI_HEAP_TYPE_NULL;
-}
-
-int HGSMIHeapRelocate (HGSMIHEAP *pHeap,
-                       uint32_t u32HeapType,
-                       void *pvBase,
-                       uint32_t offHeapHandle,
-                       uintptr_t offDelta,
-                       HGSMISIZE cbArea,
-                       HGSMIOFFSET offBase)
-{
-    if (   !pHeap
-        || !pvBase)
-    {
-        return VERR_INVALID_PARAMETER;
-    }
-
-    int rc = HGSMIAreaInitialize (&pHeap->area, pvBase, cbArea, offBase);
-
-    if (RT_SUCCESS (rc))
-    {
-        if (u32HeapType == HGSMI_HEAP_TYPE_OFFSET)
-        {
-            pHeap->u.hOff = (RTHEAPOFFSET)((uint8_t *)pvBase + offHeapHandle);
-        }
-        else if (u32HeapType == HGSMI_HEAP_TYPE_POINTER)
-        {
-            pHeap->u.hPtr = (RTHEAPSIMPLE)((uint8_t *)pvBase + offHeapHandle);
-            rc = RTHeapSimpleRelocate (pHeap->u.hPtr, offDelta); AssertRC(rc);
-        }
-        else
-        {
-            /* HGSMI_HEAP_TYPE_MA does not need the relocation. */
-            rc = VERR_NOT_SUPPORTED;
-        }
-
-        if (RT_SUCCESS(rc))
-        {
-            pHeap->cRefs = 0;
-            pHeap->u32HeapType = u32HeapType;
-        }
-        else
-        {
-            HGSMIAreaClear (&pHeap->area);
-        }
-    }
-
-    return rc;
-}
-
-int HGSMIHeapRestoreMA(HGSMIHEAP *pHeap,
-                       void *pvBase,
-                       HGSMISIZE cbArea,
-                       HGSMIOFFSET offBase,
-                       uint32_t cBlocks,
-                       HGSMIOFFSET *paDescriptors,
-                       HGSMISIZE cbMaxBlock,
-                       HGSMIENV *pEnv)
-{
-    int rc = HGSMIAreaInitialize(&pHeap->area, pvBase, cbArea, offBase);
-
-    if (RT_SUCCESS (rc))
-    {
-        rc = HGSMIMAInit(&pHeap->u.ma, &pHeap->area, paDescriptors, cBlocks, cbMaxBlock, pEnv);
-
-        if (RT_SUCCESS(rc))
-        {
-            pHeap->cRefs = 0;
-            pHeap->u32HeapType = HGSMI_HEAP_TYPE_MA;
-        }
-        else
-        {
-            HGSMIAreaClear(&pHeap->area);
-        }
-    }
-
-    return rc;
-}
-
 int HGSMIHeapSetup (HGSMIHEAP *pHeap,
-                    uint32_t u32HeapType,
                     void *pvBase,
                     HGSMISIZE cbArea,
@@ -288,27 +193,6 @@
     if (RT_SUCCESS (rc))
     {
-        if (u32HeapType == HGSMI_HEAP_TYPE_MA)
-        {
-            rc = HGSMIMAInit(&pHeap->u.ma, &pHeap->area, NULL, 0, 0, pEnv);
-        }
-        else if (u32HeapType == HGSMI_HEAP_TYPE_POINTER)
-        {
-            rc = RTHeapSimpleInit (&pHeap->u.hPtr, pvBase, cbArea);
-        }
-        else if (u32HeapType == HGSMI_HEAP_TYPE_OFFSET)
-        {
-            rc = RTHeapOffsetInit (&pHeap->u.hOff, pvBase, cbArea);
-        }
-        else
-        {
-            rc = VERR_NOT_SUPPORTED;
-        }
-
-        if (RT_SUCCESS (rc))
-        {
-            pHeap->cRefs = 0;
-            pHeap->u32HeapType = u32HeapType;
-        }
-        else
+        rc = HGSMIMAInit(&pHeap->ma, &pHeap->area, NULL, 0, 0, pEnv);
+        if (RT_FAILURE(rc))
         {
             HGSMIAreaClear (&pHeap->area);
@@ -323,10 +207,5 @@
     if (pHeap)
     {
-        if (pHeap->u32HeapType == HGSMI_HEAP_TYPE_MA)
-        {
-            HGSMIMAUninit(&pHeap->u.ma);
-        }
-        Assert(!pHeap->cRefs);
-        HGSMIHeapSetupUninitialized(pHeap);
+        HGSMIMAUninit(&pHeap->ma);
     }
 }
@@ -343,17 +222,13 @@
         return NULL;
 
-    hgsmiBufferInitializeSingle (&pHeap->area, pHeader, cbData, u8Channel, u16ChannelInfo);
+    HGSMIOFFSET offBuffer = HGSMIBufferInitializeSingle(HGSMIHeapArea(pHeap), pHeader,
+                                                        cbAlloc, u8Channel, u16ChannelInfo);
+    if (offBuffer == HGSMIOFFSET_VOID)
+    {
+        HGSMIHeapBufferFree(pHeap, pHeader);
+        return NULL;
+    }
 
     return HGSMIBufferData (pHeader);
-}
-
-HGSMIOFFSET HGSMIHeapBufferOffset (HGSMIHEAP *pHeap,
-                                   void *pvData)
-{
-    HGSMIBUFFERHEADER *pHeader = HGSMIBufferHeaderFromData (pvData);
-
-    HGSMIOFFSET offBuffer = HGSMIPointerToOffset (&pHeap->area, pHeader);
-
-    return offBuffer;
 }
 
@@ -361,6 +236,5 @@
                     void *pvData)
 {
-    if (   pvData
-        && pHeap->u32HeapType != HGSMI_HEAP_TYPE_NULL)
+    if (pvData)
     {
         HGSMIBUFFERHEADER *pHeader = HGSMIBufferHeaderFromData (pvData);
@@ -372,23 +246,5 @@
 void* HGSMIHeapBufferAlloc (HGSMIHEAP *pHeap, HGSMISIZE cbBuffer)
 {
-    void* pvBuf = NULL;
-    if (pHeap->u32HeapType == HGSMI_HEAP_TYPE_MA)
-    {
-        pvBuf = HGSMIMAAlloc(&pHeap->u.ma, cbBuffer);
-    }
-    else if (pHeap->u32HeapType == HGSMI_HEAP_TYPE_POINTER)
-    {
-        pvBuf = RTHeapSimpleAlloc (pHeap->u.hPtr, cbBuffer, 0);
-    }
-    else if (pHeap->u32HeapType == HGSMI_HEAP_TYPE_OFFSET)
-    {
-        pvBuf = RTHeapOffsetAlloc (pHeap->u.hOff, cbBuffer, 0);
-    }
-
-    if (pvBuf)
-    {
-        ++pHeap->cRefs;
-    }
-
+    void *pvBuf = HGSMIMAAlloc(&pHeap->ma, cbBuffer);
     return pvBuf;
 }
@@ -397,18 +253,5 @@
                          void *pvBuf)
 {
-    if (pHeap->u32HeapType == HGSMI_HEAP_TYPE_MA)
-    {
-        HGSMIMAFree(&pHeap->u.ma, pvBuf);
-    }
-    else if (pHeap->u32HeapType == HGSMI_HEAP_TYPE_POINTER)
-    {
-        RTHeapSimpleFree (pHeap->u.hPtr, pvBuf);
-    }
-    else if (pHeap->u32HeapType == HGSMI_HEAP_TYPE_OFFSET)
-    {
-        RTHeapOffsetFree (pHeap->u.hOff, pvBuf);
-    }
-
-    --pHeap->cRefs;
+    HGSMIMAFree(&pHeap->ma, pvBuf);
 }
 
@@ -457,5 +300,5 @@
             uint32_t u32Checksum = HGSMIChecksum(offBuffer, &header, &tail);
             LogFlowFunc(("checksum check: u32Checksum = 0x%x pTail->u32Checksum = 0x%x\n",
-                         u32Checksum, pTail->u32Checksum));
+                         u32Checksum, tail.u32Checksum));
             if (u32Checksum == tail.u32Checksum)
             {
@@ -468,5 +311,5 @@
             {
                 LogFunc(("invalid checksum 0x%x, expected 0x%x!!!\n",
-                         u32Checksum, pTail->u32Checksum));
+                         u32Checksum, tail.u32Checksum));
                 rc = VERR_INVALID_STATE;
                 HGSMI_STRICT_ASSERT_FAILED();
@@ -487,25 +330,15 @@
 /* A wrapper to safely call the handler.
  */
-static int hgsmiChannelHandlerCall(const HGSMICHANNELHANDLER *pHandler,
-                                   const HGSMIBUFFERCONTEXT *pBufferContext)
+static void hgsmiChannelHandlerCall(const HGSMICHANNELHANDLER *pHandler,
+                                    const HGSMIBUFFERCONTEXT *pBufferContext)
 {
     LogFlowFunc(("pHandler %p\n", pHandler));
-
-    int rc;
 
     if (   pHandler
         && pHandler->pfnHandler)
     {
-        rc = pHandler->pfnHandler(pHandler->pvHandler, pBufferContext->pHeader->u16ChannelInfo,
-                                  pBufferContext->pvData, pBufferContext->cbData);
-    }
-    else
-    {
-        /* It is a NOOP case here. */
-        rc = VINF_SUCCESS;
-    }
-
-    LogFlowFunc(("leave rc = %Rrc\n", rc));
-    return rc;
+        pHandler->pfnHandler(pHandler->pvHandler, pBufferContext->pHeader->u16ChannelInfo,
+                             pBufferContext->pvData, pBufferContext->cbData);
+    }
 }
 
@@ -557,5 +390,5 @@
         if (pChannel)
         {
-            rc = hgsmiChannelHandlerCall(&pChannel->handler, &bufferContext);
+            hgsmiChannelHandlerCall(&pChannel->handler, &bufferContext);
             HGSMI_STRICT_ASSERT(RT_SUCCESS(hgsmiVerifyBuffer(pArea, offBuffer, &bufferContext)));
         }
