VirtualBox

Changeset 24575 in vbox for trunk/src/VBox/VMM


Ignore:
Timestamp:
Nov 11, 2009 9:54:23 AM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
54705
Message:

SSM: Reduce the number of ifndef SSM_STANDALONE checks by moving code.

File:
1 edited

Legend:

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

    r24574 r24575  
    68486848}
    68496849
    6850 #ifndef SSM_STANDALONE
    6851 
    6852 /**
    6853  * VMSetError wrapper for load errors that inserts the saved state details.
    6854  *
    6855  * @returns rc.
    6856  * @param   pSSM                The saved state handle.
    6857  * @param   rc                  The status code of the error. Use RT_SRC_POS.
    6858  * @param   RT_SRC_POS_DECL     The source location.
    6859  * @param   pszFormat           The message format string.
    6860  * @param   ...                 Variable argument list.
    6861  */
    6862 VMMR3DECL(int) SSMR3SetLoadError(PSSMHANDLE pSSM, int rc, RT_SRC_POS_DECL, const char *pszFormat, ...)
    6863 {
    6864     va_list va;
    6865     va_start(va, pszFormat);
    6866     rc = SSMR3SetLoadErrorV(pSSM, rc, RT_SRC_POS_ARGS, pszFormat, va);
    6867     va_end(va);
    6868     return rc;
    6869 }
    6870 
    6871 
    6872 /**
    6873  * VMSetError wrapper for load errors that inserts the saved state details.
    6874  *
    6875  * @returns rc.
    6876  * @param   pSSM                The saved state handle.
    6877  * @param   rc                  The status code of the error.
    6878  * @param   RT_SRC_POS_DECL     The error location, use RT_SRC_POS.
    6879  * @param   pszFormat           The message format string.
    6880  * @param   va                  Variable argument list.
    6881  */
    6882 VMMR3DECL(int) SSMR3SetLoadErrorV(PSSMHANDLE pSSM, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va)
    6883 {
    6884     /*
    6885      * Input validations.
    6886      */
    6887     SSM_ASSERT_READABLE_RET(pSSM);
    6888     AssertPtr(pszFormat);
    6889     Assert(RT_FAILURE_NP(rc));
    6890 
    6891     /*
    6892      * Format the incoming error.
    6893      */
    6894     char *pszMsg;
    6895     RTStrAPrintfV(&pszMsg, pszFormat, va);
    6896     if (!pszMsg)
    6897     {
    6898         VMSetError(pSSM->pVM, VERR_NO_MEMORY, RT_SRC_POS,
    6899                    N_("SSMR3SetLoadErrorV ran out of memory formatting: %s\n"), pszFormat);
    6900         return rc;
    6901     }
    6902 
    6903     /*
    6904      * Forward to VMSetError with the additional info.
    6905      */
    6906     PSSMUNIT    pUnit       = pSSM->u.Read.pCurUnit;
    6907     const char *pszName     = pUnit ? pUnit->szName      : "unknown";
    6908     uint32_t    uInstance   = pUnit ? pUnit->u32Instance : 0;
    6909     if (   pSSM->enmOp == SSMSTATE_LOAD_EXEC
    6910         && pSSM->u.Read.uCurUnitPass == SSM_PASS_FINAL)
    6911         rc = VMSetError(pSSM->pVM, rc, RT_SRC_POS_ARGS, N_("%s#%u: %s [ver=%u pass=final]"),
    6912                         pszName, uInstance, pszMsg, pSSM->u.Read.uCurUnitVer);
    6913     else if (pSSM->enmOp == SSMSTATE_LOAD_EXEC)
    6914         rc = VMSetError(pSSM->pVM, rc, RT_SRC_POS_ARGS, N_("%s#%u: %s [ver=%u pass=#%u]"),
    6915                         pszName, uInstance, pszMsg, pSSM->u.Read.uCurUnitVer, pSSM->u.Read.uCurUnitPass);
    6916     else if (pSSM->enmOp == SSMSTATE_LOAD_PREP)
    6917         rc = VMSetError(pSSM->pVM, rc, RT_SRC_POS_ARGS, N_("%s#%u: %s [prep]"),
    6918                         pszName, uInstance, pszMsg);
    6919     else if (pSSM->enmOp == SSMSTATE_LOAD_DONE)
    6920         rc = VMSetError(pSSM->pVM, rc, RT_SRC_POS_ARGS, N_("%s#%u: %s [done]"),
    6921                         pszName, uInstance, pszMsg);
    6922     else if (pSSM->enmOp == SSMSTATE_OPEN_READ)
    6923         rc = VMSetError(pSSM->pVM, rc, RT_SRC_POS_ARGS, N_("%s#%u: %s [read]"),
    6924                         pszName, uInstance, pszMsg);
    6925     else
    6926         AssertFailed();
    6927     pSSM->u.Read.fHaveSetError = true;
    6928     RTStrFree(pszMsg);
    6929     return rc;
    6930 }
    6931 
    6932 
    6933 /**
    6934  * SSMR3SetLoadError wrapper that returns VERR_SSM_LOAD_CONFIG_MISMATCH.
    6935  *
    6936  * @returns VERR_SSM_LOAD_CONFIG_MISMATCH.
    6937  * @param   pSSM                The saved state handle.
    6938  * @param   RT_SRC_POS_DECL     The error location, use RT_SRC_POS.
    6939  * @param   pszFormat           The message format string.
    6940  * @param   va                  Variable argument list.
    6941  */
    6942 VMMR3DECL(int) SSMR3SetCfgError(PSSMHANDLE pSSM, RT_SRC_POS_DECL, const char *pszFormat, ...)
    6943 {
    6944     va_list va;
    6945     va_start(va, pszFormat);
    6946     int rc = SSMR3SetLoadErrorV(pSSM, VERR_SSM_LOAD_CONFIG_MISMATCH, RT_SRC_POS_ARGS, pszFormat, va);
    6947     va_end(va);
    6948     return rc;
    6949 }
    6950 
    6951 #endif /* !SSM_STANDALONE */
    69526850
    69536851/**
     
    74887386        Log(("SSM: Failed to open save state file '%s', rc=%Rrc.\n",  pszFilename, rc));
    74897387    return rc;
     7388}
     7389
     7390
     7391/**
     7392 * Verifies the directory.
     7393 *
     7394 * @returns VBox status code.
     7395 *
     7396 * @param   pDir        The full directory.
     7397 * @param   cbDir       The size of the directory.
     7398 * @param   offDir      The directory stream offset.
     7399 * @param   cDirEntries The directory entry count from the footer.
     7400 * @param   cbHdr       The header size.
     7401 * @param   uSvnRev     The SVN revision that saved the state. Bug detection.
     7402 */
     7403static int ssmR3ValidateDirectory(PSSMFILEDIR pDir, size_t cbDir, uint64_t offDir, uint32_t cDirEntries,
     7404                                  uint32_t cbHdr, uint32_t uSvnRev)
     7405{
     7406    AssertLogRelReturn(!memcmp(pDir->szMagic, SSMFILEDIR_MAGIC, sizeof(pDir->szMagic)), VERR_SSM_INTEGRITY_DIR_MAGIC);
     7407    SSM_CHECK_CRC32_RET(pDir, cbDir, ("Bad directory CRC: %08x, actual %08x\n", u32CRC, u32ActualCRC));
     7408    AssertLogRelMsgReturn(pDir->cEntries == cDirEntries,
     7409                          ("Bad directory entry count: %#x, expected %#x (from the footer)\n", pDir->cEntries, cDirEntries),
     7410                           VERR_SSM_INTEGRITY_DIR);
     7411    AssertLogRelReturn(RT_UOFFSETOF(SSMFILEDIR, aEntries[pDir->cEntries]) == cbDir, VERR_SSM_INTEGRITY_DIR);
     7412
     7413    for (uint32_t i = 0; i < pDir->cEntries; i++)
     7414    {
     7415        AssertLogRelMsgReturn(  (   pDir->aEntries[i].off >= cbHdr
     7416                                 && pDir->aEntries[i].off <  offDir)
     7417                              || (   pDir->aEntries[i].off == 0 /* bug in unreleased code */
     7418                                  && uSvnRev < 53365),
     7419                              ("off=%#llx cbHdr=%#x offDir=%#llx\n", pDir->aEntries[i].off, cbHdr, offDir),
     7420                              VERR_SSM_INTEGRITY_DIR);
     7421    }
     7422    return VINF_SUCCESS;
    74907423}
    74917424
     
    77177650}
    77187651
    7719 #endif /* !SSM_STANDALONE */
    7720 
    7721 
    7722 /**
    7723  * Verifies the directory.
    7724  *
    7725  * @returns VBox status code.
    7726  *
    7727  * @param   pDir        The full directory.
    7728  * @param   cbDir       The size of the directory.
    7729  * @param   offDir      The directory stream offset.
    7730  * @param   cDirEntries The directory entry count from the footer.
    7731  * @param   cbHdr       The header size.
    7732  * @param   uSvnRev     The SVN revision that saved the state. Bug detection.
    7733  */
    7734 static int ssmR3ValidateDirectory(PSSMFILEDIR pDir, size_t cbDir, uint64_t offDir, uint32_t cDirEntries,
    7735                                   uint32_t cbHdr, uint32_t uSvnRev)
    7736 {
    7737     AssertLogRelReturn(!memcmp(pDir->szMagic, SSMFILEDIR_MAGIC, sizeof(pDir->szMagic)), VERR_SSM_INTEGRITY_DIR_MAGIC);
    7738     SSM_CHECK_CRC32_RET(pDir, cbDir, ("Bad directory CRC: %08x, actual %08x\n", u32CRC, u32ActualCRC));
    7739     AssertLogRelMsgReturn(pDir->cEntries == cDirEntries,
    7740                           ("Bad directory entry count: %#x, expected %#x (from the footer)\n", pDir->cEntries, cDirEntries),
    7741                            VERR_SSM_INTEGRITY_DIR);
    7742     AssertLogRelReturn(RT_UOFFSETOF(SSMFILEDIR, aEntries[pDir->cEntries]) == cbDir, VERR_SSM_INTEGRITY_DIR);
    7743 
    7744     for (uint32_t i = 0; i < pDir->cEntries; i++)
    7745     {
    7746         AssertLogRelMsgReturn(  (   pDir->aEntries[i].off >= cbHdr
    7747                                  && pDir->aEntries[i].off <  offDir)
    7748                               || (   pDir->aEntries[i].off == 0 /* bug in unreleased code */
    7749                                   && uSvnRev < 53365),
    7750                               ("off=%#llx cbHdr=%#x offDir=%#llx\n", pDir->aEntries[i].off, cbHdr, offDir),
    7751                               VERR_SSM_INTEGRITY_DIR);
    7752     }
    7753     return VINF_SUCCESS;
    7754 }
    7755 
    7756 #ifndef SSM_STANDALONE
    77577652
    77587653/**
     
    81918086}
    81928087
     8088
     8089/**
     8090 * VMSetError wrapper for load errors that inserts the saved state details.
     8091 *
     8092 * @returns rc.
     8093 * @param   pSSM                The saved state handle.
     8094 * @param   rc                  The status code of the error. Use RT_SRC_POS.
     8095 * @param   RT_SRC_POS_DECL     The source location.
     8096 * @param   pszFormat           The message format string.
     8097 * @param   ...                 Variable argument list.
     8098 */
     8099VMMR3DECL(int) SSMR3SetLoadError(PSSMHANDLE pSSM, int rc, RT_SRC_POS_DECL, const char *pszFormat, ...)
     8100{
     8101    va_list va;
     8102    va_start(va, pszFormat);
     8103    rc = SSMR3SetLoadErrorV(pSSM, rc, RT_SRC_POS_ARGS, pszFormat, va);
     8104    va_end(va);
     8105    return rc;
     8106}
     8107
     8108
     8109/**
     8110 * VMSetError wrapper for load errors that inserts the saved state details.
     8111 *
     8112 * @returns rc.
     8113 * @param   pSSM                The saved state handle.
     8114 * @param   rc                  The status code of the error.
     8115 * @param   RT_SRC_POS_DECL     The error location, use RT_SRC_POS.
     8116 * @param   pszFormat           The message format string.
     8117 * @param   va                  Variable argument list.
     8118 */
     8119VMMR3DECL(int) SSMR3SetLoadErrorV(PSSMHANDLE pSSM, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va)
     8120{
     8121    /*
     8122     * Input validations.
     8123     */
     8124    SSM_ASSERT_READABLE_RET(pSSM);
     8125    AssertPtr(pszFormat);
     8126    Assert(RT_FAILURE_NP(rc));
     8127
     8128    /*
     8129     * Format the incoming error.
     8130     */
     8131    char *pszMsg;
     8132    RTStrAPrintfV(&pszMsg, pszFormat, va);
     8133    if (!pszMsg)
     8134    {
     8135        VMSetError(pSSM->pVM, VERR_NO_MEMORY, RT_SRC_POS,
     8136                   N_("SSMR3SetLoadErrorV ran out of memory formatting: %s\n"), pszFormat);
     8137        return rc;
     8138    }
     8139
     8140    /*
     8141     * Forward to VMSetError with the additional info.
     8142     */
     8143    PSSMUNIT    pUnit       = pSSM->u.Read.pCurUnit;
     8144    const char *pszName     = pUnit ? pUnit->szName      : "unknown";
     8145    uint32_t    uInstance   = pUnit ? pUnit->u32Instance : 0;
     8146    if (   pSSM->enmOp == SSMSTATE_LOAD_EXEC
     8147        && pSSM->u.Read.uCurUnitPass == SSM_PASS_FINAL)
     8148        rc = VMSetError(pSSM->pVM, rc, RT_SRC_POS_ARGS, N_("%s#%u: %s [ver=%u pass=final]"),
     8149                        pszName, uInstance, pszMsg, pSSM->u.Read.uCurUnitVer);
     8150    else if (pSSM->enmOp == SSMSTATE_LOAD_EXEC)
     8151        rc = VMSetError(pSSM->pVM, rc, RT_SRC_POS_ARGS, N_("%s#%u: %s [ver=%u pass=#%u]"),
     8152                        pszName, uInstance, pszMsg, pSSM->u.Read.uCurUnitVer, pSSM->u.Read.uCurUnitPass);
     8153    else if (pSSM->enmOp == SSMSTATE_LOAD_PREP)
     8154        rc = VMSetError(pSSM->pVM, rc, RT_SRC_POS_ARGS, N_("%s#%u: %s [prep]"),
     8155                        pszName, uInstance, pszMsg);
     8156    else if (pSSM->enmOp == SSMSTATE_LOAD_DONE)
     8157        rc = VMSetError(pSSM->pVM, rc, RT_SRC_POS_ARGS, N_("%s#%u: %s [done]"),
     8158                        pszName, uInstance, pszMsg);
     8159    else if (pSSM->enmOp == SSMSTATE_OPEN_READ)
     8160        rc = VMSetError(pSSM->pVM, rc, RT_SRC_POS_ARGS, N_("%s#%u: %s [read]"),
     8161                        pszName, uInstance, pszMsg);
     8162    else
     8163        AssertFailed();
     8164    pSSM->u.Read.fHaveSetError = true;
     8165    RTStrFree(pszMsg);
     8166    return rc;
     8167}
     8168
     8169
     8170/**
     8171 * SSMR3SetLoadError wrapper that returns VERR_SSM_LOAD_CONFIG_MISMATCH.
     8172 *
     8173 * @returns VERR_SSM_LOAD_CONFIG_MISMATCH.
     8174 * @param   pSSM                The saved state handle.
     8175 * @param   RT_SRC_POS_DECL     The error location, use RT_SRC_POS.
     8176 * @param   pszFormat           The message format string.
     8177 * @param   va                  Variable argument list.
     8178 */
     8179VMMR3DECL(int) SSMR3SetCfgError(PSSMHANDLE pSSM, RT_SRC_POS_DECL, const char *pszFormat, ...)
     8180{
     8181    va_list va;
     8182    va_start(va, pszFormat);
     8183    int rc = SSMR3SetLoadErrorV(pSSM, VERR_SSM_LOAD_CONFIG_MISMATCH, RT_SRC_POS_ARGS, pszFormat, va);
     8184    va_end(va);
     8185    return rc;
     8186}
     8187
    81938188#endif /* !SSM_STANDALONE */
    8194 
    81958189
    81968190/**
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette