VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMR0/VMMR0.cpp@ 45781

Last change on this file since 45781 was 45749, checked in by vboxsync, 12 years ago

VMM: Introduced VMCPUSTATE_STARTED_HM for indicating that we're between HMR3Enter and HMR3Leave. Added HMIsInHwVirtCtx and VMMIsLongJumpArmed methods/macros.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 55.7 KB
Line 
1/* $Id: VMMR0.cpp 45749 2013-04-26 00:14:09Z vboxsync $ */
2/** @file
3 * VMM - Host Context Ring 0.
4 */
5
6/*
7 * Copyright (C) 2006-2012 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/*******************************************************************************
19* Header Files *
20*******************************************************************************/
21#define LOG_GROUP LOG_GROUP_VMM
22#include <VBox/vmm/vmm.h>
23#include <VBox/sup.h>
24#include <VBox/vmm/trpm.h>
25#include <VBox/vmm/cpum.h>
26#include <VBox/vmm/pdmapi.h>
27#include <VBox/vmm/pgm.h>
28#include <VBox/vmm/stam.h>
29#include <VBox/vmm/tm.h>
30#include "VMMInternal.h"
31#include <VBox/vmm/vm.h>
32#ifdef VBOX_WITH_PCI_PASSTHROUGH
33# include <VBox/vmm/pdmpci.h>
34#endif
35
36#include <VBox/vmm/gvmm.h>
37#include <VBox/vmm/gmm.h>
38#include <VBox/intnet.h>
39#include <VBox/vmm/hm.h>
40#include <VBox/param.h>
41#include <VBox/err.h>
42#include <VBox/version.h>
43#include <VBox/log.h>
44
45#include <iprt/asm-amd64-x86.h>
46#include <iprt/assert.h>
47#include <iprt/crc.h>
48#include <iprt/mp.h>
49#include <iprt/once.h>
50#include <iprt/stdarg.h>
51#include <iprt/string.h>
52#include <iprt/thread.h>
53#include <iprt/timer.h>
54
55#include "dtrace/VBoxVMM.h"
56
57
58#if defined(_MSC_VER) && defined(RT_ARCH_AMD64) /** @todo check this with with VC7! */
59# pragma intrinsic(_AddressOfReturnAddress)
60#endif
61
62
63/*******************************************************************************
64* Internal Functions *
65*******************************************************************************/
66RT_C_DECLS_BEGIN
67#if defined(RT_ARCH_X86) && (defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD))
68extern uint64_t __udivdi3(uint64_t, uint64_t);
69extern uint64_t __umoddi3(uint64_t, uint64_t);
70#endif
71RT_C_DECLS_END
72
73
74/*******************************************************************************
75* Global Variables *
76*******************************************************************************/
77/** Drag in necessary library bits.
78 * The runtime lives here (in VMMR0.r0) and VBoxDD*R0.r0 links against us. */
79PFNRT g_VMMGCDeps[] =
80{
81 (PFNRT)RTCrc32,
82 (PFNRT)RTOnce,
83#if defined(RT_ARCH_X86) && (defined(RT_OS_SOLARIS) || defined(RT_OS_FREEBSD))
84 (PFNRT)__udivdi3,
85 (PFNRT)__umoddi3,
86#endif
87 NULL
88};
89
90#ifdef RT_OS_SOLARIS
91/* Dependency information for the native solaris loader. */
92extern "C" { char _depends_on[] = "vboxdrv"; }
93#endif
94
95
96
97/**
98 * Initialize the module.
99 * This is called when we're first loaded.
100 *
101 * @returns 0 on success.
102 * @returns VBox status on failure.
103 * @param hMod Image handle for use in APIs.
104 */
105DECLEXPORT(int) ModuleInit(void *hMod)
106{
107#ifdef VBOX_WITH_DTRACE_R0
108 /*
109 * The first thing to do is register the static tracepoints.
110 * (Deregistration is automatic.)
111 */
112 int rc2 = SUPR0TracerRegisterModule(hMod, &g_VTGObjHeader);
113 if (RT_FAILURE(rc2))
114 return rc2;
115#endif
116 LogFlow(("ModuleInit:\n"));
117
118 /*
119 * Initialize the VMM, GVMM, GMM, HM, PGM (Darwin) and INTNET.
120 */
121 int rc = vmmInitFormatTypes();
122 if (RT_SUCCESS(rc))
123 {
124 rc = GVMMR0Init();
125 if (RT_SUCCESS(rc))
126 {
127 rc = GMMR0Init();
128 if (RT_SUCCESS(rc))
129 {
130 rc = HMR0Init();
131 if (RT_SUCCESS(rc))
132 {
133 rc = PGMRegisterStringFormatTypes();
134 if (RT_SUCCESS(rc))
135 {
136#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
137 rc = PGMR0DynMapInit();
138#endif
139 if (RT_SUCCESS(rc))
140 {
141 rc = IntNetR0Init();
142 if (RT_SUCCESS(rc))
143 {
144#ifdef VBOX_WITH_PCI_PASSTHROUGH
145 rc = PciRawR0Init();
146#endif
147 if (RT_SUCCESS(rc))
148 {
149 rc = CPUMR0ModuleInit();
150 if (RT_SUCCESS(rc))
151 {
152#ifdef VBOX_WITH_TRIPLE_FAULT_HACK
153 rc = vmmR0TripleFaultHackInit();
154 if (RT_SUCCESS(rc))
155#endif
156 {
157 LogFlow(("ModuleInit: returns success.\n"));
158 return VINF_SUCCESS;
159 }
160
161 /*
162 * Bail out.
163 */
164#ifdef VBOX_WITH_TRIPLE_FAULT_HACK
165 vmmR0TripleFaultHackTerm();
166#endif
167 }
168 else
169 LogRel(("ModuleInit: CPUMR0ModuleInit -> %Rrc\n", rc));
170#ifdef VBOX_WITH_PCI_PASSTHROUGH
171 PciRawR0Term();
172#endif
173 }
174 else
175 LogRel(("ModuleInit: PciRawR0Init -> %Rrc\n", rc));
176 IntNetR0Term();
177 }
178 else
179 LogRel(("ModuleInit: IntNetR0Init -> %Rrc\n", rc));
180#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
181 PGMR0DynMapTerm();
182#endif
183 }
184 else
185 LogRel(("ModuleInit: PGMR0DynMapInit -> %Rrc\n", rc));
186 PGMDeregisterStringFormatTypes();
187 }
188 else
189 LogRel(("ModuleInit: PGMRegisterStringFormatTypes -> %Rrc\n", rc));
190 HMR0Term();
191 }
192 else
193 LogRel(("ModuleInit: HMR0Init -> %Rrc\n", rc));
194 GMMR0Term();
195 }
196 else
197 LogRel(("ModuleInit: GMMR0Init -> %Rrc\n", rc));
198 GVMMR0Term();
199 }
200 else
201 LogRel(("ModuleInit: GVMMR0Init -> %Rrc\n", rc));
202 vmmTermFormatTypes();
203 }
204 else
205 LogRel(("ModuleInit: vmmInitFormatTypes -> %Rrc\n", rc));
206
207 LogFlow(("ModuleInit: failed %Rrc\n", rc));
208 return rc;
209}
210
211
212/**
213 * Terminate the module.
214 * This is called when we're finally unloaded.
215 *
216 * @param hMod Image handle for use in APIs.
217 */
218DECLEXPORT(void) ModuleTerm(void *hMod)
219{
220 LogFlow(("ModuleTerm:\n"));
221
222 /*
223 * Terminate the CPUM module (Local APIC cleanup).
224 */
225 CPUMR0ModuleTerm();
226
227 /*
228 * Terminate the internal network service.
229 */
230 IntNetR0Term();
231
232 /*
233 * PGM (Darwin), HM and PciRaw global cleanup.
234 */
235#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
236 PGMR0DynMapTerm();
237#endif
238#ifdef VBOX_WITH_PCI_PASSTHROUGH
239 PciRawR0Term();
240#endif
241 PGMDeregisterStringFormatTypes();
242 HMR0Term();
243#ifdef VBOX_WITH_TRIPLE_FAULT_HACK
244 vmmR0TripleFaultHackTerm();
245#endif
246
247 /*
248 * Destroy the GMM and GVMM instances.
249 */
250 GMMR0Term();
251 GVMMR0Term();
252
253 vmmTermFormatTypes();
254
255 LogFlow(("ModuleTerm: returns\n"));
256}
257
258
259/**
260 * Initiates the R0 driver for a particular VM instance.
261 *
262 * @returns VBox status code.
263 *
264 * @param pVM Pointer to the VM.
265 * @param uSvnRev The SVN revision of the ring-3 part.
266 * @thread EMT.
267 */
268static int vmmR0InitVM(PVM pVM, uint32_t uSvnRev)
269{
270 /*
271 * Match the SVN revisions.
272 */
273 if (uSvnRev != VMMGetSvnRev())
274 {
275 LogRel(("VMMR0InitVM: Revision mismatch, r3=%d r0=%d\n", uSvnRev, VMMGetSvnRev()));
276 SUPR0Printf("VMMR0InitVM: Revision mismatch, r3=%d r0=%d\n", uSvnRev, VMMGetSvnRev());
277 return VERR_VMM_R0_VERSION_MISMATCH;
278 }
279 if ( !VALID_PTR(pVM)
280 || pVM->pVMR0 != pVM)
281 return VERR_INVALID_PARAMETER;
282
283#ifdef LOG_ENABLED
284 /*
285 * Register the EMT R0 logger instance for VCPU 0.
286 */
287 PVMCPU pVCpu = &pVM->aCpus[0];
288
289 PVMMR0LOGGER pR0Logger = pVCpu->vmm.s.pR0LoggerR0;
290 if (pR0Logger)
291 {
292# if 0 /* testing of the logger. */
293 LogCom(("vmmR0InitVM: before %p\n", RTLogDefaultInstance()));
294 LogCom(("vmmR0InitVM: pfnFlush=%p actual=%p\n", pR0Logger->Logger.pfnFlush, vmmR0LoggerFlush));
295 LogCom(("vmmR0InitVM: pfnLogger=%p actual=%p\n", pR0Logger->Logger.pfnLogger, vmmR0LoggerWrapper));
296 LogCom(("vmmR0InitVM: offScratch=%d fFlags=%#x fDestFlags=%#x\n", pR0Logger->Logger.offScratch, pR0Logger->Logger.fFlags, pR0Logger->Logger.fDestFlags));
297
298 RTLogSetDefaultInstanceThread(&pR0Logger->Logger, (uintptr_t)pVM->pSession);
299 LogCom(("vmmR0InitVM: after %p reg\n", RTLogDefaultInstance()));
300 RTLogSetDefaultInstanceThread(NULL, pVM->pSession);
301 LogCom(("vmmR0InitVM: after %p dereg\n", RTLogDefaultInstance()));
302
303 pR0Logger->Logger.pfnLogger("hello ring-0 logger\n");
304 LogCom(("vmmR0InitVM: returned successfully from direct logger call.\n"));
305 pR0Logger->Logger.pfnFlush(&pR0Logger->Logger);
306 LogCom(("vmmR0InitVM: returned successfully from direct flush call.\n"));
307
308 RTLogSetDefaultInstanceThread(&pR0Logger->Logger, (uintptr_t)pVM->pSession);
309 LogCom(("vmmR0InitVM: after %p reg2\n", RTLogDefaultInstance()));
310 pR0Logger->Logger.pfnLogger("hello ring-0 logger\n");
311 LogCom(("vmmR0InitVM: returned successfully from direct logger call (2). offScratch=%d\n", pR0Logger->Logger.offScratch));
312 RTLogSetDefaultInstanceThread(NULL, pVM->pSession);
313 LogCom(("vmmR0InitVM: after %p dereg2\n", RTLogDefaultInstance()));
314
315 RTLogLoggerEx(&pR0Logger->Logger, 0, ~0U, "hello ring-0 logger (RTLogLoggerEx)\n");
316 LogCom(("vmmR0InitVM: RTLogLoggerEx returned fine offScratch=%d\n", pR0Logger->Logger.offScratch));
317
318 RTLogSetDefaultInstanceThread(&pR0Logger->Logger, (uintptr_t)pVM->pSession);
319 RTLogPrintf("hello ring-0 logger (RTLogPrintf)\n");
320 LogCom(("vmmR0InitVM: RTLogPrintf returned fine offScratch=%d\n", pR0Logger->Logger.offScratch));
321# endif
322 Log(("Switching to per-thread logging instance %p (key=%p)\n", &pR0Logger->Logger, pVM->pSession));
323 RTLogSetDefaultInstanceThread(&pR0Logger->Logger, (uintptr_t)pVM->pSession);
324 pR0Logger->fRegistered = true;
325 }
326#endif /* LOG_ENABLED */
327
328 /*
329 * Check if the host supports high resolution timers or not.
330 */
331 if ( pVM->vmm.s.fUsePeriodicPreemptionTimers
332 && !RTTimerCanDoHighResolution())
333 pVM->vmm.s.fUsePeriodicPreemptionTimers = false;
334
335 /*
336 * Initialize the per VM data for GVMM and GMM.
337 */
338 int rc = GVMMR0InitVM(pVM);
339// if (RT_SUCCESS(rc))
340// rc = GMMR0InitPerVMData(pVM);
341 if (RT_SUCCESS(rc))
342 {
343 /*
344 * Init HM, CPUM and PGM (Darwin only).
345 */
346 rc = HMR0InitVM(pVM);
347 if (RT_SUCCESS(rc))
348 {
349 rc = CPUMR0Init(pVM); /** @todo rename to CPUMR0InitVM */
350 if (RT_SUCCESS(rc))
351 {
352#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
353 rc = PGMR0DynMapInitVM(pVM);
354#endif
355 if (RT_SUCCESS(rc))
356 {
357#ifdef VBOX_WITH_PCI_PASSTHROUGH
358 rc = PciRawR0InitVM(pVM);
359#endif
360 if (RT_SUCCESS(rc))
361 {
362 GVMMR0DoneInitVM(pVM);
363 return rc;
364 }
365 }
366
367 /* bail out */
368 }
369#ifdef VBOX_WITH_PCI_PASSTHROUGH
370 PciRawR0TermVM(pVM);
371#endif
372 HMR0TermVM(pVM);
373 }
374 }
375
376
377 RTLogSetDefaultInstanceThread(NULL, (uintptr_t)pVM->pSession);
378 return rc;
379}
380
381
382/**
383 * Terminates the R0 bits for a particular VM instance.
384 *
385 * This is normally called by ring-3 as part of the VM termination process, but
386 * may alternatively be called during the support driver session cleanup when
387 * the VM object is destroyed (see GVMM).
388 *
389 * @returns VBox status code.
390 *
391 * @param pVM Pointer to the VM.
392 * @param pGVM Pointer to the global VM structure. Optional.
393 * @thread EMT or session clean up thread.
394 */
395VMMR0DECL(int) VMMR0TermVM(PVM pVM, PGVM pGVM)
396{
397#ifdef VBOX_WITH_PCI_PASSTHROUGH
398 PciRawR0TermVM(pVM);
399#endif
400
401
402 /*
403 * Tell GVMM what we're up to and check that we only do this once.
404 */
405 if (GVMMR0DoingTermVM(pVM, pGVM))
406 {
407 /** @todo I wish to call PGMR0PhysFlushHandyPages(pVM, &pVM->aCpus[idCpu])
408 * here to make sure we don't leak any shared pages if we crash... */
409#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
410 PGMR0DynMapTermVM(pVM);
411#endif
412 HMR0TermVM(pVM);
413 }
414
415 /*
416 * Deregister the logger.
417 */
418 RTLogSetDefaultInstanceThread(NULL, (uintptr_t)pVM->pSession);
419 return VINF_SUCCESS;
420}
421
422
423#ifdef VBOX_WITH_STATISTICS
424/**
425 * Record return code statistics
426 * @param pVM Pointer to the VM.
427 * @param pVCpu Pointer to the VMCPU.
428 * @param rc The status code.
429 */
430static void vmmR0RecordRC(PVM pVM, PVMCPU pVCpu, int rc)
431{
432 /*
433 * Collect statistics.
434 */
435 switch (rc)
436 {
437 case VINF_SUCCESS:
438 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetNormal);
439 break;
440 case VINF_EM_RAW_INTERRUPT:
441 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetInterrupt);
442 break;
443 case VINF_EM_RAW_INTERRUPT_HYPER:
444 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetInterruptHyper);
445 break;
446 case VINF_EM_RAW_GUEST_TRAP:
447 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetGuestTrap);
448 break;
449 case VINF_EM_RAW_RING_SWITCH:
450 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetRingSwitch);
451 break;
452 case VINF_EM_RAW_RING_SWITCH_INT:
453 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetRingSwitchInt);
454 break;
455 case VINF_EM_RAW_STALE_SELECTOR:
456 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetStaleSelector);
457 break;
458 case VINF_EM_RAW_IRET_TRAP:
459 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetIRETTrap);
460 break;
461 case VINF_IOM_R3_IOPORT_READ:
462 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetIORead);
463 break;
464 case VINF_IOM_R3_IOPORT_WRITE:
465 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetIOWrite);
466 break;
467 case VINF_IOM_R3_MMIO_READ:
468 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetMMIORead);
469 break;
470 case VINF_IOM_R3_MMIO_WRITE:
471 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetMMIOWrite);
472 break;
473 case VINF_IOM_R3_MMIO_READ_WRITE:
474 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetMMIOReadWrite);
475 break;
476 case VINF_PATM_HC_MMIO_PATCH_READ:
477 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetMMIOPatchRead);
478 break;
479 case VINF_PATM_HC_MMIO_PATCH_WRITE:
480 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetMMIOPatchWrite);
481 break;
482 case VINF_EM_RAW_EMULATE_INSTR:
483 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetEmulate);
484 break;
485 case VINF_EM_RAW_EMULATE_IO_BLOCK:
486 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetIOBlockEmulate);
487 break;
488 case VINF_PATCH_EMULATE_INSTR:
489 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPatchEmulate);
490 break;
491 case VINF_EM_RAW_EMULATE_INSTR_LDT_FAULT:
492 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetLDTFault);
493 break;
494 case VINF_EM_RAW_EMULATE_INSTR_GDT_FAULT:
495 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetGDTFault);
496 break;
497 case VINF_EM_RAW_EMULATE_INSTR_IDT_FAULT:
498 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetIDTFault);
499 break;
500 case VINF_EM_RAW_EMULATE_INSTR_TSS_FAULT:
501 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetTSSFault);
502 break;
503 case VINF_EM_RAW_EMULATE_INSTR_PD_FAULT:
504 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPDFault);
505 break;
506 case VINF_CSAM_PENDING_ACTION:
507 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetCSAMTask);
508 break;
509 case VINF_PGM_SYNC_CR3:
510 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetSyncCR3);
511 break;
512 case VINF_PATM_PATCH_INT3:
513 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPatchInt3);
514 break;
515 case VINF_PATM_PATCH_TRAP_PF:
516 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPatchPF);
517 break;
518 case VINF_PATM_PATCH_TRAP_GP:
519 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPatchGP);
520 break;
521 case VINF_PATM_PENDING_IRQ_AFTER_IRET:
522 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPatchIretIRQ);
523 break;
524 case VINF_EM_RESCHEDULE_REM:
525 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetRescheduleREM);
526 break;
527 case VINF_EM_RAW_TO_R3:
528 if (VM_FF_ISPENDING(pVM, VM_FF_TM_VIRTUAL_SYNC))
529 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetToR3TMVirt);
530 else if (VM_FF_ISPENDING(pVM, VM_FF_PGM_NEED_HANDY_PAGES))
531 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetToR3HandyPages);
532 else if (VM_FF_ISPENDING(pVM, VM_FF_PDM_QUEUES))
533 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetToR3PDMQueues);
534 else if (VM_FF_ISPENDING(pVM, VM_FF_EMT_RENDEZVOUS))
535 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetToR3Rendezvous);
536 else if (VM_FF_ISPENDING(pVM, VM_FF_PDM_DMA))
537 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetToR3DMA);
538 else if (VMCPU_FF_ISPENDING(pVCpu, VMCPU_FF_TIMER))
539 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetToR3Timer);
540 else if (VMCPU_FF_ISPENDING(pVCpu, VMCPU_FF_PDM_CRITSECT))
541 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetToR3CritSect);
542 else if (VMCPU_FF_ISPENDING(pVCpu, VMCPU_FF_TO_R3))
543 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetToR3);
544 else
545 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetToR3Unknown);
546 break;
547
548 case VINF_EM_RAW_TIMER_PENDING:
549 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetTimerPending);
550 break;
551 case VINF_EM_RAW_INTERRUPT_PENDING:
552 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetInterruptPending);
553 break;
554 case VINF_VMM_CALL_HOST:
555 switch (pVCpu->vmm.s.enmCallRing3Operation)
556 {
557 case VMMCALLRING3_PDM_CRIT_SECT_ENTER:
558 STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallPDMCritSectEnter);
559 break;
560 case VMMCALLRING3_PDM_LOCK:
561 STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallPDMLock);
562 break;
563 case VMMCALLRING3_PGM_POOL_GROW:
564 STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallPGMPoolGrow);
565 break;
566 case VMMCALLRING3_PGM_LOCK:
567 STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallPGMLock);
568 break;
569 case VMMCALLRING3_PGM_MAP_CHUNK:
570 STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallPGMMapChunk);
571 break;
572 case VMMCALLRING3_PGM_ALLOCATE_HANDY_PAGES:
573 STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallPGMAllocHandy);
574 break;
575 case VMMCALLRING3_REM_REPLAY_HANDLER_NOTIFICATIONS:
576 STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallRemReplay);
577 break;
578 case VMMCALLRING3_VMM_LOGGER_FLUSH:
579 STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallLogFlush);
580 break;
581 case VMMCALLRING3_VM_SET_ERROR:
582 STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallVMSetError);
583 break;
584 case VMMCALLRING3_VM_SET_RUNTIME_ERROR:
585 STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallVMSetRuntimeError);
586 break;
587 case VMMCALLRING3_VM_R0_ASSERTION:
588 default:
589 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetCallRing3);
590 break;
591 }
592 break;
593 case VINF_PATM_DUPLICATE_FUNCTION:
594 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPATMDuplicateFn);
595 break;
596 case VINF_PGM_CHANGE_MODE:
597 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPGMChangeMode);
598 break;
599 case VINF_PGM_POOL_FLUSH_PENDING:
600 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPGMFlushPending);
601 break;
602 case VINF_EM_PENDING_REQUEST:
603 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPendingRequest);
604 break;
605 case VINF_EM_HM_PATCH_TPR_INSTR:
606 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPatchTPR);
607 break;
608 default:
609 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetMisc);
610 break;
611 }
612}
613#endif /* VBOX_WITH_STATISTICS */
614
615
616/**
617 * Unused ring-0 entry point that used to be called from the interrupt gate.
618 *
619 * Will be removed one of the next times we do a major SUPDrv version bump.
620 *
621 * @returns VBox status code.
622 * @param pVM Pointer to the VM.
623 * @param enmOperation Which operation to execute.
624 * @param pvArg Argument to the operation.
625 * @remarks Assume called with interrupts disabled.
626 */
627VMMR0DECL(int) VMMR0EntryInt(PVM pVM, VMMR0OPERATION enmOperation, void *pvArg)
628{
629 /*
630 * We're returning VERR_NOT_SUPPORT here so we've got something else
631 * than -1 which the interrupt gate glue code might return.
632 */
633 Log(("operation %#x is not supported\n", enmOperation));
634 NOREF(enmOperation); NOREF(pvArg); NOREF(pVM);
635 return VERR_NOT_SUPPORTED;
636}
637
638
639/**
640 * The Ring 0 entry point, called by the fast-ioctl path.
641 *
642 * @param pVM Pointer to the VM.
643 * The return code is stored in pVM->vmm.s.iLastGZRc.
644 * @param idCpu The Virtual CPU ID of the calling EMT.
645 * @param enmOperation Which operation to execute.
646 * @remarks Assume called with interrupts _enabled_.
647 */
648VMMR0DECL(void) VMMR0EntryFast(PVM pVM, VMCPUID idCpu, VMMR0OPERATION enmOperation)
649{
650 if (RT_UNLIKELY(idCpu >= pVM->cCpus))
651 return;
652 PVMCPU pVCpu = &pVM->aCpus[idCpu];
653
654 switch (enmOperation)
655 {
656 /*
657 * Switch to GC and run guest raw mode code.
658 * Disable interrupts before doing the world switch.
659 */
660 case VMMR0_DO_RAW_RUN:
661 {
662#ifndef VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0
663 /* Some safety precautions first. */
664 if (RT_UNLIKELY(!PGMGetHyperCR3(pVCpu)))
665 {
666 pVCpu->vmm.s.iLastGZRc = VERR_PGM_NO_CR3_SHADOW_ROOT;
667 break;
668 }
669#endif
670
671 /* Disable preemption and update the periodic preemption timer. */
672 RTTHREADPREEMPTSTATE PreemptState = RTTHREADPREEMPTSTATE_INITIALIZER;
673 RTThreadPreemptDisable(&PreemptState);
674 RTCPUID idHostCpu = RTMpCpuId();
675#ifdef VBOX_WITH_VMMR0_DISABLE_LAPIC_NMI
676 CPUMR0SetLApic(pVM, idHostCpu);
677#endif
678 ASMAtomicWriteU32(&pVCpu->idHostCpu, idHostCpu);
679 if (pVM->vmm.s.fUsePeriodicPreemptionTimers)
680 GVMMR0SchedUpdatePeriodicPreemptionTimer(pVM, pVCpu->idHostCpu, TMCalcHostTimerFrequency(pVM, pVCpu));
681
682 /* We might need to disable VT-x if the active switcher turns off paging. */
683 bool fVTxDisabled;
684 int rc = HMR0EnterSwitcher(pVM, pVM->vmm.s.enmSwitcher, &fVTxDisabled);
685 if (RT_SUCCESS(rc))
686 {
687 RTCCUINTREG uFlags = ASMIntDisableFlags();
688
689 for (;;)
690 {
691 VMCPU_SET_STATE(pVCpu, VMCPUSTATE_STARTED_EXEC);
692 TMNotifyStartOfExecution(pVCpu);
693
694 rc = pVM->vmm.s.pfnR0ToRawMode(pVM);
695 pVCpu->vmm.s.iLastGZRc = rc;
696
697 TMNotifyEndOfExecution(pVCpu);
698 VMCPU_SET_STATE(pVCpu, VMCPUSTATE_STARTED);
699
700 if (rc != VINF_VMM_CALL_TRACER)
701 break;
702 SUPR0TracerUmodProbeFire(pVM->pSession, &pVCpu->vmm.s.TracerCtx);
703 }
704
705 /* Re-enable VT-x if previously turned off. */
706 HMR0LeaveSwitcher(pVM, fVTxDisabled);
707
708 if ( rc == VINF_EM_RAW_INTERRUPT
709 || rc == VINF_EM_RAW_INTERRUPT_HYPER)
710 TRPMR0DispatchHostInterrupt(pVM);
711
712 ASMSetFlags(uFlags);
713
714#ifdef VBOX_WITH_STATISTICS
715 STAM_COUNTER_INC(&pVM->vmm.s.StatRunRC);
716 vmmR0RecordRC(pVM, pVCpu, rc);
717#endif
718 }
719 else
720 pVCpu->vmm.s.iLastGZRc = rc;
721 ASMAtomicWriteU32(&pVCpu->idHostCpu, NIL_RTCPUID);
722 RTThreadPreemptRestore(&PreemptState);
723 break;
724 }
725
726 /*
727 * Run guest code using the available hardware acceleration technology.
728 *
729 * Disable interrupts before we do anything interesting. On Windows we avoid
730 * this by having the support driver raise the IRQL before calling us, this way
731 * we hope to get away with page faults and later calling into the kernel.
732 */
733 case VMMR0_DO_HM_RUN:
734 {
735#ifdef VBOX_WITH_VMMR0_DISABLE_PREEMPTION
736 RTTHREADPREEMPTSTATE PreemptState = RTTHREADPREEMPTSTATE_INITIALIZER;
737 RTThreadPreemptDisable(&PreemptState);
738#elif !defined(RT_OS_WINDOWS)
739 RTCCUINTREG uFlags = ASMIntDisableFlags();
740#endif
741 ASMAtomicWriteU32(&pVCpu->idHostCpu, RTMpCpuId());
742 if (pVM->vmm.s.fUsePeriodicPreemptionTimers)
743 GVMMR0SchedUpdatePeriodicPreemptionTimer(pVM, pVCpu->idHostCpu, TMCalcHostTimerFrequency(pVM, pVCpu));
744
745#ifdef LOG_ENABLED
746 if (pVCpu->idCpu > 0)
747 {
748 /* Lazy registration of ring 0 loggers. */
749 PVMMR0LOGGER pR0Logger = pVCpu->vmm.s.pR0LoggerR0;
750 if ( pR0Logger
751 && !pR0Logger->fRegistered)
752 {
753 RTLogSetDefaultInstanceThread(&pR0Logger->Logger, (uintptr_t)pVM->pSession);
754 pR0Logger->fRegistered = true;
755 }
756 }
757#endif
758 int rc;
759 if (!HMR0SuspendPending())
760 {
761 rc = HMR0Enter(pVM, pVCpu);
762 if (RT_SUCCESS(rc))
763 {
764 VMCPU_SET_STATE(pVCpu, VMCPUSTATE_STARTED_HM);
765
766 rc = vmmR0CallRing3SetJmp(&pVCpu->vmm.s.CallRing3JmpBufR0, HMR0RunGuestCode, pVM, pVCpu); /* this may resume code. */
767 int rc2 = HMR0Leave(pVM, pVCpu);
768 AssertRC(rc2);
769
770 VMCPU_ASSERT_STATE(pVCpu, VMCPUSTATE_STARTED_HM);
771 VMCPU_SET_STATE(pVCpu, VMCPUSTATE_STARTED);
772 }
773 STAM_COUNTER_INC(&pVM->vmm.s.StatRunRC);
774 }
775 else
776 {
777 /* System is about to go into suspend mode; go back to ring 3. */
778 rc = VINF_EM_RAW_INTERRUPT;
779 }
780 pVCpu->vmm.s.iLastGZRc = rc;
781
782 ASMAtomicWriteU32(&pVCpu->idHostCpu, NIL_RTCPUID);
783#ifdef VBOX_WITH_VMMR0_DISABLE_PREEMPTION
784 RTThreadPreemptRestore(&PreemptState);
785#elif !defined(RT_OS_WINDOWS)
786 ASMSetFlags(uFlags);
787#endif
788
789#ifdef VBOX_WITH_STATISTICS
790 vmmR0RecordRC(pVM, pVCpu, rc);
791#endif
792 /* No special action required for external interrupts, just return. */
793 break;
794 }
795
796 /*
797 * For profiling.
798 */
799 case VMMR0_DO_NOP:
800 pVCpu->vmm.s.iLastGZRc = VINF_SUCCESS;
801 break;
802
803 /*
804 * Impossible.
805 */
806 default:
807 AssertMsgFailed(("%#x\n", enmOperation));
808 pVCpu->vmm.s.iLastGZRc = VERR_NOT_SUPPORTED;
809 break;
810 }
811}
812
813
814/**
815 * Validates a session or VM session argument.
816 *
817 * @returns true / false accordingly.
818 * @param pVM Pointer to the VM.
819 * @param pSession The session argument.
820 */
821DECLINLINE(bool) vmmR0IsValidSession(PVM pVM, PSUPDRVSESSION pClaimedSession, PSUPDRVSESSION pSession)
822{
823 /* This must be set! */
824 if (!pSession)
825 return false;
826
827 /* Only one out of the two. */
828 if (pVM && pClaimedSession)
829 return false;
830 if (pVM)
831 pClaimedSession = pVM->pSession;
832 return pClaimedSession == pSession;
833}
834
835
836/**
837 * VMMR0EntryEx worker function, either called directly or when ever possible
838 * called thru a longjmp so we can exit safely on failure.
839 *
840 * @returns VBox status code.
841 * @param pVM Pointer to the VM.
842 * @param idCpu Virtual CPU ID argument. Must be NIL_VMCPUID if pVM
843 * is NIL_RTR0PTR, and may be NIL_VMCPUID if it isn't
844 * @param enmOperation Which operation to execute.
845 * @param pReqHdr This points to a SUPVMMR0REQHDR packet. Optional.
846 * The support driver validates this if it's present.
847 * @param u64Arg Some simple constant argument.
848 * @param pSession The session of the caller.
849 * @remarks Assume called with interrupts _enabled_.
850 */
851static int vmmR0EntryExWorker(PVM pVM, VMCPUID idCpu, VMMR0OPERATION enmOperation, PSUPVMMR0REQHDR pReqHdr, uint64_t u64Arg, PSUPDRVSESSION pSession)
852{
853 /*
854 * Common VM pointer validation.
855 */
856 if (pVM)
857 {
858 if (RT_UNLIKELY( !VALID_PTR(pVM)
859 || ((uintptr_t)pVM & PAGE_OFFSET_MASK)))
860 {
861 SUPR0Printf("vmmR0EntryExWorker: Invalid pVM=%p! (op=%d)\n", pVM, enmOperation);
862 return VERR_INVALID_POINTER;
863 }
864 if (RT_UNLIKELY( pVM->enmVMState < VMSTATE_CREATING
865 || pVM->enmVMState > VMSTATE_TERMINATED
866 || pVM->pVMR0 != pVM))
867 {
868 SUPR0Printf("vmmR0EntryExWorker: Invalid pVM=%p:{enmVMState=%d, .pVMR0=%p}! (op=%d)\n",
869 pVM, pVM->enmVMState, pVM->pVMR0, enmOperation);
870 return VERR_INVALID_POINTER;
871 }
872
873 if (RT_UNLIKELY(idCpu >= pVM->cCpus && idCpu != NIL_VMCPUID))
874 {
875 SUPR0Printf("vmmR0EntryExWorker: Invalid idCpu (%u vs cCpus=%u)\n", idCpu, pVM->cCpus);
876 return VERR_INVALID_PARAMETER;
877 }
878 }
879 else if (RT_UNLIKELY(idCpu != NIL_VMCPUID))
880 {
881 SUPR0Printf("vmmR0EntryExWorker: Invalid idCpu=%u\n", idCpu);
882 return VERR_INVALID_PARAMETER;
883 }
884
885
886 switch (enmOperation)
887 {
888 /*
889 * GVM requests
890 */
891 case VMMR0_DO_GVMM_CREATE_VM:
892 if (pVM || u64Arg || idCpu != NIL_VMCPUID)
893 return VERR_INVALID_PARAMETER;
894 return GVMMR0CreateVMReq((PGVMMCREATEVMREQ)pReqHdr);
895
896 case VMMR0_DO_GVMM_DESTROY_VM:
897 if (pReqHdr || u64Arg)
898 return VERR_INVALID_PARAMETER;
899 return GVMMR0DestroyVM(pVM);
900
901 case VMMR0_DO_GVMM_REGISTER_VMCPU:
902 {
903 if (!pVM)
904 return VERR_INVALID_PARAMETER;
905 return GVMMR0RegisterVCpu(pVM, idCpu);
906 }
907
908 case VMMR0_DO_GVMM_SCHED_HALT:
909 if (pReqHdr)
910 return VERR_INVALID_PARAMETER;
911 return GVMMR0SchedHalt(pVM, idCpu, u64Arg);
912
913 case VMMR0_DO_GVMM_SCHED_WAKE_UP:
914 if (pReqHdr || u64Arg)
915 return VERR_INVALID_PARAMETER;
916 return GVMMR0SchedWakeUp(pVM, idCpu);
917
918 case VMMR0_DO_GVMM_SCHED_POKE:
919 if (pReqHdr || u64Arg)
920 return VERR_INVALID_PARAMETER;
921 return GVMMR0SchedPoke(pVM, idCpu);
922
923 case VMMR0_DO_GVMM_SCHED_WAKE_UP_AND_POKE_CPUS:
924 if (u64Arg)
925 return VERR_INVALID_PARAMETER;
926 return GVMMR0SchedWakeUpAndPokeCpusReq(pVM, (PGVMMSCHEDWAKEUPANDPOKECPUSREQ)pReqHdr);
927
928 case VMMR0_DO_GVMM_SCHED_POLL:
929 if (pReqHdr || u64Arg > 1)
930 return VERR_INVALID_PARAMETER;
931 return GVMMR0SchedPoll(pVM, idCpu, !!u64Arg);
932
933 case VMMR0_DO_GVMM_QUERY_STATISTICS:
934 if (u64Arg)
935 return VERR_INVALID_PARAMETER;
936 return GVMMR0QueryStatisticsReq(pVM, (PGVMMQUERYSTATISTICSSREQ)pReqHdr);
937
938 case VMMR0_DO_GVMM_RESET_STATISTICS:
939 if (u64Arg)
940 return VERR_INVALID_PARAMETER;
941 return GVMMR0ResetStatisticsReq(pVM, (PGVMMRESETSTATISTICSSREQ)pReqHdr);
942
943 /*
944 * Initialize the R0 part of a VM instance.
945 */
946 case VMMR0_DO_VMMR0_INIT:
947 return vmmR0InitVM(pVM, (uint32_t)u64Arg);
948
949 /*
950 * Terminate the R0 part of a VM instance.
951 */
952 case VMMR0_DO_VMMR0_TERM:
953 return VMMR0TermVM(pVM, NULL);
954
955 /*
956 * Attempt to enable hm mode and check the current setting.
957 */
958 case VMMR0_DO_HM_ENABLE:
959 return HMR0EnableAllCpus(pVM);
960
961 /*
962 * Setup the hardware accelerated session.
963 */
964 case VMMR0_DO_HM_SETUP_VM:
965 return HMR0SetupVM(pVM);
966
967 /*
968 * Switch to RC to execute Hypervisor function.
969 */
970 case VMMR0_DO_CALL_HYPERVISOR:
971 {
972 int rc;
973 bool fVTxDisabled;
974
975#ifndef VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0
976 if (RT_UNLIKELY(!PGMGetHyperCR3(VMMGetCpu0(pVM))))
977 return VERR_PGM_NO_CR3_SHADOW_ROOT;
978#endif
979
980 RTCCUINTREG fFlags = ASMIntDisableFlags();
981
982#ifdef VBOX_WITH_VMMR0_DISABLE_LAPIC_NMI
983 RTCPUID idHostCpu = RTMpCpuId();
984 CPUMR0SetLApic(pVM, idHostCpu);
985#endif
986
987 /* We might need to disable VT-x if the active switcher turns off paging. */
988 rc = HMR0EnterSwitcher(pVM, pVM->vmm.s.enmSwitcher, &fVTxDisabled);
989 if (RT_FAILURE(rc))
990 return rc;
991
992 rc = pVM->vmm.s.pfnR0ToRawMode(pVM);
993
994 /* Re-enable VT-x if previously turned off. */
995 HMR0LeaveSwitcher(pVM, fVTxDisabled);
996
997 /** @todo dispatch interrupts? */
998 ASMSetFlags(fFlags);
999 return rc;
1000 }
1001
1002 /*
1003 * PGM wrappers.
1004 */
1005 case VMMR0_DO_PGM_ALLOCATE_HANDY_PAGES:
1006 if (idCpu == NIL_VMCPUID)
1007 return VERR_INVALID_CPU_ID;
1008 return PGMR0PhysAllocateHandyPages(pVM, &pVM->aCpus[idCpu]);
1009
1010 case VMMR0_DO_PGM_FLUSH_HANDY_PAGES:
1011 if (idCpu == NIL_VMCPUID)
1012 return VERR_INVALID_CPU_ID;
1013 return PGMR0PhysFlushHandyPages(pVM, &pVM->aCpus[idCpu]);
1014
1015 case VMMR0_DO_PGM_ALLOCATE_LARGE_HANDY_PAGE:
1016 if (idCpu == NIL_VMCPUID)
1017 return VERR_INVALID_CPU_ID;
1018 return PGMR0PhysAllocateLargeHandyPage(pVM, &pVM->aCpus[idCpu]);
1019
1020 case VMMR0_DO_PGM_PHYS_SETUP_IOMMU:
1021 if (idCpu != 0)
1022 return VERR_INVALID_CPU_ID;
1023 return PGMR0PhysSetupIommu(pVM);
1024
1025 /*
1026 * GMM wrappers.
1027 */
1028 case VMMR0_DO_GMM_INITIAL_RESERVATION:
1029 if (u64Arg)
1030 return VERR_INVALID_PARAMETER;
1031 return GMMR0InitialReservationReq(pVM, idCpu, (PGMMINITIALRESERVATIONREQ)pReqHdr);
1032
1033 case VMMR0_DO_GMM_UPDATE_RESERVATION:
1034 if (u64Arg)
1035 return VERR_INVALID_PARAMETER;
1036 return GMMR0UpdateReservationReq(pVM, idCpu, (PGMMUPDATERESERVATIONREQ)pReqHdr);
1037
1038 case VMMR0_DO_GMM_ALLOCATE_PAGES:
1039 if (u64Arg)
1040 return VERR_INVALID_PARAMETER;
1041 return GMMR0AllocatePagesReq(pVM, idCpu, (PGMMALLOCATEPAGESREQ)pReqHdr);
1042
1043 case VMMR0_DO_GMM_FREE_PAGES:
1044 if (u64Arg)
1045 return VERR_INVALID_PARAMETER;
1046 return GMMR0FreePagesReq(pVM, idCpu, (PGMMFREEPAGESREQ)pReqHdr);
1047
1048 case VMMR0_DO_GMM_FREE_LARGE_PAGE:
1049 if (u64Arg)
1050 return VERR_INVALID_PARAMETER;
1051 return GMMR0FreeLargePageReq(pVM, idCpu, (PGMMFREELARGEPAGEREQ)pReqHdr);
1052
1053 case VMMR0_DO_GMM_QUERY_HYPERVISOR_MEM_STATS:
1054 if (u64Arg)
1055 return VERR_INVALID_PARAMETER;
1056 return GMMR0QueryHypervisorMemoryStatsReq(pVM, (PGMMMEMSTATSREQ)pReqHdr);
1057
1058 case VMMR0_DO_GMM_QUERY_MEM_STATS:
1059 if (idCpu == NIL_VMCPUID)
1060 return VERR_INVALID_CPU_ID;
1061 if (u64Arg)
1062 return VERR_INVALID_PARAMETER;
1063 return GMMR0QueryMemoryStatsReq(pVM, idCpu, (PGMMMEMSTATSREQ)pReqHdr);
1064
1065 case VMMR0_DO_GMM_BALLOONED_PAGES:
1066 if (u64Arg)
1067 return VERR_INVALID_PARAMETER;
1068 return GMMR0BalloonedPagesReq(pVM, idCpu, (PGMMBALLOONEDPAGESREQ)pReqHdr);
1069
1070 case VMMR0_DO_GMM_MAP_UNMAP_CHUNK:
1071 if (u64Arg)
1072 return VERR_INVALID_PARAMETER;
1073 return GMMR0MapUnmapChunkReq(pVM, (PGMMMAPUNMAPCHUNKREQ)pReqHdr);
1074
1075 case VMMR0_DO_GMM_SEED_CHUNK:
1076 if (pReqHdr)
1077 return VERR_INVALID_PARAMETER;
1078 return GMMR0SeedChunk(pVM, idCpu, (RTR3PTR)u64Arg);
1079
1080 case VMMR0_DO_GMM_REGISTER_SHARED_MODULE:
1081 if (idCpu == NIL_VMCPUID)
1082 return VERR_INVALID_CPU_ID;
1083 if (u64Arg)
1084 return VERR_INVALID_PARAMETER;
1085 return GMMR0RegisterSharedModuleReq(pVM, idCpu, (PGMMREGISTERSHAREDMODULEREQ)pReqHdr);
1086
1087 case VMMR0_DO_GMM_UNREGISTER_SHARED_MODULE:
1088 if (idCpu == NIL_VMCPUID)
1089 return VERR_INVALID_CPU_ID;
1090 if (u64Arg)
1091 return VERR_INVALID_PARAMETER;
1092 return GMMR0UnregisterSharedModuleReq(pVM, idCpu, (PGMMUNREGISTERSHAREDMODULEREQ)pReqHdr);
1093
1094 case VMMR0_DO_GMM_RESET_SHARED_MODULES:
1095 if (idCpu == NIL_VMCPUID)
1096 return VERR_INVALID_CPU_ID;
1097 if ( u64Arg
1098 || pReqHdr)
1099 return VERR_INVALID_PARAMETER;
1100 return GMMR0ResetSharedModules(pVM, idCpu);
1101
1102#ifdef VBOX_WITH_PAGE_SHARING
1103 case VMMR0_DO_GMM_CHECK_SHARED_MODULES:
1104 {
1105 if (idCpu == NIL_VMCPUID)
1106 return VERR_INVALID_CPU_ID;
1107 if ( u64Arg
1108 || pReqHdr)
1109 return VERR_INVALID_PARAMETER;
1110
1111 PVMCPU pVCpu = &pVM->aCpus[idCpu];
1112 Assert(pVCpu->hNativeThreadR0 == RTThreadNativeSelf());
1113
1114# ifdef DEBUG_sandervl
1115 /* Make sure that log flushes can jump back to ring-3; annoying to get an incomplete log (this is risky though as the code doesn't take this into account). */
1116 /* Todo: this can have bad side effects for unexpected jumps back to r3. */
1117 int rc = GMMR0CheckSharedModulesStart(pVM);
1118 if (rc == VINF_SUCCESS)
1119 {
1120 rc = vmmR0CallRing3SetJmp(&pVCpu->vmm.s.CallRing3JmpBufR0, GMMR0CheckSharedModules, pVM, pVCpu); /* this may resume code. */
1121 Assert( rc == VINF_SUCCESS
1122 || (rc == VINF_VMM_CALL_HOST && pVCpu->vmm.s.enmCallRing3Operation == VMMCALLRING3_VMM_LOGGER_FLUSH));
1123 GMMR0CheckSharedModulesEnd(pVM);
1124 }
1125# else
1126 int rc = GMMR0CheckSharedModules(pVM, pVCpu);
1127# endif
1128 return rc;
1129 }
1130#endif
1131
1132#if defined(VBOX_STRICT) && HC_ARCH_BITS == 64
1133 case VMMR0_DO_GMM_FIND_DUPLICATE_PAGE:
1134 if (u64Arg)
1135 return VERR_INVALID_PARAMETER;
1136 return GMMR0FindDuplicatePageReq(pVM, (PGMMFINDDUPLICATEPAGEREQ)pReqHdr);
1137#endif
1138
1139 case VMMR0_DO_GMM_QUERY_STATISTICS:
1140 if (u64Arg)
1141 return VERR_INVALID_PARAMETER;
1142 return GMMR0QueryStatisticsReq(pVM, (PGMMQUERYSTATISTICSSREQ)pReqHdr);
1143
1144 case VMMR0_DO_GMM_RESET_STATISTICS:
1145 if (u64Arg)
1146 return VERR_INVALID_PARAMETER;
1147 return GMMR0ResetStatisticsReq(pVM, (PGMMRESETSTATISTICSSREQ)pReqHdr);
1148
1149 /*
1150 * A quick GCFGM mock-up.
1151 */
1152 /** @todo GCFGM with proper access control, ring-3 management interface and all that. */
1153 case VMMR0_DO_GCFGM_SET_VALUE:
1154 case VMMR0_DO_GCFGM_QUERY_VALUE:
1155 {
1156 if (pVM || !pReqHdr || u64Arg || idCpu != NIL_VMCPUID)
1157 return VERR_INVALID_PARAMETER;
1158 PGCFGMVALUEREQ pReq = (PGCFGMVALUEREQ)pReqHdr;
1159 if (pReq->Hdr.cbReq != sizeof(*pReq))
1160 return VERR_INVALID_PARAMETER;
1161 int rc;
1162 if (enmOperation == VMMR0_DO_GCFGM_SET_VALUE)
1163 {
1164 rc = GVMMR0SetConfig(pReq->pSession, &pReq->szName[0], pReq->u64Value);
1165 //if (rc == VERR_CFGM_VALUE_NOT_FOUND)
1166 // rc = GMMR0SetConfig(pReq->pSession, &pReq->szName[0], pReq->u64Value);
1167 }
1168 else
1169 {
1170 rc = GVMMR0QueryConfig(pReq->pSession, &pReq->szName[0], &pReq->u64Value);
1171 //if (rc == VERR_CFGM_VALUE_NOT_FOUND)
1172 // rc = GMMR0QueryConfig(pReq->pSession, &pReq->szName[0], &pReq->u64Value);
1173 }
1174 return rc;
1175 }
1176
1177 /*
1178 * PDM Wrappers.
1179 */
1180 case VMMR0_DO_PDM_DRIVER_CALL_REQ_HANDLER:
1181 {
1182 if (!pVM || !pReqHdr || u64Arg || idCpu != NIL_VMCPUID)
1183 return VERR_INVALID_PARAMETER;
1184 return PDMR0DriverCallReqHandler(pVM, (PPDMDRIVERCALLREQHANDLERREQ)pReqHdr);
1185 }
1186
1187 case VMMR0_DO_PDM_DEVICE_CALL_REQ_HANDLER:
1188 {
1189 if (!pVM || !pReqHdr || u64Arg || idCpu != NIL_VMCPUID)
1190 return VERR_INVALID_PARAMETER;
1191 return PDMR0DeviceCallReqHandler(pVM, (PPDMDEVICECALLREQHANDLERREQ)pReqHdr);
1192 }
1193
1194 /*
1195 * Requests to the internal networking service.
1196 */
1197 case VMMR0_DO_INTNET_OPEN:
1198 {
1199 PINTNETOPENREQ pReq = (PINTNETOPENREQ)pReqHdr;
1200 if (u64Arg || !pReq || !vmmR0IsValidSession(pVM, pReq->pSession, pSession) || idCpu != NIL_VMCPUID)
1201 return VERR_INVALID_PARAMETER;
1202 return IntNetR0OpenReq(pSession, pReq);
1203 }
1204
1205 case VMMR0_DO_INTNET_IF_CLOSE:
1206 if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFCLOSEREQ)pReqHdr)->pSession, pSession) || idCpu != NIL_VMCPUID)
1207 return VERR_INVALID_PARAMETER;
1208 return IntNetR0IfCloseReq(pSession, (PINTNETIFCLOSEREQ)pReqHdr);
1209
1210 case VMMR0_DO_INTNET_IF_GET_BUFFER_PTRS:
1211 if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFGETBUFFERPTRSREQ)pReqHdr)->pSession, pSession) || idCpu != NIL_VMCPUID)
1212 return VERR_INVALID_PARAMETER;
1213 return IntNetR0IfGetBufferPtrsReq(pSession, (PINTNETIFGETBUFFERPTRSREQ)pReqHdr);
1214
1215 case VMMR0_DO_INTNET_IF_SET_PROMISCUOUS_MODE:
1216 if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFSETPROMISCUOUSMODEREQ)pReqHdr)->pSession, pSession) || idCpu != NIL_VMCPUID)
1217 return VERR_INVALID_PARAMETER;
1218 return IntNetR0IfSetPromiscuousModeReq(pSession, (PINTNETIFSETPROMISCUOUSMODEREQ)pReqHdr);
1219
1220 case VMMR0_DO_INTNET_IF_SET_MAC_ADDRESS:
1221 if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFSETMACADDRESSREQ)pReqHdr)->pSession, pSession) || idCpu != NIL_VMCPUID)
1222 return VERR_INVALID_PARAMETER;
1223 return IntNetR0IfSetMacAddressReq(pSession, (PINTNETIFSETMACADDRESSREQ)pReqHdr);
1224
1225 case VMMR0_DO_INTNET_IF_SET_ACTIVE:
1226 if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFSETACTIVEREQ)pReqHdr)->pSession, pSession) || idCpu != NIL_VMCPUID)
1227 return VERR_INVALID_PARAMETER;
1228 return IntNetR0IfSetActiveReq(pSession, (PINTNETIFSETACTIVEREQ)pReqHdr);
1229
1230 case VMMR0_DO_INTNET_IF_SEND:
1231 if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFSENDREQ)pReqHdr)->pSession, pSession) || idCpu != NIL_VMCPUID)
1232 return VERR_INVALID_PARAMETER;
1233 return IntNetR0IfSendReq(pSession, (PINTNETIFSENDREQ)pReqHdr);
1234
1235 case VMMR0_DO_INTNET_IF_WAIT:
1236 if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFWAITREQ)pReqHdr)->pSession, pSession) || idCpu != NIL_VMCPUID)
1237 return VERR_INVALID_PARAMETER;
1238 return IntNetR0IfWaitReq(pSession, (PINTNETIFWAITREQ)pReqHdr);
1239
1240 case VMMR0_DO_INTNET_IF_ABORT_WAIT:
1241 if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFWAITREQ)pReqHdr)->pSession, pSession) || idCpu != NIL_VMCPUID)
1242 return VERR_INVALID_PARAMETER;
1243 return IntNetR0IfAbortWaitReq(pSession, (PINTNETIFABORTWAITREQ)pReqHdr);
1244
1245#ifdef VBOX_WITH_PCI_PASSTHROUGH
1246 /*
1247 * Requests to host PCI driver service.
1248 */
1249 case VMMR0_DO_PCIRAW_REQ:
1250 if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PPCIRAWSENDREQ)pReqHdr)->pSession, pSession) || idCpu != NIL_VMCPUID)
1251 return VERR_INVALID_PARAMETER;
1252 return PciRawR0ProcessReq(pSession, pVM, (PPCIRAWSENDREQ)pReqHdr);
1253#endif
1254 /*
1255 * For profiling.
1256 */
1257 case VMMR0_DO_NOP:
1258 case VMMR0_DO_SLOW_NOP:
1259 return VINF_SUCCESS;
1260
1261 /*
1262 * For testing Ring-0 APIs invoked in this environment.
1263 */
1264 case VMMR0_DO_TESTS:
1265 /** @todo make new test */
1266 return VINF_SUCCESS;
1267
1268
1269#if HC_ARCH_BITS == 32 && defined(VBOX_WITH_64_BITS_GUESTS) && !defined(VBOX_WITH_HYBRID_32BIT_KERNEL)
1270 case VMMR0_DO_TEST_SWITCHER3264:
1271 if (idCpu == NIL_VMCPUID)
1272 return VERR_INVALID_CPU_ID;
1273 return HMR0TestSwitcher3264(pVM);
1274#endif
1275 default:
1276 /*
1277 * We're returning VERR_NOT_SUPPORT here so we've got something else
1278 * than -1 which the interrupt gate glue code might return.
1279 */
1280 Log(("operation %#x is not supported\n", enmOperation));
1281 return VERR_NOT_SUPPORTED;
1282 }
1283}
1284
1285
1286/**
1287 * Argument for vmmR0EntryExWrapper containing the arguments for VMMR0EntryEx.
1288 */
1289typedef struct VMMR0ENTRYEXARGS
1290{
1291 PVM pVM;
1292 VMCPUID idCpu;
1293 VMMR0OPERATION enmOperation;
1294 PSUPVMMR0REQHDR pReq;
1295 uint64_t u64Arg;
1296 PSUPDRVSESSION pSession;
1297} VMMR0ENTRYEXARGS;
1298/** Pointer to a vmmR0EntryExWrapper argument package. */
1299typedef VMMR0ENTRYEXARGS *PVMMR0ENTRYEXARGS;
1300
1301/**
1302 * This is just a longjmp wrapper function for VMMR0EntryEx calls.
1303 *
1304 * @returns VBox status code.
1305 * @param pvArgs The argument package
1306 */
1307static DECLCALLBACK(int) vmmR0EntryExWrapper(void *pvArgs)
1308{
1309 return vmmR0EntryExWorker(((PVMMR0ENTRYEXARGS)pvArgs)->pVM,
1310 ((PVMMR0ENTRYEXARGS)pvArgs)->idCpu,
1311 ((PVMMR0ENTRYEXARGS)pvArgs)->enmOperation,
1312 ((PVMMR0ENTRYEXARGS)pvArgs)->pReq,
1313 ((PVMMR0ENTRYEXARGS)pvArgs)->u64Arg,
1314 ((PVMMR0ENTRYEXARGS)pvArgs)->pSession);
1315}
1316
1317
1318/**
1319 * The Ring 0 entry point, called by the support library (SUP).
1320 *
1321 * @returns VBox status code.
1322 * @param pVM Pointer to the VM.
1323 * @param idCpu Virtual CPU ID argument. Must be NIL_VMCPUID if pVM
1324 * is NIL_RTR0PTR, and may be NIL_VMCPUID if it isn't
1325 * @param enmOperation Which operation to execute.
1326 * @param pReq Pointer to the SUPVMMR0REQHDR packet. Optional.
1327 * @param u64Arg Some simple constant argument.
1328 * @param pSession The session of the caller.
1329 * @remarks Assume called with interrupts _enabled_.
1330 */
1331VMMR0DECL(int) VMMR0EntryEx(PVM pVM, VMCPUID idCpu, VMMR0OPERATION enmOperation, PSUPVMMR0REQHDR pReq, uint64_t u64Arg, PSUPDRVSESSION pSession)
1332{
1333 /*
1334 * Requests that should only happen on the EMT thread will be
1335 * wrapped in a setjmp so we can assert without causing trouble.
1336 */
1337 if ( VALID_PTR(pVM)
1338 && pVM->pVMR0
1339 && idCpu < pVM->cCpus)
1340 {
1341 switch (enmOperation)
1342 {
1343 /* These might/will be called before VMMR3Init. */
1344 case VMMR0_DO_GMM_INITIAL_RESERVATION:
1345 case VMMR0_DO_GMM_UPDATE_RESERVATION:
1346 case VMMR0_DO_GMM_ALLOCATE_PAGES:
1347 case VMMR0_DO_GMM_FREE_PAGES:
1348 case VMMR0_DO_GMM_BALLOONED_PAGES:
1349 /* On the mac we might not have a valid jmp buf, so check these as well. */
1350 case VMMR0_DO_VMMR0_INIT:
1351 case VMMR0_DO_VMMR0_TERM:
1352 {
1353 PVMCPU pVCpu = &pVM->aCpus[idCpu];
1354
1355 if (!pVCpu->vmm.s.CallRing3JmpBufR0.pvSavedStack)
1356 break;
1357
1358 /** @todo validate this EMT claim... GVM knows. */
1359 VMMR0ENTRYEXARGS Args;
1360 Args.pVM = pVM;
1361 Args.idCpu = idCpu;
1362 Args.enmOperation = enmOperation;
1363 Args.pReq = pReq;
1364 Args.u64Arg = u64Arg;
1365 Args.pSession = pSession;
1366 return vmmR0CallRing3SetJmpEx(&pVCpu->vmm.s.CallRing3JmpBufR0, vmmR0EntryExWrapper, &Args);
1367 }
1368
1369 default:
1370 break;
1371 }
1372 }
1373 return vmmR0EntryExWorker(pVM, idCpu, enmOperation, pReq, u64Arg, pSession);
1374}
1375
1376
1377/**
1378 * Checks whether we've armed the ring-0 long jump machinery.
1379 *
1380 * @returns @c true / @c false
1381 * @param pVCpu The caller's cross context virtual CPU structure.
1382 * @thread EMT
1383 * @sa VMMIsLongJumpArmed
1384 */
1385VMMR0_INT_DECL(bool) VMMR0IsLongJumpArmed(PVMCPU pVCpu)
1386{
1387#ifdef RT_ARCH_X86
1388 return pVCpu->vmm.s.CallRing3JmpBufR0.eip
1389 && !pVCpu->vmm.s.CallRing3JmpBufR0.fInRing3Call;
1390#else
1391 return pVCpu->vmm.s.CallRing3JmpBufR0.rip
1392 && !pVCpu->vmm.s.CallRing3JmpBufR0.fInRing3Call;
1393#endif
1394}
1395
1396
1397/**
1398 * Internal R0 logger worker: Flush logger.
1399 *
1400 * @param pLogger The logger instance to flush.
1401 * @remark This function must be exported!
1402 */
1403VMMR0DECL(void) vmmR0LoggerFlush(PRTLOGGER pLogger)
1404{
1405#ifdef LOG_ENABLED
1406 /*
1407 * Convert the pLogger into a VM handle and 'call' back to Ring-3.
1408 * (This is a bit paranoid code.)
1409 */
1410 PVMMR0LOGGER pR0Logger = (PVMMR0LOGGER)((uintptr_t)pLogger - RT_OFFSETOF(VMMR0LOGGER, Logger));
1411 if ( !VALID_PTR(pR0Logger)
1412 || !VALID_PTR(pR0Logger + 1)
1413 || pLogger->u32Magic != RTLOGGER_MAGIC)
1414 {
1415# ifdef DEBUG
1416 SUPR0Printf("vmmR0LoggerFlush: pLogger=%p!\n", pLogger);
1417# endif
1418 return;
1419 }
1420 if (pR0Logger->fFlushingDisabled)
1421 return; /* quietly */
1422
1423 PVM pVM = pR0Logger->pVM;
1424 if ( !VALID_PTR(pVM)
1425 || pVM->pVMR0 != pVM)
1426 {
1427# ifdef DEBUG
1428 SUPR0Printf("vmmR0LoggerFlush: pVM=%p! pVMR0=%p! pLogger=%p\n", pVM, pVM->pVMR0, pLogger);
1429# endif
1430 return;
1431 }
1432
1433 PVMCPU pVCpu = VMMGetCpu(pVM);
1434 if (pVCpu)
1435 {
1436 /*
1437 * Check that the jump buffer is armed.
1438 */
1439# ifdef RT_ARCH_X86
1440 if ( !pVCpu->vmm.s.CallRing3JmpBufR0.eip
1441 || pVCpu->vmm.s.CallRing3JmpBufR0.fInRing3Call)
1442# else
1443 if ( !pVCpu->vmm.s.CallRing3JmpBufR0.rip
1444 || pVCpu->vmm.s.CallRing3JmpBufR0.fInRing3Call)
1445# endif
1446 {
1447# ifdef DEBUG
1448 SUPR0Printf("vmmR0LoggerFlush: Jump buffer isn't armed!\n");
1449# endif
1450 return;
1451 }
1452 VMMRZCallRing3(pVM, pVCpu, VMMCALLRING3_VMM_LOGGER_FLUSH, 0);
1453 }
1454# ifdef DEBUG
1455 else
1456 SUPR0Printf("vmmR0LoggerFlush: invalid VCPU context!\n");
1457# endif
1458#endif
1459}
1460
1461/**
1462 * Internal R0 logger worker: Custom prefix.
1463 *
1464 * @returns Number of chars written.
1465 *
1466 * @param pLogger The logger instance.
1467 * @param pchBuf The output buffer.
1468 * @param cchBuf The size of the buffer.
1469 * @param pvUser User argument (ignored).
1470 */
1471VMMR0DECL(size_t) vmmR0LoggerPrefix(PRTLOGGER pLogger, char *pchBuf, size_t cchBuf, void *pvUser)
1472{
1473 NOREF(pvUser);
1474#ifdef LOG_ENABLED
1475 PVMMR0LOGGER pR0Logger = (PVMMR0LOGGER)((uintptr_t)pLogger - RT_OFFSETOF(VMMR0LOGGER, Logger));
1476 if ( !VALID_PTR(pR0Logger)
1477 || !VALID_PTR(pR0Logger + 1)
1478 || pLogger->u32Magic != RTLOGGER_MAGIC
1479 || cchBuf < 2)
1480 return 0;
1481
1482 static const char s_szHex[17] = "0123456789abcdef";
1483 VMCPUID const idCpu = pR0Logger->idCpu;
1484 pchBuf[1] = s_szHex[ idCpu & 15];
1485 pchBuf[0] = s_szHex[(idCpu >> 4) & 15];
1486
1487 return 2;
1488#else
1489 return 0;
1490#endif
1491}
1492
1493#ifdef LOG_ENABLED
1494
1495/**
1496 * Disables flushing of the ring-0 debug log.
1497 *
1498 * @param pVCpu Pointer to the VMCPU.
1499 */
1500VMMR0DECL(void) VMMR0LogFlushDisable(PVMCPU pVCpu)
1501{
1502 if (pVCpu->vmm.s.pR0LoggerR0)
1503 pVCpu->vmm.s.pR0LoggerR0->fFlushingDisabled = true;
1504}
1505
1506
1507/**
1508 * Enables flushing of the ring-0 debug log.
1509 *
1510 * @param pVCpu Pointer to the VMCPU.
1511 */
1512VMMR0DECL(void) VMMR0LogFlushEnable(PVMCPU pVCpu)
1513{
1514 if (pVCpu->vmm.s.pR0LoggerR0)
1515 pVCpu->vmm.s.pR0LoggerR0->fFlushingDisabled = false;
1516}
1517
1518
1519/**
1520 * Checks if log flushing is disabled or not.
1521 *
1522 * @param pVCpu Pointer to the VMCPU.
1523 */
1524VMMR0DECL(bool) VMMR0IsLogFlushDisabled(PVMCPU pVCpu)
1525{
1526 if (pVCpu->vmm.s.pR0LoggerR0)
1527 return pVCpu->vmm.s.pR0LoggerR0->fFlushingDisabled;
1528 return true;
1529}
1530#endif /* LOG_ENABLED */
1531
1532/**
1533 * Jump back to ring-3 if we're the EMT and the longjmp is armed.
1534 *
1535 * @returns true if the breakpoint should be hit, false if it should be ignored.
1536 */
1537DECLEXPORT(bool) RTCALL RTAssertShouldPanic(void)
1538{
1539#if 0
1540 return true;
1541#else
1542 PVM pVM = GVMMR0GetVMByEMT(NIL_RTNATIVETHREAD);
1543 if (pVM)
1544 {
1545 PVMCPU pVCpu = VMMGetCpu(pVM);
1546
1547 if (pVCpu)
1548 {
1549#ifdef RT_ARCH_X86
1550 if ( pVCpu->vmm.s.CallRing3JmpBufR0.eip
1551 && !pVCpu->vmm.s.CallRing3JmpBufR0.fInRing3Call)
1552#else
1553 if ( pVCpu->vmm.s.CallRing3JmpBufR0.rip
1554 && !pVCpu->vmm.s.CallRing3JmpBufR0.fInRing3Call)
1555#endif
1556 {
1557 int rc = VMMRZCallRing3(pVM, pVCpu, VMMCALLRING3_VM_R0_ASSERTION, 0);
1558 return RT_FAILURE_NP(rc);
1559 }
1560 }
1561 }
1562#ifdef RT_OS_LINUX
1563 return true;
1564#else
1565 return false;
1566#endif
1567#endif
1568}
1569
1570
1571/**
1572 * Override this so we can push it up to ring-3.
1573 *
1574 * @param pszExpr Expression. Can be NULL.
1575 * @param uLine Location line number.
1576 * @param pszFile Location file name.
1577 * @param pszFunction Location function name.
1578 */
1579DECLEXPORT(void) RTCALL RTAssertMsg1Weak(const char *pszExpr, unsigned uLine, const char *pszFile, const char *pszFunction)
1580{
1581 /*
1582 * To the log.
1583 */
1584 LogAlways(("\n!!R0-Assertion Failed!!\n"
1585 "Expression: %s\n"
1586 "Location : %s(%d) %s\n",
1587 pszExpr, pszFile, uLine, pszFunction));
1588
1589 /*
1590 * To the global VMM buffer.
1591 */
1592 PVM pVM = GVMMR0GetVMByEMT(NIL_RTNATIVETHREAD);
1593 if (pVM)
1594 RTStrPrintf(pVM->vmm.s.szRing0AssertMsg1, sizeof(pVM->vmm.s.szRing0AssertMsg1),
1595 "\n!!R0-Assertion Failed!!\n"
1596 "Expression: %s\n"
1597 "Location : %s(%d) %s\n",
1598 pszExpr, pszFile, uLine, pszFunction);
1599
1600 /*
1601 * Continue the normal way.
1602 */
1603 RTAssertMsg1(pszExpr, uLine, pszFile, pszFunction);
1604}
1605
1606
1607/**
1608 * Callback for RTLogFormatV which writes to the ring-3 log port.
1609 * See PFNLOGOUTPUT() for details.
1610 */
1611static DECLCALLBACK(size_t) rtLogOutput(void *pv, const char *pachChars, size_t cbChars)
1612{
1613 for (size_t i = 0; i < cbChars; i++)
1614 LogAlways(("%c", pachChars[i]));
1615
1616 NOREF(pv);
1617 return cbChars;
1618}
1619
1620
1621/**
1622 * Override this so we can push it up to ring-3.
1623 *
1624 * @param pszFormat The format string.
1625 * @param va Arguments.
1626 */
1627DECLEXPORT(void) RTCALL RTAssertMsg2WeakV(const char *pszFormat, va_list va)
1628{
1629 va_list vaCopy;
1630
1631 /*
1632 * Push the message to the logger.
1633 */
1634 PRTLOGGER pLog = RTLogDefaultInstance(); /** @todo we want this for release as well! */
1635 if (pLog)
1636 {
1637 va_copy(vaCopy, va);
1638 RTLogFormatV(rtLogOutput, pLog, pszFormat, vaCopy);
1639 va_end(vaCopy);
1640 }
1641
1642 /*
1643 * Push it to the global VMM buffer.
1644 */
1645 PVM pVM = GVMMR0GetVMByEMT(NIL_RTNATIVETHREAD);
1646 if (pVM)
1647 {
1648 va_copy(vaCopy, va);
1649 RTStrPrintfV(pVM->vmm.s.szRing0AssertMsg2, sizeof(pVM->vmm.s.szRing0AssertMsg2), pszFormat, vaCopy);
1650 va_end(vaCopy);
1651 }
1652
1653 /*
1654 * Continue the normal way.
1655 */
1656 RTAssertMsg2V(pszFormat, va);
1657}
1658
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