VirtualBox

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

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

VMMR0: Fixed bogus pSession argument passed to vmmR0EntryExWorker when going thru vmmR0CallHostSetJmpEx.

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