VirtualBox

source: vbox/trunk/src/VBox/VMM/include/VMMInternal.h@ 91283

Last change on this file since 91283 was 91245, checked in by vboxsync, 3 years ago

VMM/PGM: Removed VMMCALLRING3_PGM_MAP_CHUNK and PGMR3PhysChunkMap as it's unused now after bugref:9627 became default everywhere. bugref:10093

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 28.4 KB
Line 
1/* $Id: VMMInternal.h 91245 2021-09-15 10:53:06Z vboxsync $ */
2/** @file
3 * VMM - Internal header file.
4 */
5
6/*
7 * Copyright (C) 2006-2020 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 VMM_INCLUDED_SRC_include_VMMInternal_h
19#define VMM_INCLUDED_SRC_include_VMMInternal_h
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23
24#include <VBox/cdefs.h>
25#include <VBox/sup.h>
26#include <VBox/vmm/stam.h>
27#include <VBox/vmm/vmm.h>
28#include <VBox/param.h>
29#include <VBox/log.h>
30#include <iprt/critsect.h>
31
32#if !defined(IN_VMM_R3) && !defined(IN_VMM_R0) && !defined(IN_VMM_RC)
33# error "Not in VMM! This is an internal header!"
34#endif
35#if HC_ARCH_BITS == 32
36# error "32-bit hosts are no longer supported. Go back to 6.0 or earlier!"
37#endif
38
39
40
41/** @defgroup grp_vmm_int Internals
42 * @ingroup grp_vmm
43 * @internal
44 * @{
45 */
46
47/** @def VBOX_WITH_RC_RELEASE_LOGGING
48 * Enables RC release logging. */
49#define VBOX_WITH_RC_RELEASE_LOGGING
50
51/** @def VBOX_WITH_R0_LOGGING
52 * Enables Ring-0 logging (non-release).
53 *
54 * Ring-0 logging isn't 100% safe yet (thread id reuse / process exit cleanup),
55 * so you have to sign up here by adding your defined(DEBUG_<userid>) to the
56 * \#if, or by adding VBOX_WITH_R0_LOGGING to your LocalConfig.kmk.
57 */
58#if defined(DEBUG_sandervl) || defined(DEBUG_frank) || defined(DEBUG_ramshankar) || defined(DOXYGEN_RUNNING)
59# define VBOX_WITH_R0_LOGGING
60#endif
61
62/** @def VBOX_STRICT_VMM_STACK
63 * Enables VMM stack guard pages to catch stack over- and underruns. */
64#if defined(VBOX_STRICT) || defined(DOXYGEN_RUNNING)
65# define VBOX_STRICT_VMM_STACK
66#endif
67
68
69/** Number of buffers per logger. */
70#define VMMLOGGER_BUFFER_COUNT 4
71
72/**
73 * R0 logger data (ring-0 only data).
74 */
75typedef struct VMMR0PERVCPULOGGER
76{
77 /** Pointer to the logger instance.
78 * The RTLOGGER::u32UserValue1 member is used for flags and magic, while the
79 * RTLOGGER::u64UserValue2 member is the corresponding PGVMCPU value.
80 * RTLOGGER::u64UserValue3 is currently and set to the PGVMCPU value too. */
81 R0PTRTYPE(PRTLOGGER) pLogger;
82 /** Log buffer descriptor.
83 * The buffer is allocated in a common block for all VCpus, see VMMR0PERVM. */
84 RTLOGBUFFERDESC aBufDescs[VMMLOGGER_BUFFER_COUNT];
85 /** Flag indicating whether we've registered the instance already. */
86 bool fRegistered;
87 /** Set if the EMT is waiting on hEventFlushWait. */
88 bool fEmtWaiting;
89 /** Set while we're inside vmmR0LoggerFlushCommon to prevent recursion. */
90 bool fFlushing;
91 bool afPadding[1];
92 /** Number of buffers currently queued for flushing. */
93 uint32_t volatile cFlushing;
94 /** The event semaphore the EMT waits on while the buffer is being flushed. */
95 RTSEMEVENT hEventFlushWait;
96} VMMR0PERVCPULOGGER;
97/** Pointer to the R0 logger data (ring-0 only). */
98typedef VMMR0PERVCPULOGGER *PVMMR0PERVCPULOGGER;
99
100
101/**
102 * R0 logger data shared with ring-3 (per CPU).
103 */
104typedef struct VMMR3CPULOGGER
105{
106 /** Buffer info. */
107 struct
108 {
109 /** Auxiliary buffer descriptor. */
110 RTLOGBUFFERAUXDESC AuxDesc;
111 /** Ring-3 mapping of the logging buffer. */
112 R3PTRTYPE(char *) pchBufR3;
113 } aBufs[VMMLOGGER_BUFFER_COUNT];
114 /** The current buffer. */
115 uint32_t idxBuf;
116 /** Number of buffers currently queued for flushing (copy of
117 * VMMR0PERVCPULOGGER::cFlushing). */
118 uint32_t volatile cFlushing;
119 /** The buffer size. */
120 uint32_t cbBuf;
121 /** Number of bytes dropped because the flush context didn't allow waiting. */
122 uint32_t cbDropped;
123 STAMCOUNTER StatFlushes;
124 STAMCOUNTER StatCannotBlock;
125 STAMPROFILE StatWait;
126 STAMPROFILE StatRaces;
127 STAMCOUNTER StatRacesToR0;
128} VMMR3CPULOGGER;
129/** Pointer to r0 logger data shared with ring-3. */
130typedef VMMR3CPULOGGER *PVMMR3CPULOGGER;
131
132/** @name Logger indexes for VMMR0PERVCPU::u.aLoggers and VMMCPU::u.aLoggers.
133 * @{ */
134#define VMMLOGGER_IDX_REGULAR 0
135#define VMMLOGGER_IDX_RELEASE 1
136#define VMMLOGGER_IDX_MAX 2
137/** @} */
138
139
140/**
141 * Jump buffer for the setjmp/longjmp like constructs used to
142 * quickly 'call' back into Ring-3.
143 */
144typedef struct VMMR0JMPBUF
145{
146 /** Traditional jmp_buf stuff
147 * @{ */
148#if HC_ARCH_BITS == 32
149 uint32_t ebx;
150 uint32_t esi;
151 uint32_t edi;
152 uint32_t ebp;
153 uint32_t esp;
154 uint32_t eip;
155 uint32_t eflags;
156#endif
157#if HC_ARCH_BITS == 64
158 uint64_t rbx;
159# ifdef RT_OS_WINDOWS
160 uint64_t rsi;
161 uint64_t rdi;
162# endif
163 uint64_t rbp;
164 uint64_t r12;
165 uint64_t r13;
166 uint64_t r14;
167 uint64_t r15;
168 uint64_t rsp;
169 uint64_t rip;
170# ifdef RT_OS_WINDOWS
171 uint128_t xmm6;
172 uint128_t xmm7;
173 uint128_t xmm8;
174 uint128_t xmm9;
175 uint128_t xmm10;
176 uint128_t xmm11;
177 uint128_t xmm12;
178 uint128_t xmm13;
179 uint128_t xmm14;
180 uint128_t xmm15;
181# endif
182 uint64_t rflags;
183#endif
184 /** @} */
185
186 /** Flag that indicates that we've done a ring-3 call. */
187 bool fInRing3Call;
188 /** The number of bytes we've saved. */
189 uint32_t cbSavedStack;
190 /** Pointer to the buffer used to save the stack.
191 * This is assumed to be 8KB. */
192 RTR0PTR pvSavedStack;
193 /** Esp we we match against esp on resume to make sure the stack wasn't relocated. */
194 RTHCUINTREG SpCheck;
195 /** The esp we should resume execution with after the restore. */
196 RTHCUINTREG SpResume;
197 /** ESP/RSP at the time of the jump to ring 3. */
198 RTHCUINTREG SavedEsp;
199 /** EBP/RBP at the time of the jump to ring 3. */
200 RTHCUINTREG SavedEbp;
201 /** EIP/RIP within vmmR0CallRing3LongJmp for assisting unwinding. */
202 RTHCUINTREG SavedEipForUnwind;
203 /** Unwind: The vmmR0CallRing3SetJmp return address value. */
204 RTHCUINTREG UnwindRetPcValue;
205 /** Unwind: The vmmR0CallRing3SetJmp return address stack location. */
206 RTHCUINTREG UnwindRetPcLocation;
207
208 /** The function last being executed here. */
209 RTHCUINTREG pfn;
210 /** The first argument to the function. */
211 RTHCUINTREG pvUser1;
212 /** The second argument to the function. */
213 RTHCUINTREG pvUser2;
214
215#if HC_ARCH_BITS == 32
216 /** Alignment padding. */
217 uint32_t uPadding;
218#endif
219
220 /** Stats: Max amount of stack used. */
221 uint32_t cbUsedMax;
222 /** Stats: Average stack usage. (Avg = cbUsedTotal / cUsedTotal) */
223 uint32_t cbUsedAvg;
224 /** Stats: Total amount of stack used. */
225 uint64_t cbUsedTotal;
226 /** Stats: Number of stack usages. */
227 uint64_t cUsedTotal;
228} VMMR0JMPBUF;
229/** Pointer to a ring-0 jump buffer. */
230typedef VMMR0JMPBUF *PVMMR0JMPBUF;
231
232
233/**
234 * Log flusher job.
235 *
236 * There is a ring buffer of these in ring-0 (VMMR0PERVM::aLogFlushRing) and a
237 * copy of the current one in the shared VM structure (VMM::LogFlusherItem).
238 */
239typedef union VMMLOGFLUSHERENTRY
240{
241 struct
242 {
243 /** The virtual CPU ID. */
244 uint32_t idCpu : 16;
245 /** The logger: 0 for release, 1 for debug. */
246 uint32_t idxLogger : 8;
247 /** The buffer to be flushed. */
248 uint32_t idxBuffer : 7;
249 /** Set by the flusher thread once it fetched the entry and started
250 * processing it. */
251 uint32_t fProcessing : 1;
252 } s;
253 uint32_t u32;
254} VMMLOGFLUSHERENTRY;
255
256
257/**
258 * VMM Data (part of VM)
259 */
260typedef struct VMM
261{
262 /** Whether we should use the periodic preemption timers. */
263 bool fUsePeriodicPreemptionTimers;
264 /** Alignment padding. */
265 bool afPadding0[7];
266
267#if 0 /* pointless when timers doesn't run on EMT */
268 /** The EMT yield timer. */
269 TMTIMERHANDLE hYieldTimer;
270 /** The period to the next timeout when suspended or stopped.
271 * This is 0 when running. */
272 uint32_t cYieldResumeMillies;
273 /** The EMT yield timer interval (milliseconds). */
274 uint32_t cYieldEveryMillies;
275 /** The timestamp of the previous yield. (nano) */
276 uint64_t u64LastYield;
277#endif
278
279 /** @name EMT Rendezvous
280 * @{ */
281 /** Semaphore to wait on upon entering ordered execution. */
282 R3PTRTYPE(PRTSEMEVENT) pahEvtRendezvousEnterOrdered;
283 /** Semaphore to wait on upon entering for one-by-one execution. */
284 RTSEMEVENT hEvtRendezvousEnterOneByOne;
285 /** Semaphore to wait on upon entering for all-at-once execution. */
286 RTSEMEVENTMULTI hEvtMulRendezvousEnterAllAtOnce;
287 /** Semaphore to wait on when done. */
288 RTSEMEVENTMULTI hEvtMulRendezvousDone;
289 /** Semaphore the VMMR3EmtRendezvous caller waits on at the end. */
290 RTSEMEVENT hEvtRendezvousDoneCaller;
291 /** Semaphore to wait on upon recursing. */
292 RTSEMEVENTMULTI hEvtMulRendezvousRecursionPush;
293 /** Semaphore to wait on after done with recursion (caller restoring state). */
294 RTSEMEVENTMULTI hEvtMulRendezvousRecursionPop;
295 /** Semaphore the initiator waits on while the EMTs are getting into position
296 * on hEvtMulRendezvousRecursionPush. */
297 RTSEMEVENT hEvtRendezvousRecursionPushCaller;
298 /** Semaphore the initiator waits on while the EMTs sitting on
299 * hEvtMulRendezvousRecursionPop wakes up and leave. */
300 RTSEMEVENT hEvtRendezvousRecursionPopCaller;
301 /** Callback. */
302 R3PTRTYPE(PFNVMMEMTRENDEZVOUS) volatile pfnRendezvous;
303 /** The user argument for the callback. */
304 RTR3PTR volatile pvRendezvousUser;
305 /** Flags. */
306 volatile uint32_t fRendezvousFlags;
307 /** The number of EMTs that has entered. */
308 volatile uint32_t cRendezvousEmtsEntered;
309 /** The number of EMTs that has done their job. */
310 volatile uint32_t cRendezvousEmtsDone;
311 /** The number of EMTs that has returned. */
312 volatile uint32_t cRendezvousEmtsReturned;
313 /** The status code. */
314 volatile int32_t i32RendezvousStatus;
315 /** Spin lock. */
316 volatile uint32_t u32RendezvousLock;
317 /** The recursion depth. */
318 volatile uint32_t cRendezvousRecursions;
319 /** The number of EMTs that have entered the recursion routine. */
320 volatile uint32_t cRendezvousEmtsRecursingPush;
321 /** The number of EMTs that have leaft the recursion routine. */
322 volatile uint32_t cRendezvousEmtsRecursingPop;
323 /** Triggers rendezvous recursion in the other threads. */
324 volatile bool fRendezvousRecursion;
325
326 /** @} */
327
328 /** RTThreadPreemptIsPendingTrusty() result, set by vmmR0InitVM() for
329 * release logging purposes. */
330 bool fIsPreemptPendingApiTrusty : 1;
331 /** The RTThreadPreemptIsPossible() result, set by vmmR0InitVM() for
332 * release logging purposes. */
333 bool fIsPreemptPossible : 1;
334 /** Set if ring-0 uses context hooks. */
335 bool fIsUsingContextHooks : 1;
336
337 bool afAlignment2[2]; /**< Alignment padding. */
338
339 /** Buffer for storing the standard assertion message for a ring-0 assertion.
340 * Used for saving the assertion message text for the release log and guru
341 * meditation dump. */
342 char szRing0AssertMsg1[512];
343 /** Buffer for storing the custom message for a ring-0 assertion. */
344 char szRing0AssertMsg2[256];
345
346 /** @name Logging
347 * @{ */
348 /** Used when setting up ring-0 logger. */
349 uint64_t nsProgramStart;
350 /** Log flusher thread. */
351 RTTHREAD hLogFlusherThread;
352 /** Copy of the current work log flusher work item. */
353 VMMLOGFLUSHERENTRY volatile LogFlusherItem;
354 STAMCOUNTER StatLogFlusherFlushes;
355 STAMCOUNTER StatLogFlusherNoWakeUp;
356 /** @} */
357
358 /** Number of VMMR0_DO_HM_RUN or VMMR0_DO_NEM_RUN calls. */
359 STAMCOUNTER StatRunGC;
360
361 /** Statistics for each of the RC/R0 return codes.
362 * @{ */
363 STAMCOUNTER StatRZRetNormal;
364 STAMCOUNTER StatRZRetInterrupt;
365 STAMCOUNTER StatRZRetInterruptHyper;
366 STAMCOUNTER StatRZRetGuestTrap;
367 STAMCOUNTER StatRZRetRingSwitch;
368 STAMCOUNTER StatRZRetRingSwitchInt;
369 STAMCOUNTER StatRZRetStaleSelector;
370 STAMCOUNTER StatRZRetIRETTrap;
371 STAMCOUNTER StatRZRetEmulate;
372 STAMCOUNTER StatRZRetPatchEmulate;
373 STAMCOUNTER StatRZRetIORead;
374 STAMCOUNTER StatRZRetIOWrite;
375 STAMCOUNTER StatRZRetIOCommitWrite;
376 STAMCOUNTER StatRZRetMMIORead;
377 STAMCOUNTER StatRZRetMMIOWrite;
378 STAMCOUNTER StatRZRetMMIOCommitWrite;
379 STAMCOUNTER StatRZRetMMIOPatchRead;
380 STAMCOUNTER StatRZRetMMIOPatchWrite;
381 STAMCOUNTER StatRZRetMMIOReadWrite;
382 STAMCOUNTER StatRZRetMSRRead;
383 STAMCOUNTER StatRZRetMSRWrite;
384 STAMCOUNTER StatRZRetLDTFault;
385 STAMCOUNTER StatRZRetGDTFault;
386 STAMCOUNTER StatRZRetIDTFault;
387 STAMCOUNTER StatRZRetTSSFault;
388 STAMCOUNTER StatRZRetCSAMTask;
389 STAMCOUNTER StatRZRetSyncCR3;
390 STAMCOUNTER StatRZRetMisc;
391 STAMCOUNTER StatRZRetPatchInt3;
392 STAMCOUNTER StatRZRetPatchPF;
393 STAMCOUNTER StatRZRetPatchGP;
394 STAMCOUNTER StatRZRetPatchIretIRQ;
395 STAMCOUNTER StatRZRetRescheduleREM;
396 STAMCOUNTER StatRZRetToR3Total;
397 STAMCOUNTER StatRZRetToR3FF;
398 STAMCOUNTER StatRZRetToR3Unknown;
399 STAMCOUNTER StatRZRetToR3TMVirt;
400 STAMCOUNTER StatRZRetToR3HandyPages;
401 STAMCOUNTER StatRZRetToR3PDMQueues;
402 STAMCOUNTER StatRZRetToR3Rendezvous;
403 STAMCOUNTER StatRZRetToR3Timer;
404 STAMCOUNTER StatRZRetToR3DMA;
405 STAMCOUNTER StatRZRetToR3CritSect;
406 STAMCOUNTER StatRZRetToR3Iem;
407 STAMCOUNTER StatRZRetToR3Iom;
408 STAMCOUNTER StatRZRetTimerPending;
409 STAMCOUNTER StatRZRetInterruptPending;
410 STAMCOUNTER StatRZRetCallRing3;
411 STAMCOUNTER StatRZRetPATMDuplicateFn;
412 STAMCOUNTER StatRZRetPGMChangeMode;
413 STAMCOUNTER StatRZRetPendingRequest;
414 STAMCOUNTER StatRZRetPGMFlushPending;
415 STAMCOUNTER StatRZRetPatchTPR;
416 STAMCOUNTER StatRZCallPGMAllocHandy;
417 /** @} */
418} VMM;
419/** Pointer to VMM. */
420typedef VMM *PVMM;
421
422
423/**
424 * VMMCPU Data (part of VMCPU)
425 */
426typedef struct VMMCPU
427{
428 /** The last RC/R0 return code. */
429 int32_t iLastGZRc;
430 /** Alignment padding. */
431 uint32_t u32Padding0;
432
433 /** VMM stack, pointer to the top of the stack in R3.
434 * Stack is allocated from the hypervisor heap and is page aligned
435 * and always writable in RC. */
436 R3PTRTYPE(uint8_t *) pbEMTStackR3;
437
438 /** @name Rendezvous
439 * @{ */
440 /** Whether the EMT is executing a rendezvous right now. For detecting
441 * attempts at recursive rendezvous. */
442 bool volatile fInRendezvous;
443 bool afPadding1[2];
444 /** @} */
445
446 /** Whether we can HLT in VMMR0 rather than having to return to EM.
447 * Updated by vmR3SetHaltMethodU(). */
448 bool fMayHaltInRing0;
449 /** The minimum delta for which we can HLT in ring-0 for.
450 * The deadlines we can calculate are from TM, so, if it's too close
451 * we should just return to ring-3 and run the timer wheel, no point
452 * in spinning in ring-0.
453 * Updated by vmR3SetHaltMethodU(). */
454 uint32_t cNsSpinBlockThreshold;
455 /** Number of ring-0 halts (used for depreciating following values). */
456 uint32_t cR0Halts;
457 /** Number of ring-0 halts succeeding (VINF_SUCCESS) recently. */
458 uint32_t cR0HaltsSucceeded;
459 /** Number of ring-0 halts failing (VINF_EM_HALT) recently. */
460 uint32_t cR0HaltsToRing3;
461 /** Padding */
462 uint32_t u32Padding2;
463
464 /** @name Raw-mode context tracing data.
465 * @{ */
466 SUPDRVTRACERUSRCTX TracerCtx;
467 /** @} */
468
469 /** Alignment padding, making sure u64CallRing3Arg and CallRing3JmpBufR0 are nicely aligned. */
470 uint32_t au32Padding3[1];
471
472 /** @name Call Ring-3
473 * Formerly known as host calls.
474 * @{ */
475 /** The disable counter. */
476 uint32_t cCallRing3Disabled;
477 /** The pending operation. */
478 VMMCALLRING3 enmCallRing3Operation;
479 /** The result of the last operation. */
480 int32_t rcCallRing3;
481 /** The argument to the operation. */
482 uint64_t u64CallRing3Arg;
483 /** The Ring-0 notification callback. */
484 R0PTRTYPE(PFNVMMR0CALLRING3NOTIFICATION) pfnCallRing3CallbackR0;
485 /** The Ring-0 notification callback user argument. */
486 R0PTRTYPE(void *) pvCallRing3CallbackUserR0;
487 /** The Ring-0 jmp buffer.
488 * @remarks The size of this type isn't stable in assembly, so don't put
489 * anything that needs to be accessed from assembly after it. */
490 VMMR0JMPBUF CallRing3JmpBufR0;
491 /** @} */
492
493 /**
494 * Loggers.
495 */
496 union
497 {
498 struct
499 {
500 /** The R0 logger data shared with ring-3. */
501 VMMR3CPULOGGER Logger;
502 /** The R0 release logger data shared with ring-3. */
503 VMMR3CPULOGGER RelLogger;
504 } s;
505 /** Array view. */
506 VMMR3CPULOGGER aLoggers[VMMLOGGER_IDX_MAX];
507 } u;
508
509 STAMPROFILE StatR0HaltBlock;
510 STAMPROFILE StatR0HaltBlockOnTime;
511 STAMPROFILE StatR0HaltBlockOverslept;
512 STAMPROFILE StatR0HaltBlockInsomnia;
513 STAMCOUNTER StatR0HaltExec;
514 STAMCOUNTER StatR0HaltExecFromBlock;
515 STAMCOUNTER StatR0HaltExecFromSpin;
516 STAMCOUNTER StatR0HaltToR3;
517 STAMCOUNTER StatR0HaltToR3FromSpin;
518 STAMCOUNTER StatR0HaltToR3Other;
519 STAMCOUNTER StatR0HaltToR3PendingFF;
520 STAMCOUNTER StatR0HaltToR3SmallDelta;
521 STAMCOUNTER StatR0HaltToR3PostNoInt;
522 STAMCOUNTER StatR0HaltToR3PostPendingFF;
523} VMMCPU;
524AssertCompileMemberAlignment(VMMCPU, TracerCtx, 8);
525AssertCompile( RTASSERT_OFFSET_OF(VMMCPU, u.s.Logger)
526 == RTASSERT_OFFSET_OF(VMMCPU, u.aLoggers) + sizeof(VMMR3CPULOGGER) * VMMLOGGER_IDX_REGULAR);
527AssertCompile(RTASSERT_OFFSET_OF(VMMCPU, u.s.RelLogger)
528 == RTASSERT_OFFSET_OF(VMMCPU, u.aLoggers) + sizeof(VMMR3CPULOGGER) * VMMLOGGER_IDX_RELEASE);
529
530/** Pointer to VMMCPU. */
531typedef VMMCPU *PVMMCPU;
532
533/**
534 * VMM per-VCpu ring-0 only instance data.
535 */
536typedef struct VMMR0PERVCPU
537{
538 /** The EMT hash table index. */
539 uint16_t idxEmtHash;
540 /** Flag indicating whether we've disabled flushing (world switch) or not. */
541 bool fLogFlushingDisabled;
542 bool afPadding1[5];
543 /** Pointer to the VMMR0EntryFast preemption state structure.
544 * This is used to temporarily restore preemption before blocking. */
545 R0PTRTYPE(PRTTHREADPREEMPTSTATE) pPreemptState;
546 /** Thread context switching hook (ring-0). */
547 RTTHREADCTXHOOK hCtxHook;
548
549 /** @name Arguments passed by VMMR0EntryEx via vmmR0CallRing3SetJmpEx.
550 * @note Cannot be put on the stack as the location may change and upset the
551 * validation of resume-after-ring-3-call logic.
552 * @{ */
553 PGVM pGVM;
554 VMCPUID idCpu;
555 VMMR0OPERATION enmOperation;
556 PSUPVMMR0REQHDR pReq;
557 uint64_t u64Arg;
558 PSUPDRVSESSION pSession;
559 /** @} */
560
561 /**
562 * Loggers
563 */
564 union
565 {
566 struct
567 {
568 /** The R0 logger data. */
569 VMMR0PERVCPULOGGER Logger;
570 /** The R0 release logger data. */
571 VMMR0PERVCPULOGGER RelLogger;
572 } s;
573 /** Array view. */
574 VMMR0PERVCPULOGGER aLoggers[VMMLOGGER_IDX_MAX];
575 } u;
576} VMMR0PERVCPU;
577AssertCompile( RTASSERT_OFFSET_OF(VMMR0PERVCPU, u.s.Logger)
578 == RTASSERT_OFFSET_OF(VMMR0PERVCPU, u.aLoggers) + sizeof(VMMR0PERVCPULOGGER) * VMMLOGGER_IDX_REGULAR);
579AssertCompile(RTASSERT_OFFSET_OF(VMMR0PERVCPU, u.s.RelLogger)
580 == RTASSERT_OFFSET_OF(VMMR0PERVCPU, u.aLoggers) + sizeof(VMMR0PERVCPULOGGER) * VMMLOGGER_IDX_RELEASE);
581/** Pointer to VMM ring-0 VMCPU instance data. */
582typedef VMMR0PERVCPU *PVMMR0PERVCPU;
583
584/** @name RTLOGGER::u32UserValue1 Flags
585 * @{ */
586/** The magic value. */
587#define VMMR0_LOGGER_FLAGS_MAGIC_VALUE UINT32_C(0x7d297f05)
588/** Part of the flags value used for the magic. */
589#define VMMR0_LOGGER_FLAGS_MAGIC_MASK UINT32_C(0xffffff0f)
590/** @} */
591
592
593/**
594 * VMM data kept in the ring-0 GVM.
595 */
596typedef struct VMMR0PERVM
597{
598 /** Set if vmmR0InitVM has been called. */
599 bool fCalledInitVm;
600 bool afPadding1[7];
601
602 /** @name Logging
603 * @{ */
604 /** Logger (debug) buffer allocation.
605 * This covers all CPUs. */
606 RTR0MEMOBJ hMemObjLogger;
607 /** The ring-3 mapping object for hMemObjLogger. */
608 RTR0MEMOBJ hMapObjLogger;
609
610 /** Release logger buffer allocation.
611 * This covers all CPUs. */
612 RTR0MEMOBJ hMemObjReleaseLogger;
613 /** The ring-3 mapping object for hMemObjReleaseLogger. */
614 RTR0MEMOBJ hMapObjReleaseLogger;
615
616 struct
617 {
618 /** Spinlock protecting the logger ring buffer and associated variables. */
619 R0PTRTYPE(RTSPINLOCK) hSpinlock;
620 /** The log flusher thread handle to make sure there is only one. */
621 RTNATIVETHREAD hThread;
622 /** The handle to the event semaphore the log flusher waits on. */
623 RTSEMEVENT hEvent;
624 /** The index of the log flusher queue head (flusher thread side). */
625 uint32_t volatile idxRingHead;
626 /** The index of the log flusher queue tail (EMT side). */
627 uint32_t volatile idxRingTail;
628 /** Set if the log flusher thread is waiting for work and needs poking. */
629 bool volatile fThreadWaiting;
630 /** Set when the log flusher thread should shut down. */
631 bool volatile fThreadShutdown;
632 /** Indicates that the log flusher thread is running. */
633 bool volatile fThreadRunning;
634 bool afPadding2[5];
635 STAMCOUNTER StatFlushes;
636 STAMCOUNTER StatNoWakeUp;
637 /** Logger ring buffer.
638 * This is for communicating with the log flusher thread. */
639 VMMLOGFLUSHERENTRY aRing[VMM_MAX_CPU_COUNT * 2 /*loggers*/ * 1 /*buffer*/ + 16 /*fudge*/];
640 } LogFlusher;
641 /** @} */
642} VMMR0PERVM;
643
644RT_C_DECLS_BEGIN
645
646int vmmInitFormatTypes(void);
647void vmmTermFormatTypes(void);
648uint32_t vmmGetBuildType(void);
649
650#ifdef IN_RING3
651int vmmR3SwitcherInit(PVM pVM);
652void vmmR3SwitcherRelocate(PVM pVM, RTGCINTPTR offDelta);
653#endif /* IN_RING3 */
654
655#ifdef IN_RING0
656
657/**
658 * World switcher assembly routine.
659 * It will call VMMRCEntry().
660 *
661 * @returns return code from VMMRCEntry().
662 * @param pVM The cross context VM structure.
663 * @param uArg See VMMRCEntry().
664 * @internal
665 */
666DECLASM(int) vmmR0WorldSwitch(PVM pVM, unsigned uArg);
667
668/**
669 * Callback function for vmmR0CallRing3SetJmp.
670 *
671 * @returns VBox status code.
672 * @param pVM The cross context VM structure.
673 * @param pVCpu The cross context virtual CPU structure of the calling EMT.
674 */
675typedef DECLCALLBACKTYPE(int, FNVMMR0SETJMP,(PVMCC pVM, PVMCPUCC pVCpu));
676/** Pointer to FNVMMR0SETJMP(). */
677typedef FNVMMR0SETJMP *PFNVMMR0SETJMP;
678
679/**
680 * The setjmp variant used for calling Ring-3.
681 *
682 * This differs from the normal setjmp in that it will resume VMMRZCallRing3 if we're
683 * in the middle of a ring-3 call. Another differences is the function pointer and
684 * argument. This has to do with resuming code and the stack frame of the caller.
685 *
686 * @returns VINF_SUCCESS on success or whatever is passed to vmmR0CallRing3LongJmp.
687 * @param pJmpBuf The jmp_buf to set.
688 * @param pfn The function to be called when not resuming.
689 * @param pVM The cross context VM structure.
690 * @param pVCpu The cross context virtual CPU structure of the calling EMT.
691 */
692DECLASM(int) vmmR0CallRing3SetJmp(PVMMR0JMPBUF pJmpBuf, PFNVMMR0SETJMP pfn, PVM pVM, PVMCPU pVCpu);
693
694
695/**
696 * Callback function for vmmR0CallRing3SetJmp2.
697 *
698 * @returns VBox status code.
699 * @param pGVM The ring-0 VM structure.
700 * @param idCpu The ID of the calling EMT.
701 */
702typedef DECLCALLBACKTYPE(int, FNVMMR0SETJMP2,(PGVM pGVM, VMCPUID idCpu));
703/** Pointer to FNVMMR0SETJMP2(). */
704typedef FNVMMR0SETJMP2 *PFNVMMR0SETJMP2;
705
706/**
707 * Same as vmmR0CallRing3SetJmp except for the function signature.
708 *
709 * @returns VINF_SUCCESS on success or whatever is passed to vmmR0CallRing3LongJmp.
710 * @param pJmpBuf The jmp_buf to set.
711 * @param pfn The function to be called when not resuming.
712 * @param pGVM The ring-0 VM structure.
713 * @param idCpu The ID of the calling EMT.
714 */
715DECLASM(int) vmmR0CallRing3SetJmp2(PVMMR0JMPBUF pJmpBuf, PFNVMMR0SETJMP2 pfn, PGVM pGVM, VMCPUID idCpu);
716
717
718/**
719 * Callback function for vmmR0CallRing3SetJmpEx.
720 *
721 * @returns VBox status code.
722 * @param pvUser The user argument.
723 */
724typedef DECLCALLBACKTYPE(int, FNVMMR0SETJMPEX,(void *pvUser));
725/** Pointer to FNVMMR0SETJMPEX(). */
726typedef FNVMMR0SETJMPEX *PFNVMMR0SETJMPEX;
727
728/**
729 * Same as vmmR0CallRing3SetJmp except for the function signature.
730 *
731 * @returns VINF_SUCCESS on success or whatever is passed to vmmR0CallRing3LongJmp.
732 * @param pJmpBuf The jmp_buf to set.
733 * @param pfn The function to be called when not resuming.
734 * @param pvUser The argument of that function.
735 * @param uCallKey Unused call parameter that should be used to help
736 * uniquely identify the call.
737 */
738DECLASM(int) vmmR0CallRing3SetJmpEx(PVMMR0JMPBUF pJmpBuf, PFNVMMR0SETJMPEX pfn, void *pvUser, uintptr_t uCallKey);
739
740
741/**
742 * Worker for VMMRZCallRing3.
743 * This will save the stack and registers.
744 *
745 * @returns rc.
746 * @param pJmpBuf Pointer to the jump buffer.
747 * @param rc The return code.
748 */
749DECLASM(int) vmmR0CallRing3LongJmp(PVMMR0JMPBUF pJmpBuf, int rc);
750
751# ifdef VBOX_WITH_TRIPLE_FAULT_HACK
752int vmmR0TripleFaultHackInit(void);
753void vmmR0TripleFaultHackTerm(void);
754# endif
755
756#endif /* IN_RING0 */
757
758RT_C_DECLS_END
759
760/** @} */
761
762#endif /* !VMM_INCLUDED_SRC_include_VMMInternal_h */
Note: See TracBrowser for help on using the repository browser.

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