VirtualBox

Ignore:
Timestamp:
Nov 30, 2018 7:26:42 PM (6 years ago)
Author:
vboxsync
Message:

GuestControl,HGCM,VBoxService: Save/restore related optimizations and changes. bugref:9313

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxGuest/lib/VBoxGuestR3LibGuestCtrl.cpp

    r75824 r75853  
    307307
    308308
    309 
    310309/**
    311310 * Peeks at the next host message, waiting for one to turn up.
     
    314313 * @retval  VERR_INTERRUPTED if interrupted.  Does the necessary cleanup, so
    315314 *          caller just have to repeat this call.
     315 * @retval  VERR_VM_RESTORED if the VM has been restored (idRestoreCheck).
    316316 *
    317317 * @param   idClient        The client ID returned by VbglR3GuestCtrlConnect().
     
    319319 * @param   pcParameters    Where to store the number  of parameters which will
    320320 *                          be received in a second call to the host.
    321  */
    322 VBGLR3DECL(int) VbglR3GuestCtrlMsgPeekWait(uint32_t idClient, uint32_t *pidMsg, uint32_t *pcParameters)
     321 * @param   pidRestoreCheck Pointer to the VbglR3GetSessionId() variable to use
     322 *                          for the VM restore check.  Optional.
     323 *
     324 * @note    Restore check is only performed optimally with a 6.0 host.
     325 */
     326VBGLR3DECL(int) VbglR3GuestCtrlMsgPeekWait(uint32_t idClient, uint32_t *pidMsg, uint32_t *pcParameters, uint64_t *pidRestoreCheck)
    323327{
    324328    AssertPtrReturn(pidMsg, VERR_INVALID_POINTER);
     
    328332    if (vbglR3GuestCtrlSupportsPeekGetCancel(idClient))
    329333    {
    330         HGCMMsgCmdWaitFor Msg;
    331         VBGL_HGCM_HDR_INIT(&Msg.hdr, idClient, GUEST_MSG_PEEK_WAIT, 2);
    332         VbglHGCMParmUInt32Set(&Msg.msg, 0);
    333         VbglHGCMParmUInt32Set(&Msg.num_parms, 0);
    334         rc = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg));
     334        struct
     335        {
     336            VBGLIOCHGCMCALL Hdr;
     337            HGCMFunctionParameter idMsg;       /* Doubles as restore check on input. */
     338            HGCMFunctionParameter cParameters;
     339        } Msg;
     340        VBGL_HGCM_HDR_INIT(&Msg.Hdr, idClient, GUEST_MSG_PEEK_WAIT, 2);
     341        VbglHGCMParmUInt64Set(&Msg.idMsg, pidRestoreCheck ? *pidRestoreCheck : 0);
     342        VbglHGCMParmUInt32Set(&Msg.cParameters, 0);
     343        rc = VbglR3HGCMCall(&Msg.Hdr, sizeof(Msg));
    335344        LogRel(("VbglR3GuestCtrlMsgPeekWait -> %Rrc\n", rc));
    336345        if (RT_SUCCESS(rc))
    337346        {
    338             AssertMsgReturn(   Msg.msg.type       == VMMDevHGCMParmType_32bit
    339                             && Msg.num_parms.type == VMMDevHGCMParmType_32bit,
    340                             ("msg.type=%d num_parms.type=%d\n", Msg.msg.type, Msg.num_parms.type),
     347            AssertMsgReturn(   Msg.idMsg.type       == VMMDevHGCMParmType_64bit
     348                            && Msg.cParameters.type == VMMDevHGCMParmType_32bit,
     349                            ("msg.type=%d num_parms.type=%d\n", Msg.idMsg.type, Msg.cParameters.type),
    341350                            VERR_INTERNAL_ERROR_3);
    342351
    343             *pidMsg       = Msg.msg.u.value32;
    344             *pcParameters = Msg.num_parms.u.value32;
     352            *pidMsg       = (uint32_t)Msg.idMsg.u.value64;
     353            *pcParameters = Msg.cParameters.u.value32;
    345354            return rc;
    346355        }
     
    351360        if (rc == VERR_INTERRUPTED)
    352361        {
    353             VBGL_HGCM_HDR_INIT(&Msg.hdr, idClient, GUEST_MSG_CANCEL, 0);
    354             int rc2 = VbglR3HGCMCall(&Msg.hdr, sizeof(Msg.hdr));
     362            VBGL_HGCM_HDR_INIT(&Msg.Hdr, idClient, GUEST_MSG_CANCEL, 0);
     363            int rc2 = VbglR3HGCMCall(&Msg.Hdr, sizeof(Msg.Hdr));
    355364            AssertRC(rc2);
    356365        }
     366
     367        /*
     368         * If restored, update pidRestoreCheck.
     369         */
     370        if (rc == VERR_VM_RESTORED && pidRestoreCheck)
     371            *pidRestoreCheck = Msg.idMsg.u.value64;
    357372
    358373        *pidMsg       = UINT32_MAX - 1;
     
    363378    /*
    364379     * Fallback if host < v6.0.
     380     *
     381     * Note! The restore check isn't perfect. Would require checking afterwards
     382     *       and stash the result if we were restored during the call.  Too much
     383     *       hazzle for a downgrade scenario.
    365384     */
     385    if (pidRestoreCheck)
     386    {
     387        uint64_t idRestoreCur = *pidRestoreCheck;
     388        rc = VbglR3GetSessionId(&idRestoreCur);
     389        if (RT_SUCCESS(rc) && idRestoreCur != *pidRestoreCheck)
     390        {
     391            *pidRestoreCheck = idRestoreCur;
     392            return VERR_VM_RESTORED;
     393        }
     394    }
     395
    366396    rc = vbglR3GuestCtrlMsgWaitFor(idClient, pidMsg, pcParameters);
    367397    if (rc == VERR_TOO_MUCH_DATA)
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