VirtualBox

Changeset 55421 in vbox


Ignore:
Timestamp:
Apr 24, 2015 12:00:21 PM (10 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
99763
Message:

HGSMI: cleanup, logging, comments, move legacy host heap support from common code to the host code.

Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/HGSMI/HGSMI.h

    r55342 r55421  
    7272 */
    7373
    74 /* Heap types. */
    75 #define HGSMI_HEAP_TYPE_NULL    0 /* Heap not initialized. */
    76 #define HGSMI_HEAP_TYPE_POINTER 1 /* Deprecated. RTHEAPSIMPLE. */
    77 #define HGSMI_HEAP_TYPE_OFFSET  2 /* Deprecated. RTHEAPOFFSET. */
    78 #define HGSMI_HEAP_TYPE_MA      3 /* Memory allocator. */
    79 
    8074#pragma pack(1)
    8175typedef struct HGSMIHEAP
    8276{
    83     union
    84     {
    85         HGSMIMADATA   ma;           /* Memory Allocator */
    86         RTHEAPSIMPLE  hPtr;         /* Pointer based heap. */
    87         RTHEAPOFFSET  hOff;         /* Offset based heap. */
    88     } u;
    89     HGSMIAREA     area;             /* Description. */
    90     int           cRefs;            /* Number of heap allocations. */
    91     uint32_t      u32HeapType;      /* HGSMI_HEAP_TYPE_* */
     77    HGSMIAREA area; /* Description. */
     78    HGSMIMADATA ma; /* Memory allocator */
    9279} HGSMIHEAP;
    9380#pragma pack()
     
    180167}
    181168
    182 DECLINLINE(uint8_t *) HGSMIBufferDataFromOffset (const HGSMIAREA *pArea, HGSMIOFFSET offBuffer)
    183 {
    184     HGSMIBUFFERHEADER *pHeader = (HGSMIBUFFERHEADER *)HGSMIOffsetToPointer(pArea, offBuffer);
    185     Assert(pHeader);
    186     if(pHeader)
    187         return HGSMIBufferData(pHeader);
    188     return NULL;
     169DECLINLINE(uint8_t *) HGSMIBufferDataFromOffset(const HGSMIAREA *pArea,
     170                                                HGSMIOFFSET offBuffer)
     171{
     172    void *pvBuffer = HGSMIOffsetToPointer(pArea, offBuffer);
     173    return HGSMIBufferDataFromPtr(pvBuffer);
     174}
     175
     176DECLINLINE(HGSMIOFFSET) HGSMIBufferOffsetFromData(const HGSMIAREA *pArea,
     177                                                  void *pvData)
     178{
     179    HGSMIBUFFERHEADER *pHeader = HGSMIBufferHeaderFromData(pvData);
     180    return HGSMIPointerToOffset(pArea, pHeader);
    189181}
    190182
     
    228220                                         uint16_t u16ChannelInfo);
    229221
     222DECLINLINE(const HGSMIAREA *) HGSMIHeapArea(HGSMIHEAP *pHeap)
     223{
     224    return &pHeap->area;
     225}
     226
    230227int HGSMIHeapSetup (HGSMIHEAP *pHeap,
    231                     uint32_t u32HeapType,
    232228                    void *pvBase,
    233229                    HGSMISIZE cbArea,
     
    235231                    const HGSMIENV *pEnv);
    236232
    237 int HGSMIHeapRelocate (HGSMIHEAP *pHeap,
    238                        uint32_t u32HeapType,
    239                        void *pvBase,
    240                        uint32_t offHeapHandle,
    241                        uintptr_t offDelta,
    242                        HGSMISIZE cbArea,
    243                        HGSMIOFFSET offBase);
    244 
    245 int HGSMIHeapRestoreMA(HGSMIHEAP *pHeap,
    246                        void *pvBase,
    247                        HGSMISIZE cbArea,
    248                        HGSMIOFFSET offBase,
    249                        uint32_t cBlocks,
    250                        HGSMIOFFSET *paDescriptors,
    251                        HGSMISIZE cbMaxBlock,
    252                        HGSMIENV *pEnv);
    253 
    254 void HGSMIHeapSetupUninitialized (HGSMIHEAP *pHeap);
    255 
    256233void HGSMIHeapDestroy (HGSMIHEAP *pHeap);
    257234
     
    267244                      uint16_t u16ChannelInfo);
    268245
    269 HGSMIOFFSET HGSMIHeapBufferOffset (HGSMIHEAP *pHeap,
    270                                    void *pvData);
     246DECLINLINE(HGSMIOFFSET) HGSMIHeapBufferOffset(HGSMIHEAP *pHeap, void *pvData)
     247{
     248    return HGSMIBufferOffsetFromData(HGSMIHeapArea(pHeap), pvData);
     249}
    271250
    272251void HGSMIHeapFree (HGSMIHEAP *pHeap,
     
    275254DECLINLINE(HGSMIOFFSET) HGSMIHeapOffset(HGSMIHEAP *pHeap)
    276255{
    277     return pHeap->area.offBase;
    278 }
    279 
    280 #ifdef IN_RING3
    281 /* Needed for heap relocation: offset of the heap handle relative to the start of heap area. */
    282 DECLINLINE(HGSMIOFFSET) HGSMIHeapHandleLocationOffset(HGSMIHEAP *pHeap)
    283 {
    284     HGSMIOFFSET offHeapHandle;
    285     if (pHeap->u32HeapType == HGSMI_HEAP_TYPE_POINTER)
    286     {
    287         offHeapHandle = (HGSMIOFFSET)((uintptr_t)pHeap->u.hPtr - (uintptr_t)pHeap->area.pu8Base);
    288     }
    289     else if (pHeap->u32HeapType == HGSMI_HEAP_TYPE_OFFSET)
    290     {
    291         offHeapHandle = (HGSMIOFFSET)((uintptr_t)pHeap->u.hOff - (uintptr_t)pHeap->area.pu8Base);
    292     }
    293     else
    294     {
    295         offHeapHandle = HGSMIOFFSET_VOID;
    296     }
    297     return offHeapHandle;
    298 }
    299 #endif /* IN_RING3 */
     256    return HGSMIHeapArea(pHeap)->offBase;
     257}
    300258
    301259DECLINLINE(HGSMISIZE) HGSMIHeapSize(HGSMIHEAP *pHeap)
    302260{
    303     return pHeap->area.cbArea;
     261    return HGSMIHeapArea(pHeap)->cbArea;
    304262}
    305263
  • trunk/src/VBox/Additions/WINNT/Graphics/Video/disp/xpdm/VBoxDispVBVA.cpp

    r50542 r55421  
    425425
    426426        rc = HGSMIHeapSetup(&pDev->hgsmi.ctx.heapCtx,
    427                             HGSMI_HEAP_TYPE_MA,
    428427                            (uint8_t *)pDev->memInfo.VideoRamBase+pDev->layout.offDisplayInfo+sizeof(HGSMIHOSTFLAGS),
    429428                            pDev->layout.cbDisplayInfo-sizeof(HGSMIHOSTFLAGS),
  • trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPShgsmi.cpp

    r50859 r55421  
    186186}
    187187
    188 int VBoxSHGSMIInit(PVBOXSHGSMI pHeap, uint32_t u32HeapType, void *pvBase, HGSMISIZE cbArea, HGSMIOFFSET offBase,
     188int VBoxSHGSMIInit(PVBOXSHGSMI pHeap, void *pvBase, HGSMISIZE cbArea, HGSMIOFFSET offBase,
    189189                   const HGSMIENV *pEnv)
    190190{
    191191    KeInitializeSpinLock(&pHeap->HeapLock);
    192     return HGSMIHeapSetup(&pHeap->Heap, u32HeapType, pvBase, cbArea, offBase, pEnv);
     192    return HGSMIHeapSetup(&pHeap->Heap, pvBase, cbArea, offBase, pEnv);
    193193}
    194194
  • trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPShgsmi.h

    r50859 r55421  
    6060}
    6161
    62 int VBoxSHGSMIInit(PVBOXSHGSMI pHeap, uint32_t u32HeapType, void *pvBase, HGSMISIZE cbArea, HGSMIOFFSET offBase, const HGSMIENV *pEnv);
     62int VBoxSHGSMIInit(PVBOXSHGSMI pHeap, void *pvBase, HGSMISIZE cbArea, HGSMIOFFSET offBase, const HGSMIENV *pEnv);
    6363void VBoxSHGSMITerm(PVBOXSHGSMI pHeap);
    6464void* VBoxSHGSMIHeapAlloc(PVBOXSHGSMI pHeap, HGSMISIZE cbData, uint8_t u8Channel, uint16_t u16ChannelInfo);
  • trunk/src/VBox/Additions/WINNT/Graphics/Video/mp/wddm/VBoxMPVdma.cpp

    r52329 r55421  
    16281628        /* Setup a HGSMI heap within the adapter information area. */
    16291629        rc = VBoxSHGSMIInit(&pInfo->CmdHeap,
    1630                              HGSMI_HEAP_TYPE_MA,
    16311630                             pvBuffer,
    16321631                             cbBuffer,
  • trunk/src/VBox/Additions/common/VBoxVideo/HGSMIBase.cpp

    r55193 r55421  
    341341    pCtx->port = (RTIOPORT)VGA_PORT_HGSMI_GUEST;
    342342#ifdef VBOX_WDDM_MINIPORT
    343     return VBoxSHGSMIInit(&pCtx->heapCtx, HGSMI_HEAP_TYPE_MA, pvGuestHeapMemory,
     343    return VBoxSHGSMIInit(&pCtx->heapCtx, pvGuestHeapMemory,
    344344                          cbGuestHeapMemory, offVRAMGuestHeapMemory, pEnv);
    345345#else
    346     return HGSMIHeapSetup(&pCtx->heapCtx, HGSMI_HEAP_TYPE_MA, pvGuestHeapMemory,
     346    return HGSMIHeapSetup(&pCtx->heapCtx, pvGuestHeapMemory,
    347347                          cbGuestHeapMemory, offVRAMGuestHeapMemory, pEnv);
    348348#endif
  • trunk/src/VBox/Devices/Graphics/DevVGA_VBVA.cpp

    r55342 r55421  
    22732273                         pHeap->u32HeapOffset, pHeap->u32HeapSize));
    22742274
    2275             rc = HGSMISetupHostHeap (pIns, pHeap->u32HeapOffset, pHeap->u32HeapSize);
     2275            rc = HGSMIHostHeapSetup(pIns, pHeap->u32HeapOffset, pHeap->u32HeapSize);
    22762276        } break;
    22772277
  • trunk/src/VBox/Devices/Graphics/HGSMI/HGSMIHost.cpp

    r55401 r55421  
    6767
    6868#include <VBox/err.h>
    69 #define LOG_GROUP LOG_GROUP_DEV_VGA
     69#define LOG_GROUP LOG_GROUP_HGSMI
    7070#include <VBox/log.h>
    7171#include <VBox/vmm/ssm.h>
     
    133133
    134134
     135/* Host heap types. */
     136#define HGSMI_HEAP_TYPE_NULL    0 /* Heap not initialized. */
     137#define HGSMI_HEAP_TYPE_POINTER 1 /* Deprecated, used only for old saved states. RTHEAPSIMPLE. */
     138#define HGSMI_HEAP_TYPE_OFFSET  2 /* Deprecated, used only for old saved states. RTHEAPOFFSET. */
     139#define HGSMI_HEAP_TYPE_MA      3 /* Memory allocator. */
     140
     141typedef struct HGSMIHOSTHEAP
     142{
     143    uint32_t u32HeapType;   /* HGSMI_HEAP_TYPE_* */
     144    int32_t volatile cRefs; /* How many blocks allocated. */
     145    HGSMIAREA area;         /* Host heap location. */
     146    union
     147    {
     148        HGSMIMADATA ma;     /* Memory allocator for the default host heap implementation. */
     149        struct              /* Legacy heap implementations. For old saved states. */
     150        {
     151            union
     152            {
     153                RTHEAPSIMPLE hPtr;  /* Pointer based heap. */
     154                RTHEAPOFFSET hOff;  /* Offset based heap. */
     155            } u;
     156        } legacy;
     157    } u;
     158} HGSMIHOSTHEAP;
     159
    135160typedef struct HGSMIINSTANCE
    136161{
     
    142167
    143168    HGSMIAREA area; /* The shared memory description. */
    144     HGSMIHEAP hostHeap;                /* Host heap instance. */
     169    HGSMIHOSTHEAP hostHeap;            /* Host heap instance. */
    145170    RTCRITSECT    hostHeapCritSect;    /* Heap serialization lock. */
    146171
     
    182207    volatile uint32_t fl;              /* Status flags of the entry. */
    183208
    184     HGSMIOFFSET offBuffer;             /* Offset in the memory region of the entry data. */
     209    HGSMIOFFSET offBuffer;             /* Offset of the HGSMI buffer header in the HGSMI host heap:
     210                                        * [pIns->hostHeap.area.offBase .. offLast]. */
    185211
    186212#if 0
     
    510536}
    511537
     538static HGSMIOFFSET hgsmiHostHeapOffset(HGSMIHOSTHEAP *pHeap)
     539{
     540    return pHeap->area.offBase;
     541}
     542
     543static HGSMISIZE hgsmiHostHeapSize(HGSMIHOSTHEAP *pHeap)
     544{
     545    return pHeap->area.cbArea;
     546}
     547
     548static void *hgsmiHostHeapBufferAlloc(HGSMIHOSTHEAP *pHeap,
     549                                      HGSMISIZE cbBuffer)
     550{
     551    void *pvBuf = NULL;
     552
     553    if (pHeap->u32HeapType == HGSMI_HEAP_TYPE_MA)
     554    {
     555        pvBuf = HGSMIMAAlloc(&pHeap->u.ma, cbBuffer);
     556    }
     557    else if (pHeap->u32HeapType == HGSMI_HEAP_TYPE_POINTER)
     558    {
     559        pvBuf = RTHeapSimpleAlloc(pHeap->u.legacy.u.hPtr, cbBuffer, 0);
     560    }
     561    else if (pHeap->u32HeapType == HGSMI_HEAP_TYPE_OFFSET)
     562    {
     563        pvBuf = RTHeapOffsetAlloc(pHeap->u.legacy.u.hOff, cbBuffer, 0);
     564    }
     565
     566    if (pvBuf)
     567    {
     568        ++pHeap->cRefs;
     569    }
     570
     571    return pvBuf;
     572}
     573
     574static void hgsmiHostHeapBufferFree(HGSMIHOSTHEAP *pHeap,
     575                                    void *pvBuf)
     576{
     577    if (pHeap->u32HeapType == HGSMI_HEAP_TYPE_MA)
     578    {
     579        HGSMIMAFree(&pHeap->u.ma, pvBuf);
     580    }
     581    else if (pHeap->u32HeapType == HGSMI_HEAP_TYPE_POINTER)
     582    {
     583        RTHeapSimpleFree(pHeap->u.legacy.u.hPtr, pvBuf);
     584    }
     585    else if (pHeap->u32HeapType == HGSMI_HEAP_TYPE_OFFSET)
     586    {
     587        RTHeapOffsetFree(pHeap->u.legacy.u.hOff, pvBuf);
     588    }
     589    --pHeap->cRefs;
     590}
     591
     592static void *hgsmiHostHeapDataAlloc(HGSMIHOSTHEAP *pHeap,
     593                                    HGSMISIZE cbData,
     594                                    uint8_t u8Channel,
     595                                    uint16_t u16ChannelInfo)
     596{
     597    HGSMISIZE cbAlloc = HGSMIBufferRequiredSize(cbData);
     598    HGSMIBUFFERHEADER *pHeader = (HGSMIBUFFERHEADER *)hgsmiHostHeapBufferAlloc(pHeap, cbAlloc);
     599    if (!pHeader)
     600        return NULL;
     601
     602    HGSMIBufferInitializeSingle(&pHeap->area, pHeader, cbAlloc, u8Channel, u16ChannelInfo);
     603
     604    return HGSMIBufferDataFromPtr(pHeader);
     605}
     606
     607static void hgsmiHostHeapDataFree(HGSMIHOSTHEAP *pHeap,
     608                                  void *pvData)
     609{
     610    if (   pvData
     611        && pHeap->u32HeapType != HGSMI_HEAP_TYPE_NULL)
     612    {
     613        HGSMIBUFFERHEADER *pHeader = HGSMIBufferHeaderFromData(pvData);
     614        hgsmiHostHeapBufferFree(pHeap, pHeader);
     615    }
     616}
     617
     618/* Needed for heap relocation: offset of the heap handle relative to the start of heap area. */
     619static HGSMIOFFSET hgsmiHostHeapHandleLocationOffset(HGSMIHOSTHEAP *pHeap)
     620{
     621    HGSMIOFFSET offHeapHandle;
     622    if (pHeap->u32HeapType == HGSMI_HEAP_TYPE_POINTER)
     623    {
     624        offHeapHandle = (HGSMIOFFSET)((uintptr_t)pHeap->u.legacy.u.hPtr - (uintptr_t)pHeap->area.pu8Base);
     625    }
     626    else if (pHeap->u32HeapType == HGSMI_HEAP_TYPE_OFFSET)
     627    {
     628        offHeapHandle = (HGSMIOFFSET)((uintptr_t)pHeap->u.legacy.u.hOff - (uintptr_t)pHeap->area.pu8Base);
     629    }
     630    else
     631    {
     632        offHeapHandle = HGSMIOFFSET_VOID;
     633    }
     634    return offHeapHandle;
     635}
     636
     637static int hgsmiHostHeapRelocate(HGSMIHOSTHEAP *pHeap,
     638                                 uint32_t u32HeapType,
     639                                 void *pvBase,
     640                                 uint32_t offHeapHandle,
     641                                 uintptr_t offDelta,
     642                                 HGSMISIZE cbArea,
     643                                 HGSMIOFFSET offBase)
     644{
     645    int rc = HGSMIAreaInitialize(&pHeap->area, pvBase, cbArea, offBase);
     646    if (RT_SUCCESS(rc))
     647    {
     648        if (u32HeapType == HGSMI_HEAP_TYPE_OFFSET)
     649        {
     650            pHeap->u.legacy.u.hOff = (RTHEAPOFFSET)((uint8_t *)pvBase + offHeapHandle);
     651        }
     652        else if (u32HeapType == HGSMI_HEAP_TYPE_POINTER)
     653        {
     654            pHeap->u.legacy.u.hPtr = (RTHEAPSIMPLE)((uint8_t *)pvBase + offHeapHandle);
     655            rc = RTHeapSimpleRelocate(pHeap->u.legacy.u.hPtr, offDelta); AssertRC(rc);
     656        }
     657        else
     658        {
     659            /* HGSMI_HEAP_TYPE_MA does not need the relocation. */
     660            rc = VERR_NOT_SUPPORTED;
     661        }
     662
     663        if (RT_SUCCESS(rc))
     664        {
     665            pHeap->u32HeapType = u32HeapType;
     666        }
     667        else
     668        {
     669            HGSMIAreaClear(&pHeap->area);
     670        }
     671    }
     672
     673    return rc;
     674}
     675
     676static int hgsmiHostHeapRestoreMA(HGSMIHOSTHEAP *pHeap,
     677                                  void *pvBase,
     678                                  HGSMISIZE cbArea,
     679                                  HGSMIOFFSET offBase,
     680                                  uint32_t cBlocks,
     681                                  HGSMIOFFSET *paDescriptors,
     682                                  HGSMISIZE cbMaxBlock,
     683                                  HGSMIENV *pEnv)
     684{
     685    int rc = HGSMIAreaInitialize(&pHeap->area, pvBase, cbArea, offBase);
     686    if (RT_SUCCESS(rc))
     687    {
     688        rc = HGSMIMAInit(&pHeap->u.ma, &pHeap->area, paDescriptors, cBlocks, cbMaxBlock, pEnv);
     689
     690        if (RT_FAILURE(rc))
     691        {
     692            HGSMIAreaClear(&pHeap->area);
     693        }
     694    }
     695
     696    return rc;
     697}
     698
     699static void hgsmiHostHeapSetupUninitialized(HGSMIHOSTHEAP *pHeap)
     700{
     701    RT_ZERO(*pHeap);
     702    pHeap->u32HeapType = HGSMI_HEAP_TYPE_NULL;
     703}
     704
     705static void hgsmiHostHeapDestroy(HGSMIHOSTHEAP *pHeap)
     706{
     707    if (pHeap->u32HeapType == HGSMI_HEAP_TYPE_MA)
     708    {
     709        HGSMIMAUninit(&pHeap->u.ma);
     710    }
     711    hgsmiHostHeapSetupUninitialized(pHeap);
     712}
     713
    512714static int hgsmiHostFIFOAlloc (HGSMIINSTANCE *pIns, HGSMIHOSTFIFOENTRY **ppEntry)
    513715{
     
    557759static int hgsmiHostCommandFreeByEntry (HGSMIHOSTFIFOENTRY *pEntry)
    558760{
     761    LogFlowFunc(("offBuffer 0x%08X\n", pEntry->offBuffer));
     762
    559763    HGSMIINSTANCE *pIns = pEntry->pIns;
    560764    int rc = hgsmiFIFOLock (pIns);
     
    564768        hgsmiFIFOUnlock (pIns);
    565769
    566         void *pvMem = HGSMIBufferDataFromOffset(&pIns->area, pEntry->offBuffer);
     770        void *pvData = HGSMIBufferDataFromOffset(&pIns->hostHeap.area, pEntry->offBuffer);
    567771
    568772        rc = hgsmiHostHeapLock (pIns);
     
    570774        {
    571775            /* Deallocate the host heap memory. */
    572             HGSMIHeapFree (&pIns->hostHeap, pvMem);
     776            hgsmiHostHeapDataFree(&pIns->hostHeap, pvData);
    573777
    574778            hgsmiHostHeapUnlock(pIns);
     
    577781        hgsmiHostFIFOFree (pIns, pEntry);
    578782    }
     783
     784    LogFlowFunc(("%Rrc\n", rc));
    579785    return rc;
    580786}
    581787
    582788static int hgsmiHostCommandFree (HGSMIINSTANCE *pIns,
    583                                                 void *pvMem)
    584 {
    585     HGSMIOFFSET offMem = HGSMIHeapBufferOffset (&pIns->hostHeap, pvMem);
     789                                                void *pvData)
     790{
    586791    int rc = VINF_SUCCESS;
    587     if (offMem != HGSMIOFFSET_VOID)
    588     {
     792    if (HGSMIAreaContainsPointer(&pIns->hostHeap.area, pvData))
     793    {
     794        HGSMIHOSTFIFOENTRY *pEntry = NULL;
     795        HGSMIOFFSET offBuffer = HGSMIBufferOffsetFromData(&pIns->hostHeap.area, pvData);
     796
    589797        rc = hgsmiFIFOLock (pIns);
    590798        if(RT_SUCCESS(rc))
    591799        {
    592             /* Search the Processed list for the given offMem. */
    593             HGSMIHOSTFIFOENTRY *pEntry = NULL;
    594 
     800            /* Search the Processed list for the given offBuffer. */
    595801            HGSMIHOSTFIFOENTRY *pIter;
    596802            RTListForEach(&pIns->hostFIFOProcessed, pIter, HGSMIHOSTFIFOENTRY, nodeEntry)
     
    598804                Assert(pIter->fl == (HGSMI_F_HOST_FIFO_ALLOCATED | HGSMI_F_HOST_FIFO_PROCESSED));
    599805
    600                 if (pIter->offBuffer == offMem)
     806                if (pIter->offBuffer == offBuffer)
    601807                {
    602808                    pEntry = pIter;
     
    611817            else
    612818            {
    613                 LogRel(("HGSMI[%s]: the host frees unprocessed FIFO entry: 0x%08X\n", pIns->pszName, offMem));
    614                 AssertFailed ();
     819                AssertLogRelMsgFailed(("HGSMI[%s]: the host frees unprocessed FIFO entry: 0x%08X\n",
     820                                       pIns->pszName, offBuffer));
    615821            }
    616822
     
    621827            {
    622828                /* Deallocate the host heap memory. */
    623                 HGSMIHeapFree (&pIns->hostHeap, pvMem);
     829                hgsmiHostHeapDataFree(&pIns->hostHeap, pvData);
    624830
    625831                hgsmiHostHeapUnlock(pIns);
     
    636842    else
    637843    {
     844        AssertLogRelMsgFailed(("HGSMI[%s]: the host frees invalid FIFO entry: %p\n",
     845                               pIns->pszName, pvData));
    638846        rc = VERR_INVALID_POINTER;
    639         LogRel(("HGSMI[%s]: the host frees invalid FIFO entry: %p\n", pIns->pszName, pvMem));
    640         AssertFailed ();
    641847    }
    642848    return rc;
     
    776982#endif
    777983/**
    778  * Allocate a shared memory block. The host can write command/data to the memory.
    779  *
    780  * @param pIns   Pointer to HGSMI instance,
    781  * @param ppvMem Where to store the allocated memory pointer to data.
    782  * @param cbMem  How many bytes of data to allocate.
     984 * Allocate a shared memory buffer. The host can write command/data to the memory.
     985 * The allocated buffer contains the 'header', 'data' and the 'tail', but *ppvData
     986 * will point to the 'data'.
     987 *
     988 * @return VBox status code. Pointer to the payload data in *ppvData.
     989 * @param pIns           HGSMI instance,
     990 * @param ppvData        Where to store the allocated memory pointer to data.
     991 * @param cbData         How many bytes of data to allocate.
     992 * @param u8Channel      HGSMI channel.
     993 * @param u16ChannelInfo Command parameter.
    783994 */
    784995int HGSMIHostCommandAlloc (HGSMIINSTANCE *pIns,
    785                            void **ppvMem,
    786                            HGSMISIZE cbMem,
     996                           void **ppvData,
     997                           HGSMISIZE cbData,
    787998                           uint8_t u8Channel,
    788999                           uint16_t u16ChannelInfo)
    7891000{
    790     LogFlowFunc (("pIns = %p, cbMem = 0x%08X(%d)\n", pIns, cbMem, cbMem));
     1001    LogFlowFunc (("pIns = %p, cbData = 0x%08X(%d)\n", pIns, cbData, cbData));
    7911002
    7921003    int rc = hgsmiHostHeapLock (pIns);
    7931004    if(RT_SUCCESS(rc))
    7941005    {
    795         void *pvMem = HGSMIHeapAlloc (&pIns->hostHeap,
    796                                   cbMem,
    797                                   u8Channel,
    798                                   u16ChannelInfo);
     1006        void *pvData = hgsmiHostHeapDataAlloc(&pIns->hostHeap,
     1007                                              cbData,
     1008                                              u8Channel,
     1009                                              u16ChannelInfo);
    7991010        hgsmiHostHeapUnlock(pIns);
    8001011
    801         if (pvMem)
    802         {
    803             *ppvMem = pvMem;
     1012        if (pvData)
     1013        {
     1014            *ppvData = pvData;
    8041015        }
    8051016        else
    8061017        {
    807             LogRel((0, "HGSMIHeapAlloc: HGSMIHeapAlloc failed\n"));
    808             rc = VERR_GENERAL_FAILURE;
    809         }
    810     }
    811 
    812     LogFlowFunc (("rc = %Rrc, pvMem = %p\n", rc, *ppvMem));
    813 
     1018            LogRel(("HGSMI[%s]: host heap allocation failed %dbytes\n", pIns->pszName, cbData));
     1019            rc = VERR_NO_MEMORY;
     1020        }
     1021    }
     1022
     1023    LogFlowFunc(("%Rrc, pvData = %p\n", rc, *ppvData));
    8141024    return rc;
    8151025}
     
    8191029 * and make it freed on completion.
    8201030 * The caller does not get notified in any way on command completion,
    821  * on success return the pvMem buffer can not be used after being passed to this function
    822  *
    823  * @param pIns  Pointer to HGSMI instance,
    824  * @param pvMem The pointer returned by 'HGSMIHostCommandAlloc'.
    825  * @param bDoIrq specifies whether the guest interrupt should be generated,
    826  * i.e. in case the command is not urgent(e.g. some guest command completion notification that does not require post-processing)
    827  * the command could be posted without raising an irq.
     1031 * on successful return the pvData buffer can not be used after being passed to this function.
     1032 *
     1033 * @param pIns   HGSMI instance,
     1034 * @param pvData The pointer returned by 'HGSMIHostCommandAlloc'.
     1035 * @param bDoIrq Specifies whether the guest interrupt should be generated.
     1036 *               In case the command is not urgent (e.g. some guest command
     1037 *               completion notification that does not require post-processing)
     1038 *               the command could be posted without raising an irq.
    8281039 */
    8291040int HGSMIHostCommandProcessAndFreeAsynch (PHGSMIINSTANCE pIns,
    830                              void *pvMem,
     1041                             void *pvData,
    8311042                             bool bDoIrq)
    8321043{
    833     LogFlowFunc(("pIns = %p, pvMem = %p\n", pIns, pvMem));
     1044    LogFlowFunc(("pIns = %p, pvData = %p\n", pIns, pvData));
    8341045
    8351046#if 0
     
    8371048#endif
    8381049
    839     HGSMIOFFSET offBuffer = HGSMIHeapBufferOffset (&pIns->hostHeap, pvMem);
     1050    HGSMIOFFSET offBuffer = HGSMIBufferOffsetFromData(&pIns->hostHeap.area, pvData);
    8401051
    8411052    int rc = hgsmiHostCommandProcess (pIns, offBuffer,
     
    9251136};
    9261137
    927 int HGSMISetupHostHeap (PHGSMIINSTANCE pIns,
    928                         HGSMIOFFSET    offHeap,
    929                         HGSMISIZE      cbHeap)
     1138int HGSMIHostHeapSetup(PHGSMIINSTANCE pIns,
     1139                       HGSMIOFFSET    offHeap,
     1140                       HGSMISIZE      cbHeap)
    9301141{
    9311142    LogFlowFunc(("pIns %p, offHeap 0x%08X, cbHeap = 0x%08X\n", pIns, offHeap, cbHeap));
     
    9331144    int rc = VINF_SUCCESS;
    9341145
    935     Assert (pIns);
    936 
    937 //    if (   offHeap >= pIns->cbMem
    938 //        || cbHeap > pIns->cbMem
    939 //        || offHeap + cbHeap > pIns->cbMem)
    940 //    {
    941 //        rc = VERR_INVALID_PARAMETER;
    942 //    }
    943 //    else
     1146    AssertPtrReturn(pIns, VERR_INVALID_PARAMETER);
     1147
     1148    if (   offHeap >= pIns->area.cbArea
     1149        || cbHeap > pIns->area.cbArea
     1150        || offHeap > pIns->area.cbArea - cbHeap)
     1151    {
     1152        AssertLogRelMsgFailed(("offHeap 0x%08X, cbHeap = 0x%08X, pIns->area.cbArea 0x%08X\n",
     1153                               offHeap, cbHeap, pIns->area.cbArea));
     1154        rc = VERR_INVALID_PARAMETER;
     1155    }
     1156    else
    9441157    {
    9451158        rc = hgsmiHostHeapLock (pIns);
     
    9491162            if (pIns->hostHeap.cRefs)
    9501163            {
    951                 AssertFailed();
     1164                AssertLogRelMsgFailed(("HGSMI[%s]: host heap setup ignored. %d allocated.\n",
     1165                                       pIns->pszName, pIns->hostHeap.cRefs));
    9521166                /* It is possible to change the heap only if there is no pending allocations. */
    9531167                rc = VERR_ACCESS_DENIED;
     
    9551169            else
    9561170            {
    957                 rc = HGSMIHeapSetup (&pIns->hostHeap,
    958                                      HGSMI_HEAP_TYPE_MA,
    959                                      pIns->area.pu8Base+offHeap,
    960                                      cbHeap,
    961                                      offHeap,
    962                                      &g_hgsmiEnv);
     1171                rc = HGSMIAreaInitialize(&pIns->hostHeap.area, pIns->area.pu8Base + offHeap, cbHeap, offHeap);
     1172                if (RT_SUCCESS(rc))
     1173                {
     1174                    rc = HGSMIMAInit(&pIns->hostHeap.u.ma, &pIns->hostHeap.area, NULL, 0, 0, &g_hgsmiEnv);
     1175                }
     1176
     1177                if (RT_SUCCESS(rc))
     1178                {
     1179                    pIns->hostHeap.u32HeapType = HGSMI_HEAP_TYPE_MA;
     1180                }
     1181                else
     1182                {
     1183                    HGSMIAreaClear(&pIns->hostHeap.area);
     1184                }
    9631185            }
    9641186
     
    12051427    off = pIns->hostHeap.u32HeapType == HGSMI_HEAP_TYPE_MA?
    12061428              0:
    1207               HGSMIHeapHandleLocationOffset(&pIns->hostHeap);
     1429              hgsmiHostHeapHandleLocationOffset(&pIns->hostHeap);
    12081430    rc = SSMR3PutU32 (pSSM, off);
    12091431    if(off != HGSMIOFFSET_VOID)
    12101432    {
    1211         SSMR3PutU32 (pSSM, HGSMIHeapOffset(&pIns->hostHeap));
    1212         SSMR3PutU32 (pSSM, HGSMIHeapSize(&pIns->hostHeap));
     1433        SSMR3PutU32 (pSSM, hgsmiHostHeapOffset(&pIns->hostHeap));
     1434        SSMR3PutU32 (pSSM, hgsmiHostHeapSize(&pIns->hostHeap));
    12131435        /* need save mem pointer to calculate offset on restore */
    12141436        SSMR3PutU64 (pSSM, (uint64_t)(uintptr_t)pIns->area.pu8Base);
     
    12611483    pIns->pHGFlags = (off != HGSMIOFFSET_VOID) ? (HGSMIHOSTFLAGS*)HGSMIOffsetToPointer (&pIns->area, off) : NULL;
    12621484
    1263     HGSMIHEAP hHeap = pIns->hostHeap;
     1485    HGSMIHOSTHEAP hHeap = pIns->hostHeap;
    12641486    rc = SSMR3GetU32(pSSM, &off);
    12651487    AssertRCReturn(rc, rc);
     
    13111533                if (RT_SUCCESS(rc))
    13121534                {
    1313                     rc = HGSMIHeapRestoreMA(&pIns->hostHeap,
    1314                                             pIns->area.pu8Base+offHeap,
    1315                                             cbHeap,
    1316                                             offHeap,
    1317                                             cBlocks,
    1318                                             paDescriptors,
    1319                                             cbMaxBlock,
    1320                                             &g_hgsmiEnv);
     1535                    rc = hgsmiHostHeapRestoreMA(&pIns->hostHeap,
     1536                                                pIns->area.pu8Base+offHeap,
     1537                                                cbHeap,
     1538                                                offHeap,
     1539                                                cBlocks,
     1540                                                paDescriptors,
     1541                                                cbMaxBlock,
     1542                                                &g_hgsmiEnv);
    13211543
    13221544                    RTMemFree(paDescriptors);
     
    13321554                    pIns->hostHeap.cRefs = 0;
    13331555
    1334                     rc = HGSMIHeapRelocate(&pIns->hostHeap,
    1335                                            u32HeapType,
    1336                                            pIns->area.pu8Base+offHeap,
    1337                                            off,
    1338                                            uintptr_t(pIns->area.pu8Base) - uintptr_t(oldMem),
    1339                                            cbHeap,
    1340                                            offHeap);
     1556                    rc = hgsmiHostHeapRelocate(&pIns->hostHeap,
     1557                                               u32HeapType,
     1558                                               pIns->area.pu8Base+offHeap,
     1559                                               off,
     1560                                               uintptr_t(pIns->area.pu8Base) - uintptr_t(oldMem),
     1561                                               cbHeap,
     1562                                               offHeap);
    13411563
    13421564                    hgsmiHostHeapUnlock (pIns);
     
    15341756                 size_t         cbContext)
    15351757{
    1536     LogFlowFunc(("ppIns = %p, pVM = %p, pszName = [%s], pu8MemBase = %p, cbMem = 0x%08X, offMemBase = 0x%08X, "
     1758    LogFlowFunc(("ppIns = %p, pVM = %p, pszName = [%s], offBase = 0x%08X, pu8MemBase = %p, cbMem = 0x%08X, "
    15371759                 "pfnNotifyGuest = %p, pvNotifyGuest = %p, cbContext = %d\n",
    15381760                 ppIns,
    15391761                 pVM,
    15401762                 pszName,
     1763                 offBase,
    15411764                 pu8MemBase,
    15421765                 cbMem,
     
    15851808        pIns->pszName        = VALID_PTR(pszName)? pszName: "";
    15861809
    1587         HGSMIHeapSetupUninitialized(&pIns->hostHeap);
     1810        hgsmiHostHeapSetupUninitialized(&pIns->hostHeap);
    15881811
    15891812        pIns->pfnNotifyGuest = pfnNotifyGuest;
     
    16341857#endif
    16351858
    1636     HGSMIHeapDestroy(&pIns->hostHeap);
    1637 
    1638     HGSMIHeapSetupUninitialized(&pIns->hostHeap);
     1859    hgsmiHostHeapDestroy(&pIns->hostHeap);
    16391860
    16401861    return flags;
     
    16471868    if (pIns)
    16481869    {
    1649         HGSMIHeapDestroy(&pIns->hostHeap);
     1870        hgsmiHostHeapDestroy(&pIns->hostHeap);
    16501871
    16511872        if (RTCritSectIsInitialized (&pIns->hostHeapCritSect))
  • trunk/src/VBox/Devices/Graphics/HGSMI/HGSMIHost.h

    r55401 r55421  
    6969                              uint8_t *pu8Channel);
    7070
    71 int HGSMISetupHostHeap (PHGSMIINSTANCE pIns,
    72                         HGSMIOFFSET    offHeap,
    73                         HGSMISIZE      cbHeap);
     71int HGSMIHostHeapSetup(PHGSMIINSTANCE pIns,
     72                       HGSMIOFFSET    offHeap,
     73                       HGSMISIZE      cbHeap);
    7474
    7575int HGSMISaveStateExec (PHGSMIINSTANCE pIns, PSSMHANDLE pSSM);
     
    107107/* Allocate a buffer in the host heap. */
    108108int HGSMIHostCommandAlloc (PHGSMIINSTANCE pIns,
    109                            void **ppvMem,
    110                            HGSMISIZE cbMem,
     109                           void **ppvData,
     110                           HGSMISIZE cbData,
    111111                           uint8_t u8Channel,
    112112                           uint16_t u16ChannelInfo);
     
    116116
    117117int HGSMIHostCommandProcessAndFreeAsynch (PHGSMIINSTANCE pIns,
    118                              void *pvMem,
     118                             void *pvData,
    119119                             bool bDoIrq);
    120120
  • trunk/src/VBox/GuestHost/HGSMI/HGSMICommon.cpp

    r55342 r55421  
    101101}
    102102
    103 static HGSMIOFFSET hgsmiBufferInitializeSingle (const HGSMIAREA *pArea,
    104                                                 HGSMIBUFFERHEADER *pHeader,
    105                                                 uint32_t u32DataSize,
    106                                                 uint8_t u8Channel,
    107                                                 uint16_t u16ChannelInfo)
     103int HGSMIAreaInitialize (HGSMIAREA *pArea, void *pvBase, HGSMISIZE cbArea, HGSMIOFFSET offBase)
     104{
     105    uint8_t *pu8Base = (uint8_t *)pvBase;
     106
     107    if (  !pArea                                   /* Check that the area: */
     108        || cbArea < HGSMIBufferMinimumSize ()      /* Large enough. */
     109        || pu8Base + cbArea < pu8Base              /* No address space wrap. */
     110        || offBase > UINT32_C(0xFFFFFFFF) - cbArea /* Area within the 32 bit space: offBase + cbMem <= 0xFFFFFFFF */
     111       )
     112    {
     113        return VERR_INVALID_PARAMETER;
     114    }
     115
     116    pArea->pu8Base = pu8Base;
     117    pArea->offBase = offBase;
     118    pArea->offLast = cbArea - HGSMIBufferMinimumSize () + offBase;
     119    pArea->cbArea = cbArea;
     120
     121    return VINF_SUCCESS;
     122}
     123
     124void HGSMIAreaClear (HGSMIAREA *pArea)
     125{
     126    if (pArea)
     127    {
     128        memset (pArea, 0, sizeof (HGSMIAREA));
     129    }
     130}
     131
     132/* Initialize the memory buffer including its checksum.
     133 * No changes alloed to the header and the tail after that.
     134 */
     135HGSMIOFFSET HGSMIBufferInitializeSingle(const HGSMIAREA *pArea,
     136                                        HGSMIBUFFERHEADER *pHeader,
     137                                        HGSMISIZE cbBuffer,
     138                                        uint8_t u8Channel,
     139                                        uint16_t u16ChannelInfo)
    108140{
    109141    if (   !pArea
    110         || !pHeader)
     142        || !pHeader
     143        || cbBuffer < HGSMIBufferMinimumSize())
    111144    {
    112145        return HGSMIOFFSET_VOID;
     
    119152     */
    120153    HGSMISIZE cbMaximumDataSize = pArea->offLast - pArea->offBase;
     154    uint32_t u32DataSize = cbBuffer - HGSMIBufferMinimumSize();
    121155
    122156    if (   u32DataSize > cbMaximumDataSize
     
    143177}
    144178
    145 int HGSMIAreaInitialize (HGSMIAREA *pArea, void *pvBase, HGSMISIZE cbArea, HGSMIOFFSET offBase)
    146 {
    147     uint8_t *pu8Base = (uint8_t *)pvBase;
    148 
    149     if (  !pArea                                   /* Check that the area: */
    150         || cbArea < HGSMIBufferMinimumSize ()      /* Large enough. */
    151         || pu8Base + cbArea < pu8Base              /* No address space wrap. */
    152         || offBase > UINT32_C(0xFFFFFFFF) - cbArea /* Area within the 32 bit space: offBase + cbMem <= 0xFFFFFFFF */
    153        )
    154     {
    155         return VERR_INVALID_PARAMETER;
    156     }
    157 
    158     pArea->pu8Base = pu8Base;
    159     pArea->offBase = offBase;
    160     pArea->offLast = cbArea - HGSMIBufferMinimumSize () + offBase;
    161     pArea->cbArea = cbArea;
    162 
    163     return VINF_SUCCESS;
    164 }
    165 
    166 void HGSMIAreaClear (HGSMIAREA *pArea)
    167 {
    168     if (pArea)
    169     {
    170         memset (pArea, 0, sizeof (HGSMIAREA));
    171     }
    172 }
    173 
    174 /* Initialize the memory buffer including its checksum.
    175  * No changes alloed to the header and the tail after that.
    176  */
    177 HGSMIOFFSET HGSMIBufferInitializeSingle (const HGSMIAREA *pArea,
    178                                          HGSMIBUFFERHEADER *pHeader,
    179                                          HGSMISIZE cbBuffer,
    180                                          uint8_t u8Channel,
    181                                          uint16_t u16ChannelInfo)
    182 {
    183     if (cbBuffer < HGSMIBufferMinimumSize ())
    184     {
    185         return HGSMIOFFSET_VOID;
    186     }
    187 
    188     return hgsmiBufferInitializeSingle (pArea, pHeader, cbBuffer - HGSMIBufferMinimumSize (), u8Channel, u16ChannelInfo);
    189 }
    190 
    191 void HGSMIHeapSetupUninitialized(HGSMIHEAP *pHeap)
    192 {
    193     RT_ZERO(*pHeap);
    194     pHeap->u32HeapType = HGSMI_HEAP_TYPE_NULL;
    195 }
    196 
    197 int HGSMIHeapRelocate (HGSMIHEAP *pHeap,
    198                        uint32_t u32HeapType,
    199                        void *pvBase,
    200                        uint32_t offHeapHandle,
    201                        uintptr_t offDelta,
    202                        HGSMISIZE cbArea,
    203                        HGSMIOFFSET offBase)
    204 {
    205     if (   !pHeap
    206         || !pvBase)
    207     {
    208         return VERR_INVALID_PARAMETER;
    209     }
    210 
    211     int rc = HGSMIAreaInitialize (&pHeap->area, pvBase, cbArea, offBase);
    212 
    213     if (RT_SUCCESS (rc))
    214     {
    215         if (u32HeapType == HGSMI_HEAP_TYPE_OFFSET)
    216         {
    217             pHeap->u.hOff = (RTHEAPOFFSET)((uint8_t *)pvBase + offHeapHandle);
    218         }
    219         else if (u32HeapType == HGSMI_HEAP_TYPE_POINTER)
    220         {
    221             pHeap->u.hPtr = (RTHEAPSIMPLE)((uint8_t *)pvBase + offHeapHandle);
    222             rc = RTHeapSimpleRelocate (pHeap->u.hPtr, offDelta); AssertRC(rc);
    223         }
    224         else
    225         {
    226             /* HGSMI_HEAP_TYPE_MA does not need the relocation. */
    227             rc = VERR_NOT_SUPPORTED;
    228         }
    229 
    230         if (RT_SUCCESS(rc))
    231         {
    232             pHeap->cRefs = 0;
    233             pHeap->u32HeapType = u32HeapType;
    234         }
    235         else
    236         {
    237             HGSMIAreaClear (&pHeap->area);
    238         }
    239     }
    240 
    241     return rc;
    242 }
    243 
    244 int HGSMIHeapRestoreMA(HGSMIHEAP *pHeap,
    245                        void *pvBase,
    246                        HGSMISIZE cbArea,
    247                        HGSMIOFFSET offBase,
    248                        uint32_t cBlocks,
    249                        HGSMIOFFSET *paDescriptors,
    250                        HGSMISIZE cbMaxBlock,
    251                        HGSMIENV *pEnv)
    252 {
    253     int rc = HGSMIAreaInitialize(&pHeap->area, pvBase, cbArea, offBase);
    254 
    255     if (RT_SUCCESS (rc))
    256     {
    257         rc = HGSMIMAInit(&pHeap->u.ma, &pHeap->area, paDescriptors, cBlocks, cbMaxBlock, pEnv);
    258 
    259         if (RT_SUCCESS(rc))
    260         {
    261             pHeap->cRefs = 0;
    262             pHeap->u32HeapType = HGSMI_HEAP_TYPE_MA;
    263         }
    264         else
    265         {
    266             HGSMIAreaClear(&pHeap->area);
    267         }
    268     }
    269 
    270     return rc;
    271 }
    272 
    273179int HGSMIHeapSetup (HGSMIHEAP *pHeap,
    274                     uint32_t u32HeapType,
    275180                    void *pvBase,
    276181                    HGSMISIZE cbArea,
     
    288193    if (RT_SUCCESS (rc))
    289194    {
    290         if (u32HeapType == HGSMI_HEAP_TYPE_MA)
    291         {
    292             rc = HGSMIMAInit(&pHeap->u.ma, &pHeap->area, NULL, 0, 0, pEnv);
    293         }
    294         else if (u32HeapType == HGSMI_HEAP_TYPE_POINTER)
    295         {
    296             rc = RTHeapSimpleInit (&pHeap->u.hPtr, pvBase, cbArea);
    297         }
    298         else if (u32HeapType == HGSMI_HEAP_TYPE_OFFSET)
    299         {
    300             rc = RTHeapOffsetInit (&pHeap->u.hOff, pvBase, cbArea);
    301         }
    302         else
    303         {
    304             rc = VERR_NOT_SUPPORTED;
    305         }
    306 
    307         if (RT_SUCCESS (rc))
    308         {
    309             pHeap->cRefs = 0;
    310             pHeap->u32HeapType = u32HeapType;
    311         }
    312         else
     195        rc = HGSMIMAInit(&pHeap->ma, &pHeap->area, NULL, 0, 0, pEnv);
     196        if (RT_FAILURE(rc))
    313197        {
    314198            HGSMIAreaClear (&pHeap->area);
     
    323207    if (pHeap)
    324208    {
    325         if (pHeap->u32HeapType == HGSMI_HEAP_TYPE_MA)
    326         {
    327             HGSMIMAUninit(&pHeap->u.ma);
    328         }
    329         Assert(!pHeap->cRefs);
    330         HGSMIHeapSetupUninitialized(pHeap);
     209        HGSMIMAUninit(&pHeap->ma);
    331210    }
    332211}
     
    343222        return NULL;
    344223
    345     hgsmiBufferInitializeSingle (&pHeap->area, pHeader, cbData, u8Channel, u16ChannelInfo);
     224    HGSMIOFFSET offBuffer = HGSMIBufferInitializeSingle(HGSMIHeapArea(pHeap), pHeader,
     225                                                        cbAlloc, u8Channel, u16ChannelInfo);
     226    if (offBuffer == HGSMIOFFSET_VOID)
     227    {
     228        HGSMIHeapBufferFree(pHeap, pHeader);
     229        return NULL;
     230    }
    346231
    347232    return HGSMIBufferData (pHeader);
    348 }
    349 
    350 HGSMIOFFSET HGSMIHeapBufferOffset (HGSMIHEAP *pHeap,
    351                                    void *pvData)
    352 {
    353     HGSMIBUFFERHEADER *pHeader = HGSMIBufferHeaderFromData (pvData);
    354 
    355     HGSMIOFFSET offBuffer = HGSMIPointerToOffset (&pHeap->area, pHeader);
    356 
    357     return offBuffer;
    358233}
    359234
     
    361236                    void *pvData)
    362237{
    363     if (   pvData
    364         && pHeap->u32HeapType != HGSMI_HEAP_TYPE_NULL)
     238    if (pvData)
    365239    {
    366240        HGSMIBUFFERHEADER *pHeader = HGSMIBufferHeaderFromData (pvData);
     
    372246void* HGSMIHeapBufferAlloc (HGSMIHEAP *pHeap, HGSMISIZE cbBuffer)
    373247{
    374     void* pvBuf = NULL;
    375     if (pHeap->u32HeapType == HGSMI_HEAP_TYPE_MA)
    376     {
    377         pvBuf = HGSMIMAAlloc(&pHeap->u.ma, cbBuffer);
    378     }
    379     else if (pHeap->u32HeapType == HGSMI_HEAP_TYPE_POINTER)
    380     {
    381         pvBuf = RTHeapSimpleAlloc (pHeap->u.hPtr, cbBuffer, 0);
    382     }
    383     else if (pHeap->u32HeapType == HGSMI_HEAP_TYPE_OFFSET)
    384     {
    385         pvBuf = RTHeapOffsetAlloc (pHeap->u.hOff, cbBuffer, 0);
    386     }
    387 
    388     if (pvBuf)
    389     {
    390         ++pHeap->cRefs;
    391     }
    392 
     248    void *pvBuf = HGSMIMAAlloc(&pHeap->ma, cbBuffer);
    393249    return pvBuf;
    394250}
     
    397253                         void *pvBuf)
    398254{
    399     if (pHeap->u32HeapType == HGSMI_HEAP_TYPE_MA)
    400     {
    401         HGSMIMAFree(&pHeap->u.ma, pvBuf);
    402     }
    403     else if (pHeap->u32HeapType == HGSMI_HEAP_TYPE_POINTER)
    404     {
    405         RTHeapSimpleFree (pHeap->u.hPtr, pvBuf);
    406     }
    407     else if (pHeap->u32HeapType == HGSMI_HEAP_TYPE_OFFSET)
    408     {
    409         RTHeapOffsetFree (pHeap->u.hOff, pvBuf);
    410     }
    411 
    412     --pHeap->cRefs;
     255    HGSMIMAFree(&pHeap->ma, pvBuf);
    413256}
    414257
     
    457300            uint32_t u32Checksum = HGSMIChecksum(offBuffer, &header, &tail);
    458301            LogFlowFunc(("checksum check: u32Checksum = 0x%x pTail->u32Checksum = 0x%x\n",
    459                          u32Checksum, pTail->u32Checksum));
     302                         u32Checksum, tail.u32Checksum));
    460303            if (u32Checksum == tail.u32Checksum)
    461304            {
     
    468311            {
    469312                LogFunc(("invalid checksum 0x%x, expected 0x%x!!!\n",
    470                          u32Checksum, pTail->u32Checksum));
     313                         u32Checksum, tail.u32Checksum));
    471314                rc = VERR_INVALID_STATE;
    472315                HGSMI_STRICT_ASSERT_FAILED();
     
    487330/* A wrapper to safely call the handler.
    488331 */
    489 static int hgsmiChannelHandlerCall(const HGSMICHANNELHANDLER *pHandler,
    490                                    const HGSMIBUFFERCONTEXT *pBufferContext)
     332static void hgsmiChannelHandlerCall(const HGSMICHANNELHANDLER *pHandler,
     333                                    const HGSMIBUFFERCONTEXT *pBufferContext)
    491334{
    492335    LogFlowFunc(("pHandler %p\n", pHandler));
    493 
    494     int rc;
    495336
    496337    if (   pHandler
    497338        && pHandler->pfnHandler)
    498339    {
    499         rc = pHandler->pfnHandler(pHandler->pvHandler, pBufferContext->pHeader->u16ChannelInfo,
    500                                   pBufferContext->pvData, pBufferContext->cbData);
    501     }
    502     else
    503     {
    504         /* It is a NOOP case here. */
    505         rc = VINF_SUCCESS;
    506     }
    507 
    508     LogFlowFunc(("leave rc = %Rrc\n", rc));
    509     return rc;
     340        pHandler->pfnHandler(pHandler->pvHandler, pBufferContext->pHeader->u16ChannelInfo,
     341                             pBufferContext->pvData, pBufferContext->cbData);
     342    }
    510343}
    511344
     
    557390        if (pChannel)
    558391        {
    559             rc = hgsmiChannelHandlerCall(&pChannel->handler, &bufferContext);
     392            hgsmiChannelHandlerCall(&pChannel->handler, &bufferContext);
    560393            HGSMI_STRICT_ASSERT(RT_SUCCESS(hgsmiVerifyBuffer(pArea, offBuffer, &bufferContext)));
    561394        }
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette