VirtualBox

Ignore:
Timestamp:
Apr 3, 2018 2:23:01 PM (7 years ago)
Author:
vboxsync
Message:

DevVGA: Code cleanup in progress. bugref:9094

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Graphics/HGSMI/HGSMIHost.cpp

    r71626 r71629  
    11/* $Id$ */
    22/** @file
    3  *
    4  * VBox Host Guest Shared Memory Interface (HGSMI).
     3 * VBox Host Guest Shared Memory Interface (HGSMI), host part.
     4 *
    55 * Host part:
    66 *  - virtual hardware IO handlers;
     
    8686
    8787#ifdef VBOXHGSMI_STATE_DEBUG
    88 #define VBOXHGSMI_STATE_START_MAGIC 0x12345678
    89 #define VBOXHGSMI_STATE_STOP_MAGIC  0x87654321
    90 #define VBOXHGSMI_STATE_FIFOSTART_MAGIC 0x9abcdef1
    91 #define VBOXHGSMI_STATE_FIFOSTOP_MAGIC 0x1fedcba9
    92 
    93 #define VBOXHGSMI_SAVE_START(_pSSM)     do{ int rc2 = SSMR3PutU32(_pSSM, VBOXHGSMI_STATE_START_MAGIC);     AssertRC(rc2); }while(0)
    94 #define VBOXHGSMI_SAVE_STOP(_pSSM)      do{ int rc2 = SSMR3PutU32(_pSSM, VBOXHGSMI_STATE_STOP_MAGIC);      AssertRC(rc2); }while(0)
    95 #define VBOXHGSMI_SAVE_FIFOSTART(_pSSM) do{ int rc2 = SSMR3PutU32(_pSSM, VBOXHGSMI_STATE_FIFOSTART_MAGIC); AssertRC(rc2); }while(0)
    96 #define VBOXHGSMI_SAVE_FIFOSTOP(_pSSM)  do{ int rc2 = SSMR3PutU32(_pSSM, VBOXHGSMI_STATE_FIFOSTOP_MAGIC);  AssertRC(rc2); }while(0)
    97 
    98 #define VBOXHGSMI_LOAD_CHECK(_pSSM, _v) \
    99     do{ \
     88# define VBOXHGSMI_STATE_START_MAGIC     UINT32_C(0x12345678)
     89# define VBOXHGSMI_STATE_STOP_MAGIC      UINT32_C(0x87654321)
     90# define VBOXHGSMI_STATE_FIFOSTART_MAGIC UINT32_C(0x9abcdef1)
     91# define VBOXHGSMI_STATE_FIFOSTOP_MAGIC  UINT32_C(0x1fedcba9)
     92
     93# define VBOXHGSMI_SAVE_START(_pSSM)     do{ int rc2 = SSMR3PutU32(_pSSM, VBOXHGSMI_STATE_START_MAGIC);     AssertRC(rc2); }while(0)
     94# define VBOXHGSMI_SAVE_STOP(_pSSM)      do{ int rc2 = SSMR3PutU32(_pSSM, VBOXHGSMI_STATE_STOP_MAGIC);      AssertRC(rc2); }while(0)
     95# define VBOXHGSMI_SAVE_FIFOSTART(_pSSM) do{ int rc2 = SSMR3PutU32(_pSSM, VBOXHGSMI_STATE_FIFOSTART_MAGIC); AssertRC(rc2); }while(0)
     96# define VBOXHGSMI_SAVE_FIFOSTOP(_pSSM)  do{ int rc2 = SSMR3PutU32(_pSSM, VBOXHGSMI_STATE_FIFOSTOP_MAGIC);  AssertRC(rc2); }while(0)
     97
     98# define VBOXHGSMI_LOAD_CHECK(_pSSM, _v) \
     99    do { \
    100100        uint32_t u32; \
    101101        int rc2 = SSMR3GetU32(_pSSM, &u32); AssertRC(rc2); \
    102102        Assert(u32 == (_v)); \
    103     }while(0)
    104 
    105 #define VBOXHGSMI_LOAD_START(_pSSM) VBOXHGSMI_LOAD_CHECK(_pSSM, VBOXHGSMI_STATE_START_MAGIC)
    106 #define VBOXHGSMI_LOAD_FIFOSTART(_pSSM) VBOXHGSMI_LOAD_CHECK(_pSSM, VBOXHGSMI_STATE_FIFOSTART_MAGIC)
    107 #define VBOXHGSMI_LOAD_FIFOSTOP(_pSSM) VBOXHGSMI_LOAD_CHECK(_pSSM, VBOXHGSMI_STATE_FIFOSTOP_MAGIC)
    108 #define VBOXHGSMI_LOAD_STOP(_pSSM) VBOXHGSMI_LOAD_CHECK(_pSSM, VBOXHGSMI_STATE_STOP_MAGIC)
    109 #else
    110 #define VBOXHGSMI_SAVE_START(_pSSM) do{ }while(0)
    111 #define VBOXHGSMI_SAVE_STOP(_pSSM) do{ }while(0)
    112 #define VBOXHGSMI_SAVE_FIFOSTART(_pSSM) do{ }while(0)
    113 #define VBOXHGSMI_SAVE_FIFOSTOP(_pSSM) do{ }while(0)
    114 
    115 
    116 #define VBOXHGSMI_LOAD_START(_pSSM) do{ }while(0)
    117 #define VBOXHGSMI_LOAD_FIFOSTART(_pSSM) do{ }while(0)
    118 #define VBOXHGSMI_LOAD_FIFOSTOP(_pSSM) do{ }while(0)
    119 #define VBOXHGSMI_LOAD_STOP(_pSSM) do{ }while(0)
    120 
     103    } while(0)
     104
     105# define VBOXHGSMI_LOAD_START(_pSSM) VBOXHGSMI_LOAD_CHECK(_pSSM, VBOXHGSMI_STATE_START_MAGIC)
     106# define VBOXHGSMI_LOAD_FIFOSTART(_pSSM) VBOXHGSMI_LOAD_CHECK(_pSSM, VBOXHGSMI_STATE_FIFOSTART_MAGIC)
     107# define VBOXHGSMI_LOAD_FIFOSTOP(_pSSM) VBOXHGSMI_LOAD_CHECK(_pSSM, VBOXHGSMI_STATE_FIFOSTOP_MAGIC)
     108# define VBOXHGSMI_LOAD_STOP(_pSSM) VBOXHGSMI_LOAD_CHECK(_pSSM, VBOXHGSMI_STATE_STOP_MAGIC)
     109#else   /* !VBOXHGSMI_STATE_DEBUG */
     110# define VBOXHGSMI_SAVE_START(a_pSSM)       do { } while(0)
     111# define VBOXHGSMI_SAVE_STOP(a_pSSM)        do { } while(0)
     112# define VBOXHGSMI_SAVE_FIFOSTART(a_pSSM)   do { } while(0)
     113# define VBOXHGSMI_SAVE_FIFOSTOP(a_pSSM)    do { } while(0)
     114
     115# define VBOXHGSMI_LOAD_START(a_pSSM)       do { } while(0)
     116# define VBOXHGSMI_LOAD_FIFOSTART(a_pSSM)   do { } while(0)
     117# define VBOXHGSMI_LOAD_FIFOSTOP(a_pSSM)    do { } while(0)
     118# define VBOXHGSMI_LOAD_STOP(a_pSSM)        do { } while(0)
    121119#endif
    122120
     
    125123 */
    126124#ifdef HGSMI_STRICT
    127 #define HGSMI_STRICT_ASSERT_FAILED() AssertFailed()
    128 #define HGSMI_STRICT_ASSERT(expr) Assert(expr)
     125# define HGSMI_STRICT_ASSERT_FAILED()  AssertFailed()
     126# define HGSMI_STRICT_ASSERT(expr)      Assert(expr)
    129127#else
    130 #define HGSMI_STRICT_ASSERT_FAILED() do {} while (0)
    131 #define HGSMI_STRICT_ASSERT(expr) do {} while (0)
    132 #endif /* !HGSMI_STRICT */
    133 
    134 
    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. */
     128# define HGSMI_STRICT_ASSERT_FAILED()   do {} while (0)
     129# define HGSMI_STRICT_ASSERT(expr)      do {} while (0)
     130#endif
     131
     132
     133/** @name Host heap types.
     134 *  @{ */
     135#define HGSMI_HEAP_TYPE_NULL    0 /**< Heap not initialized. */
     136#define HGSMI_HEAP_TYPE_POINTER 1 /**< Deprecated, used only for old saved states. RTHEAPSIMPLE. */
     137#define HGSMI_HEAP_TYPE_OFFSET  2 /**< Deprecated, used only for old saved states. RTHEAPOFFSET. */
     138#define HGSMI_HEAP_TYPE_MA      3 /**< Memory allocator. */
     139/** @} */
    140140
    141141typedef struct HGSMIHOSTHEAP
    142142{
    143     uint32_t u32HeapType;   /* HGSMI_HEAP_TYPE_* */
    144     int32_t volatile cRefs; /* How many blocks allocated. */
    145     HGSMIAREA area;         /* Host heap location. */
     143    uint32_t u32HeapType;   /**< HGSMI_HEAP_TYPE_* */
     144    int32_t volatile cRefs; /**< How many blocks allocated. */
     145    HGSMIAREA area;         /**< Host heap location. */
    146146    union
    147147    {
    148         HGSMIMADATA ma;     /* Memory allocator for the default host heap implementation. */
    149         struct              /* Legacy heap implementations. For old saved states. */
     148        HGSMIMADATA ma;     /**< Memory allocator for the default host heap implementation. */
     149        struct              /**< Legacy heap implementations. For old saved states. */
    150150        {
    151151            union
    152152            {
    153                 RTHEAPSIMPLE hPtr;  /* Pointer based heap. */
    154                 RTHEAPOFFSET hOff;  /* Offset based heap. */
     153                RTHEAPSIMPLE hPtr;  /**< Pointer based heap. */
     154                RTHEAPOFFSET hOff;  /**< Offset based heap. */
    155155            } u;
    156156        } legacy;
     
    160160typedef struct HGSMIINSTANCE
    161161{
    162     PVM pVM;                           /* The VM. */
    163 
    164     const char *pszName;               /* A name for the instance. Mostyl used in the log. */
    165 
    166     RTCRITSECT   instanceCritSect;     /* For updating the instance data: FIFO's, channels. */
    167 
    168     HGSMIAREA area; /* The shared memory description. */
    169     HGSMIHOSTHEAP hostHeap;            /* Host heap instance. */
    170     RTCRITSECT    hostHeapCritSect;    /* Heap serialization lock. */
    171 
    172     RTLISTANCHOR hostFIFO;             /* Pending host buffers. */
    173     RTLISTANCHOR hostFIFORead;         /* Host buffers read by the guest. */
    174     RTLISTANCHOR hostFIFOProcessed;    /* Processed by the guest. */
    175     RTLISTANCHOR hostFIFOFree;         /* Buffers for reuse. */
     162    PVM pVM;                           /**< The VM. */
     163
     164    const char *pszName;               /**< A name for the instance. Mostyl used in the log. */
     165
     166    RTCRITSECT   instanceCritSect;     /**< For updating the instance data: FIFO's, channels. */
     167
     168    HGSMIAREA     area;                /**< The shared memory description. */
     169    HGSMIHOSTHEAP hostHeap;            /**< Host heap instance. */
     170    RTCRITSECT    hostHeapCritSect;    /**< Heap serialization lock. */
     171
     172    RTLISTANCHOR hostFIFO;             /**< Pending host buffers. */
     173    RTLISTANCHOR hostFIFORead;         /**< Host buffers read by the guest. */
     174    RTLISTANCHOR hostFIFOProcessed;    /**< Processed by the guest. */
     175    RTLISTANCHOR hostFIFOFree;         /**< Buffers for reuse. */
    176176#ifdef VBOX_WITH_WDDM
    177     RTLISTANCHOR guestCmdCompleted;    /* list of completed guest commands to be returned to the guest*/
     177    RTLISTANCHOR guestCmdCompleted;    /**< list of completed guest commands to be returned to the guest*/
    178178#endif
    179     RTCRITSECT hostFIFOCritSect;       /* FIFO serialization lock. */
    180 
    181     PFNHGSMINOTIFYGUEST pfnNotifyGuest; /* Guest notification callback. */
    182     void *pvNotifyGuest;                /* Guest notification callback context. */
     179    RTCRITSECT hostFIFOCritSect;       /**< FIFO serialization lock. */
     180
     181    PFNHGSMINOTIFYGUEST pfnNotifyGuest; /**< Guest notification callback. */
     182    void *pvNotifyGuest;                /**< Guest notification callback context. */
    183183
    184184    volatile HGSMIHOSTFLAGS *pHGFlags;
    185185
    186     HGSMICHANNELINFO channelInfo;      /* Channel handlers indexed by the channel id.
     186    HGSMICHANNELINFO channelInfo;      /**< Channel handlers indexed by the channel id.
    187187                                        * The array is accessed under the instance lock.
    188188                                        */
     
    197197    RTLISTNODE nodeEntry;
    198198
    199     HGSMIINSTANCE *pIns;               /* Backlink to the HGSMI instance. */
    200 
    201     volatile uint32_t fl;              /* Status flags of the entry. */
    202 
    203     HGSMIOFFSET offBuffer;             /* Offset of the HGSMI buffer header in the HGSMI host heap:
     199    HGSMIINSTANCE *pIns;               /**< Backlink to the HGSMI instance. */
     200
     201    volatile uint32_t fl;              /**< Status flags of the entry. */
     202
     203    HGSMIOFFSET offBuffer;             /**< Offset of the HGSMI buffer header in the HGSMI host heap:
    204204                                        * [pIns->hostHeap.area.offBase .. offLast]. */
    205205} HGSMIHOSTFIFOENTRY;
     
    213213#define HGSMI_F_HOST_FIFO_CANCELED  0x0020
    214214
    215 static DECLCALLBACK(void) hgsmiHostCommandFreeCallback (void *pvCallback);
     215static DECLCALLBACK(void) hgsmiHostCommandFreeCallback(void *pvCallback);
    216216
    217217#ifdef VBOX_WITH_WDDM
     
    220220{
    221221    RTLISTNODE nodeEntry;
    222     HGSMIOFFSET offBuffer; /* Offset of the guest command buffer. */
     222    HGSMIOFFSET offBuffer; /**< Offset of the guest command buffer. */
    223223} HGSMIGUESTCOMPLENTRY;
    224224
    225225
    226 static void hgsmiGuestCompletionFIFOFree (HGSMIINSTANCE *pIns, HGSMIGUESTCOMPLENTRY *pEntry)
     226static void hgsmiGuestCompletionFIFOFree(HGSMIINSTANCE *pIns, HGSMIGUESTCOMPLENTRY *pEntry)
    227227{
    228228    NOREF (pIns);
     
    230230}
    231231
    232 static int hgsmiGuestCompletionFIFOAlloc (HGSMIINSTANCE *pIns, HGSMIGUESTCOMPLENTRY **ppEntry)
    233 {
    234     int rc = VINF_SUCCESS;
    235 
    236     NOREF (pIns);
    237 
    238     HGSMIGUESTCOMPLENTRY *pEntry = (HGSMIGUESTCOMPLENTRY *)RTMemAllocZ (sizeof (HGSMIGUESTCOMPLENTRY));
    239 
     232static int hgsmiGuestCompletionFIFOAlloc(HGSMIINSTANCE *pIns, HGSMIGUESTCOMPLENTRY **ppEntry)
     233{
     234    HGSMIGUESTCOMPLENTRY *pEntry = (HGSMIGUESTCOMPLENTRY *)RTMemAllocZ(sizeof(HGSMIGUESTCOMPLENTRY));
    240235    if (pEntry)
     236    {
    241237        *ppEntry = pEntry;
    242     else
    243         rc = VERR_NO_MEMORY;
    244 
    245     return rc;
    246 }
    247 
    248 #endif
    249 
    250 static int hgsmiLock (HGSMIINSTANCE *pIns)
    251 {
    252     int rc = RTCritSectEnter (&pIns->instanceCritSect);
    253     AssertRC (rc);
    254     return rc;
    255 }
    256 
    257 static void hgsmiUnlock (HGSMIINSTANCE *pIns)
    258 {
    259     int rc = RTCritSectLeave (&pIns->instanceCritSect);
    260     AssertRC (rc);
    261 }
    262 
    263 static int hgsmiFIFOLock (HGSMIINSTANCE *pIns)
    264 {
    265     int rc = RTCritSectEnter (&pIns->hostFIFOCritSect);
    266     AssertRC (rc);
    267     return rc;
    268 }
    269 
    270 static void hgsmiFIFOUnlock (HGSMIINSTANCE *pIns)
    271 {
    272     int rc = RTCritSectLeave (&pIns->hostFIFOCritSect);
    273     AssertRC (rc);
     238        return VINF_SUCCESS;
     239    }
     240    NOREF(pIns);
     241    return VERR_NO_MEMORY;
     242}
     243
     244#endif /* VBOX_WITH_WDDM */
     245
     246static int hgsmiLock(HGSMIINSTANCE *pIns)
     247{
     248    int rc = RTCritSectEnter(&pIns->instanceCritSect);
     249    AssertRC(rc);
     250    return rc;
     251}
     252
     253static void hgsmiUnlock(HGSMIINSTANCE *pIns)
     254{
     255    int rc = RTCritSectLeave(&pIns->instanceCritSect);
     256    AssertRC(rc);
     257}
     258
     259static int hgsmiFIFOLock(HGSMIINSTANCE *pIns)
     260{
     261    int rc = RTCritSectEnter(&pIns->hostFIFOCritSect);
     262    AssertRC(rc);
     263    return rc;
     264}
     265
     266static void hgsmiFIFOUnlock(HGSMIINSTANCE *pIns)
     267{
     268    int rc = RTCritSectLeave(&pIns->hostFIFOCritSect);
     269    AssertRC(rc);
    274270}
    275271
     
    282278 * @thread EMT
    283279 */
    284 void HGSMIGuestWrite (PHGSMIINSTANCE pIns,
    285                       HGSMIOFFSET offBuffer)
    286 {
    287     HGSMIBufferProcess (&pIns->area, &pIns->channelInfo, offBuffer);
     280void HGSMIGuestWrite(PHGSMIINSTANCE pIns, HGSMIOFFSET offBuffer)
     281{
     282    HGSMIBufferProcess(&pIns->area, &pIns->channelInfo, offBuffer);
    288283}
    289284
     
    325320
    326321/* Called from HGSMI_IO_GUEST read handler. */
    327 HGSMIOFFSET HGSMIGuestRead (PHGSMIINSTANCE pIns)
     322HGSMIOFFSET HGSMIGuestRead(PHGSMIINSTANCE pIns)
    328323{
    329324    LogFlowFunc(("pIns %p\n", pIns));
     
    346341}
    347342
    348 static bool hgsmiProcessHostCmdCompletion(HGSMIINSTANCE *pIns,
    349                                           HGSMIOFFSET offBuffer,
    350                                           bool bCompleteFirst)
     343static bool hgsmiProcessHostCmdCompletion(HGSMIINSTANCE *pIns, HGSMIOFFSET offBuffer, bool fCompleteFirst)
    351344{
    352345    VM_ASSERT_EMT(pIns->pVM);
     
    362355        {
    363356            Assert(pIter->fl == (HGSMI_F_HOST_FIFO_ALLOCATED | HGSMI_F_HOST_FIFO_READ));
    364             if (bCompleteFirst || pIter->offBuffer == offBuffer)
     357            if (fCompleteFirst || pIter->offBuffer == offBuffer)
    365358            {
    366359                pEntry = pIter;
     
    371364        LogFlowFunc(("read list entry: %p.\n", pEntry));
    372365
    373         Assert(pEntry || bCompleteFirst);
     366        Assert(pEntry || fCompleteFirst);
    374367
    375368        if (pEntry)
     
    385378
    386379            hgsmiHostCommandFreeCallback(pEntry);
    387 
    388380            return true;
    389381        }
    390382
    391383        hgsmiFIFOUnlock(pIns);
    392         if (!bCompleteFirst)
     384        if (!fCompleteFirst)
    393385            LogRel(("HGSMI[%s]: ignored invalid write to the host FIFO: 0x%08X!!!\n", pIns->pszName, offBuffer));
    394386    }
     
    396388}
    397389
    398 /* The guest has finished processing of a buffer previously submitted by the host.
     390/**
     391 * The guest has finished processing of a buffer previously submitted by the
     392 * host.
     393 *
    399394 * Called from HGSMI_IO_HOST write handler.
    400395 * @thread EMT
    401396 */
    402 void HGSMIHostWrite (HGSMIINSTANCE *pIns,
    403                      HGSMIOFFSET offBuffer)
     397void HGSMIHostWrite(HGSMIINSTANCE *pIns, HGSMIOFFSET offBuffer)
    404398{
    405399    LogFlowFunc(("pIns %p offBuffer 0x%x\n", pIns, offBuffer));
    406400
    407     hgsmiProcessHostCmdCompletion (pIns, offBuffer, false);
    408 }
    409 
    410 /* The guest reads a new host buffer to be processed.
     401    hgsmiProcessHostCmdCompletion(pIns, offBuffer, false);
     402}
     403
     404/**
     405 * The guest reads a new host buffer to be processed.
     406 *
    411407 * Called from the HGSMI_IO_HOST read handler.
     408 *
    412409 * @thread EMT
    413410 */
    414 HGSMIOFFSET HGSMIHostRead (HGSMIINSTANCE *pIns)
     411HGSMIOFFSET HGSMIHostRead(HGSMIINSTANCE *pIns)
    415412{
    416413    LogFlowFunc(("pIns %p\n", pIns));
     
    460457
    461458
    462 /* Tells the guest that a new buffer to be processed is available from the host. */
    463 static void hgsmiNotifyGuest (HGSMIINSTANCE *pIns)
     459/** Tells the guest that a new buffer to be processed is available from the host. */
     460static void hgsmiNotifyGuest(HGSMIINSTANCE *pIns)
    464461{
    465462    if (pIns->pfnNotifyGuest)
    466     {
    467         pIns->pfnNotifyGuest (pIns->pvNotifyGuest);
    468     }
     463        pIns->pfnNotifyGuest(pIns->pvNotifyGuest);
    469464}
    470465
     
    477472uint32_t HGSMIGetHostGuestFlags(HGSMIINSTANCE *pIns)
    478473{
    479     return pIns->pHGFlags? ASMAtomicReadU32(&pIns->pHGFlags->u32HostFlags) : 0;
     474    return pIns->pHGFlags ? ASMAtomicReadU32(&pIns->pHGFlags->u32HostFlags) : 0;
    480475}
    481476
     
    483478{
    484479    AssertPtrReturnVoid(pIns->pHGFlags);
    485     ASMAtomicAndU32(&pIns->pHGFlags->u32HostFlags, (~flags));
    486 }
     480    ASMAtomicAndU32(&pIns->pHGFlags->u32HostFlags, ~flags);
     481}
     482
    487483
    488484/*
     
    492488 *
    493489 */
     490
    494491static int hgsmiHostHeapLock(HGSMIINSTANCE *pIns)
    495492{
    496493    int rc = RTCritSectEnter(&pIns->hostHeapCritSect);
    497     AssertRC (rc);
     494    AssertRC(rc);
    498495    return rc;
    499496}
     
    502499{
    503500    int rc = RTCritSectLeave(&pIns->hostHeapCritSect);
    504     AssertRC (rc);
     501    AssertRC(rc);
    505502}
    506503
     
    570567    HGSMIOFFSET offHeapHandle;
    571568    if (pHeap->u32HeapType == HGSMI_HEAP_TYPE_POINTER)
    572     {
    573569        offHeapHandle = (HGSMIOFFSET)((uintptr_t)pHeap->u.legacy.u.hPtr - (uintptr_t)pHeap->area.pu8Base);
    574     }
    575570    else if (pHeap->u32HeapType == HGSMI_HEAP_TYPE_OFFSET)
    576     {
    577571        offHeapHandle = (HGSMIOFFSET)((uintptr_t)pHeap->u.legacy.u.hOff - (uintptr_t)pHeap->area.pu8Base);
    578     }
    579572    else
    580     {
    581573        offHeapHandle = HGSMIOFFSET_VOID;
    582     }
    583574    return offHeapHandle;
    584575}
     
    596587    {
    597588        if (u32HeapType == HGSMI_HEAP_TYPE_OFFSET)
    598         {
    599589            pHeap->u.legacy.u.hOff = (RTHEAPOFFSET)((uint8_t *)pvBase + offHeapHandle);
    600         }
    601590        else if (u32HeapType == HGSMI_HEAP_TYPE_POINTER)
    602591        {
     
    611600
    612601        if (RT_SUCCESS(rc))
    613         {
    614602            pHeap->u32HeapType = u32HeapType;
    615         }
    616603        else
    617         {
    618604            HGSMIAreaClear(&pHeap->area);
    619         }
    620605    }
    621606
     
    636621    {
    637622        rc = HGSMIMAInit(&pHeap->u.ma, &pHeap->area, paDescriptors, cBlocks, cbMaxBlock, pEnv);
    638 
    639623        if (RT_SUCCESS(rc))
    640         {
    641624            pHeap->u32HeapType = HGSMI_HEAP_TYPE_MA;
    642         }
    643625        else
    644         {
    645626            HGSMIAreaClear(&pHeap->area);
    646         }
    647627    }
    648628
     
    659639{
    660640    if (pHeap->u32HeapType == HGSMI_HEAP_TYPE_MA)
    661     {
    662641        HGSMIMAUninit(&pHeap->u.ma);
    663     }
    664642    hgsmiHostHeapSetupUninitialized(pHeap);
    665643}
    666644
    667 static int hgsmiHostFIFOAlloc (HGSMIINSTANCE *pIns, HGSMIHOSTFIFOENTRY **ppEntry)
    668 {
    669     int rc = VINF_SUCCESS;
    670 
    671     NOREF (pIns);
    672 
    673     HGSMIHOSTFIFOENTRY *pEntry = (HGSMIHOSTFIFOENTRY *)RTMemAllocZ (sizeof (HGSMIHOSTFIFOENTRY));
    674 
     645static int hgsmiHostFIFOAlloc(HGSMIHOSTFIFOENTRY **ppEntry)
     646{
     647    HGSMIHOSTFIFOENTRY *pEntry = (HGSMIHOSTFIFOENTRY *)RTMemAllocZ(sizeof(HGSMIHOSTFIFOENTRY));
    675648    if (pEntry)
    676649    {
    677650        pEntry->fl = HGSMI_F_HOST_FIFO_ALLOCATED;
    678     }
    679     else
    680     {
    681         rc = VERR_NO_MEMORY;
    682     }
    683 
    684     if (RT_SUCCESS (rc))
    685     {
    686651        *ppEntry = pEntry;
    687     }
    688 
    689     return rc;
    690 }
    691 
    692 static void hgsmiHostFIFOFree (HGSMIINSTANCE *pIns, HGSMIHOSTFIFOENTRY *pEntry)
    693 {
    694     NOREF (pIns);
    695     RTMemFree (pEntry);
     652        return VINF_SUCCESS;
     653    }
     654    return VERR_NO_MEMORY;
     655}
     656
     657static void hgsmiHostFIFOFree(HGSMIHOSTFIFOENTRY *pEntry)
     658{
     659    RTMemFree(pEntry);
    696660}
    697661
     
    701665
    702666    HGSMIINSTANCE *pIns = pEntry->pIns;
    703     int rc = hgsmiFIFOLock (pIns);
     667    int rc = hgsmiFIFOLock(pIns);
    704668    if (RT_SUCCESS(rc))
    705669    {
    706670        RTListNodeRemove(&pEntry->nodeEntry);
    707         hgsmiFIFOUnlock (pIns);
     671        hgsmiFIFOUnlock(pIns);
    708672
    709673        void RT_UNTRUSTED_VOLATILE_GUEST *pvData = HGSMIBufferDataFromOffset(&pIns->hostHeap.area, pEntry->offBuffer);
    710674
    711         rc = hgsmiHostHeapLock (pIns);
     675        rc = hgsmiHostHeapLock(pIns);
    712676        if (RT_SUCCESS(rc))
    713677        {
     
    718682        }
    719683
    720         hgsmiHostFIFOFree (pIns, pEntry);
     684        hgsmiHostFIFOFree(pEntry);
    721685    }
    722686
     
    747711
    748712        if (pEntry)
    749         {
    750713            RTListNodeRemove(&pEntry->nodeEntry);
    751         }
    752714        else
    753         {
    754715            AssertLogRelMsgFailed(("HGSMI[%s]: the host frees unprocessed FIFO entry: 0x%08X\n",
    755716                                   pIns->pszName, offBuffer));
    756         }
    757 
    758         hgsmiFIFOUnlock (pIns);
    759 
    760         rc = hgsmiHostHeapLock (pIns);
     717
     718        hgsmiFIFOUnlock(pIns);
     719
     720        rc = hgsmiHostHeapLock(pIns);
    761721        if (RT_SUCCESS(rc))
    762722        {
     
    770730        {
    771731            /* Deallocate the entry. */
    772             hgsmiHostFIFOFree(pIns, pEntry);
    773         }
    774     }
    775 
    776     return rc;
    777 }
    778 
    779 static DECLCALLBACK(void) hgsmiHostCommandFreeCallback (void *pvCallback)
     732            hgsmiHostFIFOFree(pEntry);
     733        }
     734    }
     735
     736    return rc;
     737}
     738
     739static DECLCALLBACK(void) hgsmiHostCommandFreeCallback(void *pvCallback)
    780740{
    781741    /* Guest has processed the command. */
     
    785745
    786746    /* This is a simple callback, just signal the event. */
    787     hgsmiHostCommandFreeByEntry (pEntry);
    788 }
    789 
    790 static int hgsmiHostCommandWrite(HGSMIINSTANCE *pIns,
    791                                  HGSMIOFFSET offBuffer)
     747    hgsmiHostCommandFreeByEntry(pEntry);
     748}
     749
     750static int hgsmiHostCommandWrite(HGSMIINSTANCE *pIns, HGSMIOFFSET offBuffer)
    792751{
    793752    AssertPtrReturn(pIns->pHGFlags, VERR_WRONG_ORDER);
    794753
    795754    HGSMIHOSTFIFOENTRY *pEntry;
    796     int rc = hgsmiHostFIFOAlloc(pIns, &pEntry);
    797 
     755    int rc = hgsmiHostFIFOAlloc(&pEntry);
    798756    if (RT_SUCCESS(rc))
    799757    {
     
    813771        }
    814772        else
    815         {
    816             hgsmiHostFIFOFree(pIns, pEntry);
    817         }
     773            hgsmiHostFIFOFree(pEntry);
    818774    }
    819775
     
    874830
    875831        if (pvData)
    876         {
    877832            *ppvData = pvData;
    878         }
    879833        else
    880834        {
     
    978932    RT_UNTRUSTED_VALIDATED_FENCE();
    979933
    980 
    981934    /*
    982935     * Lock the heap and do the job.
     
    1026979            rc = SSMR3PutU32(pSSM, pIter->offBuffer);
    1027980            if (RT_FAILURE(rc))
    1028             {
    1029981                break;
    1030             }
    1031982        }
    1032983    }
     
    10551006            rc = SSMR3PutU32(pSSM, pIter->offBuffer);
    10561007            if (RT_FAILURE(rc))
    1057             {
    10581008                break;
    1059             }
    10601009        }
    10611010    }
     
    10661015}
    10671016
    1068 static int hgsmiHostLoadFifoEntryLocked (PHGSMIINSTANCE pIns, HGSMIHOSTFIFOENTRY **ppEntry, PSSMHANDLE pSSM)
     1017static int hgsmiHostLoadFifoEntryLocked(PHGSMIINSTANCE pIns, HGSMIHOSTFIFOENTRY **ppEntry, PSSMHANDLE pSSM)
    10691018{
    10701019    HGSMIHOSTFIFOENTRY *pEntry;
    1071     int rc = hgsmiHostFIFOAlloc (pIns, &pEntry);  AssertRC(rc);
    1072     if (RT_SUCCESS (rc))
     1020    int rc = hgsmiHostFIFOAlloc(&pEntry);  AssertRC(rc);
     1021    if (RT_SUCCESS(rc))
    10731022    {
    10741023        uint32_t u32;
    10751024        pEntry->pIns = pIns;
    1076         rc = SSMR3GetU32 (pSSM, &u32); AssertRC(rc);
     1025        rc = SSMR3GetU32(pSSM, &u32); AssertRC(rc);
    10771026        pEntry->fl = u32;
    1078         rc = SSMR3GetU32 (pSSM, &pEntry->offBuffer); AssertRC(rc);
    1079         if (RT_SUCCESS (rc))
     1027        rc = SSMR3GetU32(pSSM, &pEntry->offBuffer); AssertRC(rc);
     1028        if (RT_SUCCESS(rc))
    10801029            *ppEntry = pEntry;
    10811030        else
    1082             hgsmiHostFIFOFree (pIns, pEntry);
     1031            hgsmiHostFIFOFree(pEntry);
    10831032    }
    10841033
     
    11131062{
    11141063    HGSMIGUESTCOMPLENTRY *pEntry;
    1115     int rc = hgsmiGuestCompletionFIFOAlloc (pIns, &pEntry); AssertRC(rc);
     1064    int rc = hgsmiGuestCompletionFIFOAlloc(pIns, &pEntry); AssertRC(rc);
    11161065    if (RT_SUCCESS (rc))
    11171066    {
    1118         rc = SSMR3GetU32 (pSSM, &pEntry->offBuffer); AssertRC(rc);
    1119         if (RT_SUCCESS (rc))
     1067        rc = SSMR3GetU32(pSSM, &pEntry->offBuffer); AssertRC(rc);
     1068        if (RT_SUCCESS(rc))
    11201069            *ppEntry = pEntry;
    11211070        else
    1122             hgsmiGuestCompletionFIFOFree (pIns, pEntry);
     1071            hgsmiGuestCompletionFIFOFree(pIns, pEntry);
    11231072    }
    11241073    return rc;
     
    11581107                AssertRCBreak(rc);
    11591108
    1160                 hgsmiHostFIFOFree(pIns, pEntry);
     1109                hgsmiHostFIFOFree(pEntry);
    11611110            }
    11621111        }
     
    11981147                uint32_t i;
    11991148                for (i = 0; i < *pcBlocks; ++i)
    1200                 {
    12011149                    SSMR3GetU32(pSSM, &paDescriptors[i]);
    1202                 }
    12031150            }
    12041151            else
    1205             {
    12061152                rc = VERR_NO_MEMORY;
    1207             }
    12081153        }
    12091154
    12101155        if (RT_SUCCESS(rc))
    1211         {
    12121156            rc = SSMR3GetU32(pSSM, pcbMaxBlock);
    1213         }
    1214 
    12151157        if (RT_SUCCESS(rc))
    1216         {
    12171158            *ppaDescriptors = paDescriptors;
    1218         }
    12191159        else
    1220         {
    12211160            RTMemFree(paDescriptors);
    1222         }
    1223     }
    1224 
    1225     return rc;
    1226 }
    1227 
    1228 int HGSMIHostSaveStateExec (PHGSMIINSTANCE pIns, PSSMHANDLE pSSM)
     1161    }
     1162
     1163    return rc;
     1164}
     1165
     1166int HGSMIHostSaveStateExec(PHGSMIINSTANCE pIns, PSSMHANDLE pSSM)
    12291167{
    12301168    VBOXHGSMI_SAVE_START(pSSM);
     
    12341172    SSMR3PutU32(pSSM, pIns->hostHeap.u32HeapType);
    12351173
    1236     HGSMIOFFSET off = pIns->pHGFlags ? HGSMIPointerToOffset(&pIns->area, (const HGSMIBUFFERHEADER *)pIns->pHGFlags) : HGSMIOFFSET_VOID;
    1237     SSMR3PutU32 (pSSM, off);
    1238 
    1239     off = pIns->hostHeap.u32HeapType == HGSMI_HEAP_TYPE_MA?
    1240               0:
    1241               hgsmiHostHeapHandleLocationOffset(&pIns->hostHeap);
     1174    HGSMIOFFSET off = pIns->pHGFlags ? HGSMIPointerToOffset(&pIns->area, (const HGSMIBUFFERHEADER *)pIns->pHGFlags)
     1175                                     : HGSMIOFFSET_VOID;
     1176    SSMR3PutU32(pSSM, off);
     1177
     1178    off = pIns->hostHeap.u32HeapType == HGSMI_HEAP_TYPE_MA ? 0 : hgsmiHostHeapHandleLocationOffset(&pIns->hostHeap);
    12421179    rc = SSMR3PutU32 (pSSM, off);
    12431180    if (off != HGSMIOFFSET_VOID)
    12441181    {
    1245         SSMR3PutU32 (pSSM, hgsmiHostHeapOffset(&pIns->hostHeap));
    1246         SSMR3PutU32 (pSSM, hgsmiHostHeapSize(&pIns->hostHeap));
     1182        SSMR3PutU32(pSSM, hgsmiHostHeapOffset(&pIns->hostHeap));
     1183        SSMR3PutU32(pSSM, hgsmiHostHeapSize(&pIns->hostHeap));
    12471184        /* need save mem pointer to calculate offset on restore */
    1248         SSMR3PutU64 (pSSM, (uint64_t)(uintptr_t)pIns->area.pu8Base);
     1185        SSMR3PutU64(pSSM, (uint64_t)(uintptr_t)pIns->area.pu8Base);
    12491186        rc = hgsmiFIFOLock (pIns);
    12501187        if (RT_SUCCESS(rc))
    12511188        {
    1252             rc = hgsmiHostSaveFifoLocked (&pIns->hostFIFO, pSSM); AssertRC(rc);
    1253             rc = hgsmiHostSaveFifoLocked (&pIns->hostFIFORead, pSSM); AssertRC(rc);
    1254             rc = hgsmiHostSaveFifoLocked (&pIns->hostFIFOProcessed, pSSM); AssertRC(rc);
     1189            rc = hgsmiHostSaveFifoLocked(&pIns->hostFIFO, pSSM); AssertRC(rc);
     1190            rc = hgsmiHostSaveFifoLocked(&pIns->hostFIFORead, pSSM); AssertRC(rc);
     1191            rc = hgsmiHostSaveFifoLocked(&pIns->hostFIFOProcessed, pSSM); AssertRC(rc);
    12551192#ifdef VBOX_WITH_WDDM
    1256             rc = hgsmiHostSaveGuestCmdCompletedFifoLocked (&pIns->guestCmdCompleted, pSSM); AssertRC(rc);
     1193            rc = hgsmiHostSaveGuestCmdCompletedFifoLocked(&pIns->guestCmdCompleted, pSSM); AssertRC(rc);
    12571194#endif
    12581195
    1259             hgsmiFIFOUnlock (pIns);
     1196            hgsmiFIFOUnlock(pIns);
    12601197        }
    12611198
    12621199        if (RT_SUCCESS(rc))
    1263         {
    12641200            if (pIns->hostHeap.u32HeapType == HGSMI_HEAP_TYPE_MA)
    1265             {
    12661201                rc = hgsmiHostSaveMA(pSSM, &pIns->hostHeap.u.ma);
    1267             }
    1268         }
    12691202    }
    12701203
     
    12741207}
    12751208
    1276 int HGSMIHostLoadStateExec (PHGSMIINSTANCE pIns, PSSMHANDLE pSSM, uint32_t u32Version)
     1209int HGSMIHostLoadStateExec(PHGSMIINSTANCE pIns, PSSMHANDLE pSSM, uint32_t u32Version)
    12771210{
    12781211    if (u32Version < VGA_SAVEDSTATE_VERSION_HGSMI)
     
    12821215
    12831216    int rc;
    1284     HGSMIOFFSET off;
    12851217    uint32_t u32HeapType = HGSMI_HEAP_TYPE_NULL;
    1286 
    12871218    if (u32Version >= VGA_SAVEDSTATE_VERSION_HGSMIMA)
    12881219    {
     
    12911222    }
    12921223
     1224    HGSMIOFFSET off;
    12931225    rc = SSMR3GetU32(pSSM, &off);
    12941226    AssertLogRelRCReturn(rc, rc);
    1295     pIns->pHGFlags = (off != HGSMIOFFSET_VOID) ? (HGSMIHOSTFLAGS*)HGSMIOffsetToPointer (&pIns->area, off) : NULL;
     1227    pIns->pHGFlags = off != HGSMIOFFSET_VOID ? (HGSMIHOSTFLAGS *)HGSMIOffsetToPointer(&pIns->area, off) : NULL;
    12961228
    12971229    rc = SSMR3GetU32(pSSM, &off);
     
    13011233        /* There is a saved heap. */
    13021234        if (u32HeapType == HGSMI_HEAP_TYPE_NULL)
    1303         {
    1304             u32HeapType = u32Version > VGA_SAVEDSTATE_VERSION_HOST_HEAP?
    1305                               HGSMI_HEAP_TYPE_OFFSET:
    1306                               HGSMI_HEAP_TYPE_POINTER;
    1307         }
     1235            u32HeapType = u32Version > VGA_SAVEDSTATE_VERSION_HOST_HEAP
     1236                        ? HGSMI_HEAP_TYPE_OFFSET : HGSMI_HEAP_TYPE_POINTER;
    13081237
    13091238        HGSMIOFFSET offHeap;
     
    13171246        if (RT_SUCCESS(rc))
    13181247        {
    1319             rc = hgsmiFIFOLock (pIns);
     1248            rc = hgsmiFIFOLock(pIns);
    13201249            if (RT_SUCCESS(rc))
    13211250            {
    1322                 rc = hgsmiHostLoadFifoLocked (pIns, &pIns->hostFIFO, pSSM);
     1251                rc = hgsmiHostLoadFifoLocked(pIns, &pIns->hostFIFO, pSSM);
    13231252                if (RT_SUCCESS(rc))
    1324                     rc = hgsmiHostLoadFifoLocked (pIns, &pIns->hostFIFORead, pSSM);
     1253                    rc = hgsmiHostLoadFifoLocked(pIns, &pIns->hostFIFORead, pSSM);
    13251254                if (RT_SUCCESS(rc))
    1326                     rc = hgsmiHostLoadFifoLocked (pIns, &pIns->hostFIFOProcessed, pSSM);
     1255                    rc = hgsmiHostLoadFifoLocked(pIns, &pIns->hostFIFOProcessed, pSSM);
    13271256#ifdef VBOX_WITH_WDDM
    13281257                if (RT_SUCCESS(rc) && u32Version > VGA_SAVEDSTATE_VERSION_PRE_WDDM)
    1329                     rc = hgsmiHostLoadGuestCmdCompletedFifoLocked (pIns, &pIns->guestCmdCompleted, pSSM, u32Version);
     1258                    rc = hgsmiHostLoadGuestCmdCompletedFifoLocked(pIns, &pIns->guestCmdCompleted, pSSM, u32Version);
    13301259#endif
    13311260
    1332                 hgsmiFIFOUnlock (pIns);
     1261                hgsmiFIFOUnlock(pIns);
    13331262            }
    13341263        }
     
    13591288                     || u32HeapType == HGSMI_HEAP_TYPE_POINTER)
    13601289            {
    1361                 rc = hgsmiHostHeapLock (pIns);
    1362                 if (RT_SUCCESS (rc))
     1290                rc = hgsmiHostHeapLock(pIns);
     1291                if (RT_SUCCESS(rc))
    13631292                {
    13641293                    Assert(!pIns->hostHeap.cRefs);
     
    13731302                                               offHeap);
    13741303
    1375                     hgsmiHostHeapUnlock (pIns);
     1304                    hgsmiHostHeapUnlock(pIns);
    13761305                }
    13771306            }
     
    13901319/* Register a new HGSMI channel by a predefined index.
    13911320 */
    1392 int HGSMIHostChannelRegister(PHGSMIINSTANCE pIns,
    1393                              uint8_t u8Channel,
    1394                              PFNHGSMICHANNELHANDLER pfnChannelHandler,
    1395                              void *pvChannelHandler)
     1321int HGSMIHostChannelRegister(PHGSMIINSTANCE pIns, uint8_t u8Channel,
     1322                             PFNHGSMICHANNELHANDLER pfnChannelHandler, void *pvChannelHandler)
    13961323{
    13971324    LogFlowFunc(("pIns %p, u8Channel %x, pfnChannelHandler %p, pvChannelHandler %p\n",
     
    14121339
    14131340    LogFlowFunc(("leave rc = %Rrc\n", rc));
    1414 
    14151341    return rc;
    14161342}
     
    14831409void RT_UNTRUSTED_VOLATILE_GUEST *HGSMIOffsetToPointerHost(PHGSMIINSTANCE pIns, HGSMIOFFSET offBuffer)
    14841410{
    1485     const HGSMIAREA *pArea = &pIns->area;
    1486 
    1487     if (   offBuffer < pArea->offBase
    1488         || offBuffer > pArea->offLast)
    1489     {
    1490         LogFunc(("offset 0x%x is outside the area [0x%x;0x%x]!!!\n", offBuffer, pArea->offBase, pArea->offLast));
    1491         return NULL;
    1492     }
    1493 
    1494     return HGSMIOffsetToPointer(pArea, offBuffer);
     1411    const HGSMIAREA  *pArea   = &pIns->area;
     1412    HGSMIOFFSET const offArea = offBuffer - pArea->offBase;
     1413    ASSERT_GUEST_MSG_RETURN(offArea < pArea->cbArea,
     1414                            ("offBuffer=%#x; area %#x LB %#x\n", offBuffer, pArea->offBase, pArea->cbArea),
     1415                            NULL);
     1416    return &pArea->pu8Base[offArea];
    14951417}
    14961418
     
    14981420HGSMIOFFSET HGSMIPointerToOffsetHost(PHGSMIINSTANCE pIns, const void RT_UNTRUSTED_VOLATILE_GUEST *pv)
    14991421{
    1500     const HGSMIAREA *pArea = &pIns->area;
    1501     uintptr_t off = (uintptr_t)pv - (uintptr_t)pArea->pu8Base;
    1502     if (off < pArea->cbArea)
    1503         return pArea->offBase + (HGSMIOFFSET)off;
    1504 
    1505     LogFunc(("pointer %p is outside the area %p LB %#x!!!\n", pv, pArea->pu8Base, pArea->cbArea));
    1506     return HGSMIOFFSET_VOID;
     1422    const HGSMIAREA *pArea   = &pIns->area;
     1423    uintptr_t const  offArea = (uintptr_t)pv - (uintptr_t)pArea->pu8Base;
     1424    ASSERT_GUEST_MSG_RETURN(offArea < pArea->cbArea,
     1425                            ("pv=%p; area %#x LB %#x\n", pv, pArea->offBase, pArea->cbArea),
     1426                            HGSMIOFFSET_VOID);
     1427    return pArea->offBase + (HGSMIOFFSET)offArea;
    15071428}
    15081429
     
    15421463
    15431464
    1544 void *HGSMIContext (PHGSMIINSTANCE pIns)
     1465void *HGSMIContext(PHGSMIINSTANCE pIns)
    15451466{
    15461467    uint8_t *p = (uint8_t *)pIns;
    1547     return p + sizeof (HGSMIINSTANCE);
     1468    return p + sizeof(HGSMIINSTANCE);
    15481469}
    15491470
    15501471/* The guest submitted a buffer. */
    1551 static DECLCALLBACK(int) hgsmiChannelHandler (void *pvHandler, uint16_t u16ChannelInfo,
    1552                                               RT_UNTRUSTED_VOLATILE_GUEST void *pvBuffer, HGSMISIZE cbBuffer)
     1472static DECLCALLBACK(int) hgsmiChannelHandler(void *pvHandler, uint16_t u16ChannelInfo,
     1473                                             RT_UNTRUSTED_VOLATILE_GUEST void *pvBuffer, HGSMISIZE cbBuffer)
    15531474{
    15541475    int rc = VINF_SUCCESS;
     
    15631484        case HGSMI_CC_HOST_FLAGS_LOCATION:
    15641485        {
    1565             if (cbBuffer < sizeof (HGSMIBUFFERLOCATION))
    1566             {
    1567                 rc = VERR_INVALID_PARAMETER;
    1568                 break;
    1569             }
    1570 
    1571             HGSMIBUFFERLOCATION *pLoc = (HGSMIBUFFERLOCATION *)pvBuffer;
    1572             if (pLoc->cbLocation != sizeof(HGSMIHOSTFLAGS))
    1573             {
    1574                 rc = VERR_INVALID_PARAMETER;
    1575                 break;
    1576             }
    1577 
    1578             pIns->pHGFlags = (HGSMIHOSTFLAGS*)HGSMIOffsetToPointer (&pIns->area, pLoc->offLocation);
    1579         } break;
     1486            ASSERT_GUEST_RETURN(cbBuffer >= sizeof(HGSMIBUFFERLOCATION), VERR_INVALID_PARAMETER);
     1487            HGSMIBUFFERLOCATION RT_UNTRUSTED_VOLATILE_GUEST *pLoc = (HGSMIBUFFERLOCATION RT_UNTRUSTED_VOLATILE_GUEST *)pvBuffer;
     1488            HGSMIBUFFERLOCATION LocSafe;
     1489            LocSafe.cbLocation  = pLoc->cbLocation;
     1490            LocSafe.offLocation = pLoc->offLocation;
     1491            RT_UNTRUSTED_NONVOLATILE_COPY_FENCE();
     1492
     1493            ASSERT_GUEST_RETURN(LocSafe.cbLocation == sizeof(HGSMIHOSTFLAGS), VERR_INVALID_PARAMETER);
     1494            RT_UNTRUSTED_VALIDATED_FENCE();
     1495
     1496            pIns->pHGFlags = (HGSMIHOSTFLAGS RT_UNTRUSTED_VOLATILE_GUEST *)HGSMIOffsetToPointer(&pIns->area, pLoc->offLocation);
     1497            break;
     1498        }
    15801499
    15811500        default:
     
    15881507}
    15891508
    1590 int HGSMICreate (PHGSMIINSTANCE *ppIns,
    1591                  PVM             pVM,
    1592                  const char     *pszName,
    1593                  HGSMIOFFSET     offBase,
    1594                  uint8_t        *pu8MemBase,
    1595                  HGSMISIZE       cbMem,
    1596                  PFNHGSMINOTIFYGUEST pfnNotifyGuest,
    1597                  void           *pvNotifyGuest,
    1598                  size_t         cbContext)
     1509int HGSMICreate(PHGSMIINSTANCE *ppIns,
     1510                PVM             pVM,
     1511                const char     *pszName,
     1512                HGSMIOFFSET     offBase,
     1513                uint8_t        *pu8MemBase,
     1514                HGSMISIZE       cbMem,
     1515                PFNHGSMINOTIFYGUEST pfnNotifyGuest,
     1516                void           *pvNotifyGuest,
     1517                size_t          cbContext)
    15991518{
    16001519    LogFlowFunc(("ppIns = %p, pVM = %p, pszName = [%s], offBase = 0x%08X, pu8MemBase = %p, cbMem = 0x%08X, "
     
    16151534    AssertPtrReturn(pu8MemBase, VERR_INVALID_PARAMETER);
    16161535
    1617     int rc = VINF_SUCCESS;
    1618 
    1619     PHGSMIINSTANCE pIns = (PHGSMIINSTANCE)RTMemAllocZ (sizeof (HGSMIINSTANCE) + cbContext);
    1620 
    1621     if (!pIns)
    1622     {
     1536    int rc;
     1537    PHGSMIINSTANCE pIns = (PHGSMIINSTANCE)RTMemAllocZ(sizeof (HGSMIINSTANCE) + cbContext);
     1538    if (pIns)
     1539    {
     1540        rc = HGSMIAreaInitialize (&pIns->area, pu8MemBase, cbMem, offBase);
     1541        if (RT_SUCCESS (rc))
     1542            rc = RTCritSectInit (&pIns->instanceCritSect);
     1543        if (RT_SUCCESS (rc))
     1544            rc = RTCritSectInit (&pIns->hostHeapCritSect);
     1545        if (RT_SUCCESS (rc))
     1546            rc = RTCritSectInit (&pIns->hostFIFOCritSect);
     1547        if (RT_SUCCESS (rc))
     1548        {
     1549            pIns->pVM            = pVM;
     1550            pIns->pszName        = VALID_PTR(pszName) ? pszName : "";
     1551
     1552            hgsmiHostHeapSetupUninitialized(&pIns->hostHeap);
     1553
     1554            pIns->pfnNotifyGuest = pfnNotifyGuest;
     1555            pIns->pvNotifyGuest  = pvNotifyGuest;
     1556
     1557            RTListInit(&pIns->hostFIFO);
     1558            RTListInit(&pIns->hostFIFORead);
     1559            RTListInit(&pIns->hostFIFOProcessed);
     1560            RTListInit(&pIns->hostFIFOFree);
     1561            RTListInit(&pIns->guestCmdCompleted);
     1562
     1563            rc = HGSMIHostChannelRegister(pIns, HGSMI_CH_HGSMI, hgsmiChannelHandler, pIns);
     1564        }
     1565        if (RT_SUCCESS (rc))
     1566            *ppIns = pIns;
     1567        else
     1568            HGSMIDestroy(pIns);
     1569    }
     1570    else
    16231571        rc = VERR_NO_MEMORY;
    1624     }
    1625 
    1626     if (RT_SUCCESS (rc))
    1627     {
    1628         rc = HGSMIAreaInitialize (&pIns->area, pu8MemBase, cbMem, offBase);
    1629     }
    1630 
    1631     if (RT_SUCCESS (rc))
    1632     {
    1633         rc = RTCritSectInit (&pIns->instanceCritSect);
    1634     }
    1635 
    1636     if (RT_SUCCESS (rc))
    1637     {
    1638         rc = RTCritSectInit (&pIns->hostHeapCritSect);
    1639     }
    1640 
    1641     if (RT_SUCCESS (rc))
    1642     {
    1643         rc = RTCritSectInit (&pIns->hostFIFOCritSect);
    1644     }
    1645 
    1646     if (RT_SUCCESS (rc))
    1647     {
    1648         pIns->pVM            = pVM;
    1649 
    1650         pIns->pszName        = VALID_PTR(pszName)? pszName: "";
    1651 
    1652         hgsmiHostHeapSetupUninitialized(&pIns->hostHeap);
    1653 
    1654         pIns->pfnNotifyGuest = pfnNotifyGuest;
    1655         pIns->pvNotifyGuest  = pvNotifyGuest;
    1656 
    1657         RTListInit(&pIns->hostFIFO);
    1658         RTListInit(&pIns->hostFIFORead);
    1659         RTListInit(&pIns->hostFIFOProcessed);
    1660         RTListInit(&pIns->hostFIFOFree);
    1661         RTListInit(&pIns->guestCmdCompleted);
    1662     }
    1663 
    1664     rc = HGSMIHostChannelRegister (pIns,
    1665                                    HGSMI_CH_HGSMI,
    1666                                    hgsmiChannelHandler,
    1667                                    pIns);
    1668 
    1669     if (RT_SUCCESS (rc))
    1670     {
    1671         *ppIns = pIns;
    1672     }
    1673     else
    1674     {
    1675         HGSMIDestroy (pIns);
    1676     }
    16771572
    16781573    LogFlowFunc(("leave rc = %Rrc, pIns = %p\n", rc, pIns));
    1679 
    16801574    return rc;
    16811575}
     
    17071601}
    17081602
    1709 void HGSMIDestroy (PHGSMIINSTANCE pIns)
     1603void HGSMIDestroy(PHGSMIINSTANCE pIns)
    17101604{
    17111605    LogFlowFunc(("pIns = %p\n", pIns));
     
    17141608    {
    17151609        hgsmiHostHeapDestroy(&pIns->hostHeap);
    1716 
    1717         if (RTCritSectIsInitialized (&pIns->hostHeapCritSect))
    1718         {
    1719             RTCritSectDelete (&pIns->hostHeapCritSect);
    1720         }
    1721 
    1722         if (RTCritSectIsInitialized (&pIns->instanceCritSect))
    1723         {
    1724             RTCritSectDelete (&pIns->instanceCritSect);
    1725         }
    1726 
    1727         if (RTCritSectIsInitialized (&pIns->hostFIFOCritSect))
    1728         {
    1729             RTCritSectDelete (&pIns->hostFIFOCritSect);
    1730         }
    1731 
    1732         memset (pIns, 0, sizeof (HGSMIINSTANCE));
    1733 
    1734         RTMemFree (pIns);
     1610        if (RTCritSectIsInitialized(&pIns->hostHeapCritSect))
     1611            RTCritSectDelete(&pIns->hostHeapCritSect);
     1612        if (RTCritSectIsInitialized(&pIns->instanceCritSect))
     1613            RTCritSectDelete(&pIns->instanceCritSect);
     1614        if (RTCritSectIsInitialized(&pIns->hostFIFOCritSect))
     1615            RTCritSectDelete(&pIns->hostFIFOCritSect);
     1616
     1617        memset(pIns, 0, sizeof (HGSMIINSTANCE));
     1618        RTMemFree(pIns);
    17351619    }
    17361620
     
    17401624#ifdef VBOX_WITH_WDDM
    17411625
    1742 static int hgsmiGuestCommandComplete (HGSMIINSTANCE *pIns, HGSMIOFFSET offMem)
     1626static int hgsmiGuestCommandComplete(HGSMIINSTANCE *pIns, HGSMIOFFSET offMem)
    17431627{
    17441628    HGSMIGUESTCOMPLENTRY *pEntry = NULL;
    17451629
    17461630    AssertPtrReturn(pIns->pHGFlags, VERR_WRONG_ORDER);
    1747     int rc = hgsmiGuestCompletionFIFOAlloc (pIns, &pEntry);
     1631    int rc = hgsmiGuestCompletionFIFOAlloc(pIns, &pEntry);
    17481632    AssertRC(rc);
    1749     if (RT_SUCCESS (rc))
     1633    if (RT_SUCCESS(rc))
    17501634    {
    17511635        pEntry->offBuffer = offMem;
     
    17531637        rc = hgsmiFIFOLock(pIns);
    17541638        AssertRC(rc);
    1755         if (RT_SUCCESS (rc))
     1639        if (RT_SUCCESS(rc))
    17561640        {
    17571641            RTListAppend(&pIns->guestCmdCompleted, &pEntry->nodeEntry);
     
    17611645        }
    17621646        else
    1763         {
    17641647            hgsmiGuestCompletionFIFOFree(pIns, pEntry);
    1765         }
    17661648    }
    17671649
     
    17711653int hgsmiCompleteGuestCommand(PHGSMIINSTANCE pIns, HGSMIOFFSET offBuffer, bool fDoIrq)
    17721654{
    1773     int rc = hgsmiGuestCommandComplete (pIns, offBuffer);
     1655    int rc = hgsmiGuestCommandComplete(pIns, offBuffer);
    17741656    if (RT_SUCCESS (rc))
    17751657    {
     1658#ifdef DEBUG_misha
     1659        Assert(fDoIrq);
     1660#endif
    17761661        if (fDoIrq)
    17771662        {
     
    17791664            hgsmiNotifyGuest (pIns);
    17801665        }
    1781 #ifdef DEBUG_misha
    1782         else
    1783         {
    1784             Assert(0);
    1785         }
    1786 #endif
    17871666    }
    17881667    return rc;
     
    17921671{
    17931672    LogFlowFunc(("pIns = %p, pvMem = %p\n", pIns, pvMem));
    1794 
    1795     int rc = VINF_SUCCESS;
    17961673
    17971674    HGSMIBUFFERHEADER RT_UNTRUSTED_VOLATILE_GUEST *pHeader   = HGSMIBufferHeaderFromData(pvMem);
    17981675    HGSMIOFFSET                                    offBuffer = HGSMIPointerToOffset(&pIns->area, pHeader);
    1799 
    1800     Assert(offBuffer != HGSMIOFFSET_VOID);
    1801     if (offBuffer != HGSMIOFFSET_VOID)
    1802     {
    1803         rc = hgsmiCompleteGuestCommand(pIns, offBuffer, fDoIrq);
    1804         AssertRC (rc);
    1805     }
    1806     else
    1807     {
    1808         LogRel(("invalid cmd offset \n"));
    1809         rc = VERR_INVALID_PARAMETER;
    1810     }
     1676    ASSERT_GUEST_RETURN(offBuffer != HGSMIOFFSET_VOID, VERR_INVALID_PARAMETER);
     1677
     1678    int rc = hgsmiCompleteGuestCommand(pIns, offBuffer, fDoIrq);
     1679    AssertRC(rc);
    18111680
    18121681    LogFlowFunc(("rc = %Rrc\n", rc));
    1813 
    1814     return rc;
    1815 }
    1816 #endif
     1682    return rc;
     1683}
     1684
     1685#endif /* VBOX_WITH_WDDM */
     1686
Note: See TracChangeset for help on using the changeset viewer.

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