VirtualBox

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

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

VMM: More renaming and cleanup, caught another R3/R0 pointer - the ring-0 logger.

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