ssm.h revision de381fe54d26bc116945a70595720f9258793afb
/** @file
* SSM - The Save State Manager. (VMM)
*/
/*
* Copyright (C) 2006-2007 Sun Microsystems, Inc.
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
#ifndef ___VBox_ssm_h
#define ___VBox_ssm_h
/** @defgroup grp_ssm The Saved State Manager API
* @{
*/
/**
* Determine the major version of the SSM version. If the major SSM version of two snapshots is
* different, the snapshots are incompatible.
*/
/**
* Determine the minor version of the SSM version. If the major SSM version of two snapshots is
* the same, the code must handle incompatibilies between minor version changes (e.g. use dummy
* values for non-existent fields).
*/
/**
* Determine if the major version changed between two SSM versions.
*/
/** The special value for the final pass. */
#define SSM_PASS_FINAL UINT32_MAX
#ifdef IN_RING3
/** @defgroup grp_ssm_r3 The SSM Host Context Ring-3 API
* @{
*/
/**
*/
typedef enum SSMAFTER
{
/** Invalid. */
SSMAFTER_INVALID = 0,
/** Will resume the loaded state. */
/** Will destroy the VM after saving. */
/** Will continue execution after saving the VM. */
/** Will migrate the VM.
* The source VM will be destroyed (then one saving), the destination VM
* will continue execution. */
/** Will debug the saved state.
* This is used to drop some of the stricter consitentcy checks so it'll
* load fine in the debugger or animator. */
/** The file was opened using SSMR3Open() and we have no idea what the plan is. */
} SSMAFTER;
/**
* A structure field description.
*
* @todo Add an type field here for recording what's a GCPtr, GCPhys or anything
* else that may change and is expected to continue to work.
* @todo Later we need to add load transformations to this structure. I think a
* callback with a number of default transformations in SIG_DEF style
* would be good enough. The callback would take a user context from a new
* SSMR3GetStruct parameter or something.
*/
typedef struct SSMFIELD
{
/** Field offset into the structure. */
/** The size of the field. */
} SSMFIELD;
/** Pointer to a structure field description. */
/** Pointer to a const structure field description. */
typedef const SSMFIELD *PCSSMFIELD;
/** Emit a SSMFIELD array entry. */
/** Emit a SSMFIELD array entry for a RTGCPTR type. */
/** Emit a SSMFIELD array entry for a RTGCPHYS type. */
/** Emit the terminating entry of a SSMFIELD array. */
/** The PDM Device callback variants.
* @{
*/
/**
* Prepare state live save operation.
*
* @returns VBox status code.
* @param pDevIns Device instance of the device which registered the data unit.
* @param pSSM SSM operation handle.
* @thread Any.
*/
/** Pointer to a FNSSMDEVLIVEPREP() function. */
typedef FNSSMDEVLIVEPREP *PFNSSMDEVLIVEPREP;
/**
* Execute state live save operation.
*
* This will be called repeatedly until all units vote that the live phase has
* been concluded.
*
* @returns VBox status code.
* @param pDevIns Device instance of the device which registered the data unit.
* @param pSSM SSM operation handle.
* @param uPass The pass.
* @thread Any.
*/
/** Pointer to a FNSSMDEVLIVEEXEC() function. */
typedef FNSSMDEVLIVEEXEC *PFNSSMDEVLIVEEXEC;
/**
* Vote on whether the live part of the saving has been concluded.
*
* The vote stops once a unit has vetoed the decision, so don't rely upon this
* being called every time.
*
* @returns VBox status code.
* @retval VINF_SUCCESS if done.
* @retval VINF_SSM_VOTE_FOR_ANOTHER_PASS if another pass is needed.
* @retval VINF_SSM_VOTE_DONE_DONT_CALL_AGAIN if the live saving of the unit is
* done and there is not need calling it again before the final pass.
* @retval VERR_SSM_VOTE_FOR_GIVING_UP if its time to give up.
*
* @param pDevIns Device instance of the device which registered the data unit.
* @param pSSM SSM operation handle.
* @thread Any.
*/
/** Pointer to a FNSSMDEVLIVEVOTE() function. */
typedef FNSSMDEVLIVEVOTE *PFNSSMDEVLIVEVOTE;
/**
* Prepare state save operation.
*
* @returns VBox status code.
* @param pDevIns Device instance of the device which registered the data unit.
* @param pSSM SSM operation handle.
*/
/** Pointer to a FNSSMDEVSAVEPREP() function. */
typedef FNSSMDEVSAVEPREP *PFNSSMDEVSAVEPREP;
/**
* Execute state save operation.
*
* @returns VBox status code.
* @param pDevIns Device instance of the device which registered the data unit.
* @param pSSM SSM operation handle.
*/
/** Pointer to a FNSSMDEVSAVEEXEC() function. */
typedef FNSSMDEVSAVEEXEC *PFNSSMDEVSAVEEXEC;
/**
* Done state save operation.
*
* @returns VBox status code.
* @param pDevIns Device instance of the device which registered the data unit.
* @param pSSM SSM operation handle.
*/
/** Pointer to a FNSSMDEVSAVEDONE() function. */
typedef FNSSMDEVSAVEDONE *PFNSSMDEVSAVEDONE;
/**
* Prepare state load operation.
*
* @returns VBox status code.
* @param pDevIns Device instance of the device which registered the data unit.
* @param pSSM SSM operation handle.
*/
/** Pointer to a FNSSMDEVLOADPREP() function. */
typedef FNSSMDEVLOADPREP *PFNSSMDEVLOADPREP;
/**
* Execute state load operation.
*
* @returns VBox status code.
* @param pDevIns Device instance of the device which registered the data unit.
* @param pSSM SSM operation handle.
* @param uVersion Data layout version.
* @param uPass The pass. This is always SSM_PASS_FINAL for units
* that doesn't specify a pfnSaveLive callback.
*/
typedef DECLCALLBACK(int) FNSSMDEVLOADEXEC(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass);
/** Pointer to a FNSSMDEVLOADEXEC() function. */
typedef FNSSMDEVLOADEXEC *PFNSSMDEVLOADEXEC;
/**
* Done state load operation.
*
* @returns VBox load code.
* @param pDevIns Device instance of the device which registered the data unit.
* @param pSSM SSM operation handle.
*/
/** Pointer to a FNSSMDEVLOADDONE() function. */
typedef FNSSMDEVLOADDONE *PFNSSMDEVLOADDONE;
/** @} */
/** The PDM Driver callback variants.
* @{
*/
/**
* Prepare state live save operation.
*
* @returns VBox status code.
* @param pDrvIns Driver instance of the device which registered the
* data unit.
* @param pSSM SSM operation handle.
* @thread Any.
*/
/** Pointer to a FNSSMDRVLIVEPREP() function. */
typedef FNSSMDRVLIVEPREP *PFNSSMDRVLIVEPREP;
/**
* Execute state live save operation.
*
* This will be called repeatedly until all units vote that the live phase has
* been concluded.
*
* @returns VBox status code.
* @param pDrvIns Driver instance of the device which registered the
* data unit.
* @param pSSM SSM operation handle.
* @param uPass The data pass.
* @thread Any.
*/
/** Pointer to a FNSSMDRVLIVEEXEC() function. */
typedef FNSSMDRVLIVEEXEC *PFNSSMDRVLIVEEXEC;
/**
* Vote on whether the live part of the saving has been concluded.
*
* The vote stops once a unit has vetoed the decision, so don't rely upon this
* being called every time.
*
* @returns VBox status code.
* @retval VINF_SUCCESS if done.
* @retval VINF_SSM_VOTE_FOR_ANOTHER_PASS if another pass is needed.
* @retval VINF_SSM_VOTE_DONE_DONT_CALL_AGAIN if the live saving of the unit is
* done and there is not need calling it again before the final pass.
* @retval VERR_SSM_VOTE_FOR_GIVING_UP if its time to give up.
*
* @param pDrvIns Driver instance of the device which registered the
* data unit.
* @param pSSM SSM operation handle.
* @thread Any.
*/
/** Pointer to a FNSSMDRVLIVEVOTE() function. */
typedef FNSSMDRVLIVEVOTE *PFNSSMDRVLIVEVOTE;
/**
* Prepare state save operation.
*
* @returns VBox status code.
* @param pDrvIns Driver instance of the driver which registered the data unit.
* @param pSSM SSM operation handle.
*/
/** Pointer to a FNSSMDRVSAVEPREP() function. */
typedef FNSSMDRVSAVEPREP *PFNSSMDRVSAVEPREP;
/**
* Execute state save operation.
*
* @returns VBox status code.
* @param pDrvIns Driver instance of the driver which registered the data unit.
* @param pSSM SSM operation handle.
*/
/** Pointer to a FNSSMDRVSAVEEXEC() function. */
typedef FNSSMDRVSAVEEXEC *PFNSSMDRVSAVEEXEC;
/**
* Done state save operation.
*
* @returns VBox status code.
* @param pDrvIns Driver instance of the driver which registered the data unit.
* @param pSSM SSM operation handle.
*/
/** Pointer to a FNSSMDRVSAVEDONE() function. */
typedef FNSSMDRVSAVEDONE *PFNSSMDRVSAVEDONE;
/**
* Prepare state load operation.
*
* @returns VBox status code.
* @param pDrvIns Driver instance of the driver which registered the data unit.
* @param pSSM SSM operation handle.
*/
/** Pointer to a FNSSMDRVLOADPREP() function. */
typedef FNSSMDRVLOADPREP *PFNSSMDRVLOADPREP;
/**
* Execute state load operation.
*
* @returns VBox status code.
* @param pDrvIns Driver instance of the driver which registered the data unit.
* @param pSSM SSM operation handle.
* @param uVersion Data layout version.
* @param uPass The pass. This is always SSM_PASS_FINAL for units
* that doesn't specify a pfnSaveLive callback.
*/
typedef DECLCALLBACK(int) FNSSMDRVLOADEXEC(PPDMDRVINS pDrvIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass);
/** Pointer to a FNSSMDRVLOADEXEC() function. */
typedef FNSSMDRVLOADEXEC *PFNSSMDRVLOADEXEC;
/**
* Done state load operation.
*
* @returns VBox load code.
* @param pDrvIns Driver instance of the driver which registered the data unit.
* @param pSSM SSM operation handle.
*/
/** Pointer to a FNSSMDRVLOADDONE() function. */
typedef FNSSMDRVLOADDONE *PFNSSMDRVLOADDONE;
/** @} */
/** The internal callback variants.
* @{
*/
/**
* Prepare state live save operation.
*
* @returns VBox status code.
* @param pVM VM Handle.
* @param pSSM SSM operation handle.
* @thread Any.
*/
/** Pointer to a FNSSMINTLIVEPREP() function. */
typedef FNSSMINTLIVEPREP *PFNSSMINTLIVEPREP;
/**
* Execute state live save operation.
*
* This will be called repeatedly until all units vote that the live phase has
* been concluded.
*
* @returns VBox status code.
* @param pVM VM Handle.
* @param pSSM SSM operation handle.
* @param uPass The data pass.
* @thread Any.
*/
/** Pointer to a FNSSMINTLIVEEXEC() function. */
typedef FNSSMINTLIVEEXEC *PFNSSMINTLIVEEXEC;
/**
* Vote on whether the live part of the saving has been concluded.
*
* The vote stops once a unit has vetoed the decision, so don't rely upon this
* being called every time.
*
* @returns VBox status code.
* @retval VINF_SUCCESS if done.
* @retval VINF_SSM_VOTE_FOR_ANOTHER_PASS if another pass is needed.
* @retval VINF_SSM_VOTE_DONE_DONT_CALL_AGAIN if the live saving of the unit is
* done and there is not need calling it again before the final pass.
* @retval VERR_SSM_VOTE_FOR_GIVING_UP if its time to give up.
*
* @param pVM VM Handle.
* @param pSSM SSM operation handle.
* @thread Any.
*/
/** Pointer to a FNSSMINTLIVEVOTE() function. */
typedef FNSSMINTLIVEVOTE *PFNSSMINTLIVEVOTE;
/**
* Prepare state save operation.
*
* @returns VBox status code.
* @param pVM VM Handle.
* @param pSSM SSM operation handle.
*/
/** Pointer to a FNSSMINTSAVEPREP() function. */
typedef FNSSMINTSAVEPREP *PFNSSMINTSAVEPREP;
/**
* Execute state save operation.
*
* @returns VBox status code.
* @param pVM VM Handle.
* @param pSSM SSM operation handle.
*/
/** Pointer to a FNSSMINTSAVEEXEC() function. */
typedef FNSSMINTSAVEEXEC *PFNSSMINTSAVEEXEC;
/**
* Done state save operation.
*
* @returns VBox status code.
* @param pVM VM Handle.
* @param pSSM SSM operation handle.
*/
/** Pointer to a FNSSMINTSAVEDONE() function. */
typedef FNSSMINTSAVEDONE *PFNSSMINTSAVEDONE;
/**
* Prepare state load operation.
*
* @returns VBox status code.
* @param pVM VM Handle.
* @param pSSM SSM operation handle.
*/
/** Pointer to a FNSSMINTLOADPREP() function. */
typedef FNSSMINTLOADPREP *PFNSSMINTLOADPREP;
/**
* Execute state load operation.
*
* @returns VBox status code.
* @param pVM VM Handle.
* @param pSSM SSM operation handle.
* @param uVersion Data layout version.
* @param uPass The pass. This is always SSM_PASS_FINAL for units
* that doesn't specify a pfnSaveLive callback.
*/
typedef DECLCALLBACK(int) FNSSMINTLOADEXEC(PVM pVM, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass);
/** Pointer to a FNSSMINTLOADEXEC() function. */
typedef FNSSMINTLOADEXEC *PFNSSMINTLOADEXEC;
/**
* Done state load operation.
*
* @returns VBox load code.
* @param pVM VM Handle.
* @param pSSM SSM operation handle.
*/
/** Pointer to a FNSSMINTLOADDONE() function. */
typedef FNSSMINTLOADDONE *PFNSSMINTLOADDONE;
/** @} */
/** The External callback variants.
* @{
*/
/**
* Prepare state live save operation.
*
* @returns VBox status code.
* @param pSSM SSM operation handle.
* @param pvUser User argument.
* @thread Any.
*/
/** Pointer to a FNSSMEXTLIVEPREP() function. */
typedef FNSSMEXTLIVEPREP *PFNSSMEXTLIVEPREP;
/**
* Execute state live save operation.
*
* This will be called repeatedly until all units vote that the live phase has
* been concluded.
*
* @returns VBox status code.
* @param pSSM SSM operation handle.
* @param pvUser User argument.
* @param uPass The data pass.
* @thread Any.
*/
/** Pointer to a FNSSMEXTLIVEEXEC() function. */
typedef FNSSMEXTLIVEEXEC *PFNSSMEXTLIVEEXEC;
/**
* Vote on whether the live part of the saving has been concluded.
*
* The vote stops once a unit has vetoed the decision, so don't rely upon this
* being called every time.
*
* @returns VBox status code.
* @retval VINF_SUCCESS if done.
* @retval VINF_SSM_VOTE_FOR_ANOTHER_PASS if another pass is needed.
* @retval VINF_SSM_VOTE_DONE_DONT_CALL_AGAIN if the live saving of the unit is
* done and there is not need calling it again before the final pass.
* @retval VERR_SSM_VOTE_FOR_GIVING_UP if its time to give up.
*
* @param pSSM SSM operation handle.
* @param pvUser User argument.
* @thread Any.
*/
/** Pointer to a FNSSMEXTLIVEVOTE() function. */
typedef FNSSMEXTLIVEVOTE *PFNSSMEXTLIVEVOTE;
/**
* Prepare state save operation.
*
* @returns VBox status code.
* @param pSSM SSM operation handle.
* @param pvUser User argument.
*/
/** Pointer to a FNSSMEXTSAVEPREP() function. */
typedef FNSSMEXTSAVEPREP *PFNSSMEXTSAVEPREP;
/**
* Execute state save operation.
*
* @param pSSM SSM operation handle.
* @param pvUser User argument.
* @author The lack of return code is for legacy reasons.
*/
/** Pointer to a FNSSMEXTSAVEEXEC() function. */
typedef FNSSMEXTSAVEEXEC *PFNSSMEXTSAVEEXEC;
/**
* Done state save operation.
*
* @returns VBox status code.
* @param pSSM SSM operation handle.
* @param pvUser User argument.
*/
/** Pointer to a FNSSMEXTSAVEDONE() function. */
typedef FNSSMEXTSAVEDONE *PFNSSMEXTSAVEDONE;
/**
* Prepare state load operation.
*
* @returns VBox status code.
* @param pSSM SSM operation handle.
* @param pvUser User argument.
*/
/** Pointer to a FNSSMEXTLOADPREP() function. */
typedef FNSSMEXTLOADPREP *PFNSSMEXTLOADPREP;
/**
* Execute state load operation.
*
* @returns VBox status code.
* @param pSSM SSM operation handle.
* @param pvUser User argument.
* @param uVersion Data layout version.
* @param uPass The pass. This is always SSM_PASS_FINAL for units
* that doesn't specify a pfnSaveLive callback.
* @remark The odd return value is for legacy reasons.
*/
typedef DECLCALLBACK(int) FNSSMEXTLOADEXEC(PSSMHANDLE pSSM, void *pvUser, uint32_t uVersion, uint32_t uPass);
/** Pointer to a FNSSMEXTLOADEXEC() function. */
typedef FNSSMEXTLOADEXEC *PFNSSMEXTLOADEXEC;
/**
* Done state load operation.
*
* @returns VBox load code.
* @param pSSM SSM operation handle.
* @param pvUser User argument.
*/
/** Pointer to a FNSSMEXTLOADDONE() function. */
typedef FNSSMEXTLOADDONE *PFNSSMEXTLOADDONE;
/** @} */
/**
* SSM stream method table.
*
* This is used for live migration as well as internally in SSM.
*/
typedef struct SSMSTRMOPS
{
/** Struct magic + version (SSMSTRMOPS_VERSION). */
/**
* Write bytes to the stream.
*
* @returns VBox status code.
* @param pvUser The user argument.
* @param offStream The stream offset we're (supposed to be) at.
* @param pvBuf Pointer to the data.
* @param cbToWrite The number of bytes to write.
*/
DECLCALLBACKMEMBER(int, pfnWrite)(void *pvUser, uint64_t offStream, const void *pvBuf, size_t cbToWrite);
/**
* Read bytes to the stream.
*
* @returns VBox status code.
* @param pvUser The user argument.
* @param offStream The stream offset we're (supposed to be) at.
* @param pvBuf Where to return the bytes.
* @param cbToRead The number of bytes to read.
* @param pcbRead Where to return the number of bytes actually
* read. This may differ from cbToRead when the
* end of the stream is encountered.
*/
DECLCALLBACKMEMBER(int, pfnRead)(void *pvUser, uint64_t offStream, void *pvBuf, size_t cbToRead, size_t *pcbRead);
/**
* Seeks in the stream.
*
* @returns VBox status code.
* @retval VERR_NOT_SUPPORTED if the stream doesn't support this action.
*
* @param pvUser The user argument.
* @param offSeek The seek offset.
* @param uMethod RTFILE_SEEK_BEGIN, RTFILE_SEEK_END or
* RTFILE_SEEK_CURRENT.
* @param poffActual Where to store the new file position. Optional.
*/
DECLCALLBACKMEMBER(int, pfnSeek)(void *pvUser, int64_t offSeek, unsigned uMethod, uint64_t *poffActual);
/**
* Get the current stream position.
*
* @returns The correct stream position.
* @param pvUser The user argument.
*/
/**
*
* @returns VBox status code.
* @retval VERR_NOT_SUPPORTED if the stream doesn't support this action.
*
* @param pvUser The user argument.
*/
/**
* Close the stream.
*
* @returns VBox status code.
* @param pvUser The user argument.
*/
/** Struct magic + version (SSMSTRMOPS_VERSION). */
} SSMSTRMOPS;
/** Struct magic + version (SSMSTRMOPS_VERSION). */
VMMR3DECL(int) SSMR3RegisterDevice(PVM pVM, PPDMDEVINS pDevIns, const char *pszName, uint32_t uInstance, uint32_t uVersion, size_t cbGuess, const char *pszBefore,
VMMR3DECL(int) SSMR3RegisterDriver(PVM pVM, PPDMDRVINS pDrvIns, const char *pszName, uint32_t uInstance, uint32_t uVersion, size_t cbGuess,
VMMR3DECL(int) SSMR3RegisterInternal(PVM pVM, const char *pszName, uint32_t uInstance, uint32_t uVersion, size_t cbGuess,
VMMR3DECL(int) SSMR3RegisterExternal(PVM pVM, const char *pszName, uint32_t uInstance, uint32_t uVersion, size_t cbGuess,
PFNSSMEXTLOADPREP pfnLoadPrep, PFNSSMEXTLOADEXEC pfnLoadExec, PFNSSMEXTLOADDONE pfnLoadDone, void *pvUser);
VMMR3_INT_DECL(int) SSMR3DeregisterDevice(PVM pVM, PPDMDEVINS pDevIns, const char *pszName, uint32_t uInstance);
VMMR3_INT_DECL(int) SSMR3DeregisterDriver(PVM pVM, PPDMDRVINS pDrvIns, const char *pszName, uint32_t uInstance);
VMMR3DECL(int) SSMR3Save(PVM pVM, const char *pszFilename, SSMAFTER enmAfter, PFNVMPROGRESS pfnProgress, void *pvUser);
VMMR3_INT_DECL(int) SSMR3LiveSave(PVM pVM, const char *pszFilename, PCSSMSTRMOPS pStreamOps, void *pvStreamOps,
VMMR3DECL(int) SSMR3Load(PVM pVM, const char *pszFilename, PCSSMSTRMOPS pStreamOps, void *pvStreamOpsUser,
VMMR3DECL(int) SSMR3Seek(PSSMHANDLE pSSM, const char *pszUnit, uint32_t iInstance, uint32_t *piVersion);
/** Save operations.
* @{
*/
/** @} */
/** Load operations.
* @{
*/
/** @} */
/** @} */
#endif /* IN_RING3 */
/** @} */
#endif