VirtualBox

Changeset 75990 in vbox for trunk/src


Ignore:
Timestamp:
Dec 5, 2018 7:51:01 PM (6 years ago)
Author:
vboxsync
Message:

VMMDev,HGCM: Added cancellation notification and query helper.

Location:
trunk/src/VBox
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/VMMDev/VMMDev.cpp

    r75875 r75990  
    44274427    pThis->IHGCMPort.pfnCompleted           = hgcmCompleted;
    44284428    pThis->IHGCMPort.pfnIsCmdRestored       = hgcmIsCmdRestored;
     4429    pThis->IHGCMPort.pfnIsCmdCancelled      = hgcmIsCmdCancelled;
    44294430    pThis->IHGCMPort.pfnGetRequestor        = hgcmGetRequestor;
    44304431    pThis->IHGCMPort.pfnGetVMMDevSessionId  = hgcmGetVMMDevSessionId;
  • trunk/src/VBox/Devices/VMMDev/VMMDevHGCM.cpp

    r75979 r75990  
    11691169    {
    11701170        pCmd->fCancelled = true;
     1171
    11711172        Log(("vmmdevHGCMCancel2: Cancelled pCmd=%p / GCPhys=%#x\n", pCmd, GCPhys));
     1173        if (pThis->pHGCMDrv)
     1174            pThis->pHGCMDrv->pfnCancelled(pThis->pHGCMDrv, pCmd,
     1175                                          pCmd->enmCmdType == VBOXHGCMCMDTYPE_CALL ? pCmd->u.call.u32ClientID
     1176                                          : pCmd->enmCmdType == VBOXHGCMCMDTYPE_CONNECT ? pCmd->u.connect.u32ClientID
     1177                                          : pCmd->enmCmdType == VBOXHGCMCMDTYPE_DISCONNECT ? pCmd->u.disconnect.u32ClientID
     1178                                          : 0);
    11721179    }
    11731180    else
     
    15371544
    15381545/**
     1546 * @interface_method_impl{PDMIHGCMPORT,pfnIsCmdCancelled}
     1547 */
     1548DECLCALLBACK(bool) hgcmIsCmdCancelled(PPDMIHGCMPORT pInterface, PVBOXHGCMCMD pCmd)
     1549{
     1550    RT_NOREF(pInterface);
     1551    return pCmd && pCmd->fCancelled;
     1552}
     1553
     1554/**
    15391555 * @interface_method_impl{PDMIHGCMPORT,pfnGetRequestor}
    15401556 */
     
    15891605            LogFlowFunc(("Saving %RGp, size %d\n", pCmd->GCPhys, pCmd->cbRequest));
    15901606
     1607            /** @todo Don't save cancelled requests! It serves no purpose.  See restore and
     1608             *        @bugref{4032#c4} for details. */
    15911609            SSMR3PutU32     (pSSM, (uint32_t)pCmd->enmCmdType);
    15921610            SSMR3PutBool    (pSSM, pCmd->fCancelled);
  • trunk/src/VBox/Devices/VMMDev/VMMDevHGCM.h

    r75853 r75990  
    3131DECLCALLBACK(int)  hgcmCompleted(PPDMIHGCMPORT pInterface, int32_t result, PVBOXHGCMCMD pCmdPtr);
    3232DECLCALLBACK(bool) hgcmIsCmdRestored(PPDMIHGCMPORT pInterface, PVBOXHGCMCMD pCmd);
     33DECLCALLBACK(bool) hgcmIsCmdCancelled(PPDMIHGCMPORT pInterface, PVBOXHGCMCMD pCmd);
    3334DECLCALLBACK(uint32_t) hgcmGetRequestor(PPDMIHGCMPORT pInterface, PVBOXHGCMCMD pCmd);
    3435DECLCALLBACK(uint64_t) hgcmGetVMMDevSessionId(PPDMIHGCMPORT pInterface);
  • trunk/src/VBox/Devices/VMMDev/VMMDevState.h

    r75855 r75990  
    156156    /** LUN\#0: HGCM port interface. */
    157157    PDMIHGCMPORT IHGCMPort;
    158 # if HC_ARCH_BITS == 32
    159     RTR3PTR      R3PtrAlignment1;
    160 # endif
     158//# if HC_ARCH_BITS == 32
     159//    RTR3PTR      R3PtrAlignment1;
     160//# endif
    161161#endif
    162162    /** Pointer to base interface of the driver. */
  • trunk/src/VBox/Main/include/HGCM.h

    r75969 r75990  
    4545int HGCMGuestCall(PPDMIHGCMPORT pHGCMPort, PVBOXHGCMCMD pCmdPtr, uint32_t clientID, uint32_t function, uint32_t cParms,
    4646                  VBOXHGCMSVCPARM *paParms, uint64_t tsArrival);
     47void HGCMGuestCancelled(PPDMIHGCMPORT pHGCMPort, PVBOXHGCMCMD pCmdPtr, uint32_t idClient);
    4748
    4849int HGCMHostCall(const char *pszServiceName, uint32_t function, uint32_t cParms, VBOXHGCMSVCPARM aParms[]);
  • trunk/src/VBox/Main/src-client/HGCM.cpp

    r75978 r75990  
    143143        static DECLCALLBACK(void) svcHlpDisconnectClient(void *pvInstance, uint32_t u32ClientId);
    144144        static DECLCALLBACK(bool) svcHlpIsCallRestored(VBOXHGCMCALLHANDLE callHandle);
     145        static DECLCALLBACK(bool) svcHlpIsCallCancelled(VBOXHGCMCALLHANDLE callHandle);
    145146        static DECLCALLBACK(int)  svcHlpStamRegisterV(void *pvInstance, void *pvSample, STAMTYPE enmType,
    146147                                                      STAMVISIBILITY enmVisibility, STAMUNIT enmUnit, const char *pszDesc,
     
    197198        int GuestCall(PPDMIHGCMPORT pHGCMPort, PVBOXHGCMCMD pCmd, uint32_t u32ClientId,
    198199                      uint32_t u32Function, uint32_t cParms, VBOXHGCMSVCPARM aParms[], uint64_t tsArrival);
     200        void GuestCancelled(PPDMIHGCMPORT pHGCMPort, PVBOXHGCMCMD pCmd, uint32_t idClient);
    199201};
    200202
     
    403405 */
    404406
    405 #define SVC_MSG_LOAD       (0)  /**< Load the service library and call VBOX_HGCM_SVCLOAD_NAME entry point. */
    406 #define SVC_MSG_UNLOAD     (1)  /**< call pfnUnload and unload the service library. */
    407 #define SVC_MSG_CONNECT    (2)  /**< pfnConnect */
    408 #define SVC_MSG_DISCONNECT (3)  /**< pfnDisconnect */
    409 #define SVC_MSG_GUESTCALL  (4)  /**< pfnGuestCall */
    410 #define SVC_MSG_HOSTCALL   (5)  /**< pfnHostCall */
    411 #define SVC_MSG_LOADSTATE  (6)  /**< pfnLoadState. */
    412 #define SVC_MSG_SAVESTATE  (7)  /**< pfnSaveState. */
    413 #define SVC_MSG_QUIT       (8)  /**< Terminate the thread. */
    414 #define SVC_MSG_REGEXT     (9)  /**< pfnRegisterExtension */
    415 #define SVC_MSG_UNREGEXT   (10) /**< pfnRegisterExtension */
    416 #define SVC_MSG_NOTIFY     (11) /**< pfnNotify */
     407#define SVC_MSG_LOAD            (0)  /**< Load the service library and call VBOX_HGCM_SVCLOAD_NAME entry point. */
     408#define SVC_MSG_UNLOAD          (1)  /**< call pfnUnload and unload the service library. */
     409#define SVC_MSG_CONNECT         (2)  /**< pfnConnect */
     410#define SVC_MSG_DISCONNECT      (3)  /**< pfnDisconnect */
     411#define SVC_MSG_GUESTCALL       (4)  /**< pfnGuestCall */
     412#define SVC_MSG_HOSTCALL        (5)  /**< pfnHostCall */
     413#define SVC_MSG_LOADSTATE       (6)  /**< pfnLoadState. */
     414#define SVC_MSG_SAVESTATE       (7)  /**< pfnSaveState. */
     415#define SVC_MSG_QUIT            (8)  /**< Terminate the thread. */
     416#define SVC_MSG_REGEXT          (9)  /**< pfnRegisterExtension */
     417#define SVC_MSG_UNREGEXT        (10) /**< pfnRegisterExtension */
     418#define SVC_MSG_NOTIFY          (11) /**< pfnNotify */
     419#define SVC_MSG_GUESTCANCELLED  (12) /**< pfnCancelled */
    417420#ifdef VBOX_WITH_CRHGSMI
    418421# define SVC_MSG_HOSTFASTCALLASYNC (21) /* pfnHostCall */
     
    487490        /** The STAM_GET_TS() value when the request arrived. */
    488491        uint64_t tsArrival;
     492};
     493
     494class HGCMMsgCancelled: public HGCMMsgHeader
     495{
     496    public:
     497        HGCMMsgCancelled() {}
     498
     499        HGCMMsgCancelled(HGCMThread *pThread)
     500        {
     501            InitializeCore(SVC_MSG_GUESTCANCELLED, pThread);
     502            Initialize();
     503        }
     504        ~HGCMMsgCancelled() { Log(("~HGCMMsgCancelled %p\n", this)); }
     505
     506        /** The client identifier. */
     507        uint32_t idClient;
    489508};
    490509
     
    566585        case SVC_MSG_UNREGEXT:    return new HGCMMsgSvcUnregisterExtension();
    567586        case SVC_MSG_NOTIFY:      return new HGCMMsgNotify();
     587        case SVC_MSG_GUESTCANCELLED: return new HGCMMsgCancelled();
    568588        default:
    569589            AssertReleaseMsgFailed(("Msg id = %08X\n", u32MsgId));
     
    687707                                            HGCM_CLIENT_DATA(pSvc, pClient), pMsg->u32Function,
    688708                                            pMsg->cParms, pMsg->paParms, pMsg->tsArrival);
     709
     710                    hgcmObjDereference(pClient);
     711                }
     712                else
     713                {
     714                    rc = VERR_HGCM_INVALID_CLIENT_ID;
     715                }
     716            } break;
     717
     718            case SVC_MSG_GUESTCANCELLED:
     719            {
     720                HGCMMsgCancelled *pMsg = (HGCMMsgCancelled *)pMsgCore;
     721
     722                LogFlowFunc(("SVC_MSG_GUESTCANCELLED idClient = %d\n", pMsg->idClient));
     723
     724                HGCMClient *pClient = (HGCMClient *)hgcmObjReference(pMsg->idClient, HGCMOBJ_CLIENT);
     725
     726                if (pClient)
     727                {
     728                    pSvc->m_fntable.pfnCancelled(pSvc->m_fntable.pvService, pMsg->idClient, HGCM_CLIENT_DATA(pSvc, pClient));
    689729
    690730                    hgcmObjDereference(pClient);
     
    883923/* static */ DECLCALLBACK(bool) HGCMService::svcHlpIsCallRestored(VBOXHGCMCALLHANDLE callHandle)
    884924{
    885     HGCMMsgHeader *pMsgHdr = (HGCMMsgHeader *)(callHandle);
     925    HGCMMsgHeader *pMsgHdr = (HGCMMsgHeader *)callHandle;
    886926    AssertPtrReturn(pMsgHdr, false);
    887927
     
    893933
    894934    return pHgcmPort->pfnIsCmdRestored(pHgcmPort, pCmd);
     935}
     936
     937/**
     938 * @interface_method_impl{VBOXHGCMSVCHELPERS,pfnIsCallCancelled}
     939 */
     940/* static */ DECLCALLBACK(bool) HGCMService::svcHlpIsCallCancelled(VBOXHGCMCALLHANDLE callHandle)
     941{
     942    HGCMMsgHeader *pMsgHdr = (HGCMMsgHeader *)callHandle;
     943    AssertPtrReturn(pMsgHdr, false);
     944
     945    PVBOXHGCMCMD pCmd = pMsgHdr->pCmd;
     946    AssertPtrReturn(pCmd, false);
     947
     948    PPDMIHGCMPORT pHgcmPort = pMsgHdr->pHGCMPort;
     949    AssertPtrReturn(pHgcmPort, false);
     950
     951    return pHgcmPort->pfnIsCmdCancelled(pHgcmPort, pCmd);
    895952}
    896953
     
    10411098            m_svcHelpers.pfnDisconnectClient   = svcHlpDisconnectClient;
    10421099            m_svcHelpers.pfnIsCallRestored     = svcHlpIsCallRestored;
     1100            m_svcHelpers.pfnIsCallCancelled    = svcHlpIsCallCancelled;
    10431101            m_svcHelpers.pfnStamRegisterV      = svcHlpStamRegisterV;
    10441102            m_svcHelpers.pfnStamDeregisterV    = svcHlpStamDeregisterV;
     
    17561814                           uint32_t cParms, VBOXHGCMSVCPARM paParms[], uint64_t tsArrival)
    17571815{
    1758     LogFlow(("MAIN::HGCMService::Call\n"));
     1816    LogFlow(("MAIN::HGCMService::GuestCall\n"));
    17591817
    17601818    int rc;
     
    17621820    if (pMsg)
    17631821    {
    1764         pMsg->Reference();
     1822        pMsg->Reference(); /** @todo starts out with zero references. */
    17651823
    17661824        pMsg->pCmd        = pCmd;
     
    17761834    else
    17771835    {
    1778         Log(("MAIN::HGCMService::Call: Message allocation failed\n"));
     1836        Log(("MAIN::HGCMService::GuestCall: Message allocation failed\n"));
    17791837        rc = VERR_NO_MEMORY;
    17801838    }
     
    17821840    LogFlowFunc(("rc = %Rrc\n", rc));
    17831841    return rc;
     1842}
     1843
     1844/** Guest cancelled a request (call, connection attempt, disconnect attempt).
     1845 *
     1846 * @param   pHGCMPort      The port to be used for completion confirmation.
     1847 * @param   pCmd           The VBox HGCM context.
     1848 * @param   u32ClientId    The client handle to be disconnected and deleted.
     1849 * @return  VBox rc.
     1850 */
     1851void HGCMService::GuestCancelled(PPDMIHGCMPORT pHGCMPort, PVBOXHGCMCMD pCmd, uint32_t idClient)
     1852{
     1853    LogFlow(("MAIN::HGCMService::GuestCancelled\n"));
     1854
     1855    if (m_fntable.pfnCancelled)
     1856    {
     1857        HGCMMsgCancelled *pMsg = new (std::nothrow) HGCMMsgCancelled(m_pThread);
     1858        if (pMsg)
     1859        {
     1860            pMsg->Reference(); /** @todo starts out with zero references. */
     1861
     1862            pMsg->pCmd      = pCmd;
     1863            pMsg->pHGCMPort = pHGCMPort;
     1864            pMsg->idClient  = idClient;
     1865
     1866            hgcmMsgPost(pMsg, NULL);
     1867        }
     1868        else
     1869            Log(("MAIN::HGCMService::GuestCancelled: Message allocation failed\n"));
     1870    }
    17841871}
    17851872
     
    25792666}
    25802667
    2581 /* The guest calls the service.
     2668/** The guest calls the service.
    25822669 *
    25832670 * @param pHGCMPort      The port to be used for completion confirmation.
    25842671 * @param pCmd           The VBox HGCM context.
    2585  * @param u32ClientId    The client handle to be disconnected and deleted.
     2672 * @param u32ClientId    The client handle.
    25862673 * @param u32Function    The function number.
    25872674 * @param cParms         Number of parameters.
     
    26232710    LogFlowFunc(("rc = %Rrc\n", rc));
    26242711    return rc;
     2712}
     2713
     2714/** The guest cancelled a request (call, connect, disconnect)
     2715 *
     2716 * @param   pHGCMPort      The port to be used for completion confirmation.
     2717 * @param   pCmd           The VBox HGCM context.
     2718 * @param   idClient       The client handle.
     2719 */
     2720void HGCMGuestCancelled(PPDMIHGCMPORT pHGCMPort, PVBOXHGCMCMD pCmd, uint32_t idClient)
     2721{
     2722    LogFlowFunc(("pHGCMPort = %p, pCmd = %p, idClient = %d\n", pHGCMPort, pCmd, idClient));
     2723    AssertReturnVoid(pHGCMPort);
     2724    AssertReturnVoid(pCmd);
     2725    AssertReturnVoid(idClient != 0);
     2726
     2727    /* Resolve the client handle to the client instance pointer. */
     2728    HGCMClient *pClient = (HGCMClient *)hgcmObjReference(idClient, HGCMOBJ_CLIENT);
     2729
     2730    if (pClient)
     2731    {
     2732        AssertRelease(pClient->pService);
     2733
     2734        /* Forward the message to the service thread. */
     2735        pClient->pService->GuestCancelled(pHGCMPort, pCmd, idClient);
     2736
     2737        hgcmObjDereference(pClient);
     2738    }
     2739
     2740    LogFlowFunc(("returns\n"));
    26252741}
    26262742
  • trunk/src/VBox/Main/src-client/HGCMThread.cpp

    r75798 r75990  
    704704    pMsg->Dereference();
    705705
    706     LogFlow(("MAIN::hgcmMsgPostInternal: pMsg %p, rc = %Rrc\n", pMsg, rc));
     706    LogFlow(("MAIN::hgcmMsgPostInternal: pMsg = %p, rc = %Rrc\n", pMsg, rc));
    707707    return rc;
    708708}
  • trunk/src/VBox/Main/src-client/VMMDevInterface.cpp

    r75969 r75990  
    649649
    650650    return HGCMGuestCall(pDrv->pHGCMPort, pCmd, u32ClientID, u32Function, cParms, paParms, tsArrival);
     651}
     652
     653static DECLCALLBACK(void) iface_hgcmCancelled(PPDMIHGCMCONNECTOR pInterface, PVBOXHGCMCMD pCmd, uint32_t idClient)
     654{
     655    Log9(("Enter\n"));
     656
     657    PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, HGCMConnector);
     658    if (   pDrv->pVMMDev
     659        && pDrv->pVMMDev->hgcmIsActive())
     660        return HGCMGuestCancelled(pDrv->pHGCMPort, pCmd, idClient);
    651661}
    652662
     
    10591069    pThis->HGCMConnector.pfnDisconnect                = iface_hgcmDisconnect;
    10601070    pThis->HGCMConnector.pfnCall                      = iface_hgcmCall;
     1071    pThis->HGCMConnector.pfnCancelled                 = iface_hgcmCancelled;
    10611072#endif
    10621073
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