VirtualBox

Changeset 30668 in vbox for trunk/src/VBox/Additions


Ignore:
Timestamp:
Jul 6, 2010 2:26:53 PM (14 years ago)
Author:
vboxsync
Message:

Generate a session id for the VM that is changed every time the VM starts, resets or is restored.

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

Legend:

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

    r28800 r30668  
    7575}
    7676
     77/**
     78 * Query the session id of this VM; this is a unique id that gets changed for each VM start, reset or restore.
     79 * Useful for detection a VM restore.
     80 *
     81 * @returns IPRT status code.
     82 * pu64IdSession    Session id (out)
     83 *
     84 */
     85VBGLR3DECL(int) VbglR3GetSessionId(uint64_t *pu64IdSession)
     86{
     87    VMMDevReqSessionId Req;
     88
     89    vmmdevInitRequest(&Req.header, VMMDevReq_GetSessionId);
     90    int rc = vbglR3GRPerform(&Req.header);
     91    if (rc == VINF_SUCCESS)
     92        *pu64IdSession = Req.idSession;
     93
     94    return rc;
     95}
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServicePageSharing.cpp

    r30666 r30668  
    8787static DECLCALLBACK(int) VBoxServicePageSharingEmptyTreeCallback(PAVLPVNODECORE pNode, void *pvUser);
    8888
    89 static PAVLPVNODECORE   pKnownModuleTree = NULL;
     89static PAVLPVNODECORE   g_pKnownModuleTree = NULL;
     90static uint64_t         g_idSession = 0;
    9091
    9192/**
     
    302303        if (!pRec)
    303304        {
    304             pRec = RTAvlPVRemove(&pKnownModuleTree, ModuleInfo.modBaseAddr);
     305            pRec = RTAvlPVRemove(&g_pKnownModuleTree, ModuleInfo.modBaseAddr);
    305306            if (!pRec)
    306307            {
     
    411412            if (!pRec)
    412413            {
    413                 pRec = RTAvlPVRemove(&pKnownModuleTree, pSystemModules->Modules[i].ImageBase);
     414                pRec = RTAvlPVRemove(&g_pKnownModuleTree, pSystemModules->Modules[i].ImageBase);
    414415                if (!pRec)
    415416                {
     
    484485
    485486    /* Delete leftover modules in the old tree. */
    486     RTAvlPVDestroy(&pKnownModuleTree, VBoxServicePageSharingEmptyTreeCallback, NULL);
     487    RTAvlPVDestroy(&g_pKnownModuleTree, VBoxServicePageSharingEmptyTreeCallback, NULL);
    487488
    488489    /* Check all registered modules. */
    489490    VbglR3CheckSharedModules();
     491
    490492    /* Activate new module tree. */
    491     pKnownModuleTree = pNewTree;
     493    g_pKnownModuleTree = pNewTree;
    492494}
    493495
     
    566568#endif
    567569
     570    rc =  VbglR3GetSessionId(&g_idSession);
     571    AssertRCReturn(rc, rc);
     572
    568573    /* Never fail here. */
    569574    return VINF_SUCCESS;
     
    584589    for (;;)
    585590    {
     591        uint64_t idNewSession;
     592
    586593        VBoxServiceVerbose(3, "VBoxServicePageSharingWorker: enabled=%d\n", VbglR3PageSharingIsEnabled());
    587594
     
    605612            break;
    606613        }
     614        idNewSession = g_idSession;
     615        rc =  VbglR3GetSessionId(&idNewSession);
     616        AssertRC(rc);
     617
     618        if (idNewSession != g_idSession)
     619        {
     620            bool fUnregister = false;
     621
     622            VBoxServiceVerbose(3, "VBoxServicePageSharingWorker: VM was restored!!\n"));
     623            /* The VM was restored, so reregister all modules the next time. */
     624            RTAvlPVDestroy(&g_pKnownModuleTree, VBoxServicePageSharingEmptyTreeCallback, &fUnregister);
     625            g_pKnownModuleTree = NULL;
     626        }
     627
    607628    }
    608629
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