VirtualBox

Changeset 12440 in vbox for trunk/src


Ignore:
Timestamp:
Sep 12, 2008 6:40:20 PM (16 years ago)
Author:
vboxsync
Message:

SSM: save the vbox version and revision in the saved state. LogRel it on restore.

Location:
trunk/src/VBox/VMM
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/SSM.cpp

    r11944 r12440  
    4949#include <VBox/err.h>
    5050#include <VBox/log.h>
     51#include <VBox/version.h>
    5152
    5253#include <iprt/assert.h>
     
    219220*   Internal Functions                                                         *
    220221*******************************************************************************/
     222static int                  ssmR3LazyInit(PVM pVM);
     223static DECLCALLBACK(int)    ssmR3SelfSaveExec(PVM pVM, PSSMHANDLE pSSM);
     224static DECLCALLBACK(int)    ssmR3SelfLoadExec(PVM pVM, PSSMHANDLE pSSM, uint32_t u32Version);
    221225static int smmr3Register(PVM pVM, const char *pszName, uint32_t u32Instance, uint32_t u32Version, size_t cbGuess, PSSMUNIT *ppUnit);
    222226static int ssmr3CalcChecksum(RTFILE File, uint64_t cbFile, uint32_t *pu32CRC);
     
    233237
    234238/**
     239 * Performs lazy initialization of the SSM.
     240 *
     241 * @returns VBox status code.
     242 * @param   pVM         The VM.
     243 */
     244static int ssmR3LazyInit(PVM pVM)
     245{
     246#if 1 /* if we want 2.0.2 to remain forward compatible with 2.0.x, disable this. */
     247    /*
     248     * Register a saved state unit which we use to put the VirtualBox version,
     249     * revision and similar stuff in.
     250     */
     251    pVM->ssm.s.fInitialized = true;
     252    int rc = SSMR3RegisterInternal(pVM, "SSM", 0 /*u32Instance*/, 1/*u32Version*/, 64 /*cbGuess*/,
     253                                   NULL /*pfnSavePrep*/, ssmR3SelfSaveExec, NULL /*pfnSaveDone*/,
     254                                   NULL /*pfnSavePrep*/, ssmR3SelfLoadExec, NULL /*pfnSaveDone*/);
     255    pVM->ssm.s.fInitialized = RT_SUCCESS(rc);
     256    return rc;
     257#else
     258    pVM->ssm.s.fInitialized = true;
     259    return VINF_SUCCESS;
     260#endif
     261}
     262
     263
     264/**
     265 * For saving the version + revision and stuff.
     266 *
     267 * @returns VBox status code.
     268 * @param   pVM             Pointer to the shared VM structure.
     269 * @param   pSSM            The SSM handle.
     270 */
     271static DECLCALLBACK(int) ssmR3SelfSaveExec(PVM pVM, PSSMHANDLE pSSM)
     272{
     273    char szTmp[128];
     274
     275    /*
     276     * String table containg pairs of variable and value string.
     277     * Terminated by two empty strings.
     278     */
     279    SSMR3PutStrZ(pSSM, "VBox Version");
     280    SSMR3PutStrZ(pSSM, VBOX_VERSION_STRING);
     281    SSMR3PutStrZ(pSSM, "VBox Revision");
     282    RTStrPrintf(szTmp, sizeof(szTmp), "%d", VMMGetSvnRev());
     283    SSMR3PutStrZ(pSSM, szTmp);
     284#ifdef VBOX_OSE
     285    SSMR3PutStrZ(pSSM, "OSE");
     286    SSMR3PutStrZ(pSSM, "true");
     287#endif
     288
     289    /* terminator */
     290    SSMR3PutStrZ(pSSM, "");
     291    return SSMR3PutStrZ(pSSM, "");
     292}
     293
     294
     295/**
     296 * For load the version + revision and stuff.
     297 *
     298 * @returns VBox status code.
     299 * @param   pVM             Pointer to the shared VM structure.
     300 * @param   pSSM            The SSM handle.
     301 * @param   u32Version      The version (1).
     302 */
     303static DECLCALLBACK(int) ssmR3SelfLoadExec(PVM pVM, PSSMHANDLE pSSM, uint32_t u32Version)
     304{
     305    AssertLogRelMsgReturn(u32Version == 1, ("%d", u32Version), VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION);
     306
     307    /*
     308     * String table containg pairs of variable and value string.
     309     * Terminated by two empty strings.
     310     */
     311    LogRel(("SSM: Saved state info:\n", szVar, szValue));
     312    for (;;)
     313    {
     314        char szVar[128];
     315        char szValue[1024];
     316        int rc = SSMR3GetStrZ(pSSM, szVar, sizeof(szVar));
     317        AssertRCReturn(rc, rc);
     318        rc = SSMR3GetStrZ(pSSM, szValue, sizeof(szValue));
     319        AssertRCReturn(rc, rc);
     320        if (!szVar[0] && !szValue[0])
     321            break;
     322        LogRel(("SSM:   %s: %s\n", szVar, szValue));
     323    }
     324    return VINF_SUCCESS;
     325}
     326
     327
     328/**
    235329 * Internal registration worker.
    236330 *
     
    246340static int smmr3Register(PVM pVM, const char *pszName, uint32_t u32Instance, uint32_t u32Version, size_t cbGuess, PSSMUNIT *ppUnit)
    247341{
     342    /*
     343     * Lazy init.
     344     */
     345    if (!pVM->ssm.s.fInitialized)
     346    {
     347        int rc = ssmR3LazyInit(pVM);
     348        AssertRCReturn(rc, rc);
     349    }
     350
    248351    /*
    249352     * Walk to the end of the list checking for duplicates as we go.
     
    29013004 *
    29023005 * Note: only applies to:
    2903  * - SSMR3GetGCPtr 
     3006 * - SSMR3GetGCPtr
    29043007 * - SSMR3GetGCUIntPtr
    29053008 * - SSMR3GetGCSInt
  • trunk/src/VBox/VMM/SSMInternal.h

    r8155 r12440  
    159159
    160160
    161 
    162 /**
    163  * Converts a SSM pointer into a VM pointer.
    164  * @returns Pointer to the VM structure the SSM is part of.
    165  * @param   pSSM   Pointer to SSM instance data.
    166  */
    167 #define SSM2VM(pSSM)  ( (PVM)((char*)pSSM - pSSM->offVM) )
    168 
    169 
    170161/**
    171162 * SSM VM Instance data.
     
    174165typedef struct SSM
    175166{
    176     /** Offset to the VM structure.
    177      * See SSM2VM(). */
    178     RTUINT                  offVM;
    179 
    180167    /** FIFO of data entity descriptors. */
    181168    R3PTRTYPE(PSSMUNIT)     pHead;
    182 
     169    /** For lazy init. */
     170    bool                    fInitialized;
    183171} SSM;
    184172/** Pointer to SSM VM instance 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