VirtualBox

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

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

Pass the VMCPU id to the ring 0 callbacks.

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette