1 | /* $Id: VMMInternal.h 60847 2016-05-05 15:24:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VMM - Internal header file.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2015 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #ifndef ___VMMInternal_h
|
---|
19 | #define ___VMMInternal_h
|
---|
20 |
|
---|
21 | #include <VBox/cdefs.h>
|
---|
22 | #include <VBox/sup.h>
|
---|
23 | #include <VBox/vmm/stam.h>
|
---|
24 | #include <VBox/vmm/vmm.h>
|
---|
25 | #include <VBox/log.h>
|
---|
26 | #include <iprt/critsect.h>
|
---|
27 |
|
---|
28 | #if !defined(IN_VMM_R3) && !defined(IN_VMM_R0) && !defined(IN_VMM_RC)
|
---|
29 | # error "Not in VMM! This is an internal header!"
|
---|
30 | #endif
|
---|
31 | #if defined(RT_OS_DARWIN) && HC_ARCH_BITS == 32
|
---|
32 | # error "32-bit darwin is no longer supported. Go back to 4.3 or earlier!"
|
---|
33 | #endif
|
---|
34 |
|
---|
35 |
|
---|
36 |
|
---|
37 | /** @defgroup grp_vmm_int Internals
|
---|
38 | * @ingroup grp_vmm
|
---|
39 | * @internal
|
---|
40 | * @{
|
---|
41 | */
|
---|
42 |
|
---|
43 | /** @def VBOX_WITH_RC_RELEASE_LOGGING
|
---|
44 | * Enables RC release logging. */
|
---|
45 | #define VBOX_WITH_RC_RELEASE_LOGGING
|
---|
46 |
|
---|
47 | /** @def VBOX_WITH_R0_LOGGING
|
---|
48 | * Enables Ring-0 logging (non-release).
|
---|
49 | *
|
---|
50 | * Ring-0 logging isn't 100% safe yet (thread id reuse / process exit cleanup),
|
---|
51 | * so you have to sign up here by adding your defined(DEBUG_<userid>) to the
|
---|
52 | * \#if, or by adding VBOX_WITH_R0_LOGGING to your LocalConfig.kmk.
|
---|
53 | */
|
---|
54 | #if defined(DEBUG_sandervl) || defined(DEBUG_frank) || defined(DEBUG_ramshankar) || defined(DOXYGEN_RUNNING)
|
---|
55 | # define VBOX_WITH_R0_LOGGING
|
---|
56 | #endif
|
---|
57 |
|
---|
58 | /** @def VBOX_STRICT_VMM_STACK
|
---|
59 | * Enables VMM stack guard pages to catch stack over- and underruns. */
|
---|
60 | #if defined(VBOX_STRICT) || defined(DOXYGEN_RUNNING)
|
---|
61 | # define VBOX_STRICT_VMM_STACK
|
---|
62 | #endif
|
---|
63 |
|
---|
64 |
|
---|
65 | /**
|
---|
66 | * Converts a VMM pointer into a VM pointer.
|
---|
67 | * @returns Pointer to the VM structure the VMM is part of.
|
---|
68 | * @param pVMM Pointer to VMM instance data.
|
---|
69 | */
|
---|
70 | #define VMM2VM(pVMM) ( (PVM)((char*)pVMM - pVMM->offVM) )
|
---|
71 |
|
---|
72 |
|
---|
73 | /**
|
---|
74 | * Switcher function, HC to RC.
|
---|
75 | *
|
---|
76 | * @param pVM The cross context VM structure.
|
---|
77 | * @returns Return code indicating the action to take.
|
---|
78 | */
|
---|
79 | typedef DECLASMTYPE(int) FNVMMSWITCHERHC(PVM pVM);
|
---|
80 | /** Pointer to switcher function. */
|
---|
81 | typedef FNVMMSWITCHERHC *PFNVMMSWITCHERHC;
|
---|
82 |
|
---|
83 | /**
|
---|
84 | * Switcher function, RC to HC.
|
---|
85 | *
|
---|
86 | * @param rc VBox status code.
|
---|
87 | */
|
---|
88 | typedef DECLASMTYPE(void) FNVMMSWITCHERRC(int rc);
|
---|
89 | /** Pointer to switcher function. */
|
---|
90 | typedef FNVMMSWITCHERRC *PFNVMMSWITCHERRC;
|
---|
91 |
|
---|
92 |
|
---|
93 | /**
|
---|
94 | * The ring-0 logger instance wrapper.
|
---|
95 | *
|
---|
96 | * We need to be able to find the VM handle from the logger instance, so we wrap
|
---|
97 | * it in this structure.
|
---|
98 | */
|
---|
99 | typedef struct VMMR0LOGGER
|
---|
100 | {
|
---|
101 | /** Pointer to Pointer to the VM. */
|
---|
102 | R0PTRTYPE(PVM) pVM;
|
---|
103 | /** Size of the allocated logger instance (Logger). */
|
---|
104 | uint32_t cbLogger;
|
---|
105 | /** Flag indicating whether we've create the logger Ring-0 instance yet. */
|
---|
106 | bool fCreated;
|
---|
107 | /** Flag indicating whether we've disabled flushing (world switch) or not. */
|
---|
108 | bool fFlushingDisabled;
|
---|
109 | /** Flag indicating whether we've registered the instance already. */
|
---|
110 | bool fRegistered;
|
---|
111 | bool a8Alignment;
|
---|
112 | /** The CPU ID. */
|
---|
113 | VMCPUID idCpu;
|
---|
114 | #if HC_ARCH_BITS == 64
|
---|
115 | uint32_t u32Alignment;
|
---|
116 | #endif
|
---|
117 | /** The ring-0 logger instance. This extends beyond the size. */
|
---|
118 | RTLOGGER Logger;
|
---|
119 | } VMMR0LOGGER;
|
---|
120 | /** Pointer to a ring-0 logger instance wrapper. */
|
---|
121 | typedef VMMR0LOGGER *PVMMR0LOGGER;
|
---|
122 |
|
---|
123 |
|
---|
124 | /**
|
---|
125 | * Jump buffer for the setjmp/longjmp like constructs used to
|
---|
126 | * quickly 'call' back into Ring-3.
|
---|
127 | */
|
---|
128 | typedef struct VMMR0JMPBUF
|
---|
129 | {
|
---|
130 | /** Traditional jmp_buf stuff
|
---|
131 | * @{ */
|
---|
132 | #if HC_ARCH_BITS == 32
|
---|
133 | uint32_t ebx;
|
---|
134 | uint32_t esi;
|
---|
135 | uint32_t edi;
|
---|
136 | uint32_t ebp;
|
---|
137 | uint32_t esp;
|
---|
138 | uint32_t eip;
|
---|
139 | uint32_t eflags;
|
---|
140 | #endif
|
---|
141 | #if HC_ARCH_BITS == 64
|
---|
142 | uint64_t rbx;
|
---|
143 | # ifdef RT_OS_WINDOWS
|
---|
144 | uint64_t rsi;
|
---|
145 | uint64_t rdi;
|
---|
146 | # endif
|
---|
147 | uint64_t rbp;
|
---|
148 | uint64_t r12;
|
---|
149 | uint64_t r13;
|
---|
150 | uint64_t r14;
|
---|
151 | uint64_t r15;
|
---|
152 | uint64_t rsp;
|
---|
153 | uint64_t rip;
|
---|
154 | # ifdef RT_OS_WINDOWS
|
---|
155 | uint128_t xmm6;
|
---|
156 | uint128_t xmm7;
|
---|
157 | uint128_t xmm8;
|
---|
158 | uint128_t xmm9;
|
---|
159 | uint128_t xmm10;
|
---|
160 | uint128_t xmm11;
|
---|
161 | uint128_t xmm12;
|
---|
162 | uint128_t xmm13;
|
---|
163 | uint128_t xmm14;
|
---|
164 | uint128_t xmm15;
|
---|
165 | # endif
|
---|
166 | uint64_t rflags;
|
---|
167 | #endif
|
---|
168 | /** @} */
|
---|
169 |
|
---|
170 | /** Flag that indicates that we've done a ring-3 call. */
|
---|
171 | bool fInRing3Call;
|
---|
172 | /** The number of bytes we've saved. */
|
---|
173 | uint32_t cbSavedStack;
|
---|
174 | /** Pointer to the buffer used to save the stack.
|
---|
175 | * This is assumed to be 8KB. */
|
---|
176 | RTR0PTR pvSavedStack;
|
---|
177 | /** Esp we we match against esp on resume to make sure the stack wasn't relocated. */
|
---|
178 | RTHCUINTREG SpCheck;
|
---|
179 | /** The esp we should resume execution with after the restore. */
|
---|
180 | RTHCUINTREG SpResume;
|
---|
181 | /** ESP/RSP at the time of the jump to ring 3. */
|
---|
182 | RTHCUINTREG SavedEsp;
|
---|
183 | /** EBP/RBP at the time of the jump to ring 3. */
|
---|
184 | RTHCUINTREG SavedEbp;
|
---|
185 |
|
---|
186 | /** Stats: Max amount of stack used. */
|
---|
187 | uint32_t cbUsedMax;
|
---|
188 | /** Stats: Average stack usage. (Avg = cbUsedTotal / cUsedTotal) */
|
---|
189 | uint32_t cbUsedAvg;
|
---|
190 | /** Stats: Total amount of stack used. */
|
---|
191 | uint64_t cbUsedTotal;
|
---|
192 | /** Stats: Number of stack usages. */
|
---|
193 | uint64_t cUsedTotal;
|
---|
194 | } VMMR0JMPBUF;
|
---|
195 | /** Pointer to a ring-0 jump buffer. */
|
---|
196 | typedef VMMR0JMPBUF *PVMMR0JMPBUF;
|
---|
197 |
|
---|
198 |
|
---|
199 | /**
|
---|
200 | * VMM Data (part of VM)
|
---|
201 | */
|
---|
202 | typedef struct VMM
|
---|
203 | {
|
---|
204 | /** Offset to the VM structure.
|
---|
205 | * See VMM2VM(). */
|
---|
206 | RTINT offVM;
|
---|
207 |
|
---|
208 | /** @name World Switcher and Related
|
---|
209 | * @{
|
---|
210 | */
|
---|
211 | /** Size of the core code. */
|
---|
212 | RTUINT cbCoreCode;
|
---|
213 | /** Physical address of core code. */
|
---|
214 | RTHCPHYS HCPhysCoreCode;
|
---|
215 | /** Pointer to core code ring-3 mapping - contiguous memory.
|
---|
216 | * At present this only means the context switcher code. */
|
---|
217 | RTR3PTR pvCoreCodeR3;
|
---|
218 | /** Pointer to core code ring-0 mapping - contiguous memory.
|
---|
219 | * At present this only means the context switcher code. */
|
---|
220 | RTR0PTR pvCoreCodeR0;
|
---|
221 | /** Pointer to core code guest context mapping. */
|
---|
222 | RTRCPTR pvCoreCodeRC;
|
---|
223 | RTRCPTR pRCPadding0; /**< Alignment padding. */
|
---|
224 | #ifdef VBOX_WITH_NMI
|
---|
225 | /** The guest context address of the APIC (host) mapping. */
|
---|
226 | RTRCPTR GCPtrApicBase;
|
---|
227 | RTRCPTR pRCPadding1; /**< Alignment padding. */
|
---|
228 | #endif
|
---|
229 | /** The current switcher.
|
---|
230 | * This will be set before the VMM is fully initialized. */
|
---|
231 | VMMSWITCHER enmSwitcher;
|
---|
232 | /** Array of offsets to the different switchers within the core code. */
|
---|
233 | uint32_t aoffSwitchers[VMMSWITCHER_MAX];
|
---|
234 | uint32_t u32Padding2; /**< Alignment padding. */
|
---|
235 |
|
---|
236 | /** Resume Guest Execution. See CPUMGCResumeGuest(). */
|
---|
237 | RTRCPTR pfnCPUMRCResumeGuest;
|
---|
238 | /** Resume Guest Execution in V86 mode. See CPUMGCResumeGuestV86(). */
|
---|
239 | RTRCPTR pfnCPUMRCResumeGuestV86;
|
---|
240 | /** Call Trampoline. See vmmGCCallTrampoline(). */
|
---|
241 | RTRCPTR pfnCallTrampolineRC;
|
---|
242 | /** Guest to host switcher entry point. */
|
---|
243 | RCPTRTYPE(PFNVMMSWITCHERRC) pfnRCToHost;
|
---|
244 | /** Host to guest switcher entry point. */
|
---|
245 | R0PTRTYPE(PFNVMMSWITCHERHC) pfnR0ToRawMode;
|
---|
246 | /** @} */
|
---|
247 |
|
---|
248 | /** @name Logging
|
---|
249 | * @{
|
---|
250 | */
|
---|
251 | /** Size of the allocated logger instance (pRCLoggerRC/pRCLoggerR3). */
|
---|
252 | uint32_t cbRCLogger;
|
---|
253 | /** Pointer to the RC logger instance - RC Ptr.
|
---|
254 | * This is NULL if logging is disabled. */
|
---|
255 | RCPTRTYPE(PRTLOGGERRC) pRCLoggerRC;
|
---|
256 | /** Pointer to the GC logger instance - R3 Ptr.
|
---|
257 | * This is NULL if logging is disabled. */
|
---|
258 | R3PTRTYPE(PRTLOGGERRC) pRCLoggerR3;
|
---|
259 | /** Pointer to the GC release logger instance - R3 Ptr. */
|
---|
260 | R3PTRTYPE(PRTLOGGERRC) pRCRelLoggerR3;
|
---|
261 | /** Pointer to the GC release logger instance - RC Ptr. */
|
---|
262 | RCPTRTYPE(PRTLOGGERRC) pRCRelLoggerRC;
|
---|
263 | /** Size of the allocated release logger instance (pRCRelLoggerRC/pRCRelLoggerR3).
|
---|
264 | * This may differ from cbRCLogger. */
|
---|
265 | uint32_t cbRCRelLogger;
|
---|
266 | /** Whether log flushing has been disabled or not. */
|
---|
267 | bool fRCLoggerFlushingDisabled;
|
---|
268 | bool afAlignment1[5]; /**< Alignment padding. */
|
---|
269 | /** @} */
|
---|
270 |
|
---|
271 | /** Whether the stack guard pages have been stationed or not. */
|
---|
272 | bool fStackGuardsStationed;
|
---|
273 | /** Whether we should use the periodic preemption timers. */
|
---|
274 | bool fUsePeriodicPreemptionTimers;
|
---|
275 |
|
---|
276 | /** The EMT yield timer. */
|
---|
277 | PTMTIMERR3 pYieldTimer;
|
---|
278 | /** The period to the next timeout when suspended or stopped.
|
---|
279 | * This is 0 when running. */
|
---|
280 | uint32_t cYieldResumeMillies;
|
---|
281 | /** The EMT yield timer interval (milliseconds). */
|
---|
282 | uint32_t cYieldEveryMillies;
|
---|
283 | /** The timestamp of the previous yield. (nano) */
|
---|
284 | uint64_t u64LastYield;
|
---|
285 |
|
---|
286 | /** @name EMT Rendezvous
|
---|
287 | * @{ */
|
---|
288 | /** Semaphore to wait on upon entering ordered execution. */
|
---|
289 | R3PTRTYPE(PRTSEMEVENT) pahEvtRendezvousEnterOrdered;
|
---|
290 | /** Semaphore to wait on upon entering for one-by-one execution. */
|
---|
291 | RTSEMEVENT hEvtRendezvousEnterOneByOne;
|
---|
292 | /** Semaphore to wait on upon entering for all-at-once execution. */
|
---|
293 | RTSEMEVENTMULTI hEvtMulRendezvousEnterAllAtOnce;
|
---|
294 | /** Semaphore to wait on when done. */
|
---|
295 | RTSEMEVENTMULTI hEvtMulRendezvousDone;
|
---|
296 | /** Semaphore the VMMR3EmtRendezvous caller waits on at the end. */
|
---|
297 | RTSEMEVENT hEvtRendezvousDoneCaller;
|
---|
298 | /** Semaphore to wait on upon recursing. */
|
---|
299 | RTSEMEVENTMULTI hEvtMulRendezvousRecursionPush;
|
---|
300 | /** Semaphore to wait on after done with recursion (caller restoring state). */
|
---|
301 | RTSEMEVENTMULTI hEvtMulRendezvousRecursionPop;
|
---|
302 | /** Semaphore the initiator waits on while the EMTs are getting into position
|
---|
303 | * on hEvtMulRendezvousRecursionPush. */
|
---|
304 | RTSEMEVENT hEvtRendezvousRecursionPushCaller;
|
---|
305 | /** Semaphore the initiator waits on while the EMTs sitting on
|
---|
306 | * hEvtMulRendezvousRecursionPop wakes up and leave. */
|
---|
307 | RTSEMEVENT hEvtRendezvousRecursionPopCaller;
|
---|
308 | /** Callback. */
|
---|
309 | R3PTRTYPE(PFNVMMEMTRENDEZVOUS) volatile pfnRendezvous;
|
---|
310 | /** The user argument for the callback. */
|
---|
311 | RTR3PTR volatile pvRendezvousUser;
|
---|
312 | /** Flags. */
|
---|
313 | volatile uint32_t fRendezvousFlags;
|
---|
314 | /** The number of EMTs that has entered. */
|
---|
315 | volatile uint32_t cRendezvousEmtsEntered;
|
---|
316 | /** The number of EMTs that has done their job. */
|
---|
317 | volatile uint32_t cRendezvousEmtsDone;
|
---|
318 | /** The number of EMTs that has returned. */
|
---|
319 | volatile uint32_t cRendezvousEmtsReturned;
|
---|
320 | /** The status code. */
|
---|
321 | volatile int32_t i32RendezvousStatus;
|
---|
322 | /** Spin lock. */
|
---|
323 | volatile uint32_t u32RendezvousLock;
|
---|
324 | /** The recursion depth. */
|
---|
325 | volatile uint32_t cRendezvousRecursions;
|
---|
326 | /** The number of EMTs that have entered the recursion routine. */
|
---|
327 | volatile uint32_t cRendezvousEmtsRecursingPush;
|
---|
328 | /** The number of EMTs that have leaft the recursion routine. */
|
---|
329 | volatile uint32_t cRendezvousEmtsRecursingPop;
|
---|
330 | /** Triggers rendezvous recursion in the other threads. */
|
---|
331 | volatile bool fRendezvousRecursion;
|
---|
332 |
|
---|
333 | /** @} */
|
---|
334 | bool afAlignment2[HC_ARCH_BITS == 32 ? 7 : 3]; /**< Alignment padding. */
|
---|
335 |
|
---|
336 | /** Buffer for storing the standard assertion message for a ring-0 assertion.
|
---|
337 | * Used for saving the assertion message text for the release log and guru
|
---|
338 | * meditation dump. */
|
---|
339 | char szRing0AssertMsg1[512];
|
---|
340 | /** Buffer for storing the custom message for a ring-0 assertion. */
|
---|
341 | char szRing0AssertMsg2[256];
|
---|
342 |
|
---|
343 | /** Number of VMMR0_DO_RUN_GC calls. */
|
---|
344 | STAMCOUNTER StatRunRC;
|
---|
345 |
|
---|
346 | /** Statistics for each of the RC/R0 return codes.
|
---|
347 | * @{ */
|
---|
348 | STAMCOUNTER StatRZRetNormal;
|
---|
349 | STAMCOUNTER StatRZRetInterrupt;
|
---|
350 | STAMCOUNTER StatRZRetInterruptHyper;
|
---|
351 | STAMCOUNTER StatRZRetGuestTrap;
|
---|
352 | STAMCOUNTER StatRZRetRingSwitch;
|
---|
353 | STAMCOUNTER StatRZRetRingSwitchInt;
|
---|
354 | STAMCOUNTER StatRZRetStaleSelector;
|
---|
355 | STAMCOUNTER StatRZRetIRETTrap;
|
---|
356 | STAMCOUNTER StatRZRetEmulate;
|
---|
357 | STAMCOUNTER StatRZRetIOBlockEmulate;
|
---|
358 | STAMCOUNTER StatRZRetPatchEmulate;
|
---|
359 | STAMCOUNTER StatRZRetIORead;
|
---|
360 | STAMCOUNTER StatRZRetIOWrite;
|
---|
361 | STAMCOUNTER StatRZRetIOCommitWrite;
|
---|
362 | STAMCOUNTER StatRZRetMMIORead;
|
---|
363 | STAMCOUNTER StatRZRetMMIOWrite;
|
---|
364 | STAMCOUNTER StatRZRetMMIOCommitWrite;
|
---|
365 | STAMCOUNTER StatRZRetMMIOPatchRead;
|
---|
366 | STAMCOUNTER StatRZRetMMIOPatchWrite;
|
---|
367 | STAMCOUNTER StatRZRetMMIOReadWrite;
|
---|
368 | STAMCOUNTER StatRZRetMSRRead;
|
---|
369 | STAMCOUNTER StatRZRetMSRWrite;
|
---|
370 | STAMCOUNTER StatRZRetLDTFault;
|
---|
371 | STAMCOUNTER StatRZRetGDTFault;
|
---|
372 | STAMCOUNTER StatRZRetIDTFault;
|
---|
373 | STAMCOUNTER StatRZRetTSSFault;
|
---|
374 | STAMCOUNTER StatRZRetCSAMTask;
|
---|
375 | STAMCOUNTER StatRZRetSyncCR3;
|
---|
376 | STAMCOUNTER StatRZRetMisc;
|
---|
377 | STAMCOUNTER StatRZRetPatchInt3;
|
---|
378 | STAMCOUNTER StatRZRetPatchPF;
|
---|
379 | STAMCOUNTER StatRZRetPatchGP;
|
---|
380 | STAMCOUNTER StatRZRetPatchIretIRQ;
|
---|
381 | STAMCOUNTER StatRZRetRescheduleREM;
|
---|
382 | STAMCOUNTER StatRZRetToR3Total;
|
---|
383 | STAMCOUNTER StatRZRetToR3FF;
|
---|
384 | STAMCOUNTER StatRZRetToR3Unknown;
|
---|
385 | STAMCOUNTER StatRZRetToR3TMVirt;
|
---|
386 | STAMCOUNTER StatRZRetToR3HandyPages;
|
---|
387 | STAMCOUNTER StatRZRetToR3PDMQueues;
|
---|
388 | STAMCOUNTER StatRZRetToR3Rendezvous;
|
---|
389 | STAMCOUNTER StatRZRetToR3Timer;
|
---|
390 | STAMCOUNTER StatRZRetToR3DMA;
|
---|
391 | STAMCOUNTER StatRZRetToR3CritSect;
|
---|
392 | STAMCOUNTER StatRZRetToR3Iem;
|
---|
393 | STAMCOUNTER StatRZRetToR3Iom;
|
---|
394 | STAMCOUNTER StatRZRetTimerPending;
|
---|
395 | STAMCOUNTER StatRZRetInterruptPending;
|
---|
396 | STAMCOUNTER StatRZRetCallRing3;
|
---|
397 | STAMCOUNTER StatRZRetPATMDuplicateFn;
|
---|
398 | STAMCOUNTER StatRZRetPGMChangeMode;
|
---|
399 | STAMCOUNTER StatRZRetPendingRequest;
|
---|
400 | STAMCOUNTER StatRZRetPGMFlushPending;
|
---|
401 | STAMCOUNTER StatRZRetPatchTPR;
|
---|
402 | STAMCOUNTER StatRZCallPDMCritSectEnter;
|
---|
403 | STAMCOUNTER StatRZCallPDMLock;
|
---|
404 | STAMCOUNTER StatRZCallLogFlush;
|
---|
405 | STAMCOUNTER StatRZCallPGMPoolGrow;
|
---|
406 | STAMCOUNTER StatRZCallPGMMapChunk;
|
---|
407 | STAMCOUNTER StatRZCallPGMAllocHandy;
|
---|
408 | STAMCOUNTER StatRZCallRemReplay;
|
---|
409 | STAMCOUNTER StatRZCallVMSetError;
|
---|
410 | STAMCOUNTER StatRZCallVMSetRuntimeError;
|
---|
411 | STAMCOUNTER StatRZCallPGMLock;
|
---|
412 | /** @} */
|
---|
413 | } VMM;
|
---|
414 | /** Pointer to VMM. */
|
---|
415 | typedef VMM *PVMM;
|
---|
416 |
|
---|
417 |
|
---|
418 | /**
|
---|
419 | * VMMCPU Data (part of VMCPU)
|
---|
420 | */
|
---|
421 | typedef struct VMMCPU
|
---|
422 | {
|
---|
423 | /** Offset to the VMCPU structure.
|
---|
424 | * See VMM2VMCPU(). */
|
---|
425 | int32_t offVMCPU;
|
---|
426 |
|
---|
427 | /** The last RC/R0 return code. */
|
---|
428 | int32_t iLastGZRc;
|
---|
429 |
|
---|
430 | /** VMM stack, pointer to the top of the stack in R3.
|
---|
431 | * Stack is allocated from the hypervisor heap and is page aligned
|
---|
432 | * and always writable in RC. */
|
---|
433 | R3PTRTYPE(uint8_t *) pbEMTStackR3;
|
---|
434 | /** Pointer to the bottom of the stack - needed for doing relocations. */
|
---|
435 | RCPTRTYPE(uint8_t *) pbEMTStackRC;
|
---|
436 | /** Pointer to the bottom of the stack - needed for doing relocations. */
|
---|
437 | RCPTRTYPE(uint8_t *) pbEMTStackBottomRC;
|
---|
438 |
|
---|
439 | /** Pointer to the R0 logger instance - R3 Ptr.
|
---|
440 | * This is NULL if logging is disabled. */
|
---|
441 | R3PTRTYPE(PVMMR0LOGGER) pR0LoggerR3;
|
---|
442 | /** Pointer to the R0 logger instance - R0 Ptr.
|
---|
443 | * This is NULL if logging is disabled. */
|
---|
444 | R0PTRTYPE(PVMMR0LOGGER) pR0LoggerR0;
|
---|
445 |
|
---|
446 | /** Thread context switching hook (ring-0). */
|
---|
447 | RTTHREADCTXHOOK hCtxHook;
|
---|
448 |
|
---|
449 | /** @name Rendezvous
|
---|
450 | * @{ */
|
---|
451 | /** Whether the EMT is executing a rendezvous right now. For detecting
|
---|
452 | * attempts at recursive rendezvous. */
|
---|
453 | bool volatile fInRendezvous;
|
---|
454 | bool afPadding[HC_ARCH_BITS == 32 ? 3+4 : 7+8];
|
---|
455 | /** @} */
|
---|
456 |
|
---|
457 | /** @name Raw-mode context tracing data.
|
---|
458 | * @{ */
|
---|
459 | SUPDRVTRACERUSRCTX TracerCtx;
|
---|
460 | /** @} */
|
---|
461 |
|
---|
462 | /** Alignment padding, making sure u64CallRing3Arg is nicely aligned. */
|
---|
463 | uint32_t au32Padding1[3];
|
---|
464 |
|
---|
465 | /** @name Call Ring-3
|
---|
466 | * Formerly known as host calls.
|
---|
467 | * @{ */
|
---|
468 | /** The disable counter. */
|
---|
469 | uint32_t cCallRing3Disabled;
|
---|
470 | /** The pending operation. */
|
---|
471 | VMMCALLRING3 enmCallRing3Operation;
|
---|
472 | /** The result of the last operation. */
|
---|
473 | int32_t rcCallRing3;
|
---|
474 | /** The argument to the operation. */
|
---|
475 | uint64_t u64CallRing3Arg;
|
---|
476 | /** The Ring-0 notification callback. */
|
---|
477 | R0PTRTYPE(PFNVMMR0CALLRING3NOTIFICATION) pfnCallRing3CallbackR0;
|
---|
478 | /** The Ring-0 notification callback user argument. */
|
---|
479 | R0PTRTYPE(void *) pvCallRing3CallbackUserR0;
|
---|
480 | /** The Ring-0 jmp buffer.
|
---|
481 | * @remarks The size of this type isn't stable in assembly, so don't put
|
---|
482 | * anything that needs to be accessed from assembly after it. */
|
---|
483 | VMMR0JMPBUF CallRing3JmpBufR0;
|
---|
484 | /** @} */
|
---|
485 | } VMMCPU;
|
---|
486 | AssertCompileMemberAlignment(VMMCPU, TracerCtx, 8);
|
---|
487 | /** Pointer to VMMCPU. */
|
---|
488 | typedef VMMCPU *PVMMCPU;
|
---|
489 |
|
---|
490 |
|
---|
491 | /**
|
---|
492 | * The VMMRCEntry() codes.
|
---|
493 | */
|
---|
494 | typedef enum VMMRCOPERATION
|
---|
495 | {
|
---|
496 | /** Do GC module init. */
|
---|
497 | VMMRC_DO_VMMRC_INIT = 1,
|
---|
498 |
|
---|
499 | /** The first Trap testcase. */
|
---|
500 | VMMRC_DO_TESTCASE_TRAP_FIRST = 0x0dead000,
|
---|
501 | /** Trap 0 testcases, uArg selects the variation. */
|
---|
502 | VMMRC_DO_TESTCASE_TRAP_0 = VMMRC_DO_TESTCASE_TRAP_FIRST,
|
---|
503 | /** Trap 1 testcases, uArg selects the variation. */
|
---|
504 | VMMRC_DO_TESTCASE_TRAP_1,
|
---|
505 | /** Trap 2 testcases, uArg selects the variation. */
|
---|
506 | VMMRC_DO_TESTCASE_TRAP_2,
|
---|
507 | /** Trap 3 testcases, uArg selects the variation. */
|
---|
508 | VMMRC_DO_TESTCASE_TRAP_3,
|
---|
509 | /** Trap 4 testcases, uArg selects the variation. */
|
---|
510 | VMMRC_DO_TESTCASE_TRAP_4,
|
---|
511 | /** Trap 5 testcases, uArg selects the variation. */
|
---|
512 | VMMRC_DO_TESTCASE_TRAP_5,
|
---|
513 | /** Trap 6 testcases, uArg selects the variation. */
|
---|
514 | VMMRC_DO_TESTCASE_TRAP_6,
|
---|
515 | /** Trap 7 testcases, uArg selects the variation. */
|
---|
516 | VMMRC_DO_TESTCASE_TRAP_7,
|
---|
517 | /** Trap 8 testcases, uArg selects the variation. */
|
---|
518 | VMMRC_DO_TESTCASE_TRAP_8,
|
---|
519 | /** Trap 9 testcases, uArg selects the variation. */
|
---|
520 | VMMRC_DO_TESTCASE_TRAP_9,
|
---|
521 | /** Trap 0a testcases, uArg selects the variation. */
|
---|
522 | VMMRC_DO_TESTCASE_TRAP_0A,
|
---|
523 | /** Trap 0b testcases, uArg selects the variation. */
|
---|
524 | VMMRC_DO_TESTCASE_TRAP_0B,
|
---|
525 | /** Trap 0c testcases, uArg selects the variation. */
|
---|
526 | VMMRC_DO_TESTCASE_TRAP_0C,
|
---|
527 | /** Trap 0d testcases, uArg selects the variation. */
|
---|
528 | VMMRC_DO_TESTCASE_TRAP_0D,
|
---|
529 | /** Trap 0e testcases, uArg selects the variation. */
|
---|
530 | VMMRC_DO_TESTCASE_TRAP_0E,
|
---|
531 | /** The last trap testcase (exclusive). */
|
---|
532 | VMMRC_DO_TESTCASE_TRAP_LAST,
|
---|
533 | /** Testcase for checking interrupt forwarding. */
|
---|
534 | VMMRC_DO_TESTCASE_HYPER_INTERRUPT,
|
---|
535 | /** Switching testing and profiling stub. */
|
---|
536 | VMMRC_DO_TESTCASE_NOP,
|
---|
537 | /** Testcase for checking interrupt masking. */
|
---|
538 | VMMRC_DO_TESTCASE_INTERRUPT_MASKING,
|
---|
539 | /** Switching testing and profiling stub. */
|
---|
540 | VMMRC_DO_TESTCASE_HM_NOP,
|
---|
541 |
|
---|
542 | /** The usual 32-bit hack. */
|
---|
543 | VMMRC_DO_32_BIT_HACK = 0x7fffffff
|
---|
544 | } VMMRCOPERATION;
|
---|
545 |
|
---|
546 |
|
---|
547 |
|
---|
548 | /**
|
---|
549 | * MSR test result entry.
|
---|
550 | */
|
---|
551 | typedef struct VMMTESTMSRENTRY
|
---|
552 | {
|
---|
553 | /** The MSR number, including padding.
|
---|
554 | * Set to UINT64_MAX if invalid MSR. */
|
---|
555 | uint64_t uMsr;
|
---|
556 | /** The register value. */
|
---|
557 | uint64_t uValue;
|
---|
558 | } VMMTESTMSRENTRY;
|
---|
559 | /** Pointer to an MSR test result entry. */
|
---|
560 | typedef VMMTESTMSRENTRY *PVMMTESTMSRENTRY;
|
---|
561 |
|
---|
562 |
|
---|
563 |
|
---|
564 | RT_C_DECLS_BEGIN
|
---|
565 |
|
---|
566 | int vmmInitFormatTypes(void);
|
---|
567 | void vmmTermFormatTypes(void);
|
---|
568 | uint32_t vmmGetBuildType(void);
|
---|
569 |
|
---|
570 | #ifdef IN_RING3
|
---|
571 | int vmmR3SwitcherInit(PVM pVM);
|
---|
572 | void vmmR3SwitcherRelocate(PVM pVM, RTGCINTPTR offDelta);
|
---|
573 | #endif /* IN_RING3 */
|
---|
574 |
|
---|
575 | #ifdef IN_RING0
|
---|
576 | /**
|
---|
577 | * World switcher assembly routine.
|
---|
578 | * It will call VMMRCEntry().
|
---|
579 | *
|
---|
580 | * @returns return code from VMMRCEntry().
|
---|
581 | * @param pVM The cross context VM structure.
|
---|
582 | * @param uArg See VMMRCEntry().
|
---|
583 | * @internal
|
---|
584 | */
|
---|
585 | DECLASM(int) vmmR0WorldSwitch(PVM pVM, unsigned uArg);
|
---|
586 |
|
---|
587 | /**
|
---|
588 | * Callback function for vmmR0CallRing3SetJmp.
|
---|
589 | *
|
---|
590 | * @returns VBox status code.
|
---|
591 | * @param pVM The cross context VM structure.
|
---|
592 | */
|
---|
593 | typedef DECLCALLBACK(int) FNVMMR0SETJMP(PVM pVM, PVMCPU pVCpu);
|
---|
594 | /** Pointer to FNVMMR0SETJMP(). */
|
---|
595 | typedef FNVMMR0SETJMP *PFNVMMR0SETJMP;
|
---|
596 |
|
---|
597 | /**
|
---|
598 | * The setjmp variant used for calling Ring-3.
|
---|
599 | *
|
---|
600 | * This differs from the normal setjmp in that it will resume VMMRZCallRing3 if we're
|
---|
601 | * in the middle of a ring-3 call. Another differences is the function pointer and
|
---|
602 | * argument. This has to do with resuming code and the stack frame of the caller.
|
---|
603 | *
|
---|
604 | * @returns VINF_SUCCESS on success or whatever is passed to vmmR0CallRing3LongJmp.
|
---|
605 | * @param pJmpBuf The jmp_buf to set.
|
---|
606 | * @param pfn The function to be called when not resuming.
|
---|
607 | * @param pVM The cross context VM structure.
|
---|
608 | * @param pVCpu The cross context virtual CPU structure of the calling EMT.
|
---|
609 | */
|
---|
610 | DECLASM(int) vmmR0CallRing3SetJmp(PVMMR0JMPBUF pJmpBuf, PFNVMMR0SETJMP pfn, PVM pVM, PVMCPU pVCpu);
|
---|
611 |
|
---|
612 | /**
|
---|
613 | * Callback function for vmmR0CallRing3SetJmpEx.
|
---|
614 | *
|
---|
615 | * @returns VBox status code.
|
---|
616 | * @param pvUser The user argument.
|
---|
617 | */
|
---|
618 | typedef DECLCALLBACK(int) FNVMMR0SETJMPEX(void *pvUser);
|
---|
619 | /** Pointer to FNVMMR0SETJMP(). */
|
---|
620 | typedef FNVMMR0SETJMPEX *PFNVMMR0SETJMPEX;
|
---|
621 |
|
---|
622 | /**
|
---|
623 | * Same as vmmR0CallRing3SetJmp except for the function signature.
|
---|
624 | *
|
---|
625 | * @returns VINF_SUCCESS on success or whatever is passed to vmmR0CallRing3LongJmp.
|
---|
626 | * @param pJmpBuf The jmp_buf to set.
|
---|
627 | * @param pfn The function to be called when not resuming.
|
---|
628 | * @param pvUser The argument of that function.
|
---|
629 | */
|
---|
630 | DECLASM(int) vmmR0CallRing3SetJmpEx(PVMMR0JMPBUF pJmpBuf, PFNVMMR0SETJMPEX pfn, void *pvUser);
|
---|
631 |
|
---|
632 |
|
---|
633 | /**
|
---|
634 | * Worker for VMMRZCallRing3.
|
---|
635 | * This will save the stack and registers.
|
---|
636 | *
|
---|
637 | * @returns rc.
|
---|
638 | * @param pJmpBuf Pointer to the jump buffer.
|
---|
639 | * @param rc The return code.
|
---|
640 | */
|
---|
641 | DECLASM(int) vmmR0CallRing3LongJmp(PVMMR0JMPBUF pJmpBuf, int rc);
|
---|
642 |
|
---|
643 | /**
|
---|
644 | * Internal R0 logger worker: Logger wrapper.
|
---|
645 | */
|
---|
646 | VMMR0DECL(void) vmmR0LoggerWrapper(const char *pszFormat, ...);
|
---|
647 |
|
---|
648 | /**
|
---|
649 | * Internal R0 logger worker: Flush logger.
|
---|
650 | *
|
---|
651 | * @param pLogger The logger instance to flush.
|
---|
652 | * @remark This function must be exported!
|
---|
653 | */
|
---|
654 | VMMR0DECL(void) vmmR0LoggerFlush(PRTLOGGER pLogger);
|
---|
655 |
|
---|
656 | /**
|
---|
657 | * Internal R0 logger worker: Custom prefix.
|
---|
658 | *
|
---|
659 | * @returns Number of chars written.
|
---|
660 | *
|
---|
661 | * @param pLogger The logger instance.
|
---|
662 | * @param pchBuf The output buffer.
|
---|
663 | * @param cchBuf The size of the buffer.
|
---|
664 | * @param pvUser User argument (ignored).
|
---|
665 | */
|
---|
666 | VMMR0DECL(size_t) vmmR0LoggerPrefix(PRTLOGGER pLogger, char *pchBuf, size_t cchBuf, void *pvUser);
|
---|
667 |
|
---|
668 | # ifdef VBOX_WITH_TRIPLE_FAULT_HACK
|
---|
669 | int vmmR0TripleFaultHackInit(void);
|
---|
670 | void vmmR0TripleFaultHackTerm(void);
|
---|
671 | # endif
|
---|
672 |
|
---|
673 | #endif /* IN_RING0 */
|
---|
674 | #ifdef IN_RC
|
---|
675 |
|
---|
676 | /**
|
---|
677 | * Internal GC logger worker: Logger wrapper.
|
---|
678 | */
|
---|
679 | VMMRCDECL(void) vmmGCLoggerWrapper(const char *pszFormat, ...);
|
---|
680 |
|
---|
681 | /**
|
---|
682 | * Internal GC release logger worker: Logger wrapper.
|
---|
683 | */
|
---|
684 | VMMRCDECL(void) vmmGCRelLoggerWrapper(const char *pszFormat, ...);
|
---|
685 |
|
---|
686 | /**
|
---|
687 | * Internal GC logger worker: Flush logger.
|
---|
688 | *
|
---|
689 | * @returns VINF_SUCCESS.
|
---|
690 | * @param pLogger The logger instance to flush.
|
---|
691 | * @remark This function must be exported!
|
---|
692 | */
|
---|
693 | VMMRCDECL(int) vmmGCLoggerFlush(PRTLOGGERRC pLogger);
|
---|
694 |
|
---|
695 | /** @name Trap testcases and related labels.
|
---|
696 | * @{ */
|
---|
697 | DECLASM(void) vmmGCEnableWP(void);
|
---|
698 | DECLASM(void) vmmGCDisableWP(void);
|
---|
699 | DECLASM(int) vmmGCTestTrap3(void);
|
---|
700 | DECLASM(int) vmmGCTestTrap8(void);
|
---|
701 | DECLASM(int) vmmGCTestTrap0d(void);
|
---|
702 | DECLASM(int) vmmGCTestTrap0e(void);
|
---|
703 | DECLASM(int) vmmGCTestTrap0e_FaultEIP(void); /**< a label */
|
---|
704 | DECLASM(int) vmmGCTestTrap0e_ResumeEIP(void); /**< a label */
|
---|
705 | /** @} */
|
---|
706 |
|
---|
707 | #endif /* IN_RC */
|
---|
708 |
|
---|
709 | RT_C_DECLS_END
|
---|
710 |
|
---|
711 | /** @} */
|
---|
712 |
|
---|
713 | #endif
|
---|