VirtualBox

source: vbox/trunk/include/VBox/vm.h@ 19420

Last change on this file since 19420 was 19420, checked in by vboxsync, 16 years ago

Action flag updates

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 30.8 KB
Line 
1/** @file
2 * VM - The Virtual Machine, data.
3 */
4
5/*
6 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 *
25 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
26 * Clara, CA 95054 USA or visit http://www.sun.com if you need
27 * additional information or have any questions.
28 */
29
30#ifndef ___VBox_vm_h
31#define ___VBox_vm_h
32
33#include <VBox/cdefs.h>
34#include <VBox/types.h>
35#include <VBox/cpum.h>
36#include <VBox/stam.h>
37#include <VBox/vmapi.h>
38#include <VBox/sup.h>
39#include <VBox/vmm.h>
40
41
42/** @defgroup grp_vm The Virtual Machine
43 * @{
44 */
45
46/**
47 * The state of a virtual CPU.
48 *
49 * The VM running states are a sub-states of the VMSTATE_RUNNING state. While
50 * VMCPUSTATE_NOT_RUNNING is a place holder for the other VM states.
51 */
52typedef enum VMCPUSTATE
53{
54 /** The customary invalid zero. */
55 VMCPUSTATE_INVALID = 0,
56
57 /** Running guest code (VM running). */
58 VMCPUSTATE_RUN_EXEC,
59 /** Running guest code in the recompiler (VM running). */
60 VMCPUSTATE_RUN_EXEC_REM,
61 /** Halted (VM running). */
62 VMCPUSTATE_RUN_HALTED,
63 /** All the other bits we do while running a VM (VM running). */
64 VMCPUSTATE_RUN_MISC,
65 /** VM not running, we're servicing requests or whatever. */
66 VMCPUSTATE_NOT_RUNNING,
67 /** The end of valid virtual CPU states. */
68 VMCPUSTATE_END,
69
70 /** Ensure 32-bit type. */
71 VMCPUSTATE_32BIT_HACK = 0x7fffffff
72} VMCPUSTATE;
73
74
75/**
76 * Per virtual CPU data.
77 */
78typedef struct VMCPU
79{
80 /** Per CPU forced action.
81 * See the VMCPU_FF_* \#defines. Updated atomically. */
82 uint32_t volatile fLocalForcedActions;
83 /** The CPU state. */
84 VMCPUSTATE volatile enmState;
85
86 /** Pointer to the ring-3 UVMCPU structure. */
87 PUVMCPU pUVCpu;
88 /** Ring-3 Host Context VM Pointer. */
89 PVMR3 pVMR3;
90 /** Ring-0 Host Context VM Pointer. */
91 PVMR0 pVMR0;
92 /** Raw-mode Context VM Pointer. */
93 PVMRC pVMRC;
94 /** The CPU ID.
95 * This is the index into the VM::aCpu array. */
96 VMCPUID idCpu;
97 /** The native thread handle. */
98 RTNATIVETHREAD hNativeThread;
99
100 /** Align the next bit on a 64-byte boundary.
101 *
102 * @remarks The aligments of the members that are larger than 48 bytes should be
103 * 64-byte for cache line reasons. structs containing small amounts of
104 * data could be lumped together at the end with a < 64 byte padding
105 * following it (to grow into and align the struct size).
106 * */
107 uint32_t au32Alignment[HC_ARCH_BITS == 32 ? 8 : 4];
108
109 /** CPUM part. */
110 union
111 {
112#ifdef ___CPUMInternal_h
113 struct CPUMCPU s;
114#endif
115 char padding[4096]; /* multiple of 64 */
116 } cpum;
117
118 /** PGM part. */
119 union
120 {
121#ifdef ___PGMInternal_h
122 struct PGMCPU s;
123#endif
124 char padding[32*1024]; /* multiple of 64 */
125 } pgm;
126
127 /** HWACCM part. */
128 union
129 {
130#ifdef ___HWACCMInternal_h
131 struct HWACCMCPU s;
132#endif
133 char padding[5120]; /* multiple of 64 */
134 } hwaccm;
135
136 /** EM part. */
137 union
138 {
139#ifdef ___EMInternal_h
140 struct EMCPU s;
141#endif
142 char padding[2048]; /* multiple of 64 */
143 } em;
144
145 /** TRPM part. */
146 union
147 {
148#ifdef ___TRPMInternal_h
149 struct TRPMCPU s;
150#endif
151 char padding[128]; /* multiple of 64 */
152 } trpm;
153
154 /** TM part. */
155 union
156 {
157#ifdef ___TMInternal_h
158 struct TMCPU s;
159#endif
160 char padding[64]; /* multiple of 64 */
161 } tm;
162
163 /** VMM part.
164 * @todo Combine this with other tiny structures. */
165 union
166 {
167#ifdef ___VMMInternal_h
168 struct VMMCPU s;
169#endif
170 char padding[64]; /* multiple of 64 */
171 } vmm;
172
173 /** DBGF part.
174 * @todo Combine this with other tiny structures. */
175 union
176 {
177#ifdef ___DBGFInternal_h
178 struct DBGFCPU s;
179#endif
180 uint8_t padding[64]; /* multiple of 64 */
181 } dbgf;
182
183} VMCPU;
184
185/** Pointer to a VMCPU. */
186#ifndef ___VBox_types_h
187typedef struct VMCPU *PVMCPU;
188#endif
189
190/** The name of the Guest Context VMM Core module. */
191#define VMMGC_MAIN_MODULE_NAME "VMMGC.gc"
192/** The name of the Ring 0 Context VMM Core module. */
193#define VMMR0_MAIN_MODULE_NAME "VMMR0.r0"
194
195/** VM Forced Action Flags.
196 *
197 * Use the VM_FF_SET() and VM_FF_CLEAR() macros to change the force
198 * action mask of a VM.
199 *
200 * @{
201 */
202/** This action forces the VM to schedule and run pending timer (TM). */
203#define VM_FF_TIMER RT_BIT_32(2)
204/** PDM Queues are pending. */
205#define VM_FF_PDM_QUEUES_BIT 3
206#define VM_FF_PDM_QUEUES RT_BIT_32(VM_FF_PDM_QUEUES_BIT)
207/** PDM DMA transfers are pending. */
208#define VM_FF_PDM_DMA_BIT 4
209#define VM_FF_PDM_DMA RT_BIT_32(VM_FF_PDM_DMA_BIT)
210/** PDM critical section unlocking is pending, process promptly upon return to R3. */
211#define VM_FF_PDM_CRITSECT RT_BIT_32(5)
212/** This action forces the VM to call DBGF so DBGF can service debugger
213 * requests in the emulation thread.
214 * This action flag stays asserted till DBGF clears it.*/
215#define VM_FF_DBGF RT_BIT_32(8)
216/** This action forces the VM to service pending requests from other
217 * thread or requests which must be executed in another context. */
218#define VM_FF_REQUEST RT_BIT_32(9)
219/** Terminate the VM immediately. */
220#define VM_FF_TERMINATE RT_BIT_32(10)
221/** Reset the VM. (postponed) */
222#define VM_FF_RESET RT_BIT_32(11)
223/** PGM needs to allocate handy pages. */
224#define VM_FF_PGM_NEED_HANDY_PAGES RT_BIT_32(18)
225/** PGM is out of memory.
226 * Abandon all loops and code paths which can be resumed and get up to the EM
227 * loops. */
228#define VM_FF_PGM_NO_MEMORY RT_BIT_32(19)
229/** REM needs to be informed about handler changes. */
230#define VM_FF_REM_HANDLER_NOTIFY RT_BIT_32(29)
231/** Suspend the VM - debug only. */
232#define VM_FF_DEBUG_SUSPEND RT_BIT_32(31)
233
234
235/** This action forces the VM to service check and pending interrups on the APIC. */
236#define VMCPU_FF_INTERRUPT_APIC RT_BIT_32(0)
237/** This action forces the VM to service check and pending interrups on the PIC. */
238#define VMCPU_FF_INTERRUPT_PIC RT_BIT_32(1)
239/** This action forces the VM to schedule and run pending timer (TM). (bogus for now; needed for PATM backwards compatibility) */
240#define VMCPU_FF_TIMER RT_BIT_32(2)
241/** This action forces the VM to service pending requests from other
242 * thread or requests which must be executed in another context. */
243#define VMCPU_FF_REQUEST RT_BIT_32(9)
244/** This action forces the VM to resync the page tables before going
245 * back to execute guest code. (GLOBAL FLUSH) */
246#define VMCPU_FF_PGM_SYNC_CR3 RT_BIT_32(16)
247/** Same as VM_FF_PGM_SYNC_CR3 except that global pages can be skipped.
248 * (NON-GLOBAL FLUSH) */
249#define VMCPU_FF_PGM_SYNC_CR3_NON_GLOBAL RT_BIT_32(17)
250/** Check the interupt and trap gates */
251#define VMCPU_FF_TRPM_SYNC_IDT RT_BIT_32(20)
252/** Check Guest's TSS ring 0 stack */
253#define VMCPU_FF_SELM_SYNC_TSS RT_BIT_32(21)
254/** Check Guest's GDT table */
255#define VMCPU_FF_SELM_SYNC_GDT RT_BIT_32(22)
256/** Check Guest's LDT table */
257#define VMCPU_FF_SELM_SYNC_LDT RT_BIT_32(23)
258/** Inhibit interrupts pending. See EMGetInhibitInterruptsPC(). */
259#define VMCPU_FF_INHIBIT_INTERRUPTS RT_BIT_32(24)
260/** Check for pending TLB shootdown actions. */
261#define VMCPU_FF_TLB_SHOOTDOWN RT_BIT_32(25)
262/** CSAM needs to scan the page that's being executed */
263#define VMCPU_FF_CSAM_SCAN_PAGE RT_BIT_32(26)
264/** CSAM needs to do some homework. */
265#define VMCPU_FF_CSAM_PENDING_ACTION RT_BIT_32(27)
266/** Force return to Ring-3. */
267#define VMCPU_FF_TO_R3 RT_BIT_32(28)
268
269/** Externally VM forced actions. Used to quit the idle/wait loop. */
270#define VM_FF_EXTERNAL_SUSPENDED_MASK (VM_FF_TERMINATE | VM_FF_DBGF | VM_FF_REQUEST)
271/** Externally VMCPU forced actions. Used to quit the idle/wait loop. */
272#define VMCPU_FF_EXTERNAL_SUSPENDED_MASK (VMCPU_FF_REQUEST)
273
274/** Externally forced VM actions. Used to quit the idle/wait loop. */
275#define VM_FF_EXTERNAL_HALTED_MASK (VM_FF_TERMINATE | VM_FF_DBGF | VM_FF_TIMER | VM_FF_REQUEST | VM_FF_PDM_QUEUES | VM_FF_PDM_DMA)
276/** Externally forced VMCPU actions. Used to quit the idle/wait loop. */
277#define VMCPU_FF_EXTERNAL_HALTED_MASK (VMCPU_FF_INTERRUPT_APIC | VMCPU_FF_INTERRUPT_PIC | VMCPU_FF_REQUEST)
278
279/** High priority VM pre-execution actions. */
280#define VM_FF_HIGH_PRIORITY_PRE_MASK ( VM_FF_TERMINATE | VM_FF_DBGF | VM_FF_TIMER | VM_FF_DEBUG_SUSPEND \
281 | VM_FF_PGM_NEED_HANDY_PAGES | VM_FF_PGM_NO_MEMORY)
282/** High priority VMCPU pre-execution actions. */
283#define VMCPU_FF_HIGH_PRIORITY_PRE_MASK ( VMCPU_FF_INTERRUPT_APIC | VMCPU_FF_INTERRUPT_PIC \
284 | VMCPU_FF_PGM_SYNC_CR3 | VMCPU_FF_PGM_SYNC_CR3_NON_GLOBAL | VMCPU_FF_SELM_SYNC_TSS | VMCPU_FF_TRPM_SYNC_IDT | VMCPU_FF_SELM_SYNC_GDT | VMCPU_FF_SELM_SYNC_LDT)
285
286/** High priority VM pre raw-mode execution mask. */
287#define VM_FF_HIGH_PRIORITY_PRE_RAW_MASK (VM_FF_PGM_NEED_HANDY_PAGES | VM_FF_PGM_NO_MEMORY)
288/** High priority VMCPU pre raw-mode execution mask. */
289#define VMCPU_FF_HIGH_PRIORITY_PRE_RAW_MASK ( VMCPU_FF_PGM_SYNC_CR3 | VMCPU_FF_PGM_SYNC_CR3_NON_GLOBAL | VMCPU_FF_SELM_SYNC_TSS | VMCPU_FF_TRPM_SYNC_IDT | VMCPU_FF_SELM_SYNC_GDT | VMCPU_FF_SELM_SYNC_LDT \
290 | VMCPU_FF_INHIBIT_INTERRUPTS)
291
292/** High priority post-execution actions. */
293#define VM_FF_HIGH_PRIORITY_POST_MASK (VM_FF_PDM_CRITSECT | VM_FF_PGM_NO_MEMORY)
294/** High priority post-execution actions. */
295#define VMCPU_FF_HIGH_PRIORITY_POST_MASK (VMCPU_FF_CSAM_PENDING_ACTION)
296
297/** Normal priority VM post-execution actions. */
298#define VM_FF_NORMAL_PRIORITY_POST_MASK (VM_FF_TERMINATE | VM_FF_DBGF | VM_FF_RESET | VM_FF_PGM_NO_MEMORY)
299/** Normal priority VMCPU post-execution actions. */
300#define VMCPU_FF_NORMAL_PRIORITY_POST_MASK (VMCPU_FF_CSAM_SCAN_PAGE)
301
302/** Normal priority VM actions. */
303#define VM_FF_NORMAL_PRIORITY_MASK (VM_FF_REQUEST | VM_FF_PDM_QUEUES | VM_FF_PDM_DMA | VM_FF_REM_HANDLER_NOTIFY)
304/** Normal priority VMCPU actions. */
305#define VMCPU_FF_NORMAL_PRIORITY_MASK (VMCPU_FF_REQUEST)
306
307/** Flags to clear before resuming guest execution. */
308#define VMCPU_FF_RESUME_GUEST_MASK (VMCPU_FF_TO_R3)
309
310/** VM Flags that cause the HWACCM loops to go back to ring-3. */
311#define VM_FF_HWACCM_TO_R3_MASK (VM_FF_TIMER | VM_FF_PGM_NEED_HANDY_PAGES | VM_FF_PGM_NO_MEMORY)
312/** VMCPU Flags that cause the HWACCM loops to go back to ring-3. */
313#define VMCPU_FF_HWACCM_TO_R3_MASK (VMCPU_FF_TO_R3)
314
315/** All the forced flags. */
316#define VM_FF_ALL_MASK (~0U)
317/** All the forced VM flags. */
318#define VM_FF_ALL_BUT_RAW_MASK (~(VM_FF_HIGH_PRIORITY_PRE_RAW_MASK | VM_FF_PDM_CRITSECT) | VM_FF_PGM_NO_MEMORY)
319/** All the forced VMCPU flags. */
320#define VMCPU_FF_ALL_BUT_RAW_MASK (~(VMCPU_FF_HIGH_PRIORITY_PRE_RAW_MASK | VMCPU_FF_CSAM_PENDING_ACTION))
321
322/** @} */
323
324/** @def VM_FF_SET
325 * Sets a force action flag.
326 *
327 * @param pVM VM Handle.
328 * @param fFlag The flag to set.
329 */
330#if 1
331# define VM_FF_SET(pVM, fFlag) ASMAtomicOrU32(&(pVM)->fGlobalForcedActions, (fFlag))
332#else
333# define VM_FF_SET(pVM, fFlag) \
334 do { ASMAtomicOrU32(&(pVM)->fGlobalForcedActions, (fFlag)); \
335 RTLogPrintf("VM_FF_SET : %08x %s - %s(%d) %s\n", (pVM)->fGlobalForcedActions, #fFlag, __FILE__, __LINE__, __FUNCTION__); \
336 } while (0)
337#endif
338
339/** @def VMCPU_FF_SET
340 * Sets a force action flag for the given VCPU.
341 *
342 * @param pVCpu VMCPU Handle.
343 * @param fFlag The flag to set.
344 */
345#define VMCPU_FF_SET(pVCpu, fFlag) ASMAtomicOrU32(&(pVCpu)->fLocalForcedActions, (fFlag))
346
347/** @def VM_FF_CLEAR
348 * Clears a force action flag.
349 *
350 * @param pVM VM Handle.
351 * @param fFlag The flag to clear.
352 */
353#if 1
354# define VM_FF_CLEAR(pVM, fFlag) ASMAtomicAndU32(&(pVM)->fGlobalForcedActions, ~(fFlag))
355#else
356# define VM_FF_CLEAR(pVM, fFlag) \
357 do { ASMAtomicAndU32(&(pVM)->fGlobalForcedActions, ~(fFlag)); \
358 RTLogPrintf("VM_FF_CLEAR: %08x %s - %s(%d) %s\n", (pVM)->fGlobalForcedActions, #fFlag, __FILE__, __LINE__, __FUNCTION__); \
359 } while (0)
360#endif
361
362/** @def VMCPU_FF_CLEAR
363 * Clears a force action flag for the given VCPU.
364 *
365 * @param pVCpu VMCPU Handle.
366 * @param fFlag The flag to clear.
367 */
368#define VMCPU_FF_CLEAR(pVCpu, fFlag) ASMAtomicAndU32(&(pVCpu)->fLocalForcedActions, ~(fFlag))
369
370/** @def VM_FF_ISSET
371 * Checks if a force action flag is set.
372 *
373 * @param pVM VM Handle.
374 * @param fFlag The flag to check.
375 */
376#define VM_FF_ISSET(pVM, fFlag) (((pVM)->fGlobalForcedActions & (fFlag)) == (fFlag))
377
378/** @def VMCPU_FF_ISSET
379 * Checks if a force action flag is set for the given VCPU.
380 *
381 * @param pVCpu VMCPU Handle.
382 * @param fFlag The flag to check.
383 */
384#define VMCPU_FF_ISSET(pVCpu, fFlag) (((pVCpu)->fLocalForcedActions & (fFlag)) == (fFlag))
385
386/** @def VM_FF_ISPENDING
387 * Checks if one or more force action in the specified set is pending.
388 *
389 * @param pVM VM Handle.
390 * @param fFlags The flags to check for.
391 */
392#define VM_FF_ISPENDING(pVM, fFlags) ((pVM)->fGlobalForcedActions & (fFlags))
393
394/** @def VM_FF_TESTANDCLEAR
395 * Checks if one (!) force action in the specified set is pending and clears it atomically
396 *
397 * @returns true if the bit was set.
398 * @returns false if the bit was clear.
399 * @param pVM VM Handle.
400 * @param iBit Bit position to check and clear
401 */
402#define VM_FF_TESTANDCLEAR(pVM, iBit) (ASMBitTestAndClear(&(pVM)->fGlobalForcedActions, iBit))
403
404/** @def VMCPU_FF_ISPENDING
405 * Checks if one or more force action in the specified set is pending for the given VCPU.
406 *
407 * @param pVCpu VMCPU Handle.
408 * @param fFlags The flags to check for.
409 */
410#define VMCPU_FF_ISPENDING(pVCpu, fFlags) ((pVCpu)->fLocalForcedActions & (fFlags))
411
412/** @def VM_FF_ISPENDING
413 * Checks if one or more force action in the specified set is pending while one
414 * or more other ones are not.
415 *
416 * @param pVM VM Handle.
417 * @param fFlags The flags to check for.
418 * @param fExcpt The flags that should not be set.
419 */
420#define VM_FF_IS_PENDING_EXCEPT(pVM, fFlags, fExcpt) ( ((pVM)->fGlobalForcedActions & (fFlags)) && !((pVM)->fGlobalForcedActions & (fExcpt)) )
421
422/** @def VMCPU_FF_IS_PENDING_EXCEPT
423 * Checks if one or more force action in the specified set is pending for the given
424 * VCPU while one or more other ones are not.
425 *
426 * @param pVCpu VMCPU Handle.
427 * @param fFlags The flags to check for.
428 * @param fExcpt The flags that should not be set.
429 */
430#define VMCPU_FF_IS_PENDING_EXCEPT(pVCpu, fFlags, fExcpt) ( ((pVCpu)->fLocalForcedActions & (fFlags)) && !((pVCpu)->fLocalForcedActions & (fExcpt)) )
431
432/** @def VM_IS_EMT
433 * Checks if the current thread is the emulation thread (EMT).
434 *
435 * @remark The ring-0 variation will need attention if we expand the ring-0
436 * code to let threads other than EMT mess around with the VM.
437 */
438#ifdef IN_RC
439# define VM_IS_EMT(pVM) true
440#else
441# define VM_IS_EMT(pVM) (VMMGetCpu(pVM) != NULL)
442#endif
443
444/** @def VMCPU_IS_EMT
445 * Checks if the current thread is the emulation thread (EMT) for the specified
446 * virtual CPU.
447 */
448#ifdef IN_RC
449# define VMCPU_IS_EMT(pVCpu) true
450#else
451# define VMCPU_IS_EMT(pVCpu) (pVCpu && (pVCpu == VMMGetCpu(pVCpu->CTX_SUFF(pVM))))
452#endif
453
454/** @def VM_ASSERT_EMT
455 * Asserts that the current thread IS the emulation thread (EMT).
456 */
457#ifdef IN_RC
458# define VM_ASSERT_EMT(pVM) Assert(VM_IS_EMT(pVM))
459#elif defined(IN_RING0)
460# define VM_ASSERT_EMT(pVM) Assert(VM_IS_EMT(pVM))
461#else
462# define VM_ASSERT_EMT(pVM) \
463 AssertMsg(VM_IS_EMT(pVM), \
464 ("Not emulation thread! Thread=%RTnthrd ThreadEMT=%RTnthrd\n", RTThreadNativeSelf(), VMR3GetVMCPUNativeThread(pVM)))
465#endif
466
467/** @def VMCPU_ASSERT_EMT
468 * Asserts that the current thread IS the emulation thread (EMT) of the
469 * specified virtual CPU.
470 */
471#ifdef IN_RC
472# define VMCPU_ASSERT_EMT(pVCpu) Assert(VMCPU_IS_EMT(pVCpu))
473#elif defined(IN_RING0)
474# define VMCPU_ASSERT_EMT(pVCpu) Assert(VMCPU_IS_EMT(pVCpu))
475#else
476# define VMCPU_ASSERT_EMT(pVCpu) \
477 AssertMsg(VMCPU_IS_EMT(pVCpu), \
478 ("Not emulation thread! Thread=%RTnthrd ThreadEMT=%RTnthrd idCpu=%#x\n", \
479 RTThreadNativeSelf(), (pVCpu)->hNativeThread, (pVCpu)->idCpu))
480#endif
481
482/** @def VM_ASSERT_EMT_RETURN
483 * Asserts that the current thread IS the emulation thread (EMT) and returns if it isn't.
484 */
485#ifdef IN_RC
486# define VM_ASSERT_EMT_RETURN(pVM, rc) AssertReturn(VM_IS_EMT(pVM), (rc))
487#elif defined(IN_RING0)
488# define VM_ASSERT_EMT_RETURN(pVM, rc) AssertReturn(VM_IS_EMT(pVM), (rc))
489#else
490# define VM_ASSERT_EMT_RETURN(pVM, rc) \
491 AssertMsgReturn(VM_IS_EMT(pVM), \
492 ("Not emulation thread! Thread=%RTnthrd ThreadEMT=%RTnthrd\n", RTThreadNativeSelf(), VMR3GetVMCPUNativeThread(pVM)), \
493 (rc))
494#endif
495
496/** @def VMCPU_ASSERT_EMT_RETURN
497 * Asserts that the current thread IS the emulation thread (EMT) and returns if it isn't.
498 */
499#ifdef IN_RC
500# define VMCPU_ASSERT_EMT_RETURN(pVCpu, rc) AssertReturn(VMCPU_IS_EMT(pVCpu), (rc))
501#elif defined(IN_RING0)
502# define VMCPU_ASSERT_EMT_RETURN(pVCpu, rc) AssertReturn(VMCPU_IS_EMT(pVCpu), (rc))
503#else
504# define VMCPU_ASSERT_EMT_RETURN(pVCpu, rc) \
505 AssertMsg(VMCPU_IS_EMT(pVCpu), \
506 ("Not emulation thread! Thread=%RTnthrd ThreadEMT=%RTnthrd idCpu=%#x\n", \
507 RTThreadNativeSelf(), (pVCpu)->hNativeThread, (pVCpu)->idCpu), \
508 (rc))
509#endif
510
511
512/**
513 * Asserts that the current thread is NOT the emulation thread.
514 */
515#define VM_ASSERT_OTHER_THREAD(pVM) \
516 AssertMsg(!VM_IS_EMT(pVM), ("Not other thread!!\n"))
517
518
519/** @def VM_ASSERT_STATE_RETURN
520 * Asserts a certain VM state.
521 */
522#define VM_ASSERT_STATE(pVM, _enmState) \
523 AssertMsg((pVM)->enmVMState == (_enmState), \
524 ("state %s, expected %s\n", VMGetStateName(pVM->enmVMState), VMGetStateName(_enmState)))
525
526/** @def VM_ASSERT_STATE_RETURN
527 * Asserts a certain VM state and returns if it doesn't match.
528 */
529#define VM_ASSERT_STATE_RETURN(pVM, _enmState, rc) \
530 AssertMsgReturn((pVM)->enmVMState == (_enmState), \
531 ("state %s, expected %s\n", VMGetStateName(pVM->enmVMState), VMGetStateName(_enmState)), \
532 (rc))
533
534/** @def VM_ASSERT_VALID_EXT_RETURN
535 * Asserts a the VM handle is valid for external access, i.e. not being
536 * destroy or terminated.
537 */
538#define VM_ASSERT_VALID_EXT_RETURN(pVM, rc) \
539 AssertMsgReturn( RT_VALID_ALIGNED_PTR(pVM, PAGE_SIZE) \
540 && (unsigned)(pVM)->enmVMState < (unsigned)VMSTATE_DESTROYING, \
541 ("pVM=%p state %s\n", (pVM), RT_VALID_ALIGNED_PTR(pVM, PAGE_SIZE) \
542 ? VMGetStateName(pVM->enmVMState) : ""), \
543 (rc))
544
545/** @def VMCPU_ASSERT_VALID_EXT_RETURN
546 * Asserts a the VMCPU handle is valid for external access, i.e. not being
547 * destroy or terminated.
548 */
549#define VMCPU_ASSERT_VALID_EXT_RETURN(pVCpu, rc) \
550 AssertMsgReturn( RT_VALID_ALIGNED_PTR(pVCpu, 64) \
551 && RT_VALID_ALIGNED_PTR((pVCpu)->CTX_SUFF(pVM), PAGE_SIZE) \
552 && (unsigned)(pVCpu)->CTX_SUFF(pVM)->enmVMState < (unsigned)VMSTATE_DESTROYING, \
553 ("pVCpu=%p pVM=%p state %s\n", (pVCpu), RT_VALID_ALIGNED_PTR(pVCpu, 64) ? (pVCpu)->CTX_SUFF(pVM) : NULL, \
554 RT_VALID_ALIGNED_PTR(pVCpu, 64) && RT_VALID_ALIGNED_PTR((pVCpu)->CTX_SUFF(pVM), PAGE_SIZE) \
555 ? VMGetStateName((pVCpu)->pVMR3->enmVMState) : ""), \
556 (rc))
557
558
559/** This is the VM structure.
560 *
561 * It contains (nearly?) all the VM data which have to be available in all
562 * contexts. Even if it contains all the data the idea is to use APIs not
563 * to modify all the members all around the place. Therefore we make use of
564 * unions to hide everything which isn't local to the current source module.
565 * This means we'll have to pay a little bit of attention when adding new
566 * members to structures in the unions and make sure to keep the padding sizes
567 * up to date.
568 *
569 * Run tstVMStructSize after update!
570 */
571typedef struct VM
572{
573 /** The state of the VM.
574 * This field is read only to everyone except the VM and EM. */
575 VMSTATE enmVMState;
576 /** Forced action flags.
577 * See the VM_FF_* \#defines. Updated atomically.
578 */
579 volatile uint32_t fGlobalForcedActions;
580 /** Pointer to the array of page descriptors for the VM structure allocation. */
581 R3PTRTYPE(PSUPPAGE) paVMPagesR3;
582 /** Session handle. For use when calling SUPR0 APIs. */
583 PSUPDRVSESSION pSession;
584 /** Pointer to the ring-3 VM structure. */
585 PUVM pUVM;
586 /** Ring-3 Host Context VM Pointer. */
587 R3PTRTYPE(struct VM *) pVMR3;
588 /** Ring-0 Host Context VM Pointer. */
589 R0PTRTYPE(struct VM *) pVMR0;
590 /** Raw-mode Context VM Pointer. */
591 RCPTRTYPE(struct VM *) pVMRC;
592
593 /** The GVM VM handle. Only the GVM should modify this field. */
594 uint32_t hSelf;
595 /** Number of virtual CPUs. */
596 uint32_t cCPUs;
597
598 /** Size of the VM structure including the VMCPU array. */
599 uint32_t cbSelf;
600
601 /** Offset to the VMCPU array starting from beginning of this structure. */
602 uint32_t offVMCPU;
603
604 /** Reserved; alignment. */
605 uint32_t u32Reserved[6];
606
607 /** @name Public VMM Switcher APIs
608 * @{ */
609 /**
610 * Assembly switch entry point for returning to host context.
611 * This function will clean up the stack frame.
612 *
613 * @param eax The return code, register.
614 * @param Ctx The guest core context.
615 * @remark Assume interrupts disabled.
616 */
617 RTRCPTR pfnVMMGCGuestToHostAsmGuestCtx/*(int32_t eax, CPUMCTXCORE Ctx)*/;
618
619 /**
620 * Assembly switch entry point for returning to host context.
621 *
622 * This is an alternative entry point which we'll be using when the we have the
623 * hypervisor context and need to save that before going to the host.
624 *
625 * This is typically useful when abandoning the hypervisor because of a trap
626 * and want the trap state to be saved.
627 *
628 * @param eax The return code, register.
629 * @param ecx Pointer to the hypervisor core context, register.
630 * @remark Assume interrupts disabled.
631 */
632 RTRCPTR pfnVMMGCGuestToHostAsmHyperCtx/*(int32_t eax, PCPUMCTXCORE ecx)*/;
633
634 /**
635 * Assembly switch entry point for returning to host context.
636 *
637 * This is an alternative to the two *Ctx APIs and implies that the context has already
638 * been saved, or that it's just a brief return to HC and that the caller intends to resume
639 * whatever it is doing upon 'return' from this call.
640 *
641 * @param eax The return code, register.
642 * @remark Assume interrupts disabled.
643 */
644 RTRCPTR pfnVMMGCGuestToHostAsm/*(int32_t eax)*/;
645 /** @} */
646
647
648 /** @name Various VM data owned by VM.
649 * @{ */
650 RTTHREAD uPadding1;
651 /** The native handle of ThreadEMT. Getting the native handle
652 * is generally faster than getting the IPRT one (except on OS/2 :-). */
653 RTNATIVETHREAD uPadding2;
654 /** @} */
655
656
657 /** @name Various items that are frequently accessed.
658 * @{ */
659 /** Raw ring-3 indicator. */
660 bool fRawR3Enabled;
661 /** Raw ring-0 indicator. */
662 bool fRawR0Enabled;
663 /** PATM enabled flag.
664 * This is placed here for performance reasons. */
665 bool fPATMEnabled;
666 /** CSAM enabled flag.
667 * This is placed here for performance reasons. */
668 bool fCSAMEnabled;
669 /** Hardware VM support is available and enabled.
670 * This is placed here for performance reasons. */
671 bool fHWACCMEnabled;
672 /** Hardware VM support is required and non-optional.
673 * This is initialized together with the rest of the VM structure. */
674 bool fHwVirtExtForced;
675 /** PARAV enabled flag. */
676 bool fPARAVEnabled;
677 /** @} */
678
679
680 /* padding to make gnuc put the StatQemuToGC where msc does. */
681#if HC_ARCH_BITS == 32
682 uint32_t padding0;
683#endif
684
685 /** Profiling the total time from Qemu to GC. */
686 STAMPROFILEADV StatTotalQemuToGC;
687 /** Profiling the total time from GC to Qemu. */
688 STAMPROFILEADV StatTotalGCToQemu;
689 /** Profiling the total time spent in GC. */
690 STAMPROFILEADV StatTotalInGC;
691 /** Profiling the total time spent not in Qemu. */
692 STAMPROFILEADV StatTotalInQemu;
693 /** Profiling the VMMSwitcher code for going to GC. */
694 STAMPROFILEADV StatSwitcherToGC;
695 /** Profiling the VMMSwitcher code for going to HC. */
696 STAMPROFILEADV StatSwitcherToHC;
697 STAMPROFILEADV StatSwitcherSaveRegs;
698 STAMPROFILEADV StatSwitcherSysEnter;
699 STAMPROFILEADV StatSwitcherDebug;
700 STAMPROFILEADV StatSwitcherCR0;
701 STAMPROFILEADV StatSwitcherCR4;
702 STAMPROFILEADV StatSwitcherJmpCR3;
703 STAMPROFILEADV StatSwitcherRstrRegs;
704 STAMPROFILEADV StatSwitcherLgdt;
705 STAMPROFILEADV StatSwitcherLidt;
706 STAMPROFILEADV StatSwitcherLldt;
707 STAMPROFILEADV StatSwitcherTSS;
708
709/** @todo Realign everything on 64 byte boundaries to better match the
710 * cache-line size. */
711 /* padding - the unions must be aligned on 32 bytes boundraries. */
712 uint32_t padding[HC_ARCH_BITS == 32 ? 4+8 : 6];
713
714 /** CPUM part. */
715 union
716 {
717#ifdef ___CPUMInternal_h
718 struct CPUM s;
719#endif
720 char padding[2048]; /* multiple of 32 */
721 } cpum;
722
723 /** VMM part. */
724 union
725 {
726#ifdef ___VMMInternal_h
727 struct VMM s;
728#endif
729 char padding[1600]; /* multiple of 32 */
730 } vmm;
731
732 /** PGM part. */
733 union
734 {
735#ifdef ___PGMInternal_h
736 struct PGM s;
737#endif
738 char padding[16*1024]; /* multiple of 32 */
739 } pgm;
740
741 /** HWACCM part. */
742 union
743 {
744#ifdef ___HWACCMInternal_h
745 struct HWACCM s;
746#endif
747 char padding[512]; /* multiple of 32 */
748 } hwaccm;
749
750 /** TRPM part. */
751 union
752 {
753#ifdef ___TRPMInternal_h
754 struct TRPM s;
755#endif
756 char padding[5344]; /* multiple of 32 */
757 } trpm;
758
759 /** SELM part. */
760 union
761 {
762#ifdef ___SELMInternal_h
763 struct SELM s;
764#endif
765 char padding[544]; /* multiple of 32 */
766 } selm;
767
768 /** MM part. */
769 union
770 {
771#ifdef ___MMInternal_h
772 struct MM s;
773#endif
774 char padding[192]; /* multiple of 32 */
775 } mm;
776
777 /** CFGM part. */
778 union
779 {
780#ifdef ___CFGMInternal_h
781 struct CFGM s;
782#endif
783 char padding[32]; /* multiple of 32 */
784 } cfgm;
785
786 /** PDM part. */
787 union
788 {
789#ifdef ___PDMInternal_h
790 struct PDM s;
791#endif
792 char padding[1824]; /* multiple of 32 */
793 } pdm;
794
795 /** IOM part. */
796 union
797 {
798#ifdef ___IOMInternal_h
799 struct IOM s;
800#endif
801 char padding[4544]; /* multiple of 32 */
802 } iom;
803
804 /** PATM part. */
805 union
806 {
807#ifdef ___PATMInternal_h
808 struct PATM s;
809#endif
810 char padding[768]; /* multiple of 32 */
811 } patm;
812
813 /** CSAM part. */
814 union
815 {
816#ifdef ___CSAMInternal_h
817 struct CSAM s;
818#endif
819 char padding[3328]; /* multiple of 32 */
820 } csam;
821
822 /** PARAV part. */
823 union
824 {
825#ifdef ___PARAVInternal_h
826 struct PARAV s;
827#endif
828 char padding[128];
829 } parav;
830
831 /** EM part. */
832 union
833 {
834#ifdef ___EMInternal_h
835 struct EM s;
836#endif
837 char padding[256]; /* multiple of 32 */
838 } em;
839
840 /** TM part. */
841 union
842 {
843#ifdef ___TMInternal_h
844 struct TM s;
845#endif
846 char padding[1536]; /* multiple of 32 */
847 } tm;
848
849 /** DBGF part. */
850 union
851 {
852#ifdef ___DBGFInternal_h
853 struct DBGF s;
854#endif
855 char padding[2368]; /* multiple of 32 */
856 } dbgf;
857
858 /** SSM part. */
859 union
860 {
861#ifdef ___SSMInternal_h
862 struct SSM s;
863#endif
864 char padding[32]; /* multiple of 32 */
865 } ssm;
866
867 /** VM part. */
868 union
869 {
870#ifdef ___VMInternal_h
871 struct VMINT s;
872#endif
873 char padding[768]; /* multiple of 32 */
874 } vm;
875
876 /** REM part. */
877 union
878 {
879#ifdef ___REMInternal_h
880 struct REM s;
881#endif
882
883/** @def VM_REM_SIZE
884 * Must be multiple of 32 and coherent with REM_ENV_SIZE from REMInternal.h. */
885#if GC_ARCH_BITS == 32
886# define VM_REM_SIZE (HC_ARCH_BITS == 32 ? 0x10800 : 0x10800)
887#else
888# define VM_REM_SIZE (HC_ARCH_BITS == 32 ? 0x10900 : 0x10900)
889#endif
890 char padding[VM_REM_SIZE]; /* multiple of 32 */
891 } rem;
892
893 /** Padding for aligning the cpu array on a 64 byte boundrary. */
894 uint32_t u32Reserved2[8];
895
896 /** VMCPU array for the configured number of virtual CPUs.
897 * Must be aligned on a 64-byte boundrary. */
898 VMCPU aCpus[1];
899} VM;
900
901/** Pointer to a VM. */
902#ifndef ___VBox_types_h
903typedef struct VM *PVM;
904#endif
905
906
907#ifdef IN_RC
908__BEGIN_DECLS
909
910/** The VM structure.
911 * This is imported from the VMMGCBuiltin module, i.e. it's a one
912 * of those magic globals which we should avoid using.
913 */
914extern DECLIMPORT(VM) g_VM;
915
916__END_DECLS
917#endif
918
919/** @} */
920
921#endif
922
Note: See TracBrowser for help on using the repository browser.

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