VirtualBox

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

Last change on this file since 14719 was 14719, checked in by vboxsync, 16 years ago

VMMR0: Fixed mac breakage.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 39.2 KB
Line 
1/* $Id: VMMR0.cpp 14719 2008-11-27 16:29:24Z vboxsync $ */
2/** @file
3 * VMM - Host Context Ring 0.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22/*******************************************************************************
23* Header Files *
24*******************************************************************************/
25#define LOG_GROUP LOG_GROUP_VMM
26#include <VBox/vmm.h>
27#include <VBox/sup.h>
28#include <VBox/trpm.h>
29#include <VBox/cpum.h>
30#include <VBox/pgm.h>
31#include <VBox/stam.h>
32#include <VBox/tm.h>
33#include "VMMInternal.h"
34#include <VBox/vm.h>
35#include <VBox/gvmm.h>
36#include <VBox/gmm.h>
37#include <VBox/intnet.h>
38#include <VBox/hwaccm.h>
39#include <VBox/param.h>
40
41#include <VBox/err.h>
42#include <VBox/version.h>
43#include <VBox/log.h>
44#include <iprt/assert.h>
45#include <iprt/stdarg.h>
46#include <iprt/mp.h>
47#include <iprt/string.h>
48
49#if defined(_MSC_VER) && defined(RT_ARCH_AMD64) /** @todo check this with with VC7! */
50# pragma intrinsic(_AddressOfReturnAddress)
51#endif
52
53
54/*******************************************************************************
55* Internal Functions *
56*******************************************************************************/
57__BEGIN_DECLS
58VMMR0DECL(int) ModuleInit(void);
59VMMR0DECL(void) ModuleTerm(void);
60__END_DECLS
61
62
63/*******************************************************************************
64* Global Variables *
65*******************************************************************************/
66/** Pointer to the internal networking service instance. */
67PINTNET g_pIntNet = 0;
68
69
70/**
71 * Initialize the module.
72 * This is called when we're first loaded.
73 *
74 * @returns 0 on success.
75 * @returns VBox status on failure.
76 */
77VMMR0DECL(int) ModuleInit(void)
78{
79 LogFlow(("ModuleInit:\n"));
80
81 /*
82 * Initialize the GVMM, GMM, HWACCM, PGM (Darwin) and INTNET.
83 */
84 int rc = GVMMR0Init();
85 if (RT_SUCCESS(rc))
86 {
87 rc = GMMR0Init();
88 if (RT_SUCCESS(rc))
89 {
90 rc = HWACCMR0Init();
91 if (RT_SUCCESS(rc))
92 {
93#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
94 rc = PGMR0DynMapInit();
95#endif
96 if (RT_SUCCESS(rc))
97 {
98 LogFlow(("ModuleInit: g_pIntNet=%p\n", g_pIntNet));
99 g_pIntNet = NULL;
100 LogFlow(("ModuleInit: g_pIntNet=%p should be NULL now...\n", g_pIntNet));
101 rc = INTNETR0Create(&g_pIntNet);
102 if (RT_SUCCESS(rc))
103 {
104 LogFlow(("ModuleInit: returns success. g_pIntNet=%p\n", g_pIntNet));
105 return VINF_SUCCESS;
106 }
107
108 /* bail out */
109 g_pIntNet = NULL;
110 LogFlow(("ModuleTerm: returns %Rrc\n", rc));
111#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
112 PGMR0DynMapTerm();
113#endif
114 }
115 HWACCMR0Term();
116 }
117 GMMR0Term();
118 }
119 GVMMR0Term();
120 }
121
122 LogFlow(("ModuleInit: failed %Rrc\n", rc));
123 return rc;
124}
125
126
127/**
128 * Terminate the module.
129 * This is called when we're finally unloaded.
130 */
131VMMR0DECL(void) ModuleTerm(void)
132{
133 LogFlow(("ModuleTerm:\n"));
134
135 /*
136 * Destroy the internal networking instance.
137 */
138 if (g_pIntNet)
139 {
140 INTNETR0Destroy(g_pIntNet);
141 g_pIntNet = NULL;
142 }
143
144 /*
145 * PGM (Darwin) and HWACCM global cleanup.
146 * Destroy the GMM and GVMM instances.
147 */
148#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
149 PGMR0DynMapTerm();
150#endif
151 HWACCMR0Term();
152
153 GMMR0Term();
154 GVMMR0Term();
155
156 LogFlow(("ModuleTerm: returns\n"));
157}
158
159
160/**
161 * Initaties the R0 driver for a particular VM instance.
162 *
163 * @returns VBox status code.
164 *
165 * @param pVM The VM instance in question.
166 * @param uSvnRev The SVN revision of the ring-3 part.
167 * @thread EMT.
168 */
169static int vmmR0InitVM(PVM pVM, uint32_t uSvnRev)
170{
171 /*
172 * Match the SVN revisions.
173 */
174 if (uSvnRev != VMMGetSvnRev())
175 return VERR_VERSION_MISMATCH;
176 if ( !VALID_PTR(pVM)
177 || pVM->pVMR0 != pVM)
178 return VERR_INVALID_PARAMETER;
179
180 /*
181 * Register the EMT R0 logger instance.
182 */
183 PVMMR0LOGGER pR0Logger = pVM->vmm.s.pR0LoggerR0;
184 if (pR0Logger)
185 {
186#if 0 /* testing of the logger. */
187 LogCom(("vmmR0InitVM: before %p\n", RTLogDefaultInstance()));
188 LogCom(("vmmR0InitVM: pfnFlush=%p actual=%p\n", pR0Logger->Logger.pfnFlush, vmmR0LoggerFlush));
189 LogCom(("vmmR0InitVM: pfnLogger=%p actual=%p\n", pR0Logger->Logger.pfnLogger, vmmR0LoggerWrapper));
190 LogCom(("vmmR0InitVM: offScratch=%d fFlags=%#x fDestFlags=%#x\n", pR0Logger->Logger.offScratch, pR0Logger->Logger.fFlags, pR0Logger->Logger.fDestFlags));
191
192 RTLogSetDefaultInstanceThread(&pR0Logger->Logger, (uintptr_t)pVM->pSession);
193 LogCom(("vmmR0InitVM: after %p reg\n", RTLogDefaultInstance()));
194 RTLogSetDefaultInstanceThread(NULL, 0);
195 LogCom(("vmmR0InitVM: after %p dereg\n", RTLogDefaultInstance()));
196
197 pR0Logger->Logger.pfnLogger("hello ring-0 logger\n");
198 LogCom(("vmmR0InitVM: returned succesfully from direct logger call.\n"));
199 pR0Logger->Logger.pfnFlush(&pR0Logger->Logger);
200 LogCom(("vmmR0InitVM: returned succesfully from direct flush call.\n"));
201
202 RTLogSetDefaultInstanceThread(&pR0Logger->Logger, (uintptr_t)pVM->pSession);
203 LogCom(("vmmR0InitVM: after %p reg2\n", RTLogDefaultInstance()));
204 pR0Logger->Logger.pfnLogger("hello ring-0 logger\n");
205 LogCom(("vmmR0InitVM: returned succesfully from direct logger call (2). offScratch=%d\n", pR0Logger->Logger.offScratch));
206 RTLogSetDefaultInstanceThread(NULL, 0);
207 LogCom(("vmmR0InitVM: after %p dereg2\n", RTLogDefaultInstance()));
208
209 RTLogLoggerEx(&pR0Logger->Logger, 0, ~0U, "hello ring-0 logger (RTLogLoggerEx)\n");
210 LogCom(("vmmR0InitVM: RTLogLoggerEx returned fine offScratch=%d\n", pR0Logger->Logger.offScratch));
211
212 RTLogSetDefaultInstanceThread(&pR0Logger->Logger, (uintptr_t)pVM->pSession);
213 RTLogPrintf("hello ring-0 logger (RTLogPrintf)\n");
214 LogCom(("vmmR0InitVM: RTLogPrintf returned fine offScratch=%d\n", pR0Logger->Logger.offScratch));
215#endif
216 Log(("Switching to per-thread logging instance %p (key=%p)\n", &pR0Logger->Logger, pVM->pSession));
217 RTLogSetDefaultInstanceThread(&pR0Logger->Logger, (uintptr_t)pVM->pSession);
218 }
219
220 /*
221 * Initialize the per VM data for GVMM and GMM.
222 */
223 int rc = GVMMR0InitVM(pVM);
224// if (RT_SUCCESS(rc))
225// rc = GMMR0InitPerVMData(pVM);
226 if (RT_SUCCESS(rc))
227 {
228 /*
229 * Init HWACCM, CPUM and PGM (Darwin only).
230 */
231 rc = HWACCMR0InitVM(pVM);
232 if (RT_SUCCESS(rc))
233 {
234 rc = CPUMR0Init(pVM); /** @todo rename to CPUMR0InitVM */
235 if (RT_SUCCESS(rc))
236 {
237#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
238 rc = PGMR0DynMapInitVM(pVM);
239#endif
240 if (RT_SUCCESS(rc))
241 return rc;
242
243 /* bail out */
244 }
245 HWACCMR0TermVM(pVM);
246 }
247 }
248 RTLogSetDefaultInstanceThread(NULL, 0);
249 return rc;
250}
251
252
253/**
254 * Terminates the R0 driver for a particular VM instance.
255 *
256 * @returns VBox status code.
257 *
258 * @param pVM The VM instance in question.
259 * @thread EMT.
260 */
261static int vmmR0TermVM(PVM pVM)
262{
263/** @todo @bugref{1865,3202}: Make these tail onto the VM object destruction
264 * to make sure they are *always* executed and don't leave mess behind
265 * when the process is killed. */
266#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
267 PGMR0DynMapTermVM(pVM);
268#endif
269 HWACCMR0TermVM(pVM);
270
271 /*
272 * Deregister the logger.
273 */
274 RTLogSetDefaultInstanceThread(NULL, 0);
275 return VINF_SUCCESS;
276}
277
278
279/**
280 * Calls the ring-3 host code.
281 *
282 * @returns VBox status code of the ring-3 call.
283 * @param pVM The VM handle.
284 * @param enmOperation The operation.
285 * @param uArg The argument to the operation.
286 */
287VMMR0DECL(int) VMMR0CallHost(PVM pVM, VMMCALLHOST enmOperation, uint64_t uArg)
288{
289/** @todo profile this! */
290 pVM->vmm.s.enmCallHostOperation = enmOperation;
291 pVM->vmm.s.u64CallHostArg = uArg;
292 pVM->vmm.s.rcCallHost = VERR_INTERNAL_ERROR;
293 int rc = vmmR0CallHostLongJmp(&pVM->vmm.s.CallHostR0JmpBuf, VINF_VMM_CALL_HOST);
294 if (rc == VINF_SUCCESS)
295 rc = pVM->vmm.s.rcCallHost;
296 return rc;
297}
298
299
300#ifdef VBOX_WITH_STATISTICS
301/**
302 * Record return code statistics
303 * @param pVM The VM handle.
304 * @param rc The status code.
305 */
306static void vmmR0RecordRC(PVM pVM, int rc)
307{
308 /*
309 * Collect statistics.
310 */
311 switch (rc)
312 {
313 case VINF_SUCCESS:
314 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetNormal);
315 break;
316 case VINF_EM_RAW_INTERRUPT:
317 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetInterrupt);
318 break;
319 case VINF_EM_RAW_INTERRUPT_HYPER:
320 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetInterruptHyper);
321 break;
322 case VINF_EM_RAW_GUEST_TRAP:
323 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetGuestTrap);
324 break;
325 case VINF_EM_RAW_RING_SWITCH:
326 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetRingSwitch);
327 break;
328 case VINF_EM_RAW_RING_SWITCH_INT:
329 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetRingSwitchInt);
330 break;
331 case VINF_EM_RAW_EXCEPTION_PRIVILEGED:
332 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetExceptionPrivilege);
333 break;
334 case VINF_EM_RAW_STALE_SELECTOR:
335 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetStaleSelector);
336 break;
337 case VINF_EM_RAW_IRET_TRAP:
338 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetIRETTrap);
339 break;
340 case VINF_IOM_HC_IOPORT_READ:
341 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetIORead);
342 break;
343 case VINF_IOM_HC_IOPORT_WRITE:
344 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetIOWrite);
345 break;
346 case VINF_IOM_HC_MMIO_READ:
347 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetMMIORead);
348 break;
349 case VINF_IOM_HC_MMIO_WRITE:
350 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetMMIOWrite);
351 break;
352 case VINF_IOM_HC_MMIO_READ_WRITE:
353 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetMMIOReadWrite);
354 break;
355 case VINF_PATM_HC_MMIO_PATCH_READ:
356 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetMMIOPatchRead);
357 break;
358 case VINF_PATM_HC_MMIO_PATCH_WRITE:
359 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetMMIOPatchWrite);
360 break;
361 case VINF_EM_RAW_EMULATE_INSTR:
362 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetEmulate);
363 break;
364 case VINF_PATCH_EMULATE_INSTR:
365 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPatchEmulate);
366 break;
367 case VINF_EM_RAW_EMULATE_INSTR_LDT_FAULT:
368 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetLDTFault);
369 break;
370 case VINF_EM_RAW_EMULATE_INSTR_GDT_FAULT:
371 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetGDTFault);
372 break;
373 case VINF_EM_RAW_EMULATE_INSTR_IDT_FAULT:
374 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetIDTFault);
375 break;
376 case VINF_EM_RAW_EMULATE_INSTR_TSS_FAULT:
377 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetTSSFault);
378 break;
379 case VINF_EM_RAW_EMULATE_INSTR_PD_FAULT:
380 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPDFault);
381 break;
382 case VINF_CSAM_PENDING_ACTION:
383 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetCSAMTask);
384 break;
385 case VINF_PGM_SYNC_CR3:
386 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetSyncCR3);
387 break;
388 case VINF_PATM_PATCH_INT3:
389 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPatchInt3);
390 break;
391 case VINF_PATM_PATCH_TRAP_PF:
392 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPatchPF);
393 break;
394 case VINF_PATM_PATCH_TRAP_GP:
395 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPatchGP);
396 break;
397 case VINF_PATM_PENDING_IRQ_AFTER_IRET:
398 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPatchIretIRQ);
399 break;
400 case VERR_REM_FLUSHED_PAGES_OVERFLOW:
401 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPageOverflow);
402 break;
403 case VINF_EM_RESCHEDULE_REM:
404 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetRescheduleREM);
405 break;
406 case VINF_EM_RAW_TO_R3:
407 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetToR3);
408 break;
409 case VINF_EM_RAW_TIMER_PENDING:
410 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetTimerPending);
411 break;
412 case VINF_EM_RAW_INTERRUPT_PENDING:
413 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetInterruptPending);
414 break;
415 case VINF_VMM_CALL_HOST:
416 switch (pVM->vmm.s.enmCallHostOperation)
417 {
418 case VMMCALLHOST_PDM_LOCK:
419 STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallPDMLock);
420 break;
421 case VMMCALLHOST_PDM_QUEUE_FLUSH:
422 STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallPDMQueueFlush);
423 break;
424 case VMMCALLHOST_PGM_POOL_GROW:
425 STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallPGMPoolGrow);
426 break;
427 case VMMCALLHOST_PGM_LOCK:
428 STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallPGMLock);
429 break;
430 case VMMCALLHOST_PGM_MAP_CHUNK:
431 STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallPGMMapChunk);
432 break;
433 case VMMCALLHOST_PGM_ALLOCATE_HANDY_PAGES:
434 STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallPGMAllocHandy);
435 break;
436#ifndef VBOX_WITH_NEW_PHYS_CODE
437 case VMMCALLHOST_PGM_RAM_GROW_RANGE:
438 STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallPGMGrowRAM);
439 break;
440#endif
441 case VMMCALLHOST_REM_REPLAY_HANDLER_NOTIFICATIONS:
442 STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallRemReplay);
443 break;
444 case VMMCALLHOST_VMM_LOGGER_FLUSH:
445 STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallLogFlush);
446 break;
447 case VMMCALLHOST_VM_SET_ERROR:
448 STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallVMSetError);
449 break;
450 case VMMCALLHOST_VM_SET_RUNTIME_ERROR:
451 STAM_COUNTER_INC(&pVM->vmm.s.StatRZCallVMSetRuntimeError);
452 break;
453 case VMMCALLHOST_VM_R0_ASSERTION:
454 default:
455 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetCallHost);
456 break;
457 }
458 break;
459 case VINF_PATM_DUPLICATE_FUNCTION:
460 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPATMDuplicateFn);
461 break;
462 case VINF_PGM_CHANGE_MODE:
463 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPGMChangeMode);
464 break;
465 case VINF_EM_RAW_EMULATE_INSTR_HLT:
466 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetEmulHlt);
467 break;
468 case VINF_EM_PENDING_REQUEST:
469 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetPendingRequest);
470 break;
471 default:
472 STAM_COUNTER_INC(&pVM->vmm.s.StatRZRetMisc);
473 break;
474 }
475}
476#endif /* VBOX_WITH_STATISTICS */
477
478
479/**
480 * Unused ring-0 entry point that used to be called from the interrupt gate.
481 *
482 * Will be removed one of the next times we do a major SUPDrv version bump.
483 *
484 * @returns VBox status code.
485 * @param pVM The VM to operate on.
486 * @param enmOperation Which operation to execute.
487 * @param pvArg Argument to the operation.
488 * @remarks Assume called with interrupts disabled.
489 */
490VMMR0DECL(int) VMMR0EntryInt(PVM pVM, VMMR0OPERATION enmOperation, void *pvArg)
491{
492 switch (enmOperation)
493 {
494 default:
495 /*
496 * We're returning VERR_NOT_SUPPORT here so we've got something else
497 * than -1 which the interrupt gate glue code might return.
498 */
499 Log(("operation %#x is not supported\n", enmOperation));
500 return VERR_NOT_SUPPORTED;
501 }
502}
503
504
505/**
506 * The Ring 0 entry point, called by the fast-ioctl path.
507 *
508 * @param pVM The VM to operate on.
509 * The return code is stored in pVM->vmm.s.iLastGZRc.
510 * @param idCpu VMCPU id.
511 * @param enmOperation Which operation to execute.
512 * @remarks Assume called with interrupts _enabled_.
513 */
514VMMR0DECL(void) VMMR0EntryFast(PVM pVM, unsigned idCpu, VMMR0OPERATION enmOperation)
515{
516 if (RT_UNLIKELY(idCpu >= pVM->cCPUs))
517 {
518 pVM->vmm.s.iLastGZRc = VERR_INVALID_PARAMETER;
519 return;
520 }
521
522 switch (enmOperation)
523 {
524 /*
525 * Switch to GC and run guest raw mode code.
526 * Disable interrupts before doing the world switch.
527 */
528 case VMMR0_DO_RAW_RUN:
529 {
530 /* Safety precaution as hwaccm disables the switcher. */
531 if (RT_LIKELY(!pVM->vmm.s.fSwitcherDisabled))
532 {
533 RTCCUINTREG uFlags = ASMIntDisableFlags();
534
535 TMNotifyStartOfExecution(pVM);
536 int rc = pVM->vmm.s.pfnHostToGuestR0(pVM);
537 pVM->vmm.s.iLastGZRc = rc;
538 TMNotifyEndOfExecution(pVM);
539
540 if ( rc == VINF_EM_RAW_INTERRUPT
541 || rc == VINF_EM_RAW_INTERRUPT_HYPER)
542 TRPMR0DispatchHostInterrupt(pVM);
543
544 ASMSetFlags(uFlags);
545
546#ifdef VBOX_WITH_STATISTICS
547 STAM_COUNTER_INC(&pVM->vmm.s.StatRunRC);
548 vmmR0RecordRC(pVM, rc);
549#endif
550 }
551 else
552 {
553 Assert(!pVM->vmm.s.fSwitcherDisabled);
554 pVM->vmm.s.iLastGZRc = VERR_NOT_SUPPORTED;
555 }
556 break;
557 }
558
559 /*
560 * Run guest code using the available hardware acceleration technology.
561 *
562 * Disable interrupts before we do anything interesting. On Windows we avoid
563 * this by having the support driver raise the IRQL before calling us, this way
564 * we hope to get away with page faults and later calling into the kernel.
565 */
566 case VMMR0_DO_HWACC_RUN:
567 {
568 int rc;
569 PVMCPU pVCpu = &pVM->aCpus[idCpu];
570
571 STAM_COUNTER_INC(&pVM->vmm.s.StatRunRC);
572
573#ifndef RT_OS_WINDOWS /** @todo check other hosts */
574 RTCCUINTREG uFlags = ASMIntDisableFlags();
575#endif
576 if (!HWACCMR0SuspendPending())
577 {
578 rc = HWACCMR0Enter(pVM, pVCpu);
579 if (RT_SUCCESS(rc))
580 {
581 rc = vmmR0CallHostSetJmp(&pVM->vmm.s.CallHostR0JmpBuf, HWACCMR0RunGuestCode, pVM, pVCpu); /* this may resume code. */
582 int rc2 = HWACCMR0Leave(pVM, pVCpu);
583 AssertRC(rc2);
584 }
585 }
586 else
587 {
588 /* System is about to go into suspend mode; go back to ring 3. */
589 rc = VINF_EM_RAW_INTERRUPT;
590 }
591 pVM->vmm.s.iLastGZRc = rc;
592#ifndef RT_OS_WINDOWS /** @todo check other hosts */
593 ASMSetFlags(uFlags);
594#endif
595
596#ifdef VBOX_WITH_STATISTICS
597 vmmR0RecordRC(pVM, rc);
598#endif
599 /* No special action required for external interrupts, just return. */
600 break;
601 }
602
603 /*
604 * For profiling.
605 */
606 case VMMR0_DO_NOP:
607 pVM->vmm.s.iLastGZRc = VINF_SUCCESS;
608 break;
609
610 /*
611 * Impossible.
612 */
613 default:
614 AssertMsgFailed(("%#x\n", enmOperation));
615 pVM->vmm.s.iLastGZRc = VERR_NOT_SUPPORTED;
616 break;
617 }
618}
619
620
621/**
622 * Validates a session or VM session argument.
623 *
624 * @returns true / false accordingly.
625 * @param pVM The VM argument.
626 * @param pSession The session argument.
627 */
628DECLINLINE(bool) vmmR0IsValidSession(PVM pVM, PSUPDRVSESSION pClaimedSession, PSUPDRVSESSION pSession)
629{
630 /* This must be set! */
631 if (!pSession)
632 return false;
633
634 /* Only one out of the two. */
635 if (pVM && pClaimedSession)
636 return false;
637 if (pVM)
638 pClaimedSession = pVM->pSession;
639 return pClaimedSession == pSession;
640}
641
642
643/**
644 * VMMR0EntryEx worker function, either called directly or when ever possible
645 * called thru a longjmp so we can exit safely on failure.
646 *
647 * @returns VBox status code.
648 * @param pVM The VM to operate on.
649 * @param enmOperation Which operation to execute.
650 * @param pReqHdr This points to a SUPVMMR0REQHDR packet. Optional.
651 * The support driver validates this if it's present.
652 * @param u64Arg Some simple constant argument.
653 * @param pSession The session of the caller.
654 * @remarks Assume called with interrupts _enabled_.
655 */
656static int vmmR0EntryExWorker(PVM pVM, VMMR0OPERATION enmOperation, PSUPVMMR0REQHDR pReqHdr, uint64_t u64Arg, PSUPDRVSESSION pSession)
657{
658 /*
659 * Common VM pointer validation.
660 */
661 if (pVM)
662 {
663 if (RT_UNLIKELY( !VALID_PTR(pVM)
664 || ((uintptr_t)pVM & PAGE_OFFSET_MASK)))
665 {
666 SUPR0Printf("vmmR0EntryExWorker: Invalid pVM=%p! (op=%d)\n", pVM, enmOperation);
667 return VERR_INVALID_POINTER;
668 }
669 if (RT_UNLIKELY( pVM->enmVMState < VMSTATE_CREATING
670 || pVM->enmVMState > VMSTATE_TERMINATED
671 || pVM->pVMR0 != pVM))
672 {
673 SUPR0Printf("vmmR0EntryExWorker: Invalid pVM=%p:{enmVMState=%d, .pVMR0=%p}! (op=%d)\n",
674 pVM, pVM->enmVMState, pVM->pVMR0, enmOperation);
675 return VERR_INVALID_POINTER;
676 }
677 }
678
679 switch (enmOperation)
680 {
681 /*
682 * GVM requests
683 */
684 case VMMR0_DO_GVMM_CREATE_VM:
685 if (pVM || u64Arg)
686 return VERR_INVALID_PARAMETER;
687 return GVMMR0CreateVMReq((PGVMMCREATEVMREQ)pReqHdr);
688
689 case VMMR0_DO_GVMM_DESTROY_VM:
690 if (pReqHdr || u64Arg)
691 return VERR_INVALID_PARAMETER;
692 return GVMMR0DestroyVM(pVM);
693
694 case VMMR0_DO_GVMM_SCHED_HALT:
695 if (pReqHdr)
696 return VERR_INVALID_PARAMETER;
697 return GVMMR0SchedHalt(pVM, u64Arg);
698
699 case VMMR0_DO_GVMM_SCHED_WAKE_UP:
700 if (pReqHdr || u64Arg)
701 return VERR_INVALID_PARAMETER;
702 return GVMMR0SchedWakeUp(pVM);
703
704 case VMMR0_DO_GVMM_SCHED_POLL:
705 if (pReqHdr || u64Arg > 1)
706 return VERR_INVALID_PARAMETER;
707 return GVMMR0SchedPoll(pVM, !!u64Arg);
708
709 case VMMR0_DO_GVMM_QUERY_STATISTICS:
710 if (u64Arg)
711 return VERR_INVALID_PARAMETER;
712 return GVMMR0QueryStatisticsReq(pVM, (PGVMMQUERYSTATISTICSSREQ)pReqHdr);
713
714 case VMMR0_DO_GVMM_RESET_STATISTICS:
715 if (u64Arg)
716 return VERR_INVALID_PARAMETER;
717 return GVMMR0ResetStatisticsReq(pVM, (PGVMMRESETSTATISTICSSREQ)pReqHdr);
718
719 /*
720 * Initialize the R0 part of a VM instance.
721 */
722 case VMMR0_DO_VMMR0_INIT:
723 return vmmR0InitVM(pVM, (uint32_t)u64Arg);
724
725 /*
726 * Terminate the R0 part of a VM instance.
727 */
728 case VMMR0_DO_VMMR0_TERM:
729 return vmmR0TermVM(pVM);
730
731 /*
732 * Attempt to enable hwacc mode and check the current setting.
733 *
734 */
735 case VMMR0_DO_HWACC_ENABLE:
736 return HWACCMR0EnableAllCpus(pVM, (HWACCMSTATE)u64Arg);
737
738 /*
739 * Setup the hardware accelerated raw-mode session.
740 */
741 case VMMR0_DO_HWACC_SETUP_VM:
742 {
743 RTCCUINTREG fFlags = ASMIntDisableFlags();
744 int rc = HWACCMR0SetupVM(pVM);
745 ASMSetFlags(fFlags);
746 return rc;
747 }
748
749 /*
750 * Switch to GC to execute Hypervisor function.
751 */
752 case VMMR0_DO_CALL_HYPERVISOR:
753 {
754 /* Safety precaution as HWACCM can disable the switcher. */
755 Assert(!pVM->vmm.s.fSwitcherDisabled);
756 if (RT_UNLIKELY(pVM->vmm.s.fSwitcherDisabled))
757 return VERR_NOT_SUPPORTED;
758
759 RTCCUINTREG fFlags = ASMIntDisableFlags();
760 int rc = pVM->vmm.s.pfnHostToGuestR0(pVM);
761 /** @todo dispatch interrupts? */
762 ASMSetFlags(fFlags);
763 return rc;
764 }
765
766 /*
767 * PGM wrappers.
768 */
769 case VMMR0_DO_PGM_ALLOCATE_HANDY_PAGES:
770 return PGMR0PhysAllocateHandyPages(pVM);
771
772 /*
773 * GMM wrappers.
774 */
775 case VMMR0_DO_GMM_INITIAL_RESERVATION:
776 if (u64Arg)
777 return VERR_INVALID_PARAMETER;
778 return GMMR0InitialReservationReq(pVM, (PGMMINITIALRESERVATIONREQ)pReqHdr);
779 case VMMR0_DO_GMM_UPDATE_RESERVATION:
780 if (u64Arg)
781 return VERR_INVALID_PARAMETER;
782 return GMMR0UpdateReservationReq(pVM, (PGMMUPDATERESERVATIONREQ)pReqHdr);
783
784 case VMMR0_DO_GMM_ALLOCATE_PAGES:
785 if (u64Arg)
786 return VERR_INVALID_PARAMETER;
787 return GMMR0AllocatePagesReq(pVM, (PGMMALLOCATEPAGESREQ)pReqHdr);
788 case VMMR0_DO_GMM_FREE_PAGES:
789 if (u64Arg)
790 return VERR_INVALID_PARAMETER;
791 return GMMR0FreePagesReq(pVM, (PGMMFREEPAGESREQ)pReqHdr);
792 case VMMR0_DO_GMM_BALLOONED_PAGES:
793 if (u64Arg)
794 return VERR_INVALID_PARAMETER;
795 return GMMR0BalloonedPagesReq(pVM, (PGMMBALLOONEDPAGESREQ)pReqHdr);
796 case VMMR0_DO_GMM_DEFLATED_BALLOON:
797 if (pReqHdr)
798 return VERR_INVALID_PARAMETER;
799 return GMMR0DeflatedBalloon(pVM, (uint32_t)u64Arg);
800
801 case VMMR0_DO_GMM_MAP_UNMAP_CHUNK:
802 if (u64Arg)
803 return VERR_INVALID_PARAMETER;
804 return GMMR0MapUnmapChunkReq(pVM, (PGMMMAPUNMAPCHUNKREQ)pReqHdr);
805 case VMMR0_DO_GMM_SEED_CHUNK:
806 if (pReqHdr)
807 return VERR_INVALID_PARAMETER;
808 return GMMR0SeedChunk(pVM, (RTR3PTR)u64Arg);
809
810 /*
811 * A quick GCFGM mock-up.
812 */
813 /** @todo GCFGM with proper access control, ring-3 management interface and all that. */
814 case VMMR0_DO_GCFGM_SET_VALUE:
815 case VMMR0_DO_GCFGM_QUERY_VALUE:
816 {
817 if (pVM || !pReqHdr || u64Arg)
818 return VERR_INVALID_PARAMETER;
819 PGCFGMVALUEREQ pReq = (PGCFGMVALUEREQ)pReqHdr;
820 if (pReq->Hdr.cbReq != sizeof(*pReq))
821 return VERR_INVALID_PARAMETER;
822 int rc;
823 if (enmOperation == VMMR0_DO_GCFGM_SET_VALUE)
824 {
825 rc = GVMMR0SetConfig(pReq->pSession, &pReq->szName[0], pReq->u64Value);
826 //if (rc == VERR_CFGM_VALUE_NOT_FOUND)
827 // rc = GMMR0SetConfig(pReq->pSession, &pReq->szName[0], pReq->u64Value);
828 }
829 else
830 {
831 rc = GVMMR0QueryConfig(pReq->pSession, &pReq->szName[0], &pReq->u64Value);
832 //if (rc == VERR_CFGM_VALUE_NOT_FOUND)
833 // rc = GMMR0QueryConfig(pReq->pSession, &pReq->szName[0], &pReq->u64Value);
834 }
835 return rc;
836 }
837
838
839 /*
840 * Requests to the internal networking service.
841 */
842 case VMMR0_DO_INTNET_OPEN:
843 {
844 PINTNETOPENREQ pReq = (PINTNETOPENREQ)pReqHdr;
845 if (u64Arg || !pReq || !vmmR0IsValidSession(pVM, pReq->pSession, pSession))
846 return VERR_INVALID_PARAMETER;
847 if (!g_pIntNet)
848 return VERR_NOT_SUPPORTED;
849 return INTNETR0OpenReq(g_pIntNet, pSession, pReq);
850 }
851
852 case VMMR0_DO_INTNET_IF_CLOSE:
853 if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFCLOSEREQ)pReqHdr)->pSession, pSession))
854 return VERR_INVALID_PARAMETER;
855 if (!g_pIntNet)
856 return VERR_NOT_SUPPORTED;
857 return INTNETR0IfCloseReq(g_pIntNet, pSession, (PINTNETIFCLOSEREQ)pReqHdr);
858
859 case VMMR0_DO_INTNET_IF_GET_RING3_BUFFER:
860 if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFGETRING3BUFFERREQ)pReqHdr)->pSession, pSession))
861 return VERR_INVALID_PARAMETER;
862 if (!g_pIntNet)
863 return VERR_NOT_SUPPORTED;
864 return INTNETR0IfGetRing3BufferReq(g_pIntNet, pSession, (PINTNETIFGETRING3BUFFERREQ)pReqHdr);
865
866 case VMMR0_DO_INTNET_IF_SET_PROMISCUOUS_MODE:
867 if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFSETPROMISCUOUSMODEREQ)pReqHdr)->pSession, pSession))
868 return VERR_INVALID_PARAMETER;
869 if (!g_pIntNet)
870 return VERR_NOT_SUPPORTED;
871 return INTNETR0IfSetPromiscuousModeReq(g_pIntNet, pSession, (PINTNETIFSETPROMISCUOUSMODEREQ)pReqHdr);
872
873 case VMMR0_DO_INTNET_IF_SET_MAC_ADDRESS:
874 if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFSETMACADDRESSREQ)pReqHdr)->pSession, pSession))
875 return VERR_INVALID_PARAMETER;
876 if (!g_pIntNet)
877 return VERR_NOT_SUPPORTED;
878 return INTNETR0IfSetMacAddressReq(g_pIntNet, pSession, (PINTNETIFSETMACADDRESSREQ)pReqHdr);
879
880 case VMMR0_DO_INTNET_IF_SET_ACTIVE:
881 if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFSETACTIVEREQ)pReqHdr)->pSession, pSession))
882 return VERR_INVALID_PARAMETER;
883 if (!g_pIntNet)
884 return VERR_NOT_SUPPORTED;
885 return INTNETR0IfSetActiveReq(g_pIntNet, pSession, (PINTNETIFSETACTIVEREQ)pReqHdr);
886
887 case VMMR0_DO_INTNET_IF_SEND:
888 if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFSENDREQ)pReqHdr)->pSession, pSession))
889 return VERR_INVALID_PARAMETER;
890 if (!g_pIntNet)
891 return VERR_NOT_SUPPORTED;
892 return INTNETR0IfSendReq(g_pIntNet, pSession, (PINTNETIFSENDREQ)pReqHdr);
893
894 case VMMR0_DO_INTNET_IF_WAIT:
895 if (u64Arg || !pReqHdr || !vmmR0IsValidSession(pVM, ((PINTNETIFWAITREQ)pReqHdr)->pSession, pSession))
896 return VERR_INVALID_PARAMETER;
897 if (!g_pIntNet)
898 return VERR_NOT_SUPPORTED;
899 return INTNETR0IfWaitReq(g_pIntNet, pSession, (PINTNETIFWAITREQ)pReqHdr);
900
901 /*
902 * For profiling.
903 */
904 case VMMR0_DO_NOP:
905 case VMMR0_DO_SLOW_NOP:
906 return VINF_SUCCESS;
907
908 /*
909 * For testing Ring-0 APIs invoked in this environment.
910 */
911 case VMMR0_DO_TESTS:
912 /** @todo make new test */
913 return VINF_SUCCESS;
914
915
916 default:
917 /*
918 * We're returning VERR_NOT_SUPPORT here so we've got something else
919 * than -1 which the interrupt gate glue code might return.
920 */
921 Log(("operation %#x is not supported\n", enmOperation));
922 return VERR_NOT_SUPPORTED;
923 }
924}
925
926
927/**
928 * Argument for vmmR0EntryExWrapper containing the argument s ofr VMMR0EntryEx.
929 */
930typedef struct VMMR0ENTRYEXARGS
931{
932 PVM pVM;
933 VMMR0OPERATION enmOperation;
934 PSUPVMMR0REQHDR pReq;
935 uint64_t u64Arg;
936 PSUPDRVSESSION pSession;
937} VMMR0ENTRYEXARGS;
938/** Pointer to a vmmR0EntryExWrapper argument package. */
939typedef VMMR0ENTRYEXARGS *PVMMR0ENTRYEXARGS;
940
941/**
942 * This is just a longjmp wrapper function for VMMR0EntryEx calls.
943 *
944 * @returns VBox status code.
945 * @param pvArgs The argument package
946 */
947static int vmmR0EntryExWrapper(void *pvArgs)
948{
949 return vmmR0EntryExWorker(((PVMMR0ENTRYEXARGS)pvArgs)->pVM,
950 ((PVMMR0ENTRYEXARGS)pvArgs)->enmOperation,
951 ((PVMMR0ENTRYEXARGS)pvArgs)->pReq,
952 ((PVMMR0ENTRYEXARGS)pvArgs)->u64Arg,
953 ((PVMMR0ENTRYEXARGS)pvArgs)->pSession);
954}
955
956
957/**
958 * The Ring 0 entry point, called by the support library (SUP).
959 *
960 * @returns VBox status code.
961 * @param pVM The VM to operate on.
962 * @param enmOperation Which operation to execute.
963 * @param pReq This points to a SUPVMMR0REQHDR packet. Optional.
964 * @param u64Arg Some simple constant argument.
965 * @param pSession The session of the caller.
966 * @remarks Assume called with interrupts _enabled_.
967 */
968VMMR0DECL(int) VMMR0EntryEx(PVM pVM, VMMR0OPERATION enmOperation, PSUPVMMR0REQHDR pReq, uint64_t u64Arg, PSUPDRVSESSION pSession)
969{
970 /*
971 * Requests that should only happen on the EMT thread will be
972 * wrapped in a setjmp so we can assert without causing trouble.
973 */
974 if ( VALID_PTR(pVM)
975 && pVM->pVMR0)
976 {
977 switch (enmOperation)
978 {
979 /* These might/will be called before VMMR3Init. */
980 case VMMR0_DO_GMM_INITIAL_RESERVATION:
981 case VMMR0_DO_GMM_UPDATE_RESERVATION:
982 case VMMR0_DO_GMM_ALLOCATE_PAGES:
983 case VMMR0_DO_GMM_FREE_PAGES:
984 case VMMR0_DO_GMM_BALLOONED_PAGES:
985 case VMMR0_DO_GMM_DEFLATED_BALLOON:
986 case VMMR0_DO_GMM_MAP_UNMAP_CHUNK:
987 case VMMR0_DO_GMM_SEED_CHUNK:
988 /* On the mac we might not have a valid jmp buf, so check these as well. */
989 case VMMR0_DO_VMMR0_INIT:
990 case VMMR0_DO_VMMR0_TERM:
991 {
992 if (!pVM->vmm.s.CallHostR0JmpBuf.pvSavedStack)
993 break;
994
995 /** @todo validate this EMT claim... GVM knows. */
996 VMMR0ENTRYEXARGS Args;
997 Args.pVM = pVM;
998 Args.enmOperation = enmOperation;
999 Args.pReq = pReq;
1000 Args.u64Arg = u64Arg;
1001 Args.pSession = pSession;
1002 return vmmR0CallHostSetJmpEx(&pVM->vmm.s.CallHostR0JmpBuf, vmmR0EntryExWrapper, &Args);
1003 }
1004
1005 default:
1006 break;
1007 }
1008 }
1009 return vmmR0EntryExWorker(pVM, enmOperation, pReq, u64Arg, pSession);
1010}
1011
1012
1013/**
1014 * Internal R0 logger worker: Flush logger.
1015 *
1016 * @param pLogger The logger instance to flush.
1017 * @remark This function must be exported!
1018 */
1019VMMR0DECL(void) vmmR0LoggerFlush(PRTLOGGER pLogger)
1020{
1021 /*
1022 * Convert the pLogger into a VM handle and 'call' back to Ring-3.
1023 * (This is a bit paranoid code.)
1024 */
1025 PVMMR0LOGGER pR0Logger = (PVMMR0LOGGER)((uintptr_t)pLogger - RT_OFFSETOF(VMMR0LOGGER, Logger));
1026 if ( !VALID_PTR(pR0Logger)
1027 || !VALID_PTR(pR0Logger + 1)
1028 || pLogger->u32Magic != RTLOGGER_MAGIC)
1029 {
1030#ifdef DEBUG
1031 SUPR0Printf("vmmR0LoggerFlush: pLogger=%p!\n", pLogger);
1032#endif
1033 return;
1034 }
1035 if (pR0Logger->fFlushingDisabled)
1036 return; /* quietly */
1037
1038 PVM pVM = pR0Logger->pVM;
1039 if ( !VALID_PTR(pVM)
1040 || pVM->pVMR0 != pVM)
1041 {
1042#ifdef DEBUG
1043 SUPR0Printf("vmmR0LoggerFlush: pVM=%p! pVMR0=%p! pLogger=%p\n", pVM, pVM->pVMR0, pLogger);
1044#endif
1045 return;
1046 }
1047
1048 /*
1049 * Check that the jump buffer is armed.
1050 */
1051#ifdef RT_ARCH_X86
1052 if (!pVM->vmm.s.CallHostR0JmpBuf.eip)
1053#else
1054 if (!pVM->vmm.s.CallHostR0JmpBuf.rip)
1055#endif
1056 {
1057#ifdef DEBUG
1058 SUPR0Printf("vmmR0LoggerFlush: Jump buffer isn't armed!\n");
1059#endif
1060 return;
1061 }
1062 VMMR0CallHost(pVM, VMMCALLHOST_VMM_LOGGER_FLUSH, 0);
1063}
1064
1065
1066/**
1067 * Disables flushing of the ring-0 debug log.
1068 *
1069 * @param pVCpu The shared virtual cpu structure.
1070 */
1071VMMR0DECL(void) VMMR0LogFlushDisable(PVMCPU pVCpu)
1072{
1073 PVM pVM = pVCpu->pVMR0;
1074 if (pVM->vmm.s.pR0LoggerR0)
1075 pVM->vmm.s.pR0LoggerR0->fFlushingDisabled = true;
1076}
1077
1078
1079/**
1080 * Enables flushing of the ring-0 debug log.
1081 *
1082 * @param pVCpu The shared virtual cpu structure.
1083 */
1084VMMR0DECL(void) VMMR0LogFlushEnable(PVMCPU pVCpu)
1085{
1086 PVM pVM = pVCpu->pVMR0;
1087 if (pVM->vmm.s.pR0LoggerR0)
1088 pVM->vmm.s.pR0LoggerR0->fFlushingDisabled = false;
1089}
1090
1091
1092/**
1093 * Jump back to ring-3 if we're the EMT and the longjmp is armed.
1094 *
1095 * @returns true if the breakpoint should be hit, false if it should be ignored.
1096 */
1097DECLEXPORT(bool) RTCALL RTAssertShouldPanic(void)
1098{
1099#if 0
1100 return true;
1101#else
1102 PVM pVM = GVMMR0GetVMByEMT(NIL_RTNATIVETHREAD);
1103 if (pVM)
1104 {
1105#ifdef RT_ARCH_X86
1106 if (pVM->vmm.s.CallHostR0JmpBuf.eip)
1107#else
1108 if (pVM->vmm.s.CallHostR0JmpBuf.rip)
1109#endif
1110 {
1111 int rc = VMMR0CallHost(pVM, VMMCALLHOST_VM_R0_ASSERTION, 0);
1112 return RT_FAILURE_NP(rc);
1113 }
1114 }
1115#ifdef RT_OS_LINUX
1116 return true;
1117#else
1118 return false;
1119#endif
1120#endif
1121}
1122
1123
1124/**
1125 * Override this so we can push it up to ring-3.
1126 *
1127 * @param pszExpr Expression. Can be NULL.
1128 * @param uLine Location line number.
1129 * @param pszFile Location file name.
1130 * @param pszFunction Location function name.
1131 */
1132DECLEXPORT(void) RTCALL AssertMsg1(const char *pszExpr, unsigned uLine, const char *pszFile, const char *pszFunction)
1133{
1134#if !defined(DEBUG_sandervl) && !defined(RT_OS_DARWIN)
1135 SUPR0Printf("\n!!R0-Assertion Failed!!\n"
1136 "Expression: %s\n"
1137 "Location : %s(%d) %s\n",
1138 pszExpr, pszFile, uLine, pszFunction);
1139#endif
1140 LogAlways(("\n!!R0-Assertion Failed!!\n"
1141 "Expression: %s\n"
1142 "Location : %s(%d) %s\n",
1143 pszExpr, pszFile, uLine, pszFunction));
1144
1145 PVM pVM = GVMMR0GetVMByEMT(NIL_RTNATIVETHREAD);
1146 if (pVM)
1147 RTStrPrintf(pVM->vmm.s.szRing0AssertMsg1, sizeof(pVM->vmm.s.szRing0AssertMsg1),
1148 "\n!!R0-Assertion Failed!!\n"
1149 "Expression: %s\n"
1150 "Location : %s(%d) %s\n",
1151 pszExpr, pszFile, uLine, pszFunction);
1152#ifdef RT_OS_DARWIN
1153 RTAssertMsg1(pszExpr, uLine, pszFile, pszFunction);
1154#endif
1155}
1156
1157
1158/**
1159 * Callback for RTLogFormatV which writes to the ring-3 log port.
1160 * See PFNLOGOUTPUT() for details.
1161 */
1162static DECLCALLBACK(size_t) rtLogOutput(void *pv, const char *pachChars, size_t cbChars)
1163{
1164 for (size_t i = 0; i < cbChars; i++)
1165 {
1166#if !defined(DEBUG_sandervl) && !defined(RT_OS_DARWIN)
1167 SUPR0Printf("%c", pachChars[i]);
1168#endif
1169 LogAlways(("%c", pachChars[i]));
1170 }
1171
1172 return cbChars;
1173}
1174
1175
1176DECLEXPORT(void) RTCALL AssertMsg2(const char *pszFormat, ...)
1177{
1178 va_list va;
1179
1180 PRTLOGGER pLog = RTLogDefaultInstance(); /** @todo we want this for release as well! */
1181 if (pLog)
1182 {
1183 va_start(va, pszFormat);
1184 RTLogFormatV(rtLogOutput, pLog, pszFormat, va);
1185 va_end(va);
1186
1187 PVM pVM = GVMMR0GetVMByEMT(NIL_RTNATIVETHREAD);
1188 if (pVM)
1189 {
1190 va_start(va, pszFormat);
1191 RTStrPrintfV(pVM->vmm.s.szRing0AssertMsg2, sizeof(pVM->vmm.s.szRing0AssertMsg2), pszFormat, va);
1192 va_end(va);
1193 }
1194 }
1195
1196#ifdef RT_OS_DARWIN
1197 va_start(va, pszFormat);
1198 RTAssertMsg2V(pszFormat, va);
1199 va_end(va);
1200#endif
1201}
1202
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