VirtualBox

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

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

VMMR0.cpp/RTAssertMsg2WeakV: Don't instantiate the debug logger, just use it when present. Instead, check for the release logger as well.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 56.5 KB
Line 
1/* $Id: VMMR0.cpp 45934 2013-05-07 12:50:12Z 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 if (RT_UNLIKELY( VMCPU_GET_STATE(pVCpu) != VMCPUSTATE_STARTED_HM
771 && RT_SUCCESS_NP(rc) && rc != VINF_VMM_CALL_HOST ))
772 {
773 /* Manual assert as normal assertions are going to crash in this case. */
774 pVM->vmm.s.szRing0AssertMsg1[0] = '\0';
775 RTStrPrintf(pVM->vmm.s.szRing0AssertMsg2, sizeof(pVM->vmm.s.szRing0AssertMsg2),
776 "Got VMCPU state %d expected %d.\n", VMCPU_GET_STATE(pVCpu), VMCPUSTATE_STARTED_HM);
777 rc = VERR_VMM_WRONG_HM_VMCPU_STATE;
778 }
779 VMCPU_SET_STATE(pVCpu, VMCPUSTATE_STARTED);
780 }
781 STAM_COUNTER_INC(&pVM->vmm.s.StatRunRC);
782 }
783 else
784 {
785 /* System is about to go into suspend mode; go back to ring 3. */
786 rc = VINF_EM_RAW_INTERRUPT;
787 }
788 pVCpu->vmm.s.iLastGZRc = rc;
789
790 ASMAtomicWriteU32(&pVCpu->idHostCpu, NIL_RTCPUID);
791#ifdef VBOX_WITH_VMMR0_DISABLE_PREEMPTION
792 RTThreadPreemptRestore(&PreemptState);
793#elif !defined(RT_OS_WINDOWS)
794 ASMSetFlags(uFlags);
795#endif
796
797#ifdef VBOX_WITH_STATISTICS
798 vmmR0RecordRC(pVM, pVCpu, rc);
799#endif
800 /* No special action required for external interrupts, just return. */
801 break;
802 }
803
804 /*
805 * For profiling.
806 */
807 case VMMR0_DO_NOP:
808 pVCpu->vmm.s.iLastGZRc = VINF_SUCCESS;
809 break;
810
811 /*
812 * Impossible.
813 */
814 default:
815 AssertMsgFailed(("%#x\n", enmOperation));
816 pVCpu->vmm.s.iLastGZRc = VERR_NOT_SUPPORTED;
817 break;
818 }
819}
820
821
822/**
823 * Validates a session or VM session argument.
824 *
825 * @returns true / false accordingly.
826 * @param pVM Pointer to the VM.
827 * @param pSession The session argument.
828 */
829DECLINLINE(bool) vmmR0IsValidSession(PVM pVM, PSUPDRVSESSION pClaimedSession, PSUPDRVSESSION pSession)
830{
831 /* This must be set! */
832 if (!pSession)
833 return false;
834
835 /* Only one out of the two. */
836 if (pVM && pClaimedSession)
837 return false;
838 if (pVM)
839 pClaimedSession = pVM->pSession;
840 return pClaimedSession == pSession;
841}
842
843
844/**
845 * VMMR0EntryEx worker function, either called directly or when ever possible
846 * called thru a longjmp so we can exit safely on failure.
847 *
848 * @returns VBox status code.
849 * @param pVM Pointer to the VM.
850 * @param idCpu Virtual CPU ID argument. Must be NIL_VMCPUID if pVM
851 * is NIL_RTR0PTR, and may be NIL_VMCPUID if it isn't
852 * @param enmOperation Which operation to execute.
853 * @param pReqHdr This points to a SUPVMMR0REQHDR packet. Optional.
854 * The support driver validates this if it's present.
855 * @param u64Arg Some simple constant argument.
856 * @param pSession The session of the caller.
857 * @remarks Assume called with interrupts _enabled_.
858 */
859static int vmmR0EntryExWorker(PVM pVM, VMCPUID idCpu, VMMR0OPERATION enmOperation, PSUPVMMR0REQHDR pReqHdr, uint64_t u64Arg, PSUPDRVSESSION pSession)
860{
861 /*
862 * Common VM pointer validation.
863 */
864 if (pVM)
865 {
866 if (RT_UNLIKELY( !VALID_PTR(pVM)
867 || ((uintptr_t)pVM & PAGE_OFFSET_MASK)))
868 {
869 SUPR0Printf("vmmR0EntryExWorker: Invalid pVM=%p! (op=%d)\n", pVM, enmOperation);
870 return VERR_INVALID_POINTER;
871 }
872 if (RT_UNLIKELY( pVM->enmVMState < VMSTATE_CREATING
873 || pVM->enmVMState > VMSTATE_TERMINATED
874 || pVM->pVMR0 != pVM))
875 {
876 SUPR0Printf("vmmR0EntryExWorker: Invalid pVM=%p:{enmVMState=%d, .pVMR0=%p}! (op=%d)\n",
877 pVM, pVM->enmVMState, pVM->pVMR0, enmOperation);
878 return VERR_INVALID_POINTER;
879 }
880
881 if (RT_UNLIKELY(idCpu >= pVM->cCpus && idCpu != NIL_VMCPUID))
882 {
883 SUPR0Printf("vmmR0EntryExWorker: Invalid idCpu (%u vs cCpus=%u)\n", idCpu, pVM->cCpus);
884 return VERR_INVALID_PARAMETER;
885 }
886 }
887 else if (RT_UNLIKELY(idCpu != NIL_VMCPUID))
888 {
889 SUPR0Printf("vmmR0EntryExWorker: Invalid idCpu=%u\n", idCpu);
890 return VERR_INVALID_PARAMETER;
891 }
892
893
894 switch (enmOperation)
895 {
896 /*
897 * GVM requests
898 */
899 case VMMR0_DO_GVMM_CREATE_VM:
900 if (pVM || u64Arg || idCpu != NIL_VMCPUID)
901 return VERR_INVALID_PARAMETER;
902 return GVMMR0CreateVMReq((PGVMMCREATEVMREQ)pReqHdr);
903
904 case VMMR0_DO_GVMM_DESTROY_VM:
905 if (pReqHdr || u64Arg)
906 return VERR_INVALID_PARAMETER;
907 return GVMMR0DestroyVM(pVM);
908
909 case VMMR0_DO_GVMM_REGISTER_VMCPU:
910 {
911 if (!pVM)
912 return VERR_INVALID_PARAMETER;
913 return GVMMR0RegisterVCpu(pVM, idCpu);
914 }
915
916 case VMMR0_DO_GVMM_SCHED_HALT:
917 if (pReqHdr)
918 return VERR_INVALID_PARAMETER;
919 return GVMMR0SchedHalt(pVM, idCpu, u64Arg);
920
921 case VMMR0_DO_GVMM_SCHED_WAKE_UP:
922 if (pReqHdr || u64Arg)
923 return VERR_INVALID_PARAMETER;
924 return GVMMR0SchedWakeUp(pVM, idCpu);
925
926 case VMMR0_DO_GVMM_SCHED_POKE:
927 if (pReqHdr || u64Arg)
928 return VERR_INVALID_PARAMETER;
929 return GVMMR0SchedPoke(pVM, idCpu);
930
931 case VMMR0_DO_GVMM_SCHED_WAKE_UP_AND_POKE_CPUS:
932 if (u64Arg)
933 return VERR_INVALID_PARAMETER;
934 return GVMMR0SchedWakeUpAndPokeCpusReq(pVM, (PGVMMSCHEDWAKEUPANDPOKECPUSREQ)pReqHdr);
935
936 case VMMR0_DO_GVMM_SCHED_POLL:
937 if (pReqHdr || u64Arg > 1)
938 return VERR_INVALID_PARAMETER;
939 return GVMMR0SchedPoll(pVM, idCpu, !!u64Arg);
940
941 case VMMR0_DO_GVMM_QUERY_STATISTICS:
942 if (u64Arg)
943 return VERR_INVALID_PARAMETER;
944 return GVMMR0QueryStatisticsReq(pVM, (PGVMMQUERYSTATISTICSSREQ)pReqHdr);
945
946 case VMMR0_DO_GVMM_RESET_STATISTICS:
947 if (u64Arg)
948 return VERR_INVALID_PARAMETER;
949 return GVMMR0ResetStatisticsReq(pVM, (PGVMMRESETSTATISTICSSREQ)pReqHdr);
950
951 /*
952 * Initialize the R0 part of a VM instance.
953 */
954 case VMMR0_DO_VMMR0_INIT:
955 return vmmR0InitVM(pVM, (uint32_t)u64Arg);
956
957 /*
958 * Terminate the R0 part of a VM instance.
959 */
960 case VMMR0_DO_VMMR0_TERM:
961 return VMMR0TermVM(pVM, NULL);
962
963 /*
964 * Attempt to enable hm mode and check the current setting.
965 */
966 case VMMR0_DO_HM_ENABLE:
967 return HMR0EnableAllCpus(pVM);
968
969 /*
970 * Setup the hardware accelerated session.
971 */
972 case VMMR0_DO_HM_SETUP_VM:
973 return HMR0SetupVM(pVM);
974
975 /*
976 * Switch to RC to execute Hypervisor function.
977 */
978 case VMMR0_DO_CALL_HYPERVISOR:
979 {
980 int rc;
981 bool fVTxDisabled;
982
983#ifndef VBOX_WITH_2X_4GB_ADDR_SPACE_IN_R0
984 if (RT_UNLIKELY(!PGMGetHyperCR3(VMMGetCpu0(pVM))))
985 return VERR_PGM_NO_CR3_SHADOW_ROOT;
986#endif
987
988 RTCCUINTREG fFlags = ASMIntDisableFlags();
989
990#ifdef VBOX_WITH_VMMR0_DISABLE_LAPIC_NMI
991 RTCPUID idHostCpu = RTMpCpuId();
992 CPUMR0SetLApic(pVM, idHostCpu);
993#endif
994
995 /* We might need to disable VT-x if the active switcher turns off paging. */
996 rc = HMR0EnterSwitcher(pVM, pVM->vmm.s.enmSwitcher, &fVTxDisabled);
997 if (RT_FAILURE(rc))
998 return rc;
999
1000 rc = pVM->vmm.s.pfnR0ToRawMode(pVM);
1001
1002 /* Re-enable VT-x if previously turned off. */
1003 HMR0LeaveSwitcher(pVM, fVTxDisabled);
1004
1005 /** @todo dispatch interrupts? */
1006 ASMSetFlags(fFlags);
1007 return rc;
1008 }
1009
1010 /*
1011 * PGM wrappers.
1012 */
1013 case VMMR0_DO_PGM_ALLOCATE_HANDY_PAGES:
1014 if (idCpu == NIL_VMCPUID)
1015 return VERR_INVALID_CPU_ID;
1016 return PGMR0PhysAllocateHandyPages(pVM, &pVM->aCpus[idCpu]);
1017
1018 case VMMR0_DO_PGM_FLUSH_HANDY_PAGES:
1019 if (idCpu == NIL_VMCPUID)
1020 return VERR_INVALID_CPU_ID;
1021 return PGMR0PhysFlushHandyPages(pVM, &pVM->aCpus[idCpu]);
1022
1023 case VMMR0_DO_PGM_ALLOCATE_LARGE_HANDY_PAGE:
1024 if (idCpu == NIL_VMCPUID)
1025 return VERR_INVALID_CPU_ID;
1026 return PGMR0PhysAllocateLargeHandyPage(pVM, &pVM->aCpus[idCpu]);
1027
1028 case VMMR0_DO_PGM_PHYS_SETUP_IOMMU:
1029 if (idCpu != 0)
1030 return VERR_INVALID_CPU_ID;
1031 return PGMR0PhysSetupIommu(pVM);
1032
1033 /*
1034 * GMM wrappers.
1035 */
1036 case VMMR0_DO_GMM_INITIAL_RESERVATION:
1037 if (u64Arg)
1038 return VERR_INVALID_PARAMETER;
1039 return GMMR0InitialReservationReq(pVM, idCpu, (PGMMINITIALRESERVATIONREQ)pReqHdr);
1040
1041 case VMMR0_DO_GMM_UPDATE_RESERVATION:
1042 if (u64Arg)
1043 return VERR_INVALID_PARAMETER;
1044 return GMMR0UpdateReservationReq(pVM, idCpu, (PGMMUPDATERESERVATIONREQ)pReqHdr);
1045
1046 case VMMR0_DO_GMM_ALLOCATE_PAGES:
1047 if (u64Arg)
1048 return VERR_INVALID_PARAMETER;
1049 return GMMR0AllocatePagesReq(pVM, idCpu, (PGMMALLOCATEPAGESREQ)pReqHdr);
1050
1051 case VMMR0_DO_GMM_FREE_PAGES:
1052 if (u64Arg)
1053 return VERR_INVALID_PARAMETER;
1054 return GMMR0FreePagesReq(pVM, idCpu, (PGMMFREEPAGESREQ)pReqHdr);
1055
1056 case VMMR0_DO_GMM_FREE_LARGE_PAGE:
1057 if (u64Arg)
1058 return VERR_INVALID_PARAMETER;
1059 return GMMR0FreeLargePageReq(pVM, idCpu, (PGMMFREELARGEPAGEREQ)pReqHdr);
1060
1061 case VMMR0_DO_GMM_QUERY_HYPERVISOR_MEM_STATS:
1062 if (u64Arg)
1063 return VERR_INVALID_PARAMETER;
1064 return GMMR0QueryHypervisorMemoryStatsReq(pVM, (PGMMMEMSTATSREQ)pReqHdr);
1065
1066 case VMMR0_DO_GMM_QUERY_MEM_STATS:
1067 if (idCpu == NIL_VMCPUID)
1068 return VERR_INVALID_CPU_ID;
1069 if (u64Arg)
1070 return VERR_INVALID_PARAMETER;
1071 return GMMR0QueryMemoryStatsReq(pVM, idCpu, (PGMMMEMSTATSREQ)pReqHdr);
1072
1073 case VMMR0_DO_GMM_BALLOONED_PAGES:
1074 if (u64Arg)
1075 return VERR_INVALID_PARAMETER;
1076 return GMMR0BalloonedPagesReq(pVM, idCpu, (PGMMBALLOONEDPAGESREQ)pReqHdr);
1077
1078 case VMMR0_DO_GMM_MAP_UNMAP_CHUNK:
1079 if (u64Arg)
1080 return VERR_INVALID_PARAMETER;
1081 return GMMR0MapUnmapChunkReq(pVM, (PGMMMAPUNMAPCHUNKREQ)pReqHdr);
1082
1083 case VMMR0_DO_GMM_SEED_CHUNK:
1084 if (pReqHdr)
1085 return VERR_INVALID_PARAMETER;
1086 return GMMR0SeedChunk(pVM, idCpu, (RTR3PTR)u64Arg);
1087
1088 case VMMR0_DO_GMM_REGISTER_SHARED_MODULE:
1089 if (idCpu == NIL_VMCPUID)
1090 return VERR_INVALID_CPU_ID;
1091 if (u64Arg)
1092 return VERR_INVALID_PARAMETER;
1093 return GMMR0RegisterSharedModuleReq(pVM, idCpu, (PGMMREGISTERSHAREDMODULEREQ)pReqHdr);
1094
1095 case VMMR0_DO_GMM_UNREGISTER_SHARED_MODULE:
1096 if (idCpu == NIL_VMCPUID)
1097 return VERR_INVALID_CPU_ID;
1098 if (u64Arg)
1099 return VERR_INVALID_PARAMETER;
1100 return GMMR0UnregisterSharedModuleReq(pVM, idCpu, (PGMMUNREGISTERSHAREDMODULEREQ)pReqHdr);
1101
1102 case VMMR0_DO_GMM_RESET_SHARED_MODULES:
1103 if (idCpu == NIL_VMCPUID)
1104 return VERR_INVALID_CPU_ID;
1105 if ( u64Arg
1106 || pReqHdr)
1107 return VERR_INVALID_PARAMETER;
1108 return GMMR0ResetSharedModules(pVM, idCpu);
1109
1110#ifdef VBOX_WITH_PAGE_SHARING
1111 case VMMR0_DO_GMM_CHECK_SHARED_MODULES:
1112 {
1113 if (idCpu == NIL_VMCPUID)
1114 return VERR_INVALID_CPU_ID;
1115 if ( u64Arg
1116 || pReqHdr)
1117 return VERR_INVALID_PARAMETER;
1118
1119 PVMCPU pVCpu = &pVM->aCpus[idCpu];
1120 Assert(pVCpu->hNativeThreadR0 == RTThreadNativeSelf());
1121
1122# ifdef DEBUG_sandervl
1123 /* 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). */
1124 /* Todo: this can have bad side effects for unexpected jumps back to r3. */
1125 int rc = GMMR0CheckSharedModulesStart(pVM);
1126 if (rc == VINF_SUCCESS)
1127 {
1128 rc = vmmR0CallRing3SetJmp(&pVCpu->vmm.s.CallRing3JmpBufR0, GMMR0CheckSharedModules, pVM, pVCpu); /* this may resume code. */
1129 Assert( rc == VINF_SUCCESS
1130 || (rc == VINF_VMM_CALL_HOST && pVCpu->vmm.s.enmCallRing3Operation == VMMCALLRING3_VMM_LOGGER_FLUSH));
1131 GMMR0CheckSharedModulesEnd(pVM);
1132 }
1133# else
1134 int rc = GMMR0CheckSharedModules(pVM, pVCpu);
1135# endif
1136 return rc;
1137 }
1138#endif
1139
1140#if defined(VBOX_STRICT) && HC_ARCH_BITS == 64
1141 case VMMR0_DO_GMM_FIND_DUPLICATE_PAGE:
1142 if (u64Arg)
1143 return VERR_INVALID_PARAMETER;
1144 return GMMR0FindDuplicatePageReq(pVM, (PGMMFINDDUPLICATEPAGEREQ)pReqHdr);
1145#endif
1146
1147 case VMMR0_DO_GMM_QUERY_STATISTICS:
1148 if (u64Arg)
1149 return VERR_INVALID_PARAMETER;
1150 return GMMR0QueryStatisticsReq(pVM, (PGMMQUERYSTATISTICSSREQ)pReqHdr);
1151
1152 case VMMR0_DO_GMM_RESET_STATISTICS:
1153 if (u64Arg)
1154 return VERR_INVALID_PARAMETER;
1155 return GMMR0ResetStatisticsReq(pVM, (PGMMRESETSTATISTICSSREQ)pReqHdr);
1156
1157 /*
1158 * A quick GCFGM mock-up.
1159 */
1160 /** @todo GCFGM with proper access control, ring-3 management interface and all that. */
1161 case VMMR0_DO_GCFGM_SET_VALUE:
1162 case VMMR0_DO_GCFGM_QUERY_VALUE:
1163 {
1164 if (pVM || !pReqHdr || u64Arg || idCpu != NIL_VMCPUID)
1165 return VERR_INVALID_PARAMETER;
1166 PGCFGMVALUEREQ pReq = (PGCFGMVALUEREQ)pReqHdr;
1167 if (pReq->Hdr.cbReq != sizeof(*pReq))
1168 return VERR_INVALID_PARAMETER;
1169 int rc;
1170 if (enmOperation == VMMR0_DO_GCFGM_SET_VALUE)
1171 {
1172 rc = GVMMR0SetConfig(pReq->pSession, &pReq->szName[0], pReq->u64Value);
1173 //if (rc == VERR_CFGM_VALUE_NOT_FOUND)
1174 // rc = GMMR0SetConfig(pReq->pSession, &pReq->szName[0], pReq->u64Value);
1175 }
1176 else
1177 {
1178 rc = GVMMR0QueryConfig(pReq->pSession, &pReq->szName[0], &pReq->u64Value);
1179 //if (rc == VERR_CFGM_VALUE_NOT_FOUND)
1180 // rc = GMMR0QueryConfig(pReq->pSession, &pReq->szName[0], &pReq->u64Value);
1181 }
1182 return rc;
1183 }
1184
1185 /*
1186 * PDM Wrappers.
1187 */
1188 case VMMR0_DO_PDM_DRIVER_CALL_REQ_HANDLER:
1189 {
1190 if (!pVM || !pReqHdr || u64Arg || idCpu != NIL_VMCPUID)
1191 return VERR_INVALID_PARAMETER;
1192 return PDMR0DriverCallReqHandler(pVM, (PPDMDRIVERCALLREQHANDLERREQ)pReqHdr);
1193 }
1194
1195 case VMMR0_DO_PDM_DEVICE_CALL_REQ_HANDLER:
1196 {
1197 if (!pVM || !pReqHdr || u64Arg || idCpu != NIL_VMCPUID)
1198 return VERR_INVALID_PARAMETER;
1199 return PDMR0DeviceCallReqHandler(pVM, (PPDMDEVICECALLREQHANDLERREQ)pReqHdr);
1200 }
1201
1202 /*
1203 * Requests to the internal networking service.
1204 */
1205 case VMMR0_DO_INTNET_OPEN:
1206 {
1207 PINTNETOPENREQ pReq = (PINTNETOPENREQ)pReqHdr;
1208 if (u64Arg || !pReq || !vmmR0IsValidSession(pVM, pReq->pSession, pSession) || idCpu != NIL_VMCPUID)
1209 return VERR_INVALID_PARAMETER;
1210 return IntNetR0OpenReq(pSession, pReq);
1211 }
1212
1213 case VMMR0_DO_INTNET_IF_CLOSE:
1214 if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFCLOSEREQ)pReqHdr)->pSession, pSession) || idCpu != NIL_VMCPUID)
1215 return VERR_INVALID_PARAMETER;
1216 return IntNetR0IfCloseReq(pSession, (PINTNETIFCLOSEREQ)pReqHdr);
1217
1218 case VMMR0_DO_INTNET_IF_GET_BUFFER_PTRS:
1219 if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFGETBUFFERPTRSREQ)pReqHdr)->pSession, pSession) || idCpu != NIL_VMCPUID)
1220 return VERR_INVALID_PARAMETER;
1221 return IntNetR0IfGetBufferPtrsReq(pSession, (PINTNETIFGETBUFFERPTRSREQ)pReqHdr);
1222
1223 case VMMR0_DO_INTNET_IF_SET_PROMISCUOUS_MODE:
1224 if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFSETPROMISCUOUSMODEREQ)pReqHdr)->pSession, pSession) || idCpu != NIL_VMCPUID)
1225 return VERR_INVALID_PARAMETER;
1226 return IntNetR0IfSetPromiscuousModeReq(pSession, (PINTNETIFSETPROMISCUOUSMODEREQ)pReqHdr);
1227
1228 case VMMR0_DO_INTNET_IF_SET_MAC_ADDRESS:
1229 if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFSETMACADDRESSREQ)pReqHdr)->pSession, pSession) || idCpu != NIL_VMCPUID)
1230 return VERR_INVALID_PARAMETER;
1231 return IntNetR0IfSetMacAddressReq(pSession, (PINTNETIFSETMACADDRESSREQ)pReqHdr);
1232
1233 case VMMR0_DO_INTNET_IF_SET_ACTIVE:
1234 if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFSETACTIVEREQ)pReqHdr)->pSession, pSession) || idCpu != NIL_VMCPUID)
1235 return VERR_INVALID_PARAMETER;
1236 return IntNetR0IfSetActiveReq(pSession, (PINTNETIFSETACTIVEREQ)pReqHdr);
1237
1238 case VMMR0_DO_INTNET_IF_SEND:
1239 if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFSENDREQ)pReqHdr)->pSession, pSession) || idCpu != NIL_VMCPUID)
1240 return VERR_INVALID_PARAMETER;
1241 return IntNetR0IfSendReq(pSession, (PINTNETIFSENDREQ)pReqHdr);
1242
1243 case VMMR0_DO_INTNET_IF_WAIT:
1244 if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFWAITREQ)pReqHdr)->pSession, pSession) || idCpu != NIL_VMCPUID)
1245 return VERR_INVALID_PARAMETER;
1246 return IntNetR0IfWaitReq(pSession, (PINTNETIFWAITREQ)pReqHdr);
1247
1248 case VMMR0_DO_INTNET_IF_ABORT_WAIT:
1249 if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFWAITREQ)pReqHdr)->pSession, pSession) || idCpu != NIL_VMCPUID)
1250 return VERR_INVALID_PARAMETER;
1251 return IntNetR0IfAbortWaitReq(pSession, (PINTNETIFABORTWAITREQ)pReqHdr);
1252
1253#ifdef VBOX_WITH_PCI_PASSTHROUGH
1254 /*
1255 * Requests to host PCI driver service.
1256 */
1257 case VMMR0_DO_PCIRAW_REQ:
1258 if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PPCIRAWSENDREQ)pReqHdr)->pSession, pSession) || idCpu != NIL_VMCPUID)
1259 return VERR_INVALID_PARAMETER;
1260 return PciRawR0ProcessReq(pSession, pVM, (PPCIRAWSENDREQ)pReqHdr);
1261#endif
1262 /*
1263 * For profiling.
1264 */
1265 case VMMR0_DO_NOP:
1266 case VMMR0_DO_SLOW_NOP:
1267 return VINF_SUCCESS;
1268
1269 /*
1270 * For testing Ring-0 APIs invoked in this environment.
1271 */
1272 case VMMR0_DO_TESTS:
1273 /** @todo make new test */
1274 return VINF_SUCCESS;
1275
1276
1277#if HC_ARCH_BITS == 32 && defined(VBOX_WITH_64_BITS_GUESTS) && !defined(VBOX_WITH_HYBRID_32BIT_KERNEL)
1278 case VMMR0_DO_TEST_SWITCHER3264:
1279 if (idCpu == NIL_VMCPUID)
1280 return VERR_INVALID_CPU_ID;
1281 return HMR0TestSwitcher3264(pVM);
1282#endif
1283 default:
1284 /*
1285 * We're returning VERR_NOT_SUPPORT here so we've got something else
1286 * than -1 which the interrupt gate glue code might return.
1287 */
1288 Log(("operation %#x is not supported\n", enmOperation));
1289 return VERR_NOT_SUPPORTED;
1290 }
1291}
1292
1293
1294/**
1295 * Argument for vmmR0EntryExWrapper containing the arguments for VMMR0EntryEx.
1296 */
1297typedef struct VMMR0ENTRYEXARGS
1298{
1299 PVM pVM;
1300 VMCPUID idCpu;
1301 VMMR0OPERATION enmOperation;
1302 PSUPVMMR0REQHDR pReq;
1303 uint64_t u64Arg;
1304 PSUPDRVSESSION pSession;
1305} VMMR0ENTRYEXARGS;
1306/** Pointer to a vmmR0EntryExWrapper argument package. */
1307typedef VMMR0ENTRYEXARGS *PVMMR0ENTRYEXARGS;
1308
1309/**
1310 * This is just a longjmp wrapper function for VMMR0EntryEx calls.
1311 *
1312 * @returns VBox status code.
1313 * @param pvArgs The argument package
1314 */
1315static DECLCALLBACK(int) vmmR0EntryExWrapper(void *pvArgs)
1316{
1317 return vmmR0EntryExWorker(((PVMMR0ENTRYEXARGS)pvArgs)->pVM,
1318 ((PVMMR0ENTRYEXARGS)pvArgs)->idCpu,
1319 ((PVMMR0ENTRYEXARGS)pvArgs)->enmOperation,
1320 ((PVMMR0ENTRYEXARGS)pvArgs)->pReq,
1321 ((PVMMR0ENTRYEXARGS)pvArgs)->u64Arg,
1322 ((PVMMR0ENTRYEXARGS)pvArgs)->pSession);
1323}
1324
1325
1326/**
1327 * The Ring 0 entry point, called by the support library (SUP).
1328 *
1329 * @returns VBox status code.
1330 * @param pVM Pointer to the VM.
1331 * @param idCpu Virtual CPU ID argument. Must be NIL_VMCPUID if pVM
1332 * is NIL_RTR0PTR, and may be NIL_VMCPUID if it isn't
1333 * @param enmOperation Which operation to execute.
1334 * @param pReq Pointer to the SUPVMMR0REQHDR packet. Optional.
1335 * @param u64Arg Some simple constant argument.
1336 * @param pSession The session of the caller.
1337 * @remarks Assume called with interrupts _enabled_.
1338 */
1339VMMR0DECL(int) VMMR0EntryEx(PVM pVM, VMCPUID idCpu, VMMR0OPERATION enmOperation, PSUPVMMR0REQHDR pReq, uint64_t u64Arg, PSUPDRVSESSION pSession)
1340{
1341 /*
1342 * Requests that should only happen on the EMT thread will be
1343 * wrapped in a setjmp so we can assert without causing trouble.
1344 */
1345 if ( VALID_PTR(pVM)
1346 && pVM->pVMR0
1347 && idCpu < pVM->cCpus)
1348 {
1349 switch (enmOperation)
1350 {
1351 /* These might/will be called before VMMR3Init. */
1352 case VMMR0_DO_GMM_INITIAL_RESERVATION:
1353 case VMMR0_DO_GMM_UPDATE_RESERVATION:
1354 case VMMR0_DO_GMM_ALLOCATE_PAGES:
1355 case VMMR0_DO_GMM_FREE_PAGES:
1356 case VMMR0_DO_GMM_BALLOONED_PAGES:
1357 /* On the mac we might not have a valid jmp buf, so check these as well. */
1358 case VMMR0_DO_VMMR0_INIT:
1359 case VMMR0_DO_VMMR0_TERM:
1360 {
1361 PVMCPU pVCpu = &pVM->aCpus[idCpu];
1362
1363 if (!pVCpu->vmm.s.CallRing3JmpBufR0.pvSavedStack)
1364 break;
1365
1366 /** @todo validate this EMT claim... GVM knows. */
1367 VMMR0ENTRYEXARGS Args;
1368 Args.pVM = pVM;
1369 Args.idCpu = idCpu;
1370 Args.enmOperation = enmOperation;
1371 Args.pReq = pReq;
1372 Args.u64Arg = u64Arg;
1373 Args.pSession = pSession;
1374 return vmmR0CallRing3SetJmpEx(&pVCpu->vmm.s.CallRing3JmpBufR0, vmmR0EntryExWrapper, &Args);
1375 }
1376
1377 default:
1378 break;
1379 }
1380 }
1381 return vmmR0EntryExWorker(pVM, idCpu, enmOperation, pReq, u64Arg, pSession);
1382}
1383
1384
1385/**
1386 * Checks whether we've armed the ring-0 long jump machinery.
1387 *
1388 * @returns @c true / @c false
1389 * @param pVCpu The caller's cross context virtual CPU structure.
1390 * @thread EMT
1391 * @sa VMMIsLongJumpArmed
1392 */
1393VMMR0_INT_DECL(bool) VMMR0IsLongJumpArmed(PVMCPU pVCpu)
1394{
1395#ifdef RT_ARCH_X86
1396 return pVCpu->vmm.s.CallRing3JmpBufR0.eip
1397 && !pVCpu->vmm.s.CallRing3JmpBufR0.fInRing3Call;
1398#else
1399 return pVCpu->vmm.s.CallRing3JmpBufR0.rip
1400 && !pVCpu->vmm.s.CallRing3JmpBufR0.fInRing3Call;
1401#endif
1402}
1403
1404
1405/**
1406 * Internal R0 logger worker: Flush logger.
1407 *
1408 * @param pLogger The logger instance to flush.
1409 * @remark This function must be exported!
1410 */
1411VMMR0DECL(void) vmmR0LoggerFlush(PRTLOGGER pLogger)
1412{
1413#ifdef LOG_ENABLED
1414 /*
1415 * Convert the pLogger into a VM handle and 'call' back to Ring-3.
1416 * (This is a bit paranoid code.)
1417 */
1418 PVMMR0LOGGER pR0Logger = (PVMMR0LOGGER)((uintptr_t)pLogger - RT_OFFSETOF(VMMR0LOGGER, Logger));
1419 if ( !VALID_PTR(pR0Logger)
1420 || !VALID_PTR(pR0Logger + 1)
1421 || pLogger->u32Magic != RTLOGGER_MAGIC)
1422 {
1423# ifdef DEBUG
1424 SUPR0Printf("vmmR0LoggerFlush: pLogger=%p!\n", pLogger);
1425# endif
1426 return;
1427 }
1428 if (pR0Logger->fFlushingDisabled)
1429 return; /* quietly */
1430
1431 PVM pVM = pR0Logger->pVM;
1432 if ( !VALID_PTR(pVM)
1433 || pVM->pVMR0 != pVM)
1434 {
1435# ifdef DEBUG
1436 SUPR0Printf("vmmR0LoggerFlush: pVM=%p! pVMR0=%p! pLogger=%p\n", pVM, pVM->pVMR0, pLogger);
1437# endif
1438 return;
1439 }
1440
1441 PVMCPU pVCpu = VMMGetCpu(pVM);
1442 if (pVCpu)
1443 {
1444 /*
1445 * Check that the jump buffer is armed.
1446 */
1447# ifdef RT_ARCH_X86
1448 if ( !pVCpu->vmm.s.CallRing3JmpBufR0.eip
1449 || pVCpu->vmm.s.CallRing3JmpBufR0.fInRing3Call)
1450# else
1451 if ( !pVCpu->vmm.s.CallRing3JmpBufR0.rip
1452 || pVCpu->vmm.s.CallRing3JmpBufR0.fInRing3Call)
1453# endif
1454 {
1455# ifdef DEBUG
1456 SUPR0Printf("vmmR0LoggerFlush: Jump buffer isn't armed!\n");
1457# endif
1458 return;
1459 }
1460 VMMRZCallRing3(pVM, pVCpu, VMMCALLRING3_VMM_LOGGER_FLUSH, 0);
1461 }
1462# ifdef DEBUG
1463 else
1464 SUPR0Printf("vmmR0LoggerFlush: invalid VCPU context!\n");
1465# endif
1466#endif
1467}
1468
1469/**
1470 * Internal R0 logger worker: Custom prefix.
1471 *
1472 * @returns Number of chars written.
1473 *
1474 * @param pLogger The logger instance.
1475 * @param pchBuf The output buffer.
1476 * @param cchBuf The size of the buffer.
1477 * @param pvUser User argument (ignored).
1478 */
1479VMMR0DECL(size_t) vmmR0LoggerPrefix(PRTLOGGER pLogger, char *pchBuf, size_t cchBuf, void *pvUser)
1480{
1481 NOREF(pvUser);
1482#ifdef LOG_ENABLED
1483 PVMMR0LOGGER pR0Logger = (PVMMR0LOGGER)((uintptr_t)pLogger - RT_OFFSETOF(VMMR0LOGGER, Logger));
1484 if ( !VALID_PTR(pR0Logger)
1485 || !VALID_PTR(pR0Logger + 1)
1486 || pLogger->u32Magic != RTLOGGER_MAGIC
1487 || cchBuf < 2)
1488 return 0;
1489
1490 static const char s_szHex[17] = "0123456789abcdef";
1491 VMCPUID const idCpu = pR0Logger->idCpu;
1492 pchBuf[1] = s_szHex[ idCpu & 15];
1493 pchBuf[0] = s_szHex[(idCpu >> 4) & 15];
1494
1495 return 2;
1496#else
1497 return 0;
1498#endif
1499}
1500
1501#ifdef LOG_ENABLED
1502
1503/**
1504 * Disables flushing of the ring-0 debug log.
1505 *
1506 * @param pVCpu Pointer to the VMCPU.
1507 */
1508VMMR0DECL(void) VMMR0LogFlushDisable(PVMCPU pVCpu)
1509{
1510 if (pVCpu->vmm.s.pR0LoggerR0)
1511 pVCpu->vmm.s.pR0LoggerR0->fFlushingDisabled = true;
1512}
1513
1514
1515/**
1516 * Enables flushing of the ring-0 debug log.
1517 *
1518 * @param pVCpu Pointer to the VMCPU.
1519 */
1520VMMR0DECL(void) VMMR0LogFlushEnable(PVMCPU pVCpu)
1521{
1522 if (pVCpu->vmm.s.pR0LoggerR0)
1523 pVCpu->vmm.s.pR0LoggerR0->fFlushingDisabled = false;
1524}
1525
1526
1527/**
1528 * Checks if log flushing is disabled or not.
1529 *
1530 * @param pVCpu Pointer to the VMCPU.
1531 */
1532VMMR0DECL(bool) VMMR0IsLogFlushDisabled(PVMCPU pVCpu)
1533{
1534 if (pVCpu->vmm.s.pR0LoggerR0)
1535 return pVCpu->vmm.s.pR0LoggerR0->fFlushingDisabled;
1536 return true;
1537}
1538#endif /* LOG_ENABLED */
1539
1540/**
1541 * Jump back to ring-3 if we're the EMT and the longjmp is armed.
1542 *
1543 * @returns true if the breakpoint should be hit, false if it should be ignored.
1544 */
1545DECLEXPORT(bool) RTCALL RTAssertShouldPanic(void)
1546{
1547#if 0
1548 return true;
1549#else
1550 PVM pVM = GVMMR0GetVMByEMT(NIL_RTNATIVETHREAD);
1551 if (pVM)
1552 {
1553 PVMCPU pVCpu = VMMGetCpu(pVM);
1554
1555 if (pVCpu)
1556 {
1557#ifdef RT_ARCH_X86
1558 if ( pVCpu->vmm.s.CallRing3JmpBufR0.eip
1559 && !pVCpu->vmm.s.CallRing3JmpBufR0.fInRing3Call)
1560#else
1561 if ( pVCpu->vmm.s.CallRing3JmpBufR0.rip
1562 && !pVCpu->vmm.s.CallRing3JmpBufR0.fInRing3Call)
1563#endif
1564 {
1565 int rc = VMMRZCallRing3(pVM, pVCpu, VMMCALLRING3_VM_R0_ASSERTION, 0);
1566 return RT_FAILURE_NP(rc);
1567 }
1568 }
1569 }
1570#ifdef RT_OS_LINUX
1571 return true;
1572#else
1573 return false;
1574#endif
1575#endif
1576}
1577
1578
1579/**
1580 * Override this so we can push it up to ring-3.
1581 *
1582 * @param pszExpr Expression. Can be NULL.
1583 * @param uLine Location line number.
1584 * @param pszFile Location file name.
1585 * @param pszFunction Location function name.
1586 */
1587DECLEXPORT(void) RTCALL RTAssertMsg1Weak(const char *pszExpr, unsigned uLine, const char *pszFile, const char *pszFunction)
1588{
1589 /*
1590 * To the log.
1591 */
1592 LogAlways(("\n!!R0-Assertion Failed!!\n"
1593 "Expression: %s\n"
1594 "Location : %s(%d) %s\n",
1595 pszExpr, pszFile, uLine, pszFunction));
1596
1597 /*
1598 * To the global VMM buffer.
1599 */
1600 PVM pVM = GVMMR0GetVMByEMT(NIL_RTNATIVETHREAD);
1601 if (pVM)
1602 RTStrPrintf(pVM->vmm.s.szRing0AssertMsg1, sizeof(pVM->vmm.s.szRing0AssertMsg1),
1603 "\n!!R0-Assertion Failed!!\n"
1604 "Expression: %s\n"
1605 "Location : %s(%d) %s\n",
1606 pszExpr, pszFile, uLine, pszFunction);
1607
1608 /*
1609 * Continue the normal way.
1610 */
1611 RTAssertMsg1(pszExpr, uLine, pszFile, pszFunction);
1612}
1613
1614
1615/**
1616 * Callback for RTLogFormatV which writes to the ring-3 log port.
1617 * See PFNLOGOUTPUT() for details.
1618 */
1619static DECLCALLBACK(size_t) rtLogOutput(void *pv, const char *pachChars, size_t cbChars)
1620{
1621 for (size_t i = 0; i < cbChars; i++)
1622 LogAlways(("%c", pachChars[i]));
1623
1624 NOREF(pv);
1625 return cbChars;
1626}
1627
1628
1629/**
1630 * Override this so we can push it up to ring-3.
1631 *
1632 * @param pszFormat The format string.
1633 * @param va Arguments.
1634 */
1635DECLEXPORT(void) RTCALL RTAssertMsg2WeakV(const char *pszFormat, va_list va)
1636{
1637 va_list vaCopy;
1638
1639 /*
1640 * Push the message to the loggers.
1641 */
1642 PRTLOGGER pLog = RTLogGetDefaultInstance(); /* Don't initialize it here... */
1643 if (pLog)
1644 {
1645 va_copy(vaCopy, va);
1646 RTLogFormatV(rtLogOutput, pLog, pszFormat, vaCopy);
1647 va_end(vaCopy);
1648 }
1649 pLog = RTLogRelDefaultInstance();
1650 if (pLog)
1651 {
1652 va_copy(vaCopy, va);
1653 RTLogFormatV(rtLogOutput, pLog, pszFormat, vaCopy);
1654 va_end(vaCopy);
1655 }
1656
1657 /*
1658 * Push it to the global VMM buffer.
1659 */
1660 PVM pVM = GVMMR0GetVMByEMT(NIL_RTNATIVETHREAD);
1661 if (pVM)
1662 {
1663 va_copy(vaCopy, va);
1664 RTStrPrintfV(pVM->vmm.s.szRing0AssertMsg2, sizeof(pVM->vmm.s.szRing0AssertMsg2), pszFormat, vaCopy);
1665 va_end(vaCopy);
1666 }
1667
1668 /*
1669 * Continue the normal way.
1670 */
1671 RTAssertMsg2V(pszFormat, va);
1672}
1673
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