VirtualBox

Changeset 71607 in vbox


Ignore:
Timestamp:
Apr 1, 2018 11:38:00 PM (7 years ago)
Author:
vboxsync
Message:

DevVGA,SharedOpenGL: Code cleanup in progress. bugref:9094

Location:
trunk
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/Graphics/VBoxVideoHost3D.h

    r70596 r71607  
    8383typedef void * HVBOXCRCMDSVR;
    8484
    85 /* enables the CrCmd interface, thus the hgcm interface gets disabled.
     85/** enables the CrCmd interface, thus the hgcm interface gets disabled.
    8686 * all subsequent calls will be done in the thread Enable was done,
    8787 * until the Disable is called */
    8888typedef DECLCALLBACKPTR(int, PFNVBOXCRCMD_SVR_ENABLE)(HVBOXCRCMDSVR hSvr, VBOXCRCMD_SVRENABLE_INFO *pInfo);
    89 /* Opposite to Enable (see above) */
     89/** Opposite to Enable (see above) */
    9090typedef DECLCALLBACKPTR(int, PFNVBOXCRCMD_SVR_DISABLE)(HVBOXCRCMDSVR hSvr);
    91 /* process command */
    92 typedef DECLCALLBACKPTR(int8_t, PFNVBOXCRCMD_SVR_CMD)(HVBOXCRCMDSVR hSvr, const VBOXCMDVBVA_HDR *pCmd, uint32_t cbCmd);
    93 /* process host control */
    94 typedef DECLCALLBACKPTR(int, PFNVBOXCRCMD_SVR_HOSTCTL)(HVBOXCRCMDSVR hSvr, uint8_t* pCtl, uint32_t cbCmd);
    95 /* process guest control */
    96 typedef DECLCALLBACKPTR(int, PFNVBOXCRCMD_SVR_GUESTCTL)(HVBOXCRCMDSVR hSvr, uint8_t* pCtl, uint32_t cbCmd);
    97 /* screen resize */
    98 typedef DECLCALLBACKPTR(int, PFNVBOXCRCMD_SVR_RESIZE)(HVBOXCRCMDSVR hSvr, const struct VBVAINFOSCREEN *pScreen, const uint32_t *pTargetMap);
    99 /* process SaveState */
     91/** process command */
     92typedef DECLCALLBACKPTR(int8_t, PFNVBOXCRCMD_SVR_CMD)(HVBOXCRCMDSVR hSvr,
     93                                                      const VBOXCMDVBVA_HDR RT_UNTRUSTED_VOLATILE_GUEST *pCmd, uint32_t cbCmd);
     94/** process host control */
     95typedef DECLCALLBACKPTR(int, PFNVBOXCRCMD_SVR_HOSTCTL)(HVBOXCRCMDSVR hSvr, uint8_t *pCtl, uint32_t cbCmd);
     96/** process guest control */
     97typedef DECLCALLBACKPTR(int, PFNVBOXCRCMD_SVR_GUESTCTL)(HVBOXCRCMDSVR hSvr, uint8_t RT_UNTRUSTED_VOLATILE_GUEST *pCtl,
     98                                                        uint32_t cbCmd);
     99/** screen resize */
     100typedef DECLCALLBACKPTR(int, PFNVBOXCRCMD_SVR_RESIZE)(HVBOXCRCMDSVR hSvr, const struct VBVAINFOSCREEN *pScreen,
     101                                                      const uint32_t *pTargetMap);
     102/** process SaveState */
    100103typedef DECLCALLBACKPTR(int, PFNVBOXCRCMD_SVR_SAVESTATE)(HVBOXCRCMDSVR hSvr, PSSMHANDLE pSSM);
    101 /* process LoadState */
     104/** process LoadState */
    102105typedef DECLCALLBACKPTR(int, PFNVBOXCRCMD_SVR_LOADSTATE)(HVBOXCRCMDSVR hSvr, PSSMHANDLE pSSM, uint32_t u32Version);
    103106
  • trunk/src/VBox/Devices/Graphics/DevVGA_VBVA.cpp

    r71592 r71607  
    25692569            {
    25702570                VBVAENABLE RT_UNTRUSTED_VOLATILE_GUEST *pVbvaEnable = (VBVAENABLE RT_UNTRUSTED_VOLATILE_GUEST *)pvBuffer;
    2571 
    2572                 uint32_t       u32ScreenId;
    25732571                const uint32_t u32Flags = pVbvaEnable->u32Flags;
     2572                RT_UNTRUSTED_NONVOLATILE_COPY_FENCE();
     2573
     2574                uint32_t u32ScreenId;
    25742575                if (u32Flags & VBVA_F_EXTENDED)
    25752576                {
     
    26212622                VBVACAPS RT_UNTRUSTED_VOLATILE_GUEST *pCaps = (VBVACAPS RT_UNTRUSTED_VOLATILE_GUEST *)pvBuffer;
    26222623                pVGAState->fGuestCaps = pCaps->fCaps;
     2624                RT_UNTRUSTED_NONVOLATILE_COPY_FENCE();
     2625
    26232626                pVGAState->pDrv->pfnVBVAGuestCapabilityUpdate(pVGAState->pDrv, pVGAState->fGuestCaps);
    26242627                pCaps->rc = rc = VINF_SUCCESS;
     
    26342637                VBVASCANLINECFG RT_UNTRUSTED_VOLATILE_GUEST *pCfg = (VBVASCANLINECFG RT_UNTRUSTED_VOLATILE_GUEST *)pvBuffer;
    26352638                pVGAState->fScanLineCfg = pCfg->fFlags;
     2639                RT_UNTRUSTED_NONVOLATILE_COPY_FENCE();
     2640
    26362641                pCfg->rc = rc = VINF_SUCCESS;
    26372642            }
     
    26642669                    inputMapping.cy = pInputMapping->cy;
    26652670                }
    2666                 ASMCompilerBarrier();
     2671                RT_UNTRUSTED_NONVOLATILE_COPY_FENCE();
    26672672
    26682673                LogRelFlowFunc(("VBVA: ChannelHandler: VBVA_REPORT_INPUT_MAPPING: x=%RI32, y=%RI32, cx=%RU32, cy=%RU32\n",
     
    26852690                Report.x               = pReport->x;
    26862691                Report.y               = pReport->y;
    2687                 ASMCompilerBarrier();
     2692                RT_UNTRUSTED_NONVOLATILE_COPY_FENCE();
    26882693
    26892694                LogRelFlowFunc(("VBVA: ChannelHandler: VBVA_CURSOR_POSITION: fReportPosition=%RTbool, x=%RU32, y=%RU32\n",
  • trunk/src/VBox/Devices/Graphics/DevVGA_VDMA.cpp

    r71604 r71607  
    2525#include <VBox/vmm/pgm.h>
    2626#include <VBoxVideo.h>
     27#include <VBox/AssertGuest.h>
    2728#include <iprt/semaphore.h>
    2829#include <iprt/thread.h>
     
    104105typedef struct VBVAEXHOSTCONTEXT
    105106{
    106     VBVABUFFER *pVBVA;
    107     uint32_t    cbMaxData; /**< Maximum number of data bytes addressible relative to pVBVA. */
     107    VBVABUFFER RT_UNTRUSTED_VOLATILE_GUEST *pVBVA;
     108    /** Maximum number of data bytes addressible relative to pVBVA. */
     109    uint32_t                                cbMaxData;
    108110    volatile int32_t i32State;
    109111    volatile int32_t i32EnableState;
     
    148150        struct
    149151        {
    150             uint8_t * pu8Cmd;
     152            void RT_UNTRUSTED_VOLATILE_GUEST *pvCmd;
    151153            uint32_t cbCmd;
    152154        } cmd;
     
    241243{
    242244# ifndef VBOXVDBG_MEMCACHE_DISABLE
    243     VBVAEXHOSTCTL *pCtl = (VBVAEXHOSTCTL*)RTMemCacheAlloc(pCmdVbva->CtlCache);
     245    VBVAEXHOSTCTL *pCtl = (VBVAEXHOSTCTL *)RTMemCacheAlloc(pCmdVbva->CtlCache);
    244246# else
    245     VBVAEXHOSTCTL *pCtl = (VBVAEXHOSTCTL*)RTMemAlloc(sizeof(VBVAEXHOSTCTL));
     247    VBVAEXHOSTCTL *pCtl = (VBVAEXHOSTCTL *)RTMemAlloc(sizeof(VBVAEXHOSTCTL));
    246248# endif
    247249    if (pCtl)
     
    282284
    283285/**
    284  * Worker for vboxVBVAExHPDataGet() and VBoxVBVAExHPCheckHostCtlOnDisable() that
    285  * gets the next control command.
     286 * Worker for vboxVBVAExHPDataGetInner() and VBoxVBVAExHPCheckHostCtlOnDisable()
     287 * that gets the next control command.
    286288 *
    287289 * @returns Pointer to command if found, NULL if not.
     
    375377
    376378/**
    377  * Worker for vboxVBVAExHPDataGet that processes PAUSE and RESUME requests.
     379 * Worker for vboxVBVAExHPDataGetInner that processes PAUSE and RESUME requests.
    378380 *
    379381 * Unclear why these cannot be handled the normal way.
     
    433435
    434436/**
    435  * Worker for vboxVBVAExHPDataGet.
     437 * Worker for vboxVBVAExHPDataGetInner.
    436438 *
    437439 * @retval VINF_SUCCESS
     
    442444 * @thread VDMA
    443445 */
    444 static int vboxVBVAExHPCmdGet(struct VBVAEXHOSTCONTEXT *pCmdVbva, uint8_t **ppbCmd, uint32_t *pcbCmd)
     446static int vboxVBVAExHPCmdGet(struct VBVAEXHOSTCONTEXT *pCmdVbva, uint8_t RT_UNTRUSTED_VOLATILE_GUEST **ppbCmd, uint32_t *pcbCmd)
    445447{
    446448    Assert(pCmdVbva->i32State == VBVAEXHOSTCONTEXT_STATE_PROCESSING);
    447449    Assert(pCmdVbva->i32EnableState > VBVAEXHOSTCONTEXT_ESTATE_PAUSED);
    448450
    449     VBVABUFFER volatile *pVBVA = pCmdVbva->pVBVA; /* This is shared with the guest, so careful! */
     451    VBVABUFFER RT_UNTRUSTED_VOLATILE_GUEST *pVBVA = pCmdVbva->pVBVA; /* This is shared with the guest, so careful! */
    450452
    451453    /*
     
    454456    uint32_t idxRecordFirst = ASMAtomicUoReadU32(&pVBVA->indexRecordFirst);
    455457    uint32_t idxRecordFree  = ASMAtomicReadU32(&pVBVA->indexRecordFree);
     458    RT_UNTRUSTED_NONVOLATILE_COPY_FENCE();
    456459    Log(("first = %d, free = %d\n", idxRecordFirst, idxRecordFree));
    457460    if (idxRecordFirst == idxRecordFree)
    458461        return VINF_EOF; /* No records to process. Return without assigning output variables. */
    459462    AssertReturn(idxRecordFirst < VBVA_MAX_RECORDS, VERR_INVALID_STATE);
     463    RT_UNTRUSTED_VALIDATED_FENCE();
    460464
    461465    /*
     
    464468    uint32_t const cbRecordCurrent = ASMAtomicReadU32(&pVBVA->aRecords[idxRecordFirst].cbRecord);
    465469    uint32_t const cbRecord        = cbRecordCurrent & ~VBVA_F_RECORD_PARTIAL;
     470    RT_UNTRUSTED_NONVOLATILE_COPY_FENCE();
    466471    if (   (cbRecordCurrent & VBVA_F_RECORD_PARTIAL)
    467472        || !cbRecord)
     
    474479    uint32_t const offData   = ASMAtomicReadU32(&pVBVA->off32Data);
    475480    uint32_t       cbMaxData = ASMAtomicReadU32(&pVBVA->cbData);
     481    RT_UNTRUSTED_NONVOLATILE_COPY_FENCE();
    476482    AssertLogRelMsgStmt(cbMaxData <= pCmdVbva->cbMaxData, ("%#x vs %#x\n", cbMaxData, pCmdVbva->cbMaxData),
    477483                        cbMaxData = pCmdVbva->cbMaxData);
     
    480486                          ("offData=%#x cbRecord=%#x cbMaxData=%#x cbRecord\n", offData, cbRecord, cbMaxData),
    481487                          VERR_INVALID_STATE);
     488    RT_UNTRUSTED_VALIDATED_FENCE();
    482489
    483490    /*
    484491     * Just set the return values and we're done.
    485492     */
    486     *ppbCmd  = (uint8_t *)&pVBVA->au8Data[offData];
     493    *ppbCmd = (uint8_t RT_UNTRUSTED_VOLATILE_GUEST *)&pVBVA->au8Data[offData];
    487494    *pcbCmd = cbRecord;
    488495    return VINF_SUCCESS;
     
    497504static void VBoxVBVAExHPDataCompleteCmd(struct VBVAEXHOSTCONTEXT *pCmdVbva, uint32_t cbCmd)
    498505{
    499     VBVABUFFER volatile *pVBVA       = pCmdVbva->pVBVA;
    500 
    501     /* Move data head. */
    502     uint32_t const       cbData      = pVBVA->cbData;
    503     uint32_t const       offData     = pVBVA->off32Data;
    504     if (cbData > 0)
    505         ASMAtomicWriteU32(&pVBVA->off32Data, (offData + cbCmd) % cbData);
    506     else
    507         ASMAtomicWriteU32(&pVBVA->off32Data, 0);
    508 
    509     /* Increment record pointer. */
    510     uint32_t const       idxRecFirst = pVBVA->indexRecordFirst;
    511     ASMAtomicWriteU32(&pVBVA->indexRecordFirst, (idxRecFirst + 1) % RT_ELEMENTS(pVBVA->aRecords));
     506    VBVABUFFER RT_UNTRUSTED_VOLATILE_GUEST *pVBVA = pCmdVbva->pVBVA;
     507    if (pVBVA)
     508    {
     509        /* Move data head. */
     510        uint32_t const  cbData      = pVBVA->cbData;
     511        uint32_t const  offData     = pVBVA->off32Data;
     512        RT_UNTRUSTED_NONVOLATILE_COPY_FENCE();
     513        if (cbData > 0)
     514            ASMAtomicWriteU32(&pVBVA->off32Data, (offData + cbCmd) % cbData);
     515        else
     516            ASMAtomicWriteU32(&pVBVA->off32Data, 0);
     517
     518        /* Increment record pointer. */
     519        uint32_t const  idxRecFirst = pVBVA->indexRecordFirst;
     520        RT_UNTRUSTED_NONVOLATILE_COPY_FENCE();
     521        ASMAtomicWriteU32(&pVBVA->indexRecordFirst, (idxRecFirst + 1) % RT_ELEMENTS(pVBVA->aRecords));
     522    }
    512523}
    513524
     
    528539 * @thread VDMA
    529540 */
    530 static VBVAEXHOST_DATA_TYPE vboxVBVAExHPDataGet(struct VBVAEXHOSTCONTEXT *pCmdVbva, uint8_t **ppCmd, uint32_t *pcbCmd)
     541static VBVAEXHOST_DATA_TYPE vboxVBVAExHPDataGetInner(struct VBVAEXHOSTCONTEXT *pCmdVbva,
     542                                                     uint8_t RT_UNTRUSTED_VOLATILE_GUEST **ppbCmd, uint32_t *pcbCmd)
    531543{
    532544    Assert(pCmdVbva->i32State == VBVAEXHOSTCONTEXT_STATE_PROCESSING);
    533     VBVAEXHOSTCTL*pCtl;
     545    VBVAEXHOSTCTL *pCtl;
    534546    bool fHostClt;
    535547
     
    543555                if (!vboxVBVAExHPCheckProcessCtlInternal(pCmdVbva, pCtl))
    544556                {
    545                     *ppCmd = (uint8_t*)pCtl;
     557                    *ppbCmd = (uint8_t RT_UNTRUSTED_VOLATILE_GUEST *)pCtl; /* Note! pCtl is host data, so trusted */
    546558                    *pcbCmd = sizeof (*pCtl);
    547559                    return VBVAEXHOST_DATA_TYPE_HOSTCTL;
     
    549561                continue; /* Processed by vboxVBVAExHPCheckProcessCtlInternal, get next. */
    550562            }
    551             *ppCmd = (uint8_t*)pCtl;
     563            *ppbCmd = (uint8_t RT_UNTRUSTED_VOLATILE_GUEST *)pCtl; /* Note! pCtl is host data, so trusted */
    552564            *pcbCmd = sizeof (*pCtl);
    553565            return VBVAEXHOST_DATA_TYPE_GUESTCTL;
     
    557569            return VBVAEXHOST_DATA_TYPE_NO_DATA;
    558570
    559         int rc = vboxVBVAExHPCmdGet(pCmdVbva, ppCmd, pcbCmd);
     571        int rc = vboxVBVAExHPCmdGet(pCmdVbva, ppbCmd, pcbCmd);
    560572        switch (rc)
    561573        {
     
    580592 * @thread VDMA
    581593 */
    582 static VBVAEXHOST_DATA_TYPE VBoxVBVAExHPDataGet(struct VBVAEXHOSTCONTEXT *pCmdVbva, uint8_t **ppCmd, uint32_t *pcbCmd)
    583 {
    584     VBVAEXHOST_DATA_TYPE enmType = vboxVBVAExHPDataGet(pCmdVbva, ppCmd, pcbCmd);
     594static VBVAEXHOST_DATA_TYPE VBoxVBVAExHPDataGet(struct VBVAEXHOSTCONTEXT *pCmdVbva,
     595                                                uint8_t RT_UNTRUSTED_VOLATILE_GUEST **ppbCmd, uint32_t *pcbCmd)
     596{
     597    VBVAEXHOST_DATA_TYPE enmType = vboxVBVAExHPDataGetInner(pCmdVbva, ppbCmd, pcbCmd);
    585598    if (enmType == VBVAEXHOST_DATA_TYPE_NO_DATA)
    586599    {
     
    601614        {
    602615            /* we are the processor now */
    603             enmType = vboxVBVAExHPDataGet(pCmdVbva, ppCmd, pcbCmd);
     616            enmType = vboxVBVAExHPDataGetInner(pCmdVbva, ppbCmd, pcbCmd);
    604617            if (enmType == VBVAEXHOST_DATA_TYPE_NO_DATA)
    605618            {
     
    620633DECLINLINE(bool) vboxVBVAExHSHasCommands(struct VBVAEXHOSTCONTEXT *pCmdVbva)
    621634{
    622     VBVABUFFER *pVBVA = pCmdVbva->pVBVA;
     635    VBVABUFFER RT_UNTRUSTED_VOLATILE_GUEST *pVBVA = pCmdVbva->pVBVA;
    623636    if (pVBVA)
    624637    {
    625638        uint32_t indexRecordFirst = pVBVA->indexRecordFirst;
    626         uint32_t indexRecordFree = pVBVA->indexRecordFree;
     639        uint32_t indexRecordFree  = pVBVA->indexRecordFree;
     640        RT_UNTRUSTED_NONVOLATILE_COPY_FENCE();
    627641
    628642        if (indexRecordFirst != indexRecordFree)
     
    717731 * @thread VDMA
    718732 */
    719 static int VBoxVBVAExHSEnable(struct VBVAEXHOSTCONTEXT *pCmdVbva, VBVABUFFER *pVBVA, uint8_t *pbVRam, uint32_t cbVRam)
     733static int VBoxVBVAExHSEnable(struct VBVAEXHOSTCONTEXT *pCmdVbva, VBVABUFFER RT_UNTRUSTED_VOLATILE_GUEST *pVBVA,
     734                              uint8_t *pbVRam, uint32_t cbVRam)
    720735{
    721736    if (VBoxVBVAExHSIsEnabled(pCmdVbva))
     
    727742    uintptr_t offVRam = (uintptr_t)pVBVA - (uintptr_t)pbVRam;
    728743    AssertLogRelMsgReturn(offVRam < cbVRam - sizeof(*pVBVA), ("%#p cbVRam=%#x\n", offVRam, cbVRam), VERR_OUT_OF_RANGE);
     744    RT_UNTRUSTED_VALIDATED_FENCE();
    729745
    730746    pCmdVbva->pVBVA     = pVBVA;
     
    784800    rc = SSMR3PutU32(pSSM, pCtl->u.cmd.cbCmd);
    785801    AssertRCReturn(rc, rc);
    786     rc = SSMR3PutU32(pSSM, (uint32_t)(pCtl->u.cmd.pu8Cmd - pu8VramBase));
     802    rc = SSMR3PutU32(pSSM, (uint32_t)((uintptr_t)pCtl->u.cmd.pvCmd - (uintptr_t)pu8VramBase));
    787803    AssertRCReturn(rc, rc);
    788804
     
    865881    rc = SSMR3GetU32(pSSM, &u32);
    866882    AssertLogRelRCReturn(rc, rc);
    867     pHCtl->u.cmd.pu8Cmd = pu8VramBase + u32;
     883    pHCtl->u.cmd.pvCmd = pu8VramBase + u32;
    868884
    869885    RTListAppend(&pCmdVbva->GuestCtlList, &pHCtl->Node);
     
    924940 *
    925941 */
    926 static int VBoxVBVAExHCtlSubmit(VBVAEXHOSTCONTEXT *pCmdVbva, VBVAEXHOSTCTL* pCtl, VBVAEXHOSTCTL_SOURCE enmSource,
     942static int VBoxVBVAExHCtlSubmit(VBVAEXHOSTCONTEXT *pCmdVbva, VBVAEXHOSTCTL *pCtl, VBVAEXHOSTCTL_SOURCE enmSource,
    927943                                PFNVBVAEXHOSTCTL_COMPLETE pfnComplete, void *pvComplete)
    928944{
     
    14471463    {
    14481464        *pcbCtl = pVdma->pCurRemainingHostCtl->u.cmd.cbCmd;
    1449         return pVdma->pCurRemainingHostCtl->u.cmd.pu8Cmd;
     1465        return (uint8_t *)pVdma->pCurRemainingHostCtl->u.cmd.pvCmd;
    14501466    }
    14511467
     
    15341550    }
    15351551
    1536     VBVABUFFER *pVBVA = (VBVABUFFER *)HGSMIOffsetToPointerHost(pVdma->pHgsmi, u32Offset);
     1552    VBVABUFFER RT_UNTRUSTED_VOLATILE_GUEST *pVBVA
     1553        = (VBVABUFFER RT_UNTRUSTED_VOLATILE_GUEST *)HGSMIOffsetToPointerHost(pVdma->pHgsmi, u32Offset);
    15371554    if (!pVBVA)
    15381555    {
     
    16601677            {
    16611678                if (pVdma->CrSrvInfo.pfnHostCtl)
    1662                     return pVdma->CrSrvInfo.pfnHostCtl(pVdma->CrSrvInfo.hSvr, pCmd->u.cmd.pu8Cmd, pCmd->u.cmd.cbCmd);
     1679                    return pVdma->CrSrvInfo.pfnHostCtl(pVdma->CrSrvInfo.hSvr, (uint8_t *)pCmd->u.cmd.pvCmd, pCmd->u.cmd.cbCmd);
    16631680                WARN(("VBVAEXHOSTCTL_TYPE_GHH_BE_OPAQUE for disabled vdma VBVA\n"));
    16641681            }
     
    17721789            || idxView == UINT32_C(0xFFFFFFFF))
    17731790        {
     1791            RT_UNTRUSTED_VALIDATED_FENCE();
     1792
    17741793            RT_ZERO(*pScreen);
    17751794            pScreen->u32ViewIndex = idxView;
     
    17851804                && idxView != UINT32_C(0xFFFFFFFF))
    17861805                return VERR_INVALID_PARAMETER;
     1806            RT_UNTRUSTED_VALIDATED_FENCE();
    17871807
    17881808            /* Special case for blanking using current video mode.
     
    18261846 * @thread  VDMA
    18271847 */
    1828 static int vboxVDMACrGuestCtlResizeEntryProcess(struct VBOXVDMAHOST *pVdma, VBOXCMDVBVA_RESIZE_ENTRY *pEntry)
     1848static int vboxVDMACrGuestCtlResizeEntryProcess(struct VBOXVDMAHOST *pVdma,
     1849                                                VBOXCMDVBVA_RESIZE_ENTRY RT_UNTRUSTED_VOLATILE_GUEST *pEntry)
    18291850{
    18301851    PVGASTATE pVGAState = pVdma->pVGAState;
    1831     VBVAINFOSCREEN Screen = pEntry->Screen;
     1852
     1853    VBVAINFOSCREEN Screen;
     1854    RT_COPY_VOLATILE(Screen, pEntry->Screen);
     1855    RT_UNTRUSTED_NONVOLATILE_COPY_FENCE();
    18321856
    18331857    /* Verify and cleanup local copy of the input data. */
     
    18381862        return rc;
    18391863    }
     1864    RT_UNTRUSTED_VALIDATED_FENCE();
    18401865
    18411866    VBOXCMDVBVA_SCREENMAP_DECL(uint32_t, aTargetMap);
    1842     memcpy(aTargetMap, pEntry->aTargetMap, sizeof(aTargetMap));
     1867    RT_BCOPY_VOLATILE(aTargetMap, pEntry->aTargetMap, sizeof(aTargetMap));
     1868    RT_UNTRUSTED_NONVOLATILE_COPY_FENCE();
     1869
    18431870    ASMBitClearRange(aTargetMap, pVGAState->cMonitors, VBOX_VIDEO_MAX_SCREENS);
    18441871
     
    19261953            {
    19271954                if (pVdma->CrSrvInfo.pfnGuestCtl)
    1928                     return pVdma->CrSrvInfo.pfnGuestCtl(pVdma->CrSrvInfo.hSvr, pCmd->u.cmd.pu8Cmd, pCmd->u.cmd.cbCmd);
     1955                    return pVdma->CrSrvInfo.pfnGuestCtl(pVdma->CrSrvInfo.hSvr,
     1956                                                        (uint8_t RT_UNTRUSTED_VOLATILE_GUEST *)pCmd->u.cmd.pvCmd,
     1957                                                        pCmd->u.cmd.cbCmd);
    19291958
    19301959                /* Unexpected. */
     
    19461975                {
    19471976                    uint32_t cElements = cbCmd / sizeof(VBOXCMDVBVA_RESIZE_ENTRY);
    1948                     VBOXCMDVBVA_RESIZE *pResize = (VBOXCMDVBVA_RESIZE *)pCmd->u.cmd.pu8Cmd;
     1977                    VBOXCMDVBVA_RESIZE RT_UNTRUSTED_VOLATILE_GUEST *pResize
     1978                        = (VBOXCMDVBVA_RESIZE RT_UNTRUSTED_VOLATILE_GUEST *)pCmd->u.cmd.pvCmd;
    19491979                    for (uint32_t i = 0; i < cElements; ++i)
    19501980                    {
    1951                         VBOXCMDVBVA_RESIZE_ENTRY *pEntry = &pResize->aEntries[i];
     1981                        VBOXCMDVBVA_RESIZE_ENTRY RT_UNTRUSTED_VOLATILE_GUEST *pEntry = &pResize->aEntries[i];
    19521982                        int rc = vboxVDMACrGuestCtlResizeEntryProcess(pVdma, pEntry);
    19531983                        if (RT_FAILURE(rc))
     
    19722002        case VBVAEXHOSTCTL_TYPE_GHH_ENABLE_PAUSED:
    19732003        {
    1974             VBVAENABLE *pEnable = (VBVAENABLE *)pCmd->u.cmd.pu8Cmd;
     2004            VBVAENABLE RT_UNTRUSTED_VOLATILE_GUEST *pEnable = (VBVAENABLE RT_UNTRUSTED_VOLATILE_GUEST *)pCmd->u.cmd.pvCmd;
    19752005            Assert(pCmd->u.cmd.cbCmd == sizeof(VBVAENABLE));
    19762006
    1977             uint32_t u32Offset = pEnable->u32Offset;
     2007            uint32_t const u32Offset = pEnable->u32Offset;
     2008            RT_UNTRUSTED_NONVOLATILE_COPY_FENCE();
     2009
    19782010            int rc = vdmaVBVAEnableProcess(pVdma, u32Offset);
    19792011            if (RT_SUCCESS(rc))
     
    20302062    RTGCPHYS       GCPhysPage = (RTGCPHYS)uPageNo << X86_PAGE_SHIFT;
    20312063    PGMPAGEMAPLOCK Lock;
    2032     int rc;
    20332064
    20342065    if (fIn)
    20352066    {
    20362067        const void *pvPage;
    2037         rc = PDMDevHlpPhysGCPhys2CCPtrReadOnly(pDevIns, GCPhysPage, 0, &pvPage, &Lock);
    2038         if (RT_SUCCESS(rc))
    2039         {
    2040             memcpy(pbVram, pvPage, PAGE_SIZE);
    2041             PDMDevHlpPhysReleasePageMappingLock(pDevIns, &Lock);
    2042         }
    2043         else
    2044             WARN(("PDMDevHlpPhysGCPhys2CCPtrReadOnly failed %Rrc", rc));
     2068        int rc = PDMDevHlpPhysGCPhys2CCPtrReadOnly(pDevIns, GCPhysPage, 0, &pvPage, &Lock);
     2069        ASSERT_GUEST_LOGREL_MSG_RC_RETURN(rc, ("PDMDevHlpPhysGCPhys2CCPtrReadOnly %RGp -> %Rrc\n", GCPhysPage, rc), rc);
     2070
     2071        memcpy(pbVram, pvPage, PAGE_SIZE);
     2072        PDMDevHlpPhysReleasePageMappingLock(pDevIns, &Lock);
    20452073    }
    20462074    else
    20472075    {
    20482076        void *pvPage;
    2049         rc = PDMDevHlpPhysGCPhys2CCPtr(pDevIns, GCPhysPage, 0, &pvPage, &Lock);
    2050         if (RT_SUCCESS(rc))
    2051         {
    2052             memcpy(pvPage, pbVram, PAGE_SIZE);
    2053             PDMDevHlpPhysReleasePageMappingLock(pDevIns, &Lock);
    2054         }
    2055         else
    2056             WARN(("PDMDevHlpPhysGCPhys2CCPtr failed %Rrc", rc));
    2057     }
    2058 
    2059     return rc;
     2077        int rc = PDMDevHlpPhysGCPhys2CCPtr(pDevIns, GCPhysPage, 0, &pvPage, &Lock);
     2078        ASSERT_GUEST_LOGREL_MSG_RC_RETURN(rc, ("PDMDevHlpPhysGCPhys2CCPtr %RGp -> %Rrc\n", GCPhysPage, rc), rc);
     2079
     2080        memcpy(pvPage, pbVram, PAGE_SIZE);
     2081        PDMDevHlpPhysReleasePageMappingLock(pDevIns, &Lock);
     2082    }
     2083
     2084    return VINF_SUCCESS;
    20602085}
    20612086
     
    20672092 * @thread VDMA
    20682093 */
    2069 static int8_t vboxVDMACrCmdVbvaPageTransfer(PVGASTATE pVGAState, VBOXCMDVBVA_HDR const volatile *pHdr, uint32_t cbCmd,
    2070                                             const VBOXCMDVBVA_PAGING_TRANSFER_DATA *pData)
     2094static int8_t vboxVDMACrCmdVbvaPageTransfer(PVGASTATE pVGAState, VBOXCMDVBVA_HDR const RT_UNTRUSTED_VOLATILE_GUEST *pHdr,
     2095                                            uint32_t cbCmd, const VBOXCMDVBVA_PAGING_TRANSFER_DATA RT_UNTRUSTED_VOLATILE_GUEST *pData)
    20712096{
    20722097    /*
    20732098     * Extract and validate information.
    20742099     */
    2075     AssertMsgReturn(cbCmd >= sizeof(VBOXCMDVBVA_PAGING_TRANSFER), ("%#x\n", cbCmd), -1);
     2100    ASSERT_GUEST_MSG_RETURN(cbCmd >= sizeof(VBOXCMDVBVA_PAGING_TRANSFER), ("%#x\n", cbCmd), -1);
    20762101
    20772102    bool const fIn = RT_BOOL(pHdr->u8Flags & VBOXCMDVBVA_OPF_PAGING_TRANSFER_IN);
     2103    RT_UNTRUSTED_NONVOLATILE_COPY_FENCE();
    20782104
    20792105    uint32_t cbPageNumbers = cbCmd - RT_OFFSETOF(VBOXCMDVBVA_PAGING_TRANSFER, Data.aPageNumbers);
    2080     AssertMsgReturn(!(cbPageNumbers % sizeof(VBOXCMDVBVAPAGEIDX)), ("%#x\n", cbPageNumbers), -1);
     2106    ASSERT_GUEST_MSG_RETURN(!(cbPageNumbers % sizeof(VBOXCMDVBVAPAGEIDX)), ("%#x\n", cbPageNumbers), -1);
    20812107    VBOXCMDVBVAPAGEIDX const cPages = cbPageNumbers / sizeof(VBOXCMDVBVAPAGEIDX);
    20822108
    20832109    VBOXCMDVBVAOFFSET offVRam = pData->Alloc.u.offVRAM;
    2084     AssertMsgReturn(!(offVRam & X86_PAGE_OFFSET_MASK), ("%#x\n", offVRam), -1);
    2085     AssertMsgReturn(offVRam < pVGAState->vram_size, ("%#x vs %#x\n", offVRam, pVGAState->vram_size), -1);
     2110    RT_UNTRUSTED_NONVOLATILE_COPY_FENCE();
     2111    ASSERT_GUEST_MSG_RETURN(!(offVRam & X86_PAGE_OFFSET_MASK), ("%#x\n", offVRam), -1);
     2112    ASSERT_GUEST_MSG_RETURN(offVRam < pVGAState->vram_size, ("%#x vs %#x\n", offVRam, pVGAState->vram_size), -1);
    20862113    uint32_t cVRamPages = (pVGAState->vram_size - offVRam) >> X86_PAGE_SHIFT;
    2087     AssertMsgReturn(cPages <= cVRamPages, ("cPages=%#x vs cVRamPages=%#x @ offVRam=%#x\n", cPages, cVRamPages, offVRam), -1);
     2114    ASSERT_GUEST_MSG_RETURN(cPages <= cVRamPages, ("cPages=%#x vs cVRamPages=%#x @ offVRam=%#x\n", cPages, cVRamPages, offVRam), -1);
     2115
     2116    RT_UNTRUSTED_VALIDATED_FENCE();
    20882117
    20892118    /*
     
    20942123    {
    20952124        uint32_t uPageNo = pData->aPageNumbers[iPage];
     2125        RT_UNTRUSTED_NONVOLATILE_COPY_FENCE();
    20962126        int rc = vboxVDMACrCmdVbvaProcessPagingEl(pVGAState->pDevInsR3, uPageNo, pbVRam, fIn);
    2097         AssertMsgReturn(RT_SUCCESS(rc), ("#%#x: uPageNo=%#x rc=%Rrc\n", iPage, uPageNo, rc), -1);
     2127        ASSERT_GUEST_MSG_RETURN(RT_SUCCESS(rc), ("#%#x: uPageNo=%#x rc=%Rrc\n", iPage, uPageNo, rc), -1);
    20982128    }
    20992129    return 0;
     
    21102140 * @thread VDMA
    21112141 */
    2112 static int8_t vboxVDMACrCmdVbvaPagingFill(PVGASTATE pVGAState, VBOXCMDVBVA_PAGING_FILL *pFill)
    2113 {
    2114     VBOXCMDVBVA_PAGING_FILL FillSafe = *pFill;
    2115     VBOXCMDVBVAOFFSET       offVRAM  = FillSafe.offVRAM;
    2116     if (!(offVRAM & X86_PAGE_OFFSET_MASK))
    2117     {
    2118         if (offVRAM <= pVGAState->vram_size)
    2119         {
    2120             uint32_t cbFill = FillSafe.u32CbFill;
    2121             AssertStmt(!(cbFill & 3), cbFill &= ~(uint32_t)3);
    2122 
    2123             if (   cbFill < pVGAState->vram_size
    2124                 && offVRAM <= pVGAState->vram_size - cbFill)
    2125             {
    2126                 uint32_t      *pu32Vram = (uint32_t *)((uint8_t *)pVGAState->vram_ptrR3 + offVRAM);
    2127                 uint32_t const u32Color = FillSafe.u32Pattern;
    2128 
    2129                 uint32_t cLoops = cbFill / 4;
    2130                 while (cLoops-- > 0)
    2131                     pu32Vram[cLoops] = u32Color;
    2132 
    2133                 return 0;
    2134 
    2135             }
    2136             else
    2137                 WARN(("invalid cbFill"));
    2138 
    2139         }
    2140         WARN(("invalid vram offset"));
    2141 
    2142     }
    2143     else
    2144         WARN(("offVRAM address is not on page boundary\n"));
    2145     return -1;
     2142static int8_t vboxVDMACrCmdVbvaPagingFill(PVGASTATE pVGAState, VBOXCMDVBVA_PAGING_FILL RT_UNTRUSTED_VOLATILE_GUEST *pFill)
     2143{
     2144    /*
     2145     * Copy and validate input.
     2146     */
     2147    VBOXCMDVBVA_PAGING_FILL FillSafe;
     2148    RT_COPY_VOLATILE(FillSafe, *pFill);
     2149    RT_UNTRUSTED_NONVOLATILE_COPY_FENCE();
     2150
     2151    VBOXCMDVBVAOFFSET offVRAM = FillSafe.offVRAM;
     2152    ASSERT_GUEST_MSG_RETURN(!(offVRAM & X86_PAGE_OFFSET_MASK), ("offVRAM=%#x\n", offVRAM), -1);
     2153    ASSERT_GUEST_MSG_RETURN(offVRAM <= pVGAState->vram_size, ("offVRAM=%#x\n", offVRAM), -1);
     2154
     2155    uint32_t cbFill = FillSafe.u32CbFill;
     2156    ASSERT_GUEST_STMT(!(cbFill & 3), cbFill &= ~(uint32_t)3);
     2157    ASSERT_GUEST_MSG_RETURN(   cbFill < pVGAState->vram_size
     2158                            && offVRAM <= pVGAState->vram_size - cbFill,
     2159                            ("offVRAM=%#x cbFill=%#x\n", offVRAM, cbFill), -1);
     2160
     2161    RT_UNTRUSTED_VALIDATED_FENCE();
     2162
     2163    /*
     2164     * Execute.
     2165     */
     2166    uint32_t      *pu32Vram = (uint32_t *)((uint8_t *)pVGAState->vram_ptrR3 + offVRAM);
     2167    uint32_t const u32Color = FillSafe.u32Pattern;
     2168
     2169    uint32_t cLoops = cbFill / 4;
     2170    while (cLoops-- > 0)
     2171        pu32Vram[cLoops] = u32Color;
     2172
     2173    return 0;
    21462174}
    21472175
     
    21562184 * @thread VDMA
    21572185 */
    2158 static int8_t vboxVDMACrCmdVbvaProcessCmdData(struct VBOXVDMAHOST *pVdma, const VBOXCMDVBVA_HDR *pCmd, uint32_t cbCmd)
     2186static int8_t vboxVDMACrCmdVbvaProcessCmdData(struct VBOXVDMAHOST *pVdma, const VBOXCMDVBVA_HDR RT_UNTRUSTED_VOLATILE_GUEST *pCmd,
     2187                                              uint32_t cbCmd)
    21592188{
    21602189    uint8_t bOpCode = pCmd->u8OpCode;
     2190    RT_UNTRUSTED_NONVOLATILE_COPY_FENCE();
    21612191    switch (bOpCode)
    21622192    {
     
    21652195
    21662196        case VBOXCMDVBVA_OPTYPE_PAGING_TRANSFER:
    2167             return vboxVDMACrCmdVbvaPageTransfer(pVdma->pVGAState, pCmd, cbCmd, &((VBOXCMDVBVA_PAGING_TRANSFER *)pCmd)->Data);
     2197            return vboxVDMACrCmdVbvaPageTransfer(pVdma->pVGAState, pCmd, cbCmd,
     2198                                                 &((VBOXCMDVBVA_PAGING_TRANSFER RT_UNTRUSTED_VOLATILE_GUEST *)pCmd)->Data);
    21682199
    21692200        case VBOXCMDVBVA_OPTYPE_PAGING_FILL:
    2170             if (cbCmd == sizeof(VBOXCMDVBVA_PAGING_FILL))
    2171                 return vboxVDMACrCmdVbvaPagingFill(pVdma->pVGAState, (VBOXCMDVBVA_PAGING_FILL *)pCmd);
    2172             WARN(("cmd too small"));
    2173             return -1;
     2201            ASSERT_GUEST_RETURN(cbCmd == sizeof(VBOXCMDVBVA_PAGING_FILL), -1);
     2202            return vboxVDMACrCmdVbvaPagingFill(pVdma->pVGAState, (VBOXCMDVBVA_PAGING_FILL RT_UNTRUSTED_VOLATILE_GUEST *)pCmd);
    21742203
    21752204        default:
    2176             if (pVdma->CrSrvInfo.pfnCmd)
    2177                 return pVdma->CrSrvInfo.pfnCmd(pVdma->CrSrvInfo.hSvr, pCmd, cbCmd);
    2178             /* Unexpected. */
    2179             WARN(("no HGCM"));
    2180             return -1;
     2205            ASSERT_GUEST_RETURN(pVdma->CrSrvInfo.pfnCmd != NULL, -1);
     2206            return pVdma->CrSrvInfo.pfnCmd(pVdma->CrSrvInfo.hSvr, pCmd, cbCmd);
    21812207    }
    21822208}
     
    22132239 * @thread VDMA
    22142240 */
    2215 static int8_t vboxVDMACrCmdVbvaProcess(struct VBOXVDMAHOST *pVdma, const VBOXCMDVBVA_HDR *pCmd, uint32_t cbCmd, bool fRecursion)
     2241static int8_t vboxVDMACrCmdVbvaProcess(struct VBOXVDMAHOST *pVdma, const VBOXCMDVBVA_HDR RT_UNTRUSTED_VOLATILE_GUEST *pCmd,
     2242                                       uint32_t cbCmd, bool fRecursion)
    22162243{
    22172244    int8_t        i8Result = 0;
    22182245    uint8_t const bOpCode  = pCmd->u8OpCode;
     2246    RT_UNTRUSTED_NONVOLATILE_COPY_FENCE();
    22192247    LogRelFlow(("VDMA: vboxVDMACrCmdVbvaProcess: ENTER, bOpCode=%u\n", bOpCode));
    22202248    switch (bOpCode)
     
    22252253             * Extract the command physical address and size.
    22262254             */
    2227             AssertMsgReturn(cbCmd >= sizeof(VBOXCMDVBVA_SYSMEMCMD), ("%#x\n", cbCmd), -1);
    2228             RTGCPHYS GCPhysCmd  = ((VBOXCMDVBVA_SYSMEMCMD *)pCmd)->phCmd;
     2255            ASSERT_GUEST_MSG_RETURN(cbCmd >= sizeof(VBOXCMDVBVA_SYSMEMCMD), ("%#x\n", cbCmd), -1);
     2256            RTGCPHYS GCPhysCmd  = ((VBOXCMDVBVA_SYSMEMCMD RT_UNTRUSTED_VOLATILE_GUEST *)pCmd)->phCmd;
     2257            RT_UNTRUSTED_NONVOLATILE_COPY_FENCE();
    22292258            uint32_t cbCmdPart  = X86_PAGE_SIZE - (uint32_t)(GCPhysCmd & X86_PAGE_OFFSET_MASK);
    22302259
    22312260            uint32_t cbRealCmd  = pCmd->u8Flags;
    22322261            cbRealCmd |= (uint32_t)pCmd->u.u8PrimaryID << 8;
    2233             AssertMsgReturn(cbRealCmd >= sizeof(VBOXCMDVBVA_HDR), ("%#x\n", cbRealCmd), -1);
    2234             AssertMsgReturn(cbRealCmd <= _1M, ("%#x\n", cbRealCmd), -1);
     2262            ASSERT_GUEST_MSG_RETURN(cbRealCmd >= sizeof(VBOXCMDVBVA_HDR), ("%#x\n", cbRealCmd), -1);
     2263            ASSERT_GUEST_MSG_RETURN(cbRealCmd <= _1M, ("%#x\n", cbRealCmd), -1);
    22352264
    22362265            /*
     
    22422271            VBOXCMDVBVA_HDR const *pRealCmdHdr = NULL;
    22432272            int rc = PDMDevHlpPhysGCPhys2CCPtrReadOnly(pDevIns, GCPhysCmd, 0, (const void **)&pRealCmdHdr, &Lock);
    2244             if (!RT_SUCCESS(rc))
    2245             {
    2246                 WARN(("PDMDevHlpPhysGCPhys2CCPtrReadOnly failed %Rrc\n", rc));
    2247                 return -1;
    2248             }
     2273            ASSERT_GUEST_LOGREL_MSG_RC_RETURN(rc, ("VDMA: %RGp -> %Rrc\n", GCPhysCmd, rc), -1);
    22492274            Assert((GCPhysCmd & PAGE_OFFSET_MASK) == (((uintptr_t)pRealCmdHdr) & PAGE_OFFSET_MASK));
    22502275
     
    22902315        {
    22912316            Assert(cbCmd >= sizeof(VBOXCMDVBVA_HDR)); /* caller already checked this */
    2292             AssertReturn(!fRecursion, -1);
     2317            ASSERT_GUEST_RETURN(!fRecursion, -1);
    22932318
    22942319            /* Skip current command. */
     
    22992324            while (cbCmd > 0)
    23002325            {
    2301                 AssertMsgReturn(cbCmd >= sizeof(VBOXCMDVBVA_HDR), ("%#x\n", cbCmd), -1);
     2326                ASSERT_GUEST_MSG_RETURN(cbCmd >= sizeof(VBOXCMDVBVA_HDR), ("%#x\n", cbCmd), -1);
    23022327
    23032328                uint16_t cbCurCmd = pCmd->u2.complexCmdEl.u16CbCmdHost;
    2304                 AssertMsgReturn(cbCurCmd <= cbCmd, ("cbCurCmd=%#x, cbCmd=%#x\n", cbCurCmd, cbCmd), -1);
     2329                RT_UNTRUSTED_NONVOLATILE_COPY_FENCE();
     2330                ASSERT_GUEST_MSG_RETURN(cbCurCmd <= cbCmd, ("cbCurCmd=%#x, cbCmd=%#x\n", cbCurCmd, cbCmd), -1);
    23052331
    23062332                i8Result = vboxVDMACrCmdVbvaProcess(pVdma, pCmd, cbCurCmd, true /*fRecursive*/);
    2307                 if (i8Result < 0)
    2308                 {
    2309                     WARN(("vboxVDMACrCmdVbvaProcess failed"));
    2310                     return i8Result;
    2311                 }
     2333                ASSERT_GUEST_MSG_RETURN(i8Result >= 0, ("vboxVDMACrCmdVbvaProcess -> %d\n", i8Result), i8Result);
    23122334
    23132335                /* Advance to the next command. */
    2314                 pCmd  = (VBOXCMDVBVA_HDR *)((uintptr_t)pCmd + cbCurCmd);
     2336                pCmd  = (VBOXCMDVBVA_HDR RT_UNTRUSTED_VOLATILE_GUEST *)((uintptr_t)pCmd + cbCurCmd);
    23152337                cbCmd -= cbCurCmd;
    23162338            }
     
    23302352 * @thread VDMA
    23312353 */
    2332 static void vboxVDMACrCmdProcess(struct VBOXVDMAHOST *pVdma, uint8_t* pbCmd, uint32_t cbCmd)
     2354static void vboxVDMACrCmdProcess(struct VBOXVDMAHOST *pVdma, uint8_t RT_UNTRUSTED_VOLATILE_GUEST *pbCmd, uint32_t cbCmd)
    23332355{
    23342356    if (   cbCmd > 0
    23352357        && *pbCmd == VBOXCMDVBVA_OPTYPE_NOP)
    23362358    { /* nop */ }
    2337     else if (cbCmd >= sizeof(VBOXCMDVBVA_HDR))
    2338     {
    2339         PVBOXCMDVBVA_HDR pCmd = (PVBOXCMDVBVA_HDR)pbCmd;
     2359    else
     2360    {
     2361        ASSERT_GUEST_RETURN_VOID(cbCmd >= sizeof(VBOXCMDVBVA_HDR));
     2362        VBOXCMDVBVA_HDR RT_UNTRUSTED_VOLATILE_GUEST *pCmd = (VBOXCMDVBVA_HDR RT_UNTRUSTED_VOLATILE_GUEST *)pbCmd;
    23402363
    23412364        /* check if the command is cancelled */
     
    23482371            Assert(pCmd->u8State == VBOXCMDVBVA_STATE_CANCELLED);
    23492372    }
    2350     else
    2351         WARN(("invalid command size"));
    23522373
    23532374}
     
    25462567    AssertReturn(cbBuffer >= RT_UOFFSETOF(VBOXVDMACMD_DMA_PRESENT_BLT, aDstSubRects), VERR_INVALID_PARAMETER);
    25472568    VBOXVDMACMD_DMA_PRESENT_BLT BltSafe;
    2548     memcpy(&BltSafe, (void const *)pBlt, RT_UOFFSETOF(VBOXVDMACMD_DMA_PRESENT_BLT, aDstSubRects));
     2569    RT_BCOPY_VOLATILE(&BltSafe, (void const *)pBlt, RT_UOFFSETOF(VBOXVDMACMD_DMA_PRESENT_BLT, aDstSubRects));
    25492570    RT_UNTRUSTED_NONVOLATILE_COPY_FENCE();
    25502571
     
    26262647    AssertReturn(cbBuffer >= sizeof(*pTransfer), VERR_INVALID_PARAMETER);
    26272648    VBOXVDMACMD_DMA_BPB_TRANSFER TransferSafeCopy;
    2628     memcpy(&TransferSafeCopy, (void const *)pTransfer, sizeof(TransferSafeCopy));
     2649    RT_COPY_VOLATILE(TransferSafeCopy, *pTransfer);
    26292650    RT_UNTRUSTED_NONVOLATILE_COPY_FENCE();
    26302651
     
    28202841    while (!VBoxVDMAThreadIsTerminating(&pVdma->Thread))
    28212842    {
    2822         uint8_t             *pbCmd  = NULL;
    2823         uint32_t             cbCmd  = 0;
     2843        uint8_t RT_UNTRUSTED_VOLATILE_GUEST *pbCmd = NULL;
     2844        uint32_t                             cbCmd = 0;
    28242845        VBVAEXHOST_DATA_TYPE enmType = VBoxVBVAExHPDataGet(pCmdVbva, &pbCmd, &cbCmd);
    28252846        switch (enmType)
     
    28732894 *                      requests.  Input stat is false, so it only ever need to
    28742895 *                      be set to true.
    2875  * @thread  VDMA
     2896 * @thread  EMT
    28762897 */
    28772898static int vboxVDMACommandProcess(PVBOXVDMAHOST pVdma, VBOXVDMACBUF_DR RT_UNTRUSTED_VOLATILE_GUEST *pCmd,
     
    31353156 * @param   pCmd    The command to handle.  Considered volatile.
    31363157 * @param   cbCmd   The size of the command.  At least sizeof(VBOXVDMACBUF_DR).
     3158 * @thread  EMT
    31373159 */
    31383160void vboxVDMACommand(struct VBOXVDMAHOST *pVdma, VBOXVDMACBUF_DR RT_UNTRUSTED_VOLATILE_GUEST *pCmd, uint32_t cbCmd)
     
    31703192{
    31713193    PVBOXVDMAHOST pVdma = (PVBOXVDMAHOST)pvContext;
    3172     VBOXCMDVBVA_CTL *pGCtl = (VBOXCMDVBVA_CTL*)(pCtl->u.cmd.pu8Cmd - sizeof (VBOXCMDVBVA_CTL));
     3194    VBOXCMDVBVA_CTL RT_UNTRUSTED_VOLATILE_GUEST *pGCtl
     3195        = (VBOXCMDVBVA_CTL RT_UNTRUSTED_VOLATILE_GUEST *)((uintptr_t)pCtl->u.cmd.pvCmd - sizeof(VBOXCMDVBVA_CTL));
    31733196    AssertRC(rc);
    31743197    pGCtl->i32Result = rc;
     
    31853208 */
    31863209static int vdmaVBVACtlGenericSubmit(PVBOXVDMAHOST pVdma, VBVAEXHOSTCTL_SOURCE enmSource, VBVAEXHOSTCTL_TYPE enmType,
    3187                                     uint8_t* pu8Cmd, uint32_t cbCmd, PFNVBVAEXHOSTCTL_COMPLETE pfnComplete, void *pvComplete)
     3210                                    uint8_t RT_UNTRUSTED_VOLATILE_GUEST *pbCmd, uint32_t cbCmd,
     3211                                    PFNVBVAEXHOSTCTL_COMPLETE pfnComplete, void *pvComplete)
    31883212{
    31893213    int            rc;
     
    31913215    if (pHCtl)
    31923216    {
    3193         pHCtl->u.cmd.pu8Cmd = pu8Cmd;
    3194         pHCtl->u.cmd.cbCmd  = cbCmd;
     3217        pHCtl->u.cmd.pvCmd = pbCmd;
     3218        pHCtl->u.cmd.cbCmd = cbCmd;
    31953219        rc = vdmaVBVACtlSubmit(pVdma, pHCtl, enmSource, pfnComplete, pvComplete);
    31963220        if (RT_SUCCESS(rc))
     
    32173241
    32183242    VBoxSHGSMICommandMarkAsynchCompletion(pCtl);
    3219     int rc = vdmaVBVACtlGenericSubmit(pVdma, VBVAEXHOSTCTL_SOURCE_GUEST, enmType, (uint8_t *)(pCtl + 1),
    3220                                       cbCtl - sizeof(VBOXCMDVBVA_CTL), vboxCmdVBVACmdCtlGuestCompletion, pVdma);
     3243    int rc = vdmaVBVACtlGenericSubmit(pVdma, VBVAEXHOSTCTL_SOURCE_GUEST, enmType,
     3244                                      (uint8_t RT_UNTRUSTED_VOLATILE_GUEST *)(pCtl + 1),
     3245                                      cbCtl - sizeof(VBOXCMDVBVA_CTL),
     3246                                      vboxCmdVBVACmdCtlGuestCompletion, pVdma);
    32213247    if (RT_SUCCESS(rc))
    32223248        return VINF_SUCCESS;
     
    32353261                                                          int rc, void *pvCompletion)
    32363262{
    3237     VBOXCRCMDCTL* pVboxCtl = (VBOXCRCMDCTL*)pCtl->u.cmd.pu8Cmd;
     3263    VBOXCRCMDCTL *pVboxCtl = (VBOXCRCMDCTL *)pCtl->u.cmd.pvCmd;
    32383264    if (pVboxCtl->u.pfnInternal)
    32393265        ((PFNCRCTLCOMPLETION)pVboxCtl->u.pfnInternal)(pVboxCtl, pCtl->u.cmd.cbCmd, rc, pvCompletion);
     
    33413367 * Worker for vdmaVBVACtlEnableDisableSubmitInternal() and vdmaVBVACtlEnableSubmitSync().
    33423368 */
    3343 static int vdmaVBVACtlEnableSubmitInternal(PVBOXVDMAHOST pVdma, VBVAENABLE *pEnable, bool fPaused, PFNVBVAEXHOSTCTL_COMPLETE pfnComplete, void *pvComplete)
     3369static int vdmaVBVACtlEnableSubmitInternal(PVBOXVDMAHOST pVdma, VBVAENABLE RT_UNTRUSTED_VOLATILE_GUEST *pEnable, bool fPaused,
     3370                                           PFNVBVAEXHOSTCTL_COMPLETE pfnComplete, void *pvComplete)
    33443371{
    33453372    int rc;
     
    33483375    if (pHCtl)
    33493376    {
    3350         pHCtl->u.cmd.pu8Cmd = (uint8_t *)pEnable;
     3377        pHCtl->u.cmd.pvCmd  = pEnable;
    33513378        pHCtl->u.cmd.cbCmd  = sizeof(*pEnable);
    33523379        pHCtl->pfnComplete  = pfnComplete;
     
    33563383        if (RT_SUCCESS(rc))
    33573384            return VINF_SUCCESS;
    3358         WARN(("VBoxVDMAThreadCreate failed %d\n", rc));
    3359 
     3385
     3386        WARN(("VBoxVDMAThreadCreate failed %Rrc\n", rc));
    33603387        VBoxVBVAExHCtlFree(&pVdma->CmdVbva, pHCtl);
    33613388    }
     
    34113438 * Worker for vdmaVBVACtlEnableDisableSubmitInternal().
    34123439 */
    3413 static int vdmaVBVACtlDisableSubmitInternal(PVBOXVDMAHOST pVdma, VBVAENABLE *pEnable,
     3440static int vdmaVBVACtlDisableSubmitInternal(PVBOXVDMAHOST pVdma, VBVAENABLE RT_UNTRUSTED_VOLATILE_GUEST *pEnable,
    34143441                                            PFNVBVAEXHOSTCTL_COMPLETE pfnComplete, void *pvComplete)
    34153442{
    34163443    int rc;
    3417     VBVAEXHOSTCTL* pHCtl;
    34183444    if (VBoxVBVAExHSIsDisabled(&pVdma->CmdVbva))
    34193445    {
     
    34223448    }
    34233449
    3424     pHCtl = VBoxVBVAExHCtlCreate(&pVdma->CmdVbva, VBVAEXHOSTCTL_TYPE_GHH_DISABLE);
     3450    VBVAEXHOSTCTL *pHCtl = VBoxVBVAExHCtlCreate(&pVdma->CmdVbva, VBVAEXHOSTCTL_TYPE_GHH_DISABLE);
    34253451    if (!pHCtl)
    34263452    {
     
    34293455    }
    34303456
    3431     pHCtl->u.cmd.pu8Cmd = (uint8_t*)pEnable;
    3432     pHCtl->u.cmd.cbCmd = sizeof (*pEnable);
     3457    pHCtl->u.cmd.pvCmd = pEnable;
     3458    pHCtl->u.cmd.cbCmd = sizeof(*pEnable);
    34333459    rc = vdmaVBVACtlSubmit(pVdma, pHCtl, VBVAEXHOSTCTL_SOURCE_GUEST, pfnComplete, pvComplete);
    34343460    if (RT_SUCCESS(rc))
     
    34433469 * Worker for vdmaVBVACtlEnableDisableSubmit().
    34443470 */
    3445 static int vdmaVBVACtlEnableDisableSubmitInternal(PVBOXVDMAHOST pVdma, VBVAENABLE *pEnable,
     3471static int vdmaVBVACtlEnableDisableSubmitInternal(PVBOXVDMAHOST pVdma, VBVAENABLE RT_UNTRUSTED_VOLATILE_GUEST *pEnable,
    34463472                                                  PFNVBVAEXHOSTCTL_COMPLETE pfnComplete, void *pvComplete)
    34473473{
     
    34553481 * Handler for vboxCmdVBVACmdCtl/VBOXCMDVBVACTL_TYPE_ENABLE.
    34563482 */
    3457 static int vdmaVBVACtlEnableDisableSubmit(PVBOXVDMAHOST pVdma, VBOXCMDVBVA_CTL_ENABLE *pEnable)
     3483static int vdmaVBVACtlEnableDisableSubmit(PVBOXVDMAHOST pVdma, VBOXCMDVBVA_CTL_ENABLE RT_UNTRUSTED_VOLATILE_GUEST *pEnable)
    34583484{
    34593485    VBoxSHGSMICommandMarkAsynchCompletion(&pEnable->Hdr);
     
    34853511
    34863512
    3487 static int vdmaVBVACtlSubmitSync(PVBOXVDMAHOST pVdma, VBVAEXHOSTCTL* pCtl, VBVAEXHOSTCTL_SOURCE enmSource)
     3513/**
     3514 *
     3515 */
     3516static int vdmaVBVACtlSubmitSync(PVBOXVDMAHOST pVdma, VBVAEXHOSTCTL *pCtl, VBVAEXHOSTCTL_SOURCE enmSource)
    34883517{
    34893518    VDMA_VBVA_CTL_CYNC_COMPLETION Data;
    3490     Data.rc = VERR_NOT_IMPLEMENTED;
     3519    Data.rc     = VERR_NOT_IMPLEMENTED;
     3520    Data.hEvent = NIL_RTSEMEVENT;
    34913521    int rc = RTSemEventCreate(&Data.hEvent);
    3492     if (!RT_SUCCESS(rc))
    3493     {
     3522    if (RT_SUCCESS(rc))
     3523    {
     3524        rc = vdmaVBVACtlSubmit(pVdma, pCtl, enmSource, vdmaVBVACtlSubmitSyncCompletion, &Data);
     3525        if (RT_SUCCESS(rc))
     3526        {
     3527            rc = RTSemEventWait(Data.hEvent, RT_INDEFINITE_WAIT);
     3528            if (RT_SUCCESS(rc))
     3529            {
     3530                rc = Data.rc;
     3531                if (!RT_SUCCESS(rc))
     3532                    WARN(("vdmaVBVACtlSubmitSyncCompletion returned %Rrc\n", rc));
     3533            }
     3534            else
     3535                WARN(("RTSemEventWait failed %Rrc\n", rc));
     3536        }
     3537        else
     3538            Log(("vdmaVBVACtlSubmit failed %Rrc\n", rc));
     3539
     3540        RTSemEventDestroy(Data.hEvent);
     3541    }
     3542    else
    34943543        WARN(("RTSemEventCreate failed %Rrc\n", rc));
    3495         return rc;
    3496     }
    3497 
    3498     rc = vdmaVBVACtlSubmit(pVdma, pCtl, enmSource, vdmaVBVACtlSubmitSyncCompletion, &Data);
    3499     if (RT_SUCCESS(rc))
    3500     {
    3501         rc = RTSemEventWait(Data.hEvent, RT_INDEFINITE_WAIT);
    3502         if (RT_SUCCESS(rc))
    3503         {
    3504             rc = Data.rc;
    3505             if (!RT_SUCCESS(rc))
    3506                 WARN(("vdmaVBVACtlSubmitSyncCompletion returned %Rrc\n", rc));
    3507         }
    3508         else
    3509             WARN(("RTSemEventWait failed %Rrc\n", rc));
    3510     }
    3511     else
    3512         Log(("vdmaVBVACtlSubmit failed %Rrc\n", rc));
    3513 
    3514     RTSemEventDestroy(Data.hEvent);
    3515 
    35163544    return rc;
    35173545}
     
    37203748 * @param   cbCtl               The size of it.  This is at least
    37213749 *                              sizeof(VBOXCMDVBVA_CTL).
     3750 * @thread  EMT
    37223751 */
    37233752int vboxCmdVBVACmdCtl(PVGASTATE pVGAState, VBOXCMDVBVA_CTL RT_UNTRUSTED_VOLATILE_GUEST *pCtl, uint32_t cbCtl)
    37243753{
    37253754    struct VBOXVDMAHOST *pVdma = pVGAState->pVdma;
    3726     switch (pCtl->u32Type)
     3755    uint32_t uType = pCtl->u32Type;
     3756    RT_UNTRUSTED_NONVOLATILE_COPY_FENCE();
     3757
     3758    switch (uType)
    37273759    {
    37283760        case VBOXCMDVBVACTL_TYPE_3DCTL:
     
    37343766        case VBOXCMDVBVACTL_TYPE_ENABLE:
    37353767            if (cbCtl == sizeof(VBOXCMDVBVA_CTL_ENABLE))
    3736                 return vdmaVBVACtlEnableDisableSubmit(pVdma, (VBOXCMDVBVA_CTL_ENABLE *)pCtl);
     3768                return vdmaVBVACtlEnableDisableSubmit(pVdma, (VBOXCMDVBVA_CTL_ENABLE RT_UNTRUSTED_VOLATILE_GUEST *)pCtl);
    37373769            WARN(("incorrect enable size\n"));
    37383770            break;
     
    37503782/**
    37513783 * Handler for VBVA_CMDVBVA_SUBMIT, see vbvaChannelHandler().
     3784 *
     3785 * @thread  EMT
    37523786 */
    37533787int vboxCmdVBVACmdSubmit(PVGASTATE pVGAState)
     
    37643798/**
    37653799 * Handler for VBVA_CMDVBVA_FLUSH, see vbvaChannelHandler().
     3800 *
     3801 * @thread  EMT
    37663802 */
    37673803int vboxCmdVBVACmdFlush(PVGASTATE pVGAState)
     
    38963932    uint8_t * pu8VramBase = pVGAState->vram_ptrR3;
    38973933
    3898     rc = SSMR3PutU32(pSSM, (uint32_t)(((uint8_t*)pVdma->CmdVbva.pVBVA) - pu8VramBase));
     3934    rc = SSMR3PutU32(pSSM, (uint32_t)((uintptr_t)pVdma->CmdVbva.pVBVA - (uintptr_t)pu8VramBase));
    38993935    AssertRCReturn(rc, rc);
    39003936
     
    39583994
    39593995    /* sanity */
    3960     pHCtl->u.cmd.pu8Cmd = NULL;
     3996    pHCtl->u.cmd.pvCmd = NULL;
    39613997    pHCtl->u.cmd.cbCmd = 0;
    39623998
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/presenter/server_presenter.cpp

    r69500 r71607  
    38883888}
    38893889
    3890 int8_t crVBoxServerCrCmdClrFillProcess(const VBOXCMDVBVA_CLRFILL_HDR *pCmd, uint32_t cbCmd)
    3891 {
     3890/** @todo RT_UNTRUSTED_VOLATILE_GUEST */
     3891int8_t crVBoxServerCrCmdClrFillProcess(VBOXCMDVBVA_CLRFILL_HDR const RT_UNTRUSTED_VOLATILE_GUEST *pCmdTodo, uint32_t cbCmd)
     3892{
     3893    VBOXCMDVBVA_CLRFILL_HDR const *pCmd = (VBOXCMDVBVA_CLRFILL_HDR const *)pCmdTodo;
    38923894    uint8_t u8Flags = pCmd->Hdr.u8Flags;
    38933895    uint8_t u8Cmd = (VBOXCMDVBVA_OPF_CLRFILL_TYPE_MASK & u8Flags);
     
    39123914}
    39133915
    3914 int8_t crVBoxServerCrCmdBltProcess(const VBOXCMDVBVA_BLT_HDR *pCmd, uint32_t cbCmd)
    3915 {
     3916/** @todo RT_UNTRUSTED_VOLATILE_GUEST */
     3917int8_t crVBoxServerCrCmdBltProcess(VBOXCMDVBVA_BLT_HDR const RT_UNTRUSTED_VOLATILE_GUEST *pCmdTodo, uint32_t cbCmd)
     3918{
     3919    VBOXCMDVBVA_BLT_HDR const *pCmd = (VBOXCMDVBVA_BLT_HDR const *)pCmdTodo;
    39163920    uint8_t u8Flags = pCmd->Hdr.u8Flags;
    39173921    uint8_t u8Cmd = (VBOXCMDVBVA_OPF_BLT_TYPE_MASK & u8Flags);
     
    39553959}
    39563960
    3957 int8_t crVBoxServerCrCmdFlipProcess(const VBOXCMDVBVA_FLIP *pFlip, uint32_t cbCmd)
    3958 {
     3961/** @todo RT_UNTRUSTED_VOLATILE_GUEST   */
     3962int8_t crVBoxServerCrCmdFlipProcess(VBOXCMDVBVA_FLIP const RT_UNTRUSTED_VOLATILE_GUEST *pFlipTodo, uint32_t cbCmd)
     3963{
     3964    VBOXCMDVBVA_FLIP const *pFlip = (VBOXCMDVBVA_FLIP const *)pFlipTodo;
    39593965    uint32_t hostId;
    39603966    const VBOXCMDVBVA_RECT *pPRects = pFlip->aRects;
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server.h

    r69474 r71607  
    470470void CrFbTexDataInit(CR_TEXDATA* pFbTex, const VBOXVR_TEXTURE *pTex, PFNCRTEXDATA_RELEASED pfnTextureReleased);
    471471
    472 int8_t crVBoxServerCrCmdBltProcess(const VBOXCMDVBVA_BLT_HDR *pCmd, uint32_t cbCmd);
    473 int8_t crVBoxServerCrCmdClrFillProcess(const VBOXCMDVBVA_CLRFILL_HDR *pCmd, uint32_t cbCmd);
    474 int8_t crVBoxServerCrCmdFlipProcess(const VBOXCMDVBVA_FLIP *pFlip, uint32_t cbCmd);
     472int8_t crVBoxServerCrCmdBltProcess(VBOXCMDVBVA_BLT_HDR const RT_UNTRUSTED_VOLATILE_GUEST *pCmd, uint32_t cbCmd);
     473int8_t crVBoxServerCrCmdClrFillProcess(VBOXCMDVBVA_CLRFILL_HDR const RT_UNTRUSTED_VOLATILE_GUEST *pCmd, uint32_t cbCmd);
     474int8_t crVBoxServerCrCmdFlipProcess(VBOXCMDVBVA_FLIP const RT_UNTRUSTED_VOLATILE_GUEST *pFlip, uint32_t cbCmd);
    475475
    476476
  • trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_main.c

    r69390 r71607  
    3434#include <VBox/err.h>
    3535#include <VBox/log.h>
     36#include <VBox/AssertGuest.h>
    3637
    3738#ifdef VBOXCR_LOGFPS
     
    6768int tearingdown = 0; /* can't be static */
    6869
    69 static DECLCALLBACK(int8_t) crVBoxCrCmdCmd(HVBOXCRCMDSVR hSvr, const VBOXCMDVBVA_HDR *pCmd, uint32_t cbCmd);
     70static DECLCALLBACK(int8_t) crVBoxCrCmdCmd(HVBOXCRCMDSVR hSvr,
     71                                           const VBOXCMDVBVA_HDR RT_UNTRUSTED_VOLATILE_GUEST *pCmd, uint32_t cbCmd);
    7072
    7173DECLINLINE(CRClient*) crVBoxServerClientById(uint32_t u32ClientID)
     
    28732875#ifdef VBOX_WITH_CRHGSMI
    28742876
    2875 static int32_t crVBoxServerCmdVbvaCrCmdProcess(const struct VBOXCMDVBVA_CRCMD_CMD *pCmd, uint32_t cbCmd)
    2876 {
     2877/** @todo RT_UNTRUSTED_VOLATILE_GUEST   */
     2878static int32_t crVBoxServerCmdVbvaCrCmdProcess(VBOXCMDVBVA_CRCMD_CMD const RT_UNTRUSTED_VOLATILE_GUEST *pCmdTodo, uint32_t cbCmd)
     2879{
     2880    VBOXCMDVBVA_CRCMD_CMD const *pCmd = (VBOXCMDVBVA_CRCMD_CMD const *)pCmdTodo;
    28772881    int32_t rc;
    28782882    uint32_t cBuffers = pCmd->cBuffers;
     
    32333237}
    32343238
    3235 static int crVBoxCrConnectEx(VBOXCMDVBVA_3DCTL_CONNECT *pConnect, uint32_t u32ClientId)
     3239static int crVBoxCrConnectEx(VBOXCMDVBVA_3DCTL_CONNECT RT_UNTRUSTED_VOLATILE_GUEST *pConnect, uint32_t u32ClientId)
    32363240{
    32373241    CRClient *pClient;
    32383242    int rc;
     3243    uint32_t const uMajorVersion = pConnect->u32MajorVersion;
     3244    uint32_t const uMinorVersion = pConnect->u32MinorVersion;
     3245    uint64_t const uPid          = pConnect->u64Pid;
     3246    RT_UNTRUSTED_NONVOLATILE_COPY_FENCE();
    32393247
    32403248    if (u32ClientId == CRHTABLE_HANDLE_INVALID)
     
    32523260    if (RT_SUCCESS(rc))
    32533261    {
    3254         rc = crVBoxServerClientObjSetVersion(pClient, pConnect->u32MajorVersion, pConnect->u32MinorVersion);
     3262        rc = crVBoxServerClientObjSetVersion(pClient, uMajorVersion, uMinorVersion);
    32553263        if (RT_SUCCESS(rc))
    32563264        {
    3257             rc = crVBoxServerClientObjSetPID(pClient, pConnect->u64Pid);
     3265            rc = crVBoxServerClientObjSetPID(pClient, uPid);
    32583266            if (RT_SUCCESS(rc))
    32593267            {
     
    32643272                    return VINF_SUCCESS;
    32653273                }
    3266                 else
    3267                     WARN(("CrHTablePutToSlot failed %d", rc));
     3274                WARN(("CrHTablePutToSlot failed %d", rc));
    32683275            }
    32693276            else
     
    32833290}
    32843291
    3285 static int crVBoxCrConnect(VBOXCMDVBVA_3DCTL_CONNECT *pConnect)
     3292static int crVBoxCrConnect(VBOXCMDVBVA_3DCTL_CONNECT RT_UNTRUSTED_VOLATILE_GUEST *pConnect)
    32863293{
    32873294    return crVBoxCrConnectEx(pConnect, CRHTABLE_HANDLE_INVALID);
    32883295}
    32893296
    3290 static DECLCALLBACK(int) crVBoxCrCmdGuestCtl(HVBOXCRCMDSVR hSvr, uint8_t* pCmd, uint32_t cbCmd)
    3291 {
    3292     VBOXCMDVBVA_3DCTL *pCtl = (VBOXCMDVBVA_3DCTL*)pCmd;
    3293     if (cbCmd < sizeof (VBOXCMDVBVA_3DCTL))
    3294     {
    3295         WARN(("invalid buffer size"));
    3296         return VERR_INVALID_PARAMETER;
    3297     }
    3298 
    3299     switch (pCtl->u32Type)
    3300     {
    3301         case VBOXCMDVBVA3DCTL_TYPE_CONNECT:
    3302         {
    3303             if (cbCmd != sizeof (VBOXCMDVBVA_3DCTL_CONNECT))
    3304             {
    3305                 WARN(("invalid command size"));
    3306                 return VERR_INVALID_PARAMETER;
    3307             }
    3308 
    3309             return crVBoxCrConnect((VBOXCMDVBVA_3DCTL_CONNECT*)pCtl);
    3310         }
    3311         case VBOXCMDVBVA3DCTL_TYPE_DISCONNECT:
    3312         {
    3313             if (cbCmd != sizeof (VBOXCMDVBVA_3DCTL))
    3314             {
    3315                 WARN(("invalid command size"));
    3316                 return VERR_INVALID_PARAMETER;
    3317             }
    3318 
    3319             return crVBoxCrDisconnect(pCtl->u32CmdClientId);
    3320         }
    3321         case VBOXCMDVBVA3DCTL_TYPE_CMD:
    3322         {
    3323             VBOXCMDVBVA_3DCTL_CMD *p3DCmd;
    3324             if (cbCmd < sizeof (VBOXCMDVBVA_3DCTL_CMD))
    3325             {
    3326                 WARN(("invalid size"));
    3327                 return VERR_INVALID_PARAMETER;
    3328             }
    3329 
    3330             p3DCmd = (VBOXCMDVBVA_3DCTL_CMD*)pCmd;
    3331 
    3332             return crVBoxCrCmdCmd(NULL, &p3DCmd->Cmd, cbCmd - RT_OFFSETOF(VBOXCMDVBVA_3DCTL_CMD, Cmd));
    3333         }
    3334         default:
    3335             WARN(("crVBoxCrCmdGuestCtl: invalid function %d", pCtl->u32Type));
    3336             return VERR_INVALID_PARAMETER;
     3297/**
     3298 * @interface_method_impl{VBOXCRCMD_SVRINFO,pfnGuestCtl}
     3299 */
     3300static DECLCALLBACK(int) crVBoxCrCmdGuestCtl(HVBOXCRCMDSVR hSvr, uint8_t RT_UNTRUSTED_VOLATILE_GUEST *pbCmd, uint32_t cbCmd)
     3301{
     3302    /*
     3303     * Toplevel input validation.
     3304     */
     3305    ASSERT_GUEST_LOGREL_RETURN(cbCmd >= sizeof(VBOXCMDVBVA_3DCTL), VERR_INVALID_PARAMETER);
     3306    {
     3307        VBOXCMDVBVA_3DCTL RT_UNTRUSTED_VOLATILE_GUEST *pCtl = (VBOXCMDVBVA_3DCTL RT_UNTRUSTED_VOLATILE_GUEST*)pbCmd;
     3308        const uint32_t uType = pCtl->u32Type;
     3309        RT_UNTRUSTED_NONVOLATILE_COPY_FENCE();
     3310
     3311        ASSERT_GUEST_LOGREL_RETURN(   uType == VBOXCMDVBVA3DCTL_TYPE_CMD
     3312                                   || uType == VBOXCMDVBVA3DCTL_TYPE_CONNECT
     3313                                   || uType == VBOXCMDVBVA3DCTL_TYPE_DISCONNECT
     3314                                   , VERR_INVALID_PARAMETER);
     3315        RT_UNTRUSTED_VALIDATED_FENCE();
     3316
     3317        /*
     3318         * Call worker abd process the request.
     3319         */
     3320        switch (uType)
     3321        {
     3322            case VBOXCMDVBVA3DCTL_TYPE_CMD:
     3323                ASSERT_GUEST_LOGREL_RETURN(cbCmd >= sizeof(VBOXCMDVBVA_3DCTL_CMD), VERR_INVALID_PARAMETER);
     3324                {
     3325                    VBOXCMDVBVA_3DCTL_CMD RT_UNTRUSTED_VOLATILE_GUEST *p3DCmd
     3326                        = (VBOXCMDVBVA_3DCTL_CMD RT_UNTRUSTED_VOLATILE_GUEST *)pbCmd;
     3327                    return crVBoxCrCmdCmd(NULL, &p3DCmd->Cmd, cbCmd - RT_OFFSETOF(VBOXCMDVBVA_3DCTL_CMD, Cmd));
     3328                }
     3329
     3330            case VBOXCMDVBVA3DCTL_TYPE_CONNECT:
     3331                ASSERT_GUEST_LOGREL_RETURN(cbCmd == sizeof(VBOXCMDVBVA_3DCTL_CONNECT), VERR_INVALID_PARAMETER);
     3332                return crVBoxCrConnect((VBOXCMDVBVA_3DCTL_CONNECT RT_UNTRUSTED_VOLATILE_GUEST *)pCtl);
     3333
     3334            case VBOXCMDVBVA3DCTL_TYPE_DISCONNECT:
     3335                ASSERT_GUEST_LOGREL_RETURN(cbCmd == sizeof(VBOXCMDVBVA_3DCTL), VERR_INVALID_PARAMETER);
     3336                {
     3337                    uint32_t idClient = pCtl->u32CmdClientId;
     3338                    RT_UNTRUSTED_NONVOLATILE_COPY_FENCE();
     3339                    return crVBoxCrDisconnect(idClient);
     3340                }
     3341
     3342            default:
     3343                AssertFailedReturn(VERR_IPE_NOT_REACHED_DEFAULT_CASE);
     3344        }
    33373345    }
    33383346}
     
    35123520
    35133521
    3514 static DECLCALLBACK(int8_t) crVBoxCrCmdCmd(HVBOXCRCMDSVR hSvr, const VBOXCMDVBVA_HDR *pCmd, uint32_t cbCmd)
    3515 {
    3516     switch (pCmd->u8OpCode)
     3522/**
     3523 * @interface_method_impl{VBOXCRCMD_SVRINFO,pfnCmd}
     3524 */
     3525static DECLCALLBACK(int8_t) crVBoxCrCmdCmd(HVBOXCRCMDSVR hSvr,
     3526                                           const VBOXCMDVBVA_HDR RT_UNTRUSTED_VOLATILE_GUEST *pCmd, uint32_t cbCmd)
     3527{
     3528    uint8_t bOpcode = pCmd->u8OpCode;
     3529    RT_UNTRUSTED_NONVOLATILE_COPY_FENCE();
     3530    ASSERT_GUEST_LOGREL_MSG_RETURN(   bOpcode == VBOXCMDVBVA_OPTYPE_CRCMD
     3531                                   || bOpcode == VBOXCMDVBVA_OPTYPE_FLIP
     3532                                   || bOpcode == VBOXCMDVBVA_OPTYPE_BLT
     3533                                   || bOpcode == VBOXCMDVBVA_OPTYPE_CLRFILL,
     3534                                   ("%#x\n", bOpcode), -1);
     3535    RT_UNTRUSTED_VALIDATED_FENCE();
     3536
     3537    switch (bOpcode)
    35173538    {
    35183539        case VBOXCMDVBVA_OPTYPE_CRCMD:
    3519         {
    3520             const VBOXCMDVBVA_CRCMD *pCrCmdDr;
    3521             const VBOXCMDVBVA_CRCMD_CMD *pCrCmd;
    3522             int rc;
    3523             pCrCmdDr = (const VBOXCMDVBVA_CRCMD*)pCmd;
    3524             pCrCmd = &pCrCmdDr->Cmd;
    3525             if (cbCmd < sizeof (VBOXCMDVBVA_CRCMD))
     3540            ASSERT_GUEST_LOGREL_MSG_RETURN(cbCmd >= sizeof(VBOXCMDVBVA_CRCMD), ("cbCmd=%u\n", cbCmd), -1);
    35263541            {
    3527                 WARN(("invalid buffer size"));
    3528                 return -1;
    3529             }
    3530             rc = crVBoxServerCmdVbvaCrCmdProcess(pCrCmd, cbCmd - RT_OFFSETOF(VBOXCMDVBVA_CRCMD, Cmd));
    3531             if (RT_SUCCESS(rc))
    3532             {
    3533                 /* success */
     3542                VBOXCMDVBVA_CRCMD const RT_UNTRUSTED_VOLATILE_GUEST *pCrCmdDr
     3543                    = (VBOXCMDVBVA_CRCMD const RT_UNTRUSTED_VOLATILE_GUEST *)pCmd;
     3544                VBOXCMDVBVA_CRCMD_CMD const RT_UNTRUSTED_VOLATILE_GUEST *pCrCmd = &pCrCmdDr->Cmd;
     3545                int rc = crVBoxServerCmdVbvaCrCmdProcess(pCrCmd, cbCmd - RT_OFFSETOF(VBOXCMDVBVA_CRCMD, Cmd));
     3546                ASSERT_GUEST_LOGREL_RC_RETURN(rc, -1);
    35343547                return 0;
    35353548            }
    35363549
    3537             WARN(("crVBoxServerCmdVbvaCrCmdProcess failed, rc %d", rc));
    3538             return -1;
    3539         }
    35403550        case VBOXCMDVBVA_OPTYPE_FLIP:
    3541         {
    3542             const VBOXCMDVBVA_FLIP *pFlip;
    3543 
    3544             if (cbCmd < VBOXCMDVBVA_SIZEOF_FLIPSTRUCT_MIN)
     3551            ASSERT_GUEST_LOGREL_MSG_RETURN(cbCmd >= VBOXCMDVBVA_SIZEOF_FLIPSTRUCT_MIN, ("cbCmd=%u\n", cbCmd), -1);
    35453552            {
    3546                 WARN(("invalid buffer size (cbCmd(%u) < sizeof(VBOXCMDVBVA_FLIP)(%u))", cbCmd, sizeof(VBOXCMDVBVA_FLIP)));
    3547                 return -1;
     3553                VBOXCMDVBVA_FLIP const RT_UNTRUSTED_VOLATILE_GUEST *pFlip
     3554                    = (VBOXCMDVBVA_FLIP const RT_UNTRUSTED_VOLATILE_GUEST *)pCmd;
     3555                return crVBoxServerCrCmdFlipProcess(pFlip, cbCmd);
    35483556            }
    35493557
    3550             pFlip = (const VBOXCMDVBVA_FLIP*)pCmd;
    3551             return crVBoxServerCrCmdFlipProcess(pFlip, cbCmd);
    3552         }
    35533558        case VBOXCMDVBVA_OPTYPE_BLT:
    3554         {
    3555             if (cbCmd < sizeof (VBOXCMDVBVA_BLT_HDR))
    3556             {
    3557                 WARN(("invalid buffer size"));
    3558                 return -1;
    3559             }
    3560 
    3561             return crVBoxServerCrCmdBltProcess((const VBOXCMDVBVA_BLT_HDR*)pCmd, cbCmd);
    3562         }
     3559            ASSERT_GUEST_LOGREL_MSG_RETURN(cbCmd >= sizeof(VBOXCMDVBVA_BLT_HDR), ("cbCmd=%u\n", cbCmd), -1);
     3560            return crVBoxServerCrCmdBltProcess((VBOXCMDVBVA_BLT_HDR const RT_UNTRUSTED_VOLATILE_GUEST *)pCmd, cbCmd);
     3561
    35633562        case VBOXCMDVBVA_OPTYPE_CLRFILL:
    3564         {
    3565             if (cbCmd < sizeof (VBOXCMDVBVA_CLRFILL_HDR))
    3566             {
    3567                 WARN(("invalid buffer size"));
    3568                 return -1;
    3569             }
    3570 
    3571             return crVBoxServerCrCmdClrFillProcess((const VBOXCMDVBVA_CLRFILL_HDR*)pCmd, cbCmd);
    3572         }
     3563            ASSERT_GUEST_LOGREL_MSG_RETURN(cbCmd >= sizeof(VBOXCMDVBVA_CLRFILL_HDR), ("cbCmd=%u\n", cbCmd), -1);
     3564            return crVBoxServerCrCmdClrFillProcess((VBOXCMDVBVA_CLRFILL_HDR const RT_UNTRUSTED_VOLATILE_GUEST *)pCmd, cbCmd);
     3565
    35733566        default:
    3574             WARN(("unsupported command"));
    3575             return -1;
     3567            AssertFailedReturn(VERR_IPE_NOT_REACHED_DEFAULT_CASE);
    35763568    }
    35773569    /* not reached */
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