VMMInternal.h revision 590912f31b9cb162cc45569736a9d08763e4c47b
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync/* $Id$ */
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync/** @file
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * VMM - Internal header file.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync */
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync
e64031e20c39650a7bc902a3e1aba613b9415deevboxsync/*
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * Copyright (C) 2006-2012 Oracle Corporation
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync *
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * available from http://www.virtualbox.org. This file is free software;
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * you can redistribute it and/or modify it under the terms of the GNU
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * General Public License (GPL) as published by the Free Software
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync */
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync#ifndef ___VMMInternal_h
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync#define ___VMMInternal_h
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync#include <VBox/cdefs.h>
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync#include <VBox/sup.h>
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync#include <VBox/vmm/stam.h>
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync#include <VBox/vmm/vmm.h>
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync#include <VBox/log.h>
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync#include <iprt/critsect.h>
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync#if !defined(IN_VMM_R3) && !defined(IN_VMM_R0) && !defined(IN_VMM_RC)
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync# error "Not in VMM! This is an internal header!"
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync#endif
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync/** @defgroup grp_vmm_int Internals
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync * @ingroup grp_vmm
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync * @internal
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * @{
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync */
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync/** @def VBOX_WITH_RC_RELEASE_LOGGING
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * Enables RC release logging. */
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync#define VBOX_WITH_RC_RELEASE_LOGGING
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync/** @def VBOX_WITH_R0_LOGGING
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * Enables Ring-0 logging (non-release).
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync *
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * Ring-0 logging isn't 100% safe yet (thread id reuse / process exit cleanup),
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * so you have to sign up here by adding your defined(DEBUG_<userid>) to the
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * #if, or by adding VBOX_WITH_R0_LOGGING to your LocalConfig.kmk.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync */
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync#if defined(DEBUG_sandervl) || defined(DEBUG_frank) || defined(DEBUG_ramshankar) || defined(DOXYGEN_RUNNING)
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync# define VBOX_WITH_R0_LOGGING
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync#endif
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync/** @def VBOX_STRICT_VMM_STACK
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * Enables VMM stack guard pages to catch stack over- and underruns. */
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync#if defined(VBOX_STRICT) || defined(DOXYGEN_RUNNING)
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync# define VBOX_STRICT_VMM_STACK
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync#endif
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync/**
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * Converts a VMM pointer into a VM pointer.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * @returns Pointer to the VM structure the VMM is part of.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * @param pVMM Pointer to VMM instance data.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync */
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync#define VMM2VM(pVMM) ( (PVM)((char*)pVMM - pVMM->offVM) )
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync/**
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * Switcher function, HC to RC.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync *
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync * @param pVM Pointer to the VM.
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync * @returns Return code indicating the action to take.
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync */
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsynctypedef DECLASMTYPE(int) FNVMMSWITCHERHC(PVM pVM);
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync/** Pointer to switcher function. */
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsynctypedef FNVMMSWITCHERHC *PFNVMMSWITCHERHC;
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync/**
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync * Switcher function, RC to HC.
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync *
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync * @param rc VBox status code.
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync */
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsynctypedef DECLASMTYPE(void) FNVMMSWITCHERRC(int rc);
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync/** Pointer to switcher function. */
54c3620994786a33db473956c4e6c3c7d94ab695vboxsynctypedef FNVMMSWITCHERRC *PFNVMMSWITCHERRC;
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync/**
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync * The ring-0 logger instance wrapper.
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync *
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync * We need to be able to find the VM handle from the logger instance, so we wrap
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * it in this structure.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync */
54c3620994786a33db473956c4e6c3c7d94ab695vboxsynctypedef struct VMMR0LOGGER
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync{
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync /** Pointer to Pointer to the VM. */
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync R0PTRTYPE(PVM) pVM;
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync /** Size of the allocated logger instance (Logger). */
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync uint32_t cbLogger;
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync /** Flag indicating whether we've create the logger Ring-0 instance yet. */
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync bool fCreated;
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync /** Flag indicating whether we've disabled flushing (world switch) or not. */
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync bool fFlushingDisabled;
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync /** Flag indicating whether we've registered the instance already. */
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync bool fRegistered;
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync bool a8Alignment;
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync /** The CPU ID. */
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync VMCPUID idCpu;
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync#if HC_ARCH_BITS == 64
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync uint32_t u32Alignment;
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync#endif
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync /** The ring-0 logger instance. This extends beyond the size. */
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync RTLOGGER Logger;
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync} VMMR0LOGGER;
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync/** Pointer to a ring-0 logger instance wrapper. */
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsynctypedef VMMR0LOGGER *PVMMR0LOGGER;
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync/**
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * Jump buffer for the setjmp/longjmp like constructs used to
8fa59d6e8a7241b88e10a611d883318d157317cfvboxsync * quickly 'call' back into Ring-3.
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync */
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsynctypedef struct VMMR0JMPBUF
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync{
8fa59d6e8a7241b88e10a611d883318d157317cfvboxsync /** Traditional jmp_buf stuff
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync * @{ */
8fa59d6e8a7241b88e10a611d883318d157317cfvboxsync#if HC_ARCH_BITS == 32
8fa59d6e8a7241b88e10a611d883318d157317cfvboxsync uint32_t ebx;
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync uint32_t esi;
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync uint32_t edi;
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync uint32_t ebp;
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync uint32_t esp;
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync uint32_t eip;
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync uint32_t eflags;
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync#endif
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync#if HC_ARCH_BITS == 64
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync uint64_t rbx;
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync# ifdef RT_OS_WINDOWS
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync uint64_t rsi;
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync uint64_t rdi;
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync# endif
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync uint64_t rbp;
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync uint64_t r12;
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync uint64_t r13;
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync uint64_t r14;
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync uint64_t r15;
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync uint64_t rsp;
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync uint64_t rip;
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync# ifdef RT_OS_WINDOWS
8fa59d6e8a7241b88e10a611d883318d157317cfvboxsync uint128_t xmm6;
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync uint128_t xmm7;
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync uint128_t xmm8;
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync uint128_t xmm9;
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync uint128_t xmm10;
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync uint128_t xmm11;
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync uint128_t xmm12;
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync uint128_t xmm13;
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync uint128_t xmm14;
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync uint128_t xmm15;
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync# endif
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync uint64_t rflags;
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync#endif
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync /** @} */
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync /** Flag that indicates that we've done a ring-3 call. */
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync bool fInRing3Call;
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync /** The number of bytes we've saved. */
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync uint32_t cbSavedStack;
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync /** Pointer to the buffer used to save the stack.
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync * This is assumed to be 8KB. */
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync RTR0PTR pvSavedStack;
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync /** Esp we we match against esp on resume to make sure the stack wasn't relocated. */
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync RTHCUINTREG SpCheck;
54c3620994786a33db473956c4e6c3c7d94ab695vboxsync /** The esp we should resume execution with after the restore. */
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync RTHCUINTREG SpResume;
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync /** ESP/RSP at the time of the jump to ring 3. */
e470d654059e0c976fe3ce83874ac6e8fd2338a6vboxsync RTHCUINTREG SavedEsp;
/** EBP/RBP at the time of the jump to ring 3. */
RTHCUINTREG SavedEbp;
/** Stats: Max amount of stack used. */
uint32_t cbUsedMax;
/** Stats: Average stack usage. (Avg = cbUsedTotal / cUsedTotal) */
uint32_t cbUsedAvg;
/** Stats: Total amount of stack used. */
uint64_t cbUsedTotal;
/** Stats: Number of stack usages. */
uint64_t cUsedTotal;
} VMMR0JMPBUF;
/** Pointer to a ring-0 jump buffer. */
typedef VMMR0JMPBUF *PVMMR0JMPBUF;
/**
* VMM Data (part of VM)
*/
typedef struct VMM
{
/** Offset to the VM structure.
* See VMM2VM(). */
RTINT offVM;
/** @name World Switcher and Related
* @{
*/
/** Size of the core code. */
RTUINT cbCoreCode;
/** Physical address of core code. */
RTHCPHYS HCPhysCoreCode;
/** Pointer to core code ring-3 mapping - contiguous memory.
* At present this only means the context switcher code. */
RTR3PTR pvCoreCodeR3;
/** Pointer to core code ring-0 mapping - contiguous memory.
* At present this only means the context switcher code. */
RTR0PTR pvCoreCodeR0;
/** Pointer to core code guest context mapping. */
RTRCPTR pvCoreCodeRC;
RTRCPTR pRCPadding0; /**< Alignment padding. */
#ifdef VBOX_WITH_NMI
/** The guest context address of the APIC (host) mapping. */
RTRCPTR GCPtrApicBase;
RTRCPTR pRCPadding1; /**< Alignment padding. */
#endif
/** The current switcher.
* This will be set before the VMM is fully initialized. */
VMMSWITCHER enmSwitcher;
/** Array of offsets to the different switchers within the core code. */
uint32_t aoffSwitchers[VMMSWITCHER_MAX];
uint32_t u32Padding2; /**< Alignment padding. */
/** Resume Guest Execution. See CPUMGCResumeGuest(). */
RTRCPTR pfnCPUMRCResumeGuest;
/** Resume Guest Execution in V86 mode. See CPUMGCResumeGuestV86(). */
RTRCPTR pfnCPUMRCResumeGuestV86;
/** Call Trampoline. See vmmGCCallTrampoline(). */
RTRCPTR pfnCallTrampolineRC;
/** Guest to host switcher entry point. */
RCPTRTYPE(PFNVMMSWITCHERRC) pfnRCToHost;
/** Host to guest switcher entry point. */
R0PTRTYPE(PFNVMMSWITCHERHC) pfnR0ToRawMode;
/** @} */
/** @name Logging
* @{
*/
/** Size of the allocated logger instance (pRCLoggerRC/pRCLoggerR3). */
uint32_t cbRCLogger;
/** Pointer to the RC logger instance - RC Ptr.
* This is NULL if logging is disabled. */
RCPTRTYPE(PRTLOGGERRC) pRCLoggerRC;
/** Pointer to the GC logger instance - R3 Ptr.
* This is NULL if logging is disabled. */
R3PTRTYPE(PRTLOGGERRC) pRCLoggerR3;
/** Pointer to the GC release logger instance - R3 Ptr. */
R3PTRTYPE(PRTLOGGERRC) pRCRelLoggerR3;
/** Pointer to the GC release logger instance - RC Ptr. */
RCPTRTYPE(PRTLOGGERRC) pRCRelLoggerRC;
/** Size of the allocated release logger instance (pRCRelLoggerRC/pRCRelLoggerR3).
* This may differ from cbRCLogger. */
uint32_t cbRCRelLogger;
/** Whether log flushing has been disabled or not. */
bool fRCLoggerFlushingDisabled;
bool afAlignment[5]; /**< Alignment padding. */
/** @} */
/** Whether the stack guard pages have been stationed or not. */
bool fStackGuardsStationed;
/** Whether we should use the periodic preemption timers. */
bool fUsePeriodicPreemptionTimers;
/** The EMT yield timer. */
PTMTIMERR3 pYieldTimer;
/** The period to the next timeout when suspended or stopped.
* This is 0 when running. */
uint32_t cYieldResumeMillies;
/** The EMT yield timer interval (milliseconds). */
uint32_t cYieldEveryMillies;
/** The timestamp of the previous yield. (nano) */
uint64_t u64LastYield;
/** @name EMT Rendezvous
* @{ */
/** Semaphore to wait on upon entering ordered execution. */
R3PTRTYPE(PRTSEMEVENT) pahEvtRendezvousEnterOrdered;
/** Semaphore to wait on upon entering for one-by-one execution. */
RTSEMEVENT hEvtRendezvousEnterOneByOne;
/** Semaphore to wait on upon entering for all-at-once execution. */
RTSEMEVENTMULTI hEvtMulRendezvousEnterAllAtOnce;
/** Semaphore to wait on when done. */
RTSEMEVENTMULTI hEvtMulRendezvousDone;
/** Semaphore the VMMR3EmtRendezvous caller waits on at the end. */
RTSEMEVENT hEvtRendezvousDoneCaller;
/** Callback. */
R3PTRTYPE(PFNVMMEMTRENDEZVOUS) volatile pfnRendezvous;
/** The user argument for the callback. */
RTR3PTR volatile pvRendezvousUser;
/** Flags. */
volatile uint32_t fRendezvousFlags;
/** The number of EMTs that has entered. */
volatile uint32_t cRendezvousEmtsEntered;
/** The number of EMTs that has done their job. */
volatile uint32_t cRendezvousEmtsDone;
/** The number of EMTs that has returned. */
volatile uint32_t cRendezvousEmtsReturned;
/** The status code. */
volatile int32_t i32RendezvousStatus;
/** Spin lock. */
volatile uint32_t u32RendezvousLock;
/** @} */
#if HC_ARCH_BITS == 32
uint32_t u32Alignment; /**< Alignment padding. */
#endif
/** Buffer for storing the standard assertion message for a ring-0 assertion.
* Used for saving the assertion message text for the release log and guru
* meditation dump. */
char szRing0AssertMsg1[512];
/** Buffer for storing the custom message for a ring-0 assertion. */
char szRing0AssertMsg2[256];
/** Number of VMMR0_DO_RUN_GC calls. */
STAMCOUNTER StatRunRC;
/** Statistics for each of the RC/R0 return codes.
* @{ */
STAMCOUNTER StatRZRetNormal;
STAMCOUNTER StatRZRetInterrupt;
STAMCOUNTER StatRZRetInterruptHyper;
STAMCOUNTER StatRZRetGuestTrap;
STAMCOUNTER StatRZRetRingSwitch;
STAMCOUNTER StatRZRetRingSwitchInt;
STAMCOUNTER StatRZRetStaleSelector;
STAMCOUNTER StatRZRetIRETTrap;
STAMCOUNTER StatRZRetEmulate;
STAMCOUNTER StatRZRetIOBlockEmulate;
STAMCOUNTER StatRZRetPatchEmulate;
STAMCOUNTER StatRZRetIORead;
STAMCOUNTER StatRZRetIOWrite;
STAMCOUNTER StatRZRetMMIORead;
STAMCOUNTER StatRZRetMMIOWrite;
STAMCOUNTER StatRZRetMMIOPatchRead;
STAMCOUNTER StatRZRetMMIOPatchWrite;
STAMCOUNTER StatRZRetMMIOReadWrite;
STAMCOUNTER StatRZRetLDTFault;
STAMCOUNTER StatRZRetGDTFault;
STAMCOUNTER StatRZRetIDTFault;
STAMCOUNTER StatRZRetTSSFault;
STAMCOUNTER StatRZRetPDFault;
STAMCOUNTER StatRZRetCSAMTask;
STAMCOUNTER StatRZRetSyncCR3;
STAMCOUNTER StatRZRetMisc;
STAMCOUNTER StatRZRetPatchInt3;
STAMCOUNTER StatRZRetPatchPF;
STAMCOUNTER StatRZRetPatchGP;
STAMCOUNTER StatRZRetPatchIretIRQ;
STAMCOUNTER StatRZRetRescheduleREM;
STAMCOUNTER StatRZRetToR3;
STAMCOUNTER StatRZRetToR3Unknown;
STAMCOUNTER StatRZRetToR3TMVirt;
STAMCOUNTER StatRZRetToR3HandyPages;
STAMCOUNTER StatRZRetToR3PDMQueues;
STAMCOUNTER StatRZRetToR3Rendezvous;
STAMCOUNTER StatRZRetToR3Timer;
STAMCOUNTER StatRZRetToR3DMA;
STAMCOUNTER StatRZRetToR3CritSect;
STAMCOUNTER StatRZRetTimerPending;
STAMCOUNTER StatRZRetInterruptPending;
STAMCOUNTER StatRZRetCallRing3;
STAMCOUNTER StatRZRetPATMDuplicateFn;
STAMCOUNTER StatRZRetPGMChangeMode;
STAMCOUNTER StatRZRetPendingRequest;
STAMCOUNTER StatRZRetPGMFlushPending;
STAMCOUNTER StatRZRetPatchTPR;
STAMCOUNTER StatRZCallPDMCritSectEnter;
STAMCOUNTER StatRZCallPDMLock;
STAMCOUNTER StatRZCallLogFlush;
STAMCOUNTER StatRZCallPGMPoolGrow;
STAMCOUNTER StatRZCallPGMMapChunk;
STAMCOUNTER StatRZCallPGMAllocHandy;
STAMCOUNTER StatRZCallRemReplay;
STAMCOUNTER StatRZCallVMSetError;
STAMCOUNTER StatRZCallVMSetRuntimeError;
STAMCOUNTER StatRZCallPGMLock;
/** @} */
} VMM;
/** Pointer to VMM. */
typedef VMM *PVMM;
/**
* VMMCPU Data (part of VMCPU)
*/
typedef struct VMMCPU
{
/** Offset to the VMCPU structure.
* See VMM2VMCPU(). */
int32_t offVMCPU;
/** The last RC/R0 return code. */
int32_t iLastGZRc;
/** VMM stack, pointer to the top of the stack in R3.
* Stack is allocated from the hypervisor heap and is page aligned
* and always writable in RC. */
R3PTRTYPE(uint8_t *) pbEMTStackR3;
/** Pointer to the bottom of the stack - needed for doing relocations. */
RCPTRTYPE(uint8_t *) pbEMTStackRC;
/** Pointer to the bottom of the stack - needed for doing relocations. */
RCPTRTYPE(uint8_t *) pbEMTStackBottomRC;
/** Pointer to the R0 logger instance - R3 Ptr.
* This is NULL if logging is disabled. */
R3PTRTYPE(PVMMR0LOGGER) pR0LoggerR3;
/** Pointer to the R0 logger instance - R0 Ptr.
* This is NULL if logging is disabled. */
R0PTRTYPE(PVMMR0LOGGER) pR0LoggerR0;
/** @name Thread-context hooks.
* @{*/
R0PTRTYPE(RTTHREADCTX) hR0ThreadCtx;
#if HC_ARCH_BITS == 32
uint32_t u32Padding;
#else
uint64_t u64Padding;
#endif
/** @} */
/** @name Rendezvous
* @{ */
/** Whether the EMT is executing a rendezvous right now. For detecting
* attempts at recursive rendezvous. */
bool volatile fInRendezvous;
bool afPadding[HC_ARCH_BITS == 32 ? 3 : 7];
/** @} */
/** @name Raw-mode context tracting data.
* @{ */
SUPDRVTRACERUSRCTX TracerCtx;
/** @} */
/** Alignment padding, making sure u64CallRing3Arg is nicely aligned. */
uint32_t au32Padding1[3];
/** @name Call Ring-3
* Formerly known as host calls.
* @{ */
/** The disable counter. */
uint32_t cCallRing3Disabled;
/** The pending operation. */
VMMCALLRING3 enmCallRing3Operation;
/** The result of the last operation. */
int32_t rcCallRing3;
/** The argument to the operation. */
uint64_t u64CallRing3Arg;
/** The Ring-0 notification callback. */
R0PTRTYPE(PFNVMMR0CALLRING3NOTIFICATION) pfnCallRing3CallbackR0;
/** The Ring-0 notification callback user argument. */
R0PTRTYPE(void *) pvCallRing3CallbackUserR0;
/** The Ring-0 jmp buffer.
* @remarks The size of this type isn't stable in assembly, so don't put
* anything that needs to be accessed from assembly after it. */
VMMR0JMPBUF CallRing3JmpBufR0;
/** @} */
} VMMCPU;
AssertCompileMemberAlignment(VMMCPU, TracerCtx, 8);
/** Pointer to VMMCPU. */
typedef VMMCPU *PVMMCPU;
/**
* The VMMGCEntry() codes.
*/
typedef enum VMMGCOPERATION
{
/** Do GC module init. */
VMMGC_DO_VMMGC_INIT = 1,
/** The first Trap testcase. */
VMMGC_DO_TESTCASE_TRAP_FIRST = 0x0dead000,
/** Trap 0 testcases, uArg selects the variation. */
VMMGC_DO_TESTCASE_TRAP_0 = VMMGC_DO_TESTCASE_TRAP_FIRST,
/** Trap 1 testcases, uArg selects the variation. */
VMMGC_DO_TESTCASE_TRAP_1,
/** Trap 2 testcases, uArg selects the variation. */
VMMGC_DO_TESTCASE_TRAP_2,
/** Trap 3 testcases, uArg selects the variation. */
VMMGC_DO_TESTCASE_TRAP_3,
/** Trap 4 testcases, uArg selects the variation. */
VMMGC_DO_TESTCASE_TRAP_4,
/** Trap 5 testcases, uArg selects the variation. */
VMMGC_DO_TESTCASE_TRAP_5,
/** Trap 6 testcases, uArg selects the variation. */
VMMGC_DO_TESTCASE_TRAP_6,
/** Trap 7 testcases, uArg selects the variation. */
VMMGC_DO_TESTCASE_TRAP_7,
/** Trap 8 testcases, uArg selects the variation. */
VMMGC_DO_TESTCASE_TRAP_8,
/** Trap 9 testcases, uArg selects the variation. */
VMMGC_DO_TESTCASE_TRAP_9,
/** Trap 0a testcases, uArg selects the variation. */
VMMGC_DO_TESTCASE_TRAP_0A,
/** Trap 0b testcases, uArg selects the variation. */
VMMGC_DO_TESTCASE_TRAP_0B,
/** Trap 0c testcases, uArg selects the variation. */
VMMGC_DO_TESTCASE_TRAP_0C,
/** Trap 0d testcases, uArg selects the variation. */
VMMGC_DO_TESTCASE_TRAP_0D,
/** Trap 0e testcases, uArg selects the variation. */
VMMGC_DO_TESTCASE_TRAP_0E,
/** The last trap testcase (exclusive). */
VMMGC_DO_TESTCASE_TRAP_LAST,
/** Testcase for checking interrupt forwarding. */
VMMGC_DO_TESTCASE_HYPER_INTERRUPT,
/** Switching testing and profiling stub. */
VMMGC_DO_TESTCASE_NOP,
/** Testcase for checking interrupt masking.. */
VMMGC_DO_TESTCASE_INTERRUPT_MASKING,
/** Switching testing and profiling stub. */
VMMGC_DO_TESTCASE_HM_NOP,
/** The usual 32-bit hack. */
VMMGC_DO_32_BIT_HACK = 0x7fffffff
} VMMGCOPERATION;
RT_C_DECLS_BEGIN
int vmmInitFormatTypes(void);
void vmmTermFormatTypes(void);
uint32_t vmmGetBuildType(void);
#ifdef IN_RING3
int vmmR3SwitcherInit(PVM pVM);
void vmmR3SwitcherRelocate(PVM pVM, RTGCINTPTR offDelta);
#endif /* IN_RING3 */
#ifdef IN_RING0
/**
* World switcher assembly routine.
* It will call VMMGCEntry().
*
* @returns return code from VMMGCEntry().
* @param pVM Pointer to the VM.
* @param uArg See VMMGCEntry().
* @internal
*/
DECLASM(int) vmmR0WorldSwitch(PVM pVM, unsigned uArg);
/**
* Callback function for vmmR0CallRing3SetJmp.
*
* @returns VBox status code.
* @param pVM Pointer to the VM.
*/
typedef DECLCALLBACK(int) FNVMMR0SETJMP(PVM pVM, PVMCPU pVCpu);
/** Pointer to FNVMMR0SETJMP(). */
typedef FNVMMR0SETJMP *PFNVMMR0SETJMP;
/**
* The setjmp variant used for calling Ring-3.
*
* This differs from the normal setjmp in that it will resume VMMRZCallRing3 if we're
* in the middle of a ring-3 call. Another differences is the function pointer and
* argument. This has to do with resuming code and the stack frame of the caller.
*
* @returns VINF_SUCCESS on success or whatever is passed to vmmR0CallRing3LongJmp.
* @param pJmpBuf The jmp_buf to set.
* @param pfn The function to be called when not resuming..
* @param pVM The argument of that function.
*/
DECLASM(int) vmmR0CallRing3SetJmp(PVMMR0JMPBUF pJmpBuf, PFNVMMR0SETJMP pfn, PVM pVM, PVMCPU pVCpu);
/**
* Callback function for vmmR0CallRing3SetJmpEx.
*
* @returns VBox status code.
* @param pvUser The user argument.
*/
typedef DECLCALLBACK(int) FNVMMR0SETJMPEX(void *pvUser);
/** Pointer to FNVMMR0SETJMP(). */
typedef FNVMMR0SETJMPEX *PFNVMMR0SETJMPEX;
/**
* Same as vmmR0CallRing3SetJmp except for the function signature.
*
* @returns VINF_SUCCESS on success or whatever is passed to vmmR0CallRing3LongJmp.
* @param pJmpBuf The jmp_buf to set.
* @param pfn The function to be called when not resuming..
* @param pvUser The argument of that function.
*/
DECLASM(int) vmmR0CallRing3SetJmpEx(PVMMR0JMPBUF pJmpBuf, PFNVMMR0SETJMPEX pfn, void *pvUser);
/**
* Worker for VMMRZCallRing3.
* This will save the stack and registers.
*
* @returns rc.
* @param pJmpBuf Pointer to the jump buffer.
* @param rc The return code.
*/
DECLASM(int) vmmR0CallRing3LongJmp(PVMMR0JMPBUF pJmpBuf, int rc);
/**
* Internal R0 logger worker: Logger wrapper.
*/
VMMR0DECL(void) vmmR0LoggerWrapper(const char *pszFormat, ...);
/**
* Internal R0 logger worker: Flush logger.
*
* @param pLogger The logger instance to flush.
* @remark This function must be exported!
*/
VMMR0DECL(void) vmmR0LoggerFlush(PRTLOGGER pLogger);
/**
* Internal R0 logger worker: Custom prefix.
*
* @returns Number of chars written.
*
* @param pLogger The logger instance.
* @param pchBuf The output buffer.
* @param cchBuf The size of the buffer.
* @param pvUser User argument (ignored).
*/
VMMR0DECL(size_t) vmmR0LoggerPrefix(PRTLOGGER pLogger, char *pchBuf, size_t cchBuf, void *pvUser);
# ifdef VBOX_WITH_TRIPLE_FAULT_HACK
int vmmR0TripleFaultHackInit(void);
void vmmR0TripleFaultHackTerm(void);
# endif
#endif /* IN_RING0 */
#ifdef IN_RC
/**
* Internal GC logger worker: Logger wrapper.
*/
VMMRCDECL(void) vmmGCLoggerWrapper(const char *pszFormat, ...);
/**
* Internal GC release logger worker: Logger wrapper.
*/
VMMRCDECL(void) vmmGCRelLoggerWrapper(const char *pszFormat, ...);
/**
* Internal GC logger worker: Flush logger.
*
* @returns VINF_SUCCESS.
* @param pLogger The logger instance to flush.
* @remark This function must be exported!
*/
VMMRCDECL(int) vmmGCLoggerFlush(PRTLOGGERRC pLogger);
/** @name Trap testcases and related labels.
* @{ */
DECLASM(void) vmmGCEnableWP(void);
DECLASM(void) vmmGCDisableWP(void);
DECLASM(int) vmmGCTestTrap3(void);
DECLASM(int) vmmGCTestTrap8(void);
DECLASM(int) vmmGCTestTrap0d(void);
DECLASM(int) vmmGCTestTrap0e(void);
DECLASM(int) vmmGCTestTrap0e_FaultEIP(void); /**< a label */
DECLASM(int) vmmGCTestTrap0e_ResumeEIP(void); /**< a label */
/** @} */
#endif /* IN_RC */
RT_C_DECLS_END
/** @} */
#endif