VirtualBox

Ignore:
Timestamp:
Oct 16, 2014 12:36:28 PM (10 years ago)
Author:
vboxsync
Message:

VBoxGuest: fixed heartbeat on Windows guests.

Location:
trunk/src/VBox/Additions/common/VBoxGuest
Files:
2 edited

Legend:

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

    r52789 r53077  
    691691 * @returns VBox status code.
    692692 */
    693 static int VBoxGuestHeartbeatSend(void)
    694 {
    695     VMMDevRequestHeader *pReq;
    696     int rc = VbglGRAlloc(&pReq, sizeof(*pReq), VMMDevReq_GuestHeartbeat);
    697     Log(("VBoxGuestHeartbeatSend: VbglGRAlloc VBoxGuestHeartbeatSend completed with rc=%Rrc\n", rc));
    698     if (RT_SUCCESS(rc))
    699     {
    700         rc = VbglGRPerform(pReq);
     693static int VBoxGuestHeartbeatSend(PVBOXGUESTDEVEXT pDevExt)
     694{
     695    int rc;
     696    if (pDevExt->pReqGuestHeartbeat)
     697    {
     698        rc = VbglGRPerform(pDevExt->pReqGuestHeartbeat);
    701699        Log(("VBoxGuestHeartbeatSend: VbglGRPerform VBoxGuestHeartbeatSend completed with rc=%Rrc\n", rc));
    702         VbglGRFree(pReq);
    703     }
     700    }
     701    else
     702        rc = VERR_INVALID_STATE;
    704703    return rc;
    705704}
     
    735734 * Callback for heartbeat timer.
    736735 */
    737 static DECLCALLBACK(void) VBoxGuestHeartbeatTimerHandler(PRTTIMER p1, void *p2, uint64_t p3)
     736static DECLCALLBACK(void) VBoxGuestHeartbeatTimerHandler(PRTTIMER p1, void *pvUser, uint64_t p3)
    738737{
    739738    NOREF(p1);
    740     NOREF(p2);
    741739    NOREF(p3);
    742740
    743     int rc = VBoxGuestHeartbeatSend();
     741    PVBOXGUESTDEVEXT pDevExt = (PVBOXGUESTDEVEXT)pvUser;
     742    if (!pDevExt)
     743        return;
     744
     745    int rc = VBoxGuestHeartbeatSend(pDevExt);
    744746    if (RT_FAILURE(rc))
    745747    {
     
    10321034    pDevExt->MouseNotifyCallback.pfnNotify = NULL;
    10331035    pDevExt->MouseNotifyCallback.pvUser = NULL;
     1036    pDevExt->pReqGuestHeartbeat = NULL;
    10341037
    10351038    /*
     
    11111114                        LogRelFunc(("VBoxReportGuestDriverStatus failed, rc=%Rrc\n", rc));
    11121115
     1116                    /** @todo Move heartbeat initialization into a separate function. */
    11131117                    /* Make sure that heartbeat checking is disabled. */
    11141118                    rc = VBoxGuestHeartbeatHostConfigure(pDevExt, false);
     
    11181122                        if (RT_SUCCESS(rc))
    11191123                        {
    1120                             LogFlowFunc(("Setting up heartbeat to trigger every %RU64 sec\n", pDevExt->cNsHeartbeatInterval / 1000000000));
    1121                             rc = RTTimerCreateEx(&pDevExt->pHeartbeatTimer, pDevExt->cNsHeartbeatInterval,
    1122                                                  0, (PFNRTTIMER)VBoxGuestHeartbeatTimerHandler, NULL);
     1124                            /* Preallocate the request to use it from the timer callback because:
     1125                             *    1) on Windows VbglGRAlloc must be called at IRQL <= APC_LEVEL
     1126                             *       and the timer callback runs at DISPATCH_LEVEL;
     1127                             *    2) avoid repeated allocations.
     1128                             */
     1129                            rc = VbglGRAlloc(&pDevExt->pReqGuestHeartbeat, sizeof(*pDevExt->pReqGuestHeartbeat), VMMDevReq_GuestHeartbeat);
     1130                            if (RT_FAILURE(rc))
     1131                                LogRelFunc(("VbglGRAlloc(VMMDevReq_GuestHeartbeat) %Rrc\n", rc));
     1132
     1133                            if (RT_SUCCESS(rc))
     1134                            {
     1135                                LogFlowFunc(("Setting up heartbeat to trigger every %RU64 sec\n", pDevExt->cNsHeartbeatInterval / 1000000000));
     1136                                rc = RTTimerCreateEx(&pDevExt->pHeartbeatTimer, pDevExt->cNsHeartbeatInterval,
     1137                                                     0, (PFNRTTIMER)VBoxGuestHeartbeatTimerHandler, pDevExt);
     1138                            }
     1139
    11231140                            if (RT_SUCCESS(rc))
    11241141                            {
     
    11321149                                /* Disable host heartbeat check if we failed */
    11331150                                VBoxGuestHeartbeatHostConfigure(pDevExt, false);
     1151
     1152                                VbglGRFree(pDevExt->pReqGuestHeartbeat);
     1153                                pDevExt->pReqGuestHeartbeat = NULL;
    11341154                            }
    11351155                        }
     
    12111231        VBoxGuestHeartbeatHostConfigure(pDevExt, false);
    12121232    }
     1233
     1234    VbglGRFree(pDevExt->pReqGuestHeartbeat);
     1235    pDevExt->pReqGuestHeartbeat = NULL;
    12131236
    12141237    /*
  • trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuestInternal.h

    r52789 r53077  
    186186    /** Heartbeat timer interval in nanoseconds. */
    187187    uint64_t                    cNsHeartbeatInterval;
     188    /** Preallocated VMMDevReq_GuestHeartbeat request. */
     189    VMMDevRequestHeader *pReqGuestHeartbeat;
    188190} VBOXGUESTDEVEXT;
    189191/** Pointer to the VBoxGuest driver 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