VMInternal.h revision 17ba03925269c071aa1567eb8c5a49c37a65f62f
/* $Id$ */
/** @file
* VM - Internal header file.
*/
/*
* Copyright (C) 2006-2007 innotek GmbH
*
* 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 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.
*
* If you received this file as part of a commercial VirtualBox
* distribution, then only the terms of your commercial VirtualBox
* license agreement apply instead of the previous paragraph.
*/
#ifndef ___VMInternal_h
#define ___VMInternal_h
#include <setjmp.h>
# error "Not in VM! This is an internal header!"
#endif
/** @defgroup grp_vm_int Internals
* @ingroup grp_vm
* @internal
* @{
*/
/**
* At-reset callback type.
*/
typedef enum VMATRESETTYPE
{
/** Device callback. */
VMATRESETTYPE_DEV = 1,
/** Internal callback . */
/** External callback. */
/** Pointer to at-reset callback. */
typedef struct VMATRESET *PVMATRESET;
/**
* At reset callback.
*/
typedef struct VMATRESET
{
/** Pointer to the next one in the list. */
/** Callback type. */
/** User argument for the callback. */
void *pvUser;
/** Description. */
const char *pszDesc;
/** Type specific data. */
union
{
/** VMATRESETTYPE_DEV. */
struct
{
/** Callback. */
/** Device instance. */
} Dev;
/** VMATRESETTYPE_INTERNAL. */
struct
{
/** Callback. */
} Internal;
/** VMATRESETTYPE_EXTERNAL. */
struct
{
/** Callback. */
} External;
} u;
} VMATRESET;
/**
* VM state change callback.
*/
typedef struct VMATSTATE
{
/** Pointer to the next one. */
/** Pointer to the callback. */
/** The user argument. */
void *pvUser;
} VMATSTATE;
/** Pointer to a VM state change callback. */
typedef VMATSTATE *PVMATSTATE;
/**
* VM error callback.
*/
typedef struct VMATERROR
{
/** Pointer to the next one. */
/** Pointer to the callback. */
/** The user argument. */
void *pvUser;
} VMATERROR;
/** Pointer to a VM error callback. */
typedef VMATERROR *PVMATERROR;
/**
* Chunk of memory allocated off the hypervisor heap in which
* we copy the error details.
*/
typedef struct VMERROR
{
/** The size of the chunk. */
/** The current offset into the chunk.
* We start by putting the filename and function immediatly
* after the end of the buffer. */
/** Offset from the start of this structure to the file name. */
/** The line number. */
/** Offset from the start of this structure to the function name. */
/** Offset from the start of this structure to the formatted message text. */
/** The VBox status code. */
/**
* VM runtime error callback.
*/
typedef struct VMATRUNTIMEERROR
{
/** Pointer to the next one. */
struct VMATRUNTIMEERROR *pNext;
/** Pointer to the callback. */
/** The user argument. */
void *pvUser;
/** Pointer to a VM error callback. */
typedef VMATRUNTIMEERROR *PVMATRUNTIMEERROR;
/**
* Chunk of memory allocated off the hypervisor heap in which
* we copy the runtime error details.
*/
typedef struct VMRUNTIMEERROR
{
/** The size of the chunk. */
/** The current offset into the chunk.
* We start by putting the error ID immediatly
* after the end of the buffer. */
/** Offset from the start of this structure to the error ID. */
/** Offset from the start of this structure to the formatted message text. */
/** Whether the error is fatal or not */
bool fFatal;
/** The halt method. */
typedef enum
{
/** The usual invalid value. */
VMHALTMETHOD_INVALID = 0,
/** Use the default method. */
/** The end of valid methods. (not inclusive of course) */
/** The usual 32-bit max value. */
VMHALTMETHOD_32BIT_HACK = 0x7fffffff
} VMHALTMETHOD;
/**
* Converts a VMM pointer into a VM pointer.
* @returns Pointer to the VM structure the VMM is part of.
* @param pVMM Pointer to VMM instance data.
*/
/**
* VM Internal Data (part of VM)
*/
typedef struct VMINT
{
/** Offset to the VM structure.
* See VMINT2VM(). */
/** List of registered reset callbacks. */
/** List of registered reset callbacks. */
/** List of registered state change callbacks. */
/** List of registered state change callbacks. */
/** List of registered error callbacks. */
/** List of registered error callbacks. */
/** List of registered error callbacks. */
/** List of registered error callbacks. */
/** Head of the request queue. Atomic. */
/** Array of pointers to lists of free request packets. Atomic. */
/** Number of free request packets. */
/** Wait event semaphore. */
/** VM Error Message. */
/** VM Runtime Error Message. */
/** Pointer to the DBGC instance data. */
/** If set the EMT does the final VM cleanup when it exits.
* If clear the VMR3Destroy() caller does so. */
bool fEMTDoesTheCleanup;
/** Set by VMR3SuspendNoSave; cleared by VMR3Resume; signals the VM is in an inconsistent state and saving is not allowed. */
bool fPreventSaveState;
/** vmR3EmulationThread longjmp buffer
* @todo r=bird: requires union with padding. See EMInternal.h. */
/** @name Generic Halt data
* @{
*/
/** The current halt method.
* Can be selected by CFGM option 'VM/HaltMethod'. */
/** The index into g_aHaltMethods of the current halt method. */
uint32_t volatile iHaltMethod;
/** The average time (ns) between two halts in the last second. (updated once per second) */
/** The average halt frequency for the last second. (updated once per second) */
/** The number of halts in the current period. */
/** When we started counting halts in cHalts (RTTimeNanoTS). */
/** @} */
/** Union containing data and config for the different halt algorithms. */
union
{
/**
* Method 1 & 2 - Block whenever possible, and when lagging behind
* switch to spinning with regular blocking every 5-200ms (defaults)
* depending on the accumulated lag. The blocking interval is adjusted
* with the average oversleeping of the last 64 times.
*
* The difference between 1 and 2 is that we use native absolute
* time APIs for the blocking instead of the millisecond based IPRT
* interface.
*/
struct
{
/** How many times we've blocked while cBlockedNS and cBlockedTooLongNS has been accumulating. */
/** Avg. time spend oversleeping when blocking. (Re-calculated every so often.) */
/** Total time spend oversleeping when blocking. */
/** Total time spent blocking. */
/** The timestamp (RTTimeNanoTS) of the last block. */
/** When we started spinning relentlessly in order to catch up some of the oversleeping.
* This is 0 when we're not spinning. */
/** The max interval without blocking (when spinning). */
/** The minimum interval between blocking (when spinning). */
/** The value to divide the current lag by to get the raw blocking interval (when spinning). */
/** When to start spinning (lag / nano secs). */
/** When to stop spinning (lag / nano secs). */
} Method12;
#if 0
/**
* Method 3 & 4 - Same as method 1 & 2 respectivly, except that we
* sprinkle it with yields.
*/
struct
{
/** How many times we've blocked while cBlockedNS and cBlockedTooLongNS has been accumulating. */
/** Avg. time spend oversleeping when blocking. (Re-calculated every so often.) */
/** Total time spend oversleeping when blocking. */
/** Total time spent blocking. */
/** The timestamp (RTTimeNanoTS) of the last block. */
/** How many times we've yielded while cBlockedNS and cBlockedTooLongNS has been accumulating. */
/** Avg. time spend oversleeping when yielding. */
/** Total time spend oversleeping when yielding. */
/** Total time spent yielding. */
/** The timestamp (RTTimeNanoTS) of the last block. */
/** When we started spinning relentlessly in order to catch up some of the oversleeping. */
} Method34;
#endif
} Halt;
/** @} */
/** Number of VMR3ReqAlloc returning a new packet. */
/** Number of VMR3ReqAlloc causing races. */
/** Number of VMR3ReqAlloc returning a recycled packet. */
/** Number of VMR3ReqFree calls. */
/** Number of times the request was actually freed. */
/** Profiling the halted state; yielding vs blocking. */
/**
* Emulation thread arguments.
*/
typedef struct VMEMULATIONTHREADARGS
{
/** Pointer to the VM structure. */
/** Pointer to the emulation thread arguments. */
typedef VMEMULATIONTHREADARGS *PVMEMULATIONTHREADARGS;
DECLCALLBACK(void) vmR3SetErrorV(PVM pVM, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list *args);
DECLCALLBACK(void) vmR3SetRuntimeErrorV(PVM pVM, bool fFatal, const char *pszErrorID, const char *pszFormat, va_list *args);
void vmSetRuntimeErrorCopy(PVM pVM, bool fFatal, const char *pszErrorID, const char *pszFormat, va_list args);
/** @} */
#endif