VirtualBox

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

Last change on this file since 92392 was 92392, checked in by vboxsync, 4 years ago

VMM: Removed the callring-3 API and some of the associated stuff. bugref:10093

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 27.9 KB
Line 
1/* $Id: VMMInternal.h 92392 2021-11-12 10:39:56Z 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.215389.xyz. 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 StatRZRetPATMDuplicateFn;
411 STAMCOUNTER StatRZRetPGMChangeMode;
412 STAMCOUNTER StatRZRetPendingRequest;
413 STAMCOUNTER StatRZRetPGMFlushPending;
414 STAMCOUNTER StatRZRetPatchTPR;
415 /** @} */
416} VMM;
417/** Pointer to VMM. */
418typedef VMM *PVMM;
419
420
421/**
422 * VMMCPU Data (part of VMCPU)
423 */
424typedef struct VMMCPU
425{
426 /** The last RC/R0 return code. */
427 int32_t iLastGZRc;
428 /** Alignment padding. */
429 uint32_t u32Padding0;
430
431 /** VMM stack, pointer to the top of the stack in R3.
432 * Stack is allocated from the hypervisor heap and is page aligned
433 * and always writable in RC. */
434 R3PTRTYPE(uint8_t *) pbEMTStackR3;
435
436 /** @name Rendezvous
437 * @{ */
438 /** Whether the EMT is executing a rendezvous right now. For detecting
439 * attempts at recursive rendezvous. */
440 bool volatile fInRendezvous;
441 bool afPadding1[2];
442 /** @} */
443
444 /** Whether we can HLT in VMMR0 rather than having to return to EM.
445 * Updated by vmR3SetHaltMethodU(). */
446 bool fMayHaltInRing0;
447 /** The minimum delta for which we can HLT in ring-0 for.
448 * The deadlines we can calculate are from TM, so, if it's too close
449 * we should just return to ring-3 and run the timer wheel, no point
450 * in spinning in ring-0.
451 * Updated by vmR3SetHaltMethodU(). */
452 uint32_t cNsSpinBlockThreshold;
453 /** Number of ring-0 halts (used for depreciating following values). */
454 uint32_t cR0Halts;
455 /** Number of ring-0 halts succeeding (VINF_SUCCESS) recently. */
456 uint32_t cR0HaltsSucceeded;
457 /** Number of ring-0 halts failing (VINF_EM_HALT) recently. */
458 uint32_t cR0HaltsToRing3;
459 /** Padding */
460 uint32_t u32Padding2;
461
462 /** @name Raw-mode context tracing data.
463 * @{ */
464 SUPDRVTRACERUSRCTX TracerCtx;
465 /** @} */
466
467 /** @name Call Ring-3
468 * Formerly known as host calls.
469 * @{ */
470 /** The disable counter. */
471 uint32_t cCallRing3Disabled;
472 uint32_t u32Padding3;
473 /** Ring-0 assertion notification callback. */
474 R0PTRTYPE(PFNVMMR0ASSERTIONNOTIFICATION) pfnRing0AssertCallback;
475 /** Argument for pfnRing0AssertionNotificationCallback. */
476 R0PTRTYPE(void *) pvRing0AssertCallbackUser;
477 /** The Ring-0 jmp buffer.
478 * @remarks The size of this type isn't stable in assembly, so don't put
479 * anything that needs to be accessed from assembly after it. */
480 VMMR0JMPBUF CallRing3JmpBufR0;
481 /** @} */
482
483 /**
484 * Loggers.
485 */
486 union
487 {
488 struct
489 {
490 /** The R0 logger data shared with ring-3. */
491 VMMR3CPULOGGER Logger;
492 /** The R0 release logger data shared with ring-3. */
493 VMMR3CPULOGGER RelLogger;
494 } s;
495 /** Array view. */
496 VMMR3CPULOGGER aLoggers[VMMLOGGER_IDX_MAX];
497 } u;
498
499 STAMPROFILE StatR0HaltBlock;
500 STAMPROFILE StatR0HaltBlockOnTime;
501 STAMPROFILE StatR0HaltBlockOverslept;
502 STAMPROFILE StatR0HaltBlockInsomnia;
503 STAMCOUNTER StatR0HaltExec;
504 STAMCOUNTER StatR0HaltExecFromBlock;
505 STAMCOUNTER StatR0HaltExecFromSpin;
506 STAMCOUNTER StatR0HaltToR3;
507 STAMCOUNTER StatR0HaltToR3FromSpin;
508 STAMCOUNTER StatR0HaltToR3Other;
509 STAMCOUNTER StatR0HaltToR3PendingFF;
510 STAMCOUNTER StatR0HaltToR3SmallDelta;
511 STAMCOUNTER StatR0HaltToR3PostNoInt;
512 STAMCOUNTER StatR0HaltToR3PostPendingFF;
513} VMMCPU;
514AssertCompileMemberAlignment(VMMCPU, TracerCtx, 8);
515AssertCompile( RTASSERT_OFFSET_OF(VMMCPU, u.s.Logger)
516 == RTASSERT_OFFSET_OF(VMMCPU, u.aLoggers) + sizeof(VMMR3CPULOGGER) * VMMLOGGER_IDX_REGULAR);
517AssertCompile(RTASSERT_OFFSET_OF(VMMCPU, u.s.RelLogger)
518 == RTASSERT_OFFSET_OF(VMMCPU, u.aLoggers) + sizeof(VMMR3CPULOGGER) * VMMLOGGER_IDX_RELEASE);
519
520/** Pointer to VMMCPU. */
521typedef VMMCPU *PVMMCPU;
522
523/**
524 * VMM per-VCpu ring-0 only instance data.
525 */
526typedef struct VMMR0PERVCPU
527{
528 /** The EMT hash table index. */
529 uint16_t idxEmtHash;
530 /** Flag indicating whether we've disabled flushing (world switch) or not. */
531 bool fLogFlushingDisabled;
532 bool afPadding1[5];
533 /** Pointer to the VMMR0EntryFast preemption state structure.
534 * This is used to temporarily restore preemption before blocking. */
535 R0PTRTYPE(PRTTHREADPREEMPTSTATE) pPreemptState;
536 /** Thread context switching hook (ring-0). */
537 RTTHREADCTXHOOK hCtxHook;
538
539 /** @name Arguments passed by VMMR0EntryEx via vmmR0CallRing3SetJmpEx.
540 * @note Cannot be put on the stack as the location may change and upset the
541 * validation of resume-after-ring-3-call logic.
542 * @{ */
543 PGVM pGVM;
544 VMCPUID idCpu;
545 VMMR0OPERATION enmOperation;
546 PSUPVMMR0REQHDR pReq;
547 uint64_t u64Arg;
548 PSUPDRVSESSION pSession;
549 /** @} */
550
551 /**
552 * Loggers
553 */
554 union
555 {
556 struct
557 {
558 /** The R0 logger data. */
559 VMMR0PERVCPULOGGER Logger;
560 /** The R0 release logger data. */
561 VMMR0PERVCPULOGGER RelLogger;
562 } s;
563 /** Array view. */
564 VMMR0PERVCPULOGGER aLoggers[VMMLOGGER_IDX_MAX];
565 } u;
566} VMMR0PERVCPU;
567AssertCompile( RTASSERT_OFFSET_OF(VMMR0PERVCPU, u.s.Logger)
568 == RTASSERT_OFFSET_OF(VMMR0PERVCPU, u.aLoggers) + sizeof(VMMR0PERVCPULOGGER) * VMMLOGGER_IDX_REGULAR);
569AssertCompile(RTASSERT_OFFSET_OF(VMMR0PERVCPU, u.s.RelLogger)
570 == RTASSERT_OFFSET_OF(VMMR0PERVCPU, u.aLoggers) + sizeof(VMMR0PERVCPULOGGER) * VMMLOGGER_IDX_RELEASE);
571/** Pointer to VMM ring-0 VMCPU instance data. */
572typedef VMMR0PERVCPU *PVMMR0PERVCPU;
573
574/** @name RTLOGGER::u32UserValue1 Flags
575 * @{ */
576/** The magic value. */
577#define VMMR0_LOGGER_FLAGS_MAGIC_VALUE UINT32_C(0x7d297f05)
578/** Part of the flags value used for the magic. */
579#define VMMR0_LOGGER_FLAGS_MAGIC_MASK UINT32_C(0xffffff0f)
580/** @} */
581
582
583/**
584 * VMM data kept in the ring-0 GVM.
585 */
586typedef struct VMMR0PERVM
587{
588 /** Set if vmmR0InitVM has been called. */
589 bool fCalledInitVm;
590 bool afPadding1[7];
591
592 /** @name Logging
593 * @{ */
594 /** Logger (debug) buffer allocation.
595 * This covers all CPUs. */
596 RTR0MEMOBJ hMemObjLogger;
597 /** The ring-3 mapping object for hMemObjLogger. */
598 RTR0MEMOBJ hMapObjLogger;
599
600 /** Release logger buffer allocation.
601 * This covers all CPUs. */
602 RTR0MEMOBJ hMemObjReleaseLogger;
603 /** The ring-3 mapping object for hMemObjReleaseLogger. */
604 RTR0MEMOBJ hMapObjReleaseLogger;
605
606 struct
607 {
608 /** Spinlock protecting the logger ring buffer and associated variables. */
609 R0PTRTYPE(RTSPINLOCK) hSpinlock;
610 /** The log flusher thread handle to make sure there is only one. */
611 RTNATIVETHREAD hThread;
612 /** The handle to the event semaphore the log flusher waits on. */
613 RTSEMEVENT hEvent;
614 /** The index of the log flusher queue head (flusher thread side). */
615 uint32_t volatile idxRingHead;
616 /** The index of the log flusher queue tail (EMT side). */
617 uint32_t volatile idxRingTail;
618 /** Set if the log flusher thread is waiting for work and needs poking. */
619 bool volatile fThreadWaiting;
620 /** Set when the log flusher thread should shut down. */
621 bool volatile fThreadShutdown;
622 /** Indicates that the log flusher thread is running. */
623 bool volatile fThreadRunning;
624 bool afPadding2[5];
625 STAMCOUNTER StatFlushes;
626 STAMCOUNTER StatNoWakeUp;
627 /** Logger ring buffer.
628 * This is for communicating with the log flusher thread. */
629 VMMLOGFLUSHERENTRY aRing[VMM_MAX_CPU_COUNT * 2 /*loggers*/ * 1 /*buffer*/ + 16 /*fudge*/];
630 } LogFlusher;
631 /** @} */
632} VMMR0PERVM;
633
634RT_C_DECLS_BEGIN
635
636int vmmInitFormatTypes(void);
637void vmmTermFormatTypes(void);
638uint32_t vmmGetBuildType(void);
639
640#ifdef IN_RING3
641int vmmR3SwitcherInit(PVM pVM);
642void vmmR3SwitcherRelocate(PVM pVM, RTGCINTPTR offDelta);
643#endif /* IN_RING3 */
644
645#ifdef IN_RING0
646
647/**
648 * World switcher assembly routine.
649 * It will call VMMRCEntry().
650 *
651 * @returns return code from VMMRCEntry().
652 * @param pVM The cross context VM structure.
653 * @param uArg See VMMRCEntry().
654 * @internal
655 */
656DECLASM(int) vmmR0WorldSwitch(PVM pVM, unsigned uArg);
657
658/**
659 * Callback function for vmmR0CallRing3SetJmp.
660 *
661 * @returns VBox status code.
662 * @param pVM The cross context VM structure.
663 * @param pVCpu The cross context virtual CPU structure of the calling EMT.
664 */
665typedef DECLCALLBACKTYPE(int, FNVMMR0SETJMP,(PVMCC pVM, PVMCPUCC pVCpu));
666/** Pointer to FNVMMR0SETJMP(). */
667typedef FNVMMR0SETJMP *PFNVMMR0SETJMP;
668
669/**
670 * The setjmp variant used for calling Ring-3.
671 *
672 * This differs from the normal setjmp in that it will resume VMMRZCallRing3 if we're
673 * in the middle of a ring-3 call. Another differences is the function pointer and
674 * argument. This has to do with resuming code and the stack frame of the caller.
675 *
676 * @returns VINF_SUCCESS on success or whatever is passed to vmmR0CallRing3LongJmp.
677 * @param pJmpBuf The jmp_buf to set.
678 * @param pfn The function to be called when not resuming.
679 * @param pVM The cross context VM structure.
680 * @param pVCpu The cross context virtual CPU structure of the calling EMT.
681 */
682DECLASM(int) vmmR0CallRing3SetJmp(PVMMR0JMPBUF pJmpBuf, PFNVMMR0SETJMP pfn, PVM pVM, PVMCPU pVCpu);
683
684
685/**
686 * Callback function for vmmR0CallRing3SetJmp2.
687 *
688 * @returns VBox status code.
689 * @param pGVM The ring-0 VM structure.
690 * @param idCpu The ID of the calling EMT.
691 */
692typedef DECLCALLBACKTYPE(int, FNVMMR0SETJMP2,(PGVM pGVM, VMCPUID idCpu));
693/** Pointer to FNVMMR0SETJMP2(). */
694typedef FNVMMR0SETJMP2 *PFNVMMR0SETJMP2;
695
696/**
697 * Same as vmmR0CallRing3SetJmp except for the function signature.
698 *
699 * @returns VINF_SUCCESS on success or whatever is passed to vmmR0CallRing3LongJmp.
700 * @param pJmpBuf The jmp_buf to set.
701 * @param pfn The function to be called when not resuming.
702 * @param pGVM The ring-0 VM structure.
703 * @param idCpu The ID of the calling EMT.
704 */
705DECLASM(int) vmmR0CallRing3SetJmp2(PVMMR0JMPBUF pJmpBuf, PFNVMMR0SETJMP2 pfn, PGVM pGVM, VMCPUID idCpu);
706
707
708/**
709 * Callback function for vmmR0CallRing3SetJmpEx.
710 *
711 * @returns VBox status code.
712 * @param pvUser The user argument.
713 */
714typedef DECLCALLBACKTYPE(int, FNVMMR0SETJMPEX,(void *pvUser));
715/** Pointer to FNVMMR0SETJMPEX(). */
716typedef FNVMMR0SETJMPEX *PFNVMMR0SETJMPEX;
717
718/**
719 * Same as vmmR0CallRing3SetJmp except for the function signature.
720 *
721 * @returns VINF_SUCCESS on success or whatever is passed to vmmR0CallRing3LongJmp.
722 * @param pJmpBuf The jmp_buf to set.
723 * @param pfn The function to be called when not resuming.
724 * @param pvUser The argument of that function.
725 * @param uCallKey Unused call parameter that should be used to help
726 * uniquely identify the call.
727 */
728DECLASM(int) vmmR0CallRing3SetJmpEx(PVMMR0JMPBUF pJmpBuf, PFNVMMR0SETJMPEX pfn, void *pvUser, uintptr_t uCallKey);
729
730
731/**
732 * Worker for VMMRZCallRing3.
733 * This will save the stack and registers.
734 *
735 * @returns rc.
736 * @param pJmpBuf Pointer to the jump buffer.
737 * @param rc The return code.
738 */
739DECLASM(int) vmmR0CallRing3LongJmp(PVMMR0JMPBUF pJmpBuf, int rc);
740
741# ifdef VBOX_WITH_TRIPLE_FAULT_HACK
742int vmmR0TripleFaultHackInit(void);
743void vmmR0TripleFaultHackTerm(void);
744# endif
745
746#endif /* IN_RING0 */
747
748RT_C_DECLS_END
749
750/** @} */
751
752#endif /* !VMM_INCLUDED_SRC_include_VMMInternal_h */
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