1 | /* $Id: VMMR0.cpp 272 2007-01-24 13:43:05Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VMM - Host Context Ring 0.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006 InnoTek Systemberatung GmbH
|
---|
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 as published by the Free Software Foundation,
|
---|
13 | * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
14 | * distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
15 | * be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * If you received this file as part of a commercial VirtualBox
|
---|
18 | * distribution, then only the terms of your commercial VirtualBox
|
---|
19 | * license agreement apply instead of the previous paragraph.
|
---|
20 | */
|
---|
21 |
|
---|
22 |
|
---|
23 | /*******************************************************************************
|
---|
24 | * Header Files *
|
---|
25 | *******************************************************************************/
|
---|
26 | #define LOG_GROUP LOG_GROUP_VMM
|
---|
27 | #ifdef __AMD64__ /** @todo fix logging on __AMD64__ (swapgs) */
|
---|
28 | # define LOG_DISABLED
|
---|
29 | #endif
|
---|
30 | #include <VBox/vmm.h>
|
---|
31 | #include <VBox/sup.h>
|
---|
32 | #include <VBox/trpm.h>
|
---|
33 | #include <VBox/cpum.h>
|
---|
34 | #include <VBox/stam.h>
|
---|
35 | #include <VBox/tm.h>
|
---|
36 | #include "VMMInternal.h"
|
---|
37 | #include <VBox/vm.h>
|
---|
38 | #include <VBox/intnet.h>
|
---|
39 | #include <VBox/hwaccm.h>
|
---|
40 |
|
---|
41 | #include <VBox/err.h>
|
---|
42 | #include <VBox/version.h>
|
---|
43 | #include <VBox/log.h>
|
---|
44 | #include <iprt/assert.h>
|
---|
45 |
|
---|
46 |
|
---|
47 | /*******************************************************************************
|
---|
48 | * Internal Functions *
|
---|
49 | *******************************************************************************/
|
---|
50 | static int VMMR0Init(PVM pVM, unsigned uVersion);
|
---|
51 | static int VMMR0Term(PVM pVM);
|
---|
52 | __BEGIN_DECLS
|
---|
53 | VMMR0DECL(int) ModuleInit(void);
|
---|
54 | VMMR0DECL(void) ModuleTerm(void);
|
---|
55 | __END_DECLS
|
---|
56 |
|
---|
57 |
|
---|
58 | //#define DEBUG_NO_RING0_ASSERTIONS
|
---|
59 | #ifdef DEBUG_NO_RING0_ASSERTIONS
|
---|
60 | static PVM g_pVMAssert = 0;
|
---|
61 | #endif
|
---|
62 |
|
---|
63 | /*******************************************************************************
|
---|
64 | * Global Variables *
|
---|
65 | *******************************************************************************/
|
---|
66 | #ifndef __AMD64__ /* doesn't link here */
|
---|
67 | /** Pointer to the internal networking service instance. */
|
---|
68 | PINTNET g_pIntNet = 0;
|
---|
69 | #endif
|
---|
70 |
|
---|
71 |
|
---|
72 | /**
|
---|
73 | * Initialize the module.
|
---|
74 | * This is called when we're first loaded.
|
---|
75 | *
|
---|
76 | * @returns 0 on success.
|
---|
77 | * @returns VBox status on failure.
|
---|
78 | */
|
---|
79 | VMMR0DECL(int) ModuleInit(void)
|
---|
80 | {
|
---|
81 | #ifndef __AMD64__ /* doesn't link here */
|
---|
82 | LogFlow(("ModuleInit: g_pIntNet=%p\n", g_pIntNet));
|
---|
83 | g_pIntNet = NULL;
|
---|
84 | LogFlow(("ModuleInit: g_pIntNet=%p should be NULL now...\n", g_pIntNet));
|
---|
85 | int rc = INTNETR0Create(&g_pIntNet);
|
---|
86 | if (VBOX_SUCCESS(rc))
|
---|
87 | {
|
---|
88 | LogFlow(("ModuleInit: returns success. g_pIntNet=%p\n", g_pIntNet));
|
---|
89 | return 0;
|
---|
90 | }
|
---|
91 | g_pIntNet = NULL;
|
---|
92 | LogFlow(("ModuleTerm: returns %Vrc\n", rc));
|
---|
93 | return rc;
|
---|
94 | #else
|
---|
95 | return 0;
|
---|
96 | #endif
|
---|
97 | }
|
---|
98 |
|
---|
99 |
|
---|
100 | /**
|
---|
101 | * Terminate the module.
|
---|
102 | * This is called when we're finally unloaded.
|
---|
103 | */
|
---|
104 | VMMR0DECL(void) ModuleTerm(void)
|
---|
105 | {
|
---|
106 | #ifndef __AMD64__ /* doesn't link here */
|
---|
107 | LogFlow(("ModuleTerm:\n"));
|
---|
108 | if (g_pIntNet)
|
---|
109 | {
|
---|
110 | INTNETR0Destroy(g_pIntNet);
|
---|
111 | g_pIntNet = NULL;
|
---|
112 | }
|
---|
113 | LogFlow(("ModuleTerm: returns\n"));
|
---|
114 | #endif
|
---|
115 | }
|
---|
116 |
|
---|
117 |
|
---|
118 | /**
|
---|
119 | * Initaties the R0 driver for a particular VM instance.
|
---|
120 | *
|
---|
121 | * @returns VBox status code.
|
---|
122 | *
|
---|
123 | * @param pVM The VM instance in question.
|
---|
124 | * @param uVersion The minimum module version required.
|
---|
125 | */
|
---|
126 | static int VMMR0Init(PVM pVM, unsigned uVersion)
|
---|
127 | {
|
---|
128 | /*
|
---|
129 | * Check if compatible version.
|
---|
130 | */
|
---|
131 | if ( uVersion != VBOX_VERSION
|
---|
132 | && ( VBOX_GET_VERSION_MAJOR(uVersion) != VBOX_VERSION_MAJOR
|
---|
133 | || VBOX_GET_VERSION_MINOR(uVersion) < VBOX_VERSION_MINOR))
|
---|
134 | return VERR_VERSION_MISMATCH;
|
---|
135 |
|
---|
136 | /*
|
---|
137 | * Register the EMT R0 logger instance.
|
---|
138 | */
|
---|
139 | PVMMR0LOGGER pR0Logger = pVM->vmm.s.pR0Logger;
|
---|
140 | if (pR0Logger)
|
---|
141 | {
|
---|
142 | #if 0 /* testing of the logger. */
|
---|
143 | LogCom(("VMMR0Init: before %p\n", RTLogDefaultInstance()));
|
---|
144 | LogCom(("VMMR0Init: pfnFlush=%p actual=%p\n", pR0Logger->Logger.pfnFlush, vmmR0LoggerFlush));
|
---|
145 | LogCom(("VMMR0Init: pfnLogger=%p actual=%p\n", pR0Logger->Logger.pfnLogger, vmmR0LoggerWrapper));
|
---|
146 | LogCom(("VMMR0Init: offScratch=%d fFlags=%#x fDestFlags=%#x\n", pR0Logger->Logger.offScratch, pR0Logger->Logger.fFlags, pR0Logger->Logger.fDestFlags));
|
---|
147 |
|
---|
148 | RTLogSetDefaultInstanceThread(&pR0Logger->Logger, (uintptr_t)pVM->pSession);
|
---|
149 | LogCom(("VMMR0Init: after %p reg\n", RTLogDefaultInstance()));
|
---|
150 | RTLogSetDefaultInstanceThread(NULL, 0);
|
---|
151 | LogCom(("VMMR0Init: after %p dereg\n", RTLogDefaultInstance()));
|
---|
152 |
|
---|
153 | pR0Logger->Logger.pfnLogger("hello ring-0 logger\n");
|
---|
154 | LogCom(("VMMR0Init: returned succesfully from direct logger call.\n"));
|
---|
155 | pR0Logger->Logger.pfnFlush(&pR0Logger->Logger);
|
---|
156 | LogCom(("VMMR0Init: returned succesfully from direct flush call.\n"));
|
---|
157 |
|
---|
158 | RTLogSetDefaultInstanceThread(&pR0Logger->Logger, (uintptr_t)pVM->pSession);
|
---|
159 | LogCom(("VMMR0Init: after %p reg2\n", RTLogDefaultInstance()));
|
---|
160 | pR0Logger->Logger.pfnLogger("hello ring-0 logger\n");
|
---|
161 | LogCom(("VMMR0Init: returned succesfully from direct logger call (2). offScratch=%d\n", pR0Logger->Logger.offScratch));
|
---|
162 | RTLogSetDefaultInstanceThread(NULL, 0);
|
---|
163 | LogCom(("VMMR0Init: after %p dereg2\n", RTLogDefaultInstance()));
|
---|
164 |
|
---|
165 | RTLogLoggerEx(&pR0Logger->Logger, 0, ~0U, "hello ring-0 logger (RTLogLoggerEx)\n");
|
---|
166 | LogCom(("VMMR0Init: RTLogLoggerEx returned fine offScratch=%d\n", pR0Logger->Logger.offScratch));
|
---|
167 | #endif
|
---|
168 | RTLogSetDefaultInstanceThread(&pR0Logger->Logger, (uintptr_t)pVM->pSession);
|
---|
169 | }
|
---|
170 |
|
---|
171 |
|
---|
172 | /*
|
---|
173 | * Init VMXM.
|
---|
174 | */
|
---|
175 | HWACCMR0Init(pVM);
|
---|
176 |
|
---|
177 | /*
|
---|
178 | * Init CPUM.
|
---|
179 | */
|
---|
180 | int rc = CPUMR0Init(pVM);
|
---|
181 |
|
---|
182 | if (RT_FAILURE(rc))
|
---|
183 | RTLogSetDefaultInstanceThread(NULL, 0);
|
---|
184 | return rc;
|
---|
185 | }
|
---|
186 |
|
---|
187 |
|
---|
188 | /**
|
---|
189 | * Terminates the R0 driver for a particular VM instance.
|
---|
190 | *
|
---|
191 | * @returns VBox status code.
|
---|
192 | *
|
---|
193 | * @param pVM The VM instance in question.
|
---|
194 | */
|
---|
195 | static int VMMR0Term(PVM pVM)
|
---|
196 | {
|
---|
197 | /*
|
---|
198 | * Deregister the logger.
|
---|
199 | */
|
---|
200 | RTLogSetDefaultInstanceThread(NULL, 0);
|
---|
201 | return VINF_SUCCESS;
|
---|
202 | }
|
---|
203 |
|
---|
204 |
|
---|
205 | /**
|
---|
206 | * Calls the ring-3 host code.
|
---|
207 | *
|
---|
208 | * @returns VBox status code of the ring-3 call.
|
---|
209 | * @param pVM The VM handle.
|
---|
210 | * @param enmOperation The operation.
|
---|
211 | * @param uArg The argument to the operation.
|
---|
212 | */
|
---|
213 | VMMR0DECL(int) VMMR0CallHost(PVM pVM, VMMCALLHOST enmOperation, uint64_t uArg)
|
---|
214 | {
|
---|
215 | /** @todo profile this! */
|
---|
216 | pVM->vmm.s.enmCallHostOperation = enmOperation;
|
---|
217 | pVM->vmm.s.u64CallHostArg = uArg;
|
---|
218 | pVM->vmm.s.rcCallHost = VERR_INTERNAL_ERROR;
|
---|
219 | int rc = vmmR0CallHostLongJmp(&pVM->vmm.s.CallHostR0JmpBuf, VINF_VMM_CALL_HOST);
|
---|
220 | if (rc == VINF_SUCCESS)
|
---|
221 | rc = pVM->vmm.s.rcCallHost;
|
---|
222 | return rc;
|
---|
223 | }
|
---|
224 |
|
---|
225 |
|
---|
226 | #ifdef VBOX_WITH_STATISTICS
|
---|
227 | /**
|
---|
228 | * Record return code statistics
|
---|
229 | * @param pVM The VM handle.
|
---|
230 | * @param rc The status code.
|
---|
231 | */
|
---|
232 | static void vmmR0RecordRC(PVM pVM, int rc)
|
---|
233 | {
|
---|
234 | /*
|
---|
235 | * Collect statistics.
|
---|
236 | */
|
---|
237 | switch (rc)
|
---|
238 | {
|
---|
239 | case VINF_SUCCESS:
|
---|
240 | STAM_COUNTER_INC(&pVM->vmm.s.StatGCRetNormal);
|
---|
241 | break;
|
---|
242 | case VINF_EM_RAW_INTERRUPT:
|
---|
243 | STAM_COUNTER_INC(&pVM->vmm.s.StatGCRetInterrupt);
|
---|
244 | break;
|
---|
245 | case VINF_EM_RAW_INTERRUPT_HYPER:
|
---|
246 | STAM_COUNTER_INC(&pVM->vmm.s.StatGCRetInterruptHyper);
|
---|
247 | break;
|
---|
248 | case VINF_EM_RAW_GUEST_TRAP:
|
---|
249 | STAM_COUNTER_INC(&pVM->vmm.s.StatGCRetGuestTrap);
|
---|
250 | break;
|
---|
251 | case VINF_EM_RAW_RING_SWITCH:
|
---|
252 | STAM_COUNTER_INC(&pVM->vmm.s.StatGCRetRingSwitch);
|
---|
253 | break;
|
---|
254 | case VINF_EM_RAW_RING_SWITCH_INT:
|
---|
255 | STAM_COUNTER_INC(&pVM->vmm.s.StatGCRetRingSwitchInt);
|
---|
256 | break;
|
---|
257 | case VINF_EM_RAW_EXCEPTION_PRIVILEGED:
|
---|
258 | STAM_COUNTER_INC(&pVM->vmm.s.StatGCRetExceptionPrivilege);
|
---|
259 | break;
|
---|
260 | case VINF_EM_RAW_STALE_SELECTOR:
|
---|
261 | STAM_COUNTER_INC(&pVM->vmm.s.StatGCRetStaleSelector);
|
---|
262 | break;
|
---|
263 | case VINF_EM_RAW_IRET_TRAP:
|
---|
264 | STAM_COUNTER_INC(&pVM->vmm.s.StatGCRetIRETTrap);
|
---|
265 | break;
|
---|
266 | case VINF_IOM_HC_IOPORT_READ:
|
---|
267 | STAM_COUNTER_INC(&pVM->vmm.s.StatGCRetIORead);
|
---|
268 | break;
|
---|
269 | case VINF_IOM_HC_IOPORT_WRITE:
|
---|
270 | STAM_COUNTER_INC(&pVM->vmm.s.StatGCRetIOWrite);
|
---|
271 | break;
|
---|
272 | case VINF_IOM_HC_IOPORT_READWRITE:
|
---|
273 | STAM_COUNTER_INC(&pVM->vmm.s.StatGCRetIOReadWrite);
|
---|
274 | break;
|
---|
275 | case VINF_IOM_HC_MMIO_READ:
|
---|
276 | STAM_COUNTER_INC(&pVM->vmm.s.StatGCRetMMIORead);
|
---|
277 | break;
|
---|
278 | case VINF_IOM_HC_MMIO_WRITE:
|
---|
279 | STAM_COUNTER_INC(&pVM->vmm.s.StatGCRetMMIOWrite);
|
---|
280 | break;
|
---|
281 | case VINF_IOM_HC_MMIO_READ_WRITE:
|
---|
282 | STAM_COUNTER_INC(&pVM->vmm.s.StatGCRetMMIOReadWrite);
|
---|
283 | break;
|
---|
284 | case VINF_PATM_HC_MMIO_PATCH_READ:
|
---|
285 | STAM_COUNTER_INC(&pVM->vmm.s.StatGCRetMMIOPatchRead);
|
---|
286 | break;
|
---|
287 | case VINF_PATM_HC_MMIO_PATCH_WRITE:
|
---|
288 | STAM_COUNTER_INC(&pVM->vmm.s.StatGCRetMMIOPatchWrite);
|
---|
289 | break;
|
---|
290 | case VINF_EM_RAW_EMULATE_INSTR:
|
---|
291 | STAM_COUNTER_INC(&pVM->vmm.s.StatGCRetEmulate);
|
---|
292 | break;
|
---|
293 | case VINF_PATCH_EMULATE_INSTR:
|
---|
294 | STAM_COUNTER_INC(&pVM->vmm.s.StatGCRetPatchEmulate);
|
---|
295 | break;
|
---|
296 | case VINF_EM_RAW_EMULATE_INSTR_LDT_FAULT:
|
---|
297 | STAM_COUNTER_INC(&pVM->vmm.s.StatGCRetLDTFault);
|
---|
298 | break;
|
---|
299 | case VINF_EM_RAW_EMULATE_INSTR_GDT_FAULT:
|
---|
300 | STAM_COUNTER_INC(&pVM->vmm.s.StatGCRetGDTFault);
|
---|
301 | break;
|
---|
302 | case VINF_EM_RAW_EMULATE_INSTR_IDT_FAULT:
|
---|
303 | STAM_COUNTER_INC(&pVM->vmm.s.StatGCRetIDTFault);
|
---|
304 | break;
|
---|
305 | case VINF_EM_RAW_EMULATE_INSTR_TSS_FAULT:
|
---|
306 | STAM_COUNTER_INC(&pVM->vmm.s.StatGCRetTSSFault);
|
---|
307 | break;
|
---|
308 | case VINF_EM_RAW_EMULATE_INSTR_PD_FAULT:
|
---|
309 | STAM_COUNTER_INC(&pVM->vmm.s.StatGCRetPDFault);
|
---|
310 | break;
|
---|
311 | case VINF_CSAM_PENDING_ACTION:
|
---|
312 | STAM_COUNTER_INC(&pVM->vmm.s.StatGCRetCSAMTask);
|
---|
313 | break;
|
---|
314 | case VINF_PGM_SYNC_CR3:
|
---|
315 | STAM_COUNTER_INC(&pVM->vmm.s.StatGCRetSyncCR3);
|
---|
316 | break;
|
---|
317 | case VINF_PATM_PATCH_INT3:
|
---|
318 | STAM_COUNTER_INC(&pVM->vmm.s.StatGCRetPatchInt3);
|
---|
319 | break;
|
---|
320 | case VINF_PATM_PATCH_TRAP_PF:
|
---|
321 | STAM_COUNTER_INC(&pVM->vmm.s.StatGCRetPatchPF);
|
---|
322 | break;
|
---|
323 | case VINF_PATM_PATCH_TRAP_GP:
|
---|
324 | STAM_COUNTER_INC(&pVM->vmm.s.StatGCRetPatchGP);
|
---|
325 | break;
|
---|
326 | case VINF_PATM_PENDING_IRQ_AFTER_IRET:
|
---|
327 | STAM_COUNTER_INC(&pVM->vmm.s.StatGCRetPatchIretIRQ);
|
---|
328 | break;
|
---|
329 | case VERR_REM_FLUSHED_PAGES_OVERFLOW:
|
---|
330 | STAM_COUNTER_INC(&pVM->vmm.s.StatGCRetPageOverflow);
|
---|
331 | break;
|
---|
332 | case VINF_EM_RESCHEDULE_REM:
|
---|
333 | STAM_COUNTER_INC(&pVM->vmm.s.StatGCRetRescheduleREM);
|
---|
334 | break;
|
---|
335 | case VINF_EM_RAW_TO_R3:
|
---|
336 | STAM_COUNTER_INC(&pVM->vmm.s.StatGCRetToR3);
|
---|
337 | break;
|
---|
338 | case VINF_EM_RAW_TIMER_PENDING:
|
---|
339 | STAM_COUNTER_INC(&pVM->vmm.s.StatGCRetTimerPending);
|
---|
340 | break;
|
---|
341 | case VINF_EM_RAW_INTERRUPT_PENDING:
|
---|
342 | STAM_COUNTER_INC(&pVM->vmm.s.StatGCRetInterruptPending);
|
---|
343 | break;
|
---|
344 | case VINF_VMM_CALL_HOST:
|
---|
345 | switch (pVM->vmm.s.enmCallHostOperation)
|
---|
346 | {
|
---|
347 | case VMMCALLHOST_PDM_LOCK:
|
---|
348 | STAM_COUNTER_INC(&pVM->vmm.s.StatGCRetPDMLock);
|
---|
349 | break;
|
---|
350 | case VMMCALLHOST_PDM_QUEUE_FLUSH:
|
---|
351 | STAM_COUNTER_INC(&pVM->vmm.s.StatGCRetPDMQueueFlush);
|
---|
352 | break;
|
---|
353 | case VMMCALLHOST_PGM_POOL_GROW:
|
---|
354 | STAM_COUNTER_INC(&pVM->vmm.s.StatGCRetPGMPoolGrow);
|
---|
355 | break;
|
---|
356 | case VMMCALLHOST_PGM_LOCK:
|
---|
357 | STAM_COUNTER_INC(&pVM->vmm.s.StatGCRetPGMLock);
|
---|
358 | break;
|
---|
359 | case VMMCALLHOST_REM_REPLAY_HANDLER_NOTIFICATIONS:
|
---|
360 | STAM_COUNTER_INC(&pVM->vmm.s.StatGCRetRemReplay);
|
---|
361 | break;
|
---|
362 | case VMMCALLHOST_PGM_RAM_GROW_RANGE:
|
---|
363 | STAM_COUNTER_INC(&pVM->vmm.s.StatGCRetPGMGrowRAM);
|
---|
364 | break;
|
---|
365 | case VMMCALLHOST_VMM_LOGGER_FLUSH:
|
---|
366 | STAM_COUNTER_INC(&pVM->vmm.s.StatGCRetLogFlush);
|
---|
367 | break;
|
---|
368 | case VMMCALLHOST_VM_SET_ERROR:
|
---|
369 | STAM_COUNTER_INC(&pVM->vmm.s.StatGCRetVMSetError);
|
---|
370 | break;
|
---|
371 | case VMMCALLHOST_VM_SET_RUNTIME_ERROR:
|
---|
372 | STAM_COUNTER_INC(&pVM->vmm.s.StatGCRetVMSetRuntimeError);
|
---|
373 | break;
|
---|
374 | default:
|
---|
375 | STAM_COUNTER_INC(&pVM->vmm.s.StatGCRetCallHost);
|
---|
376 | break;
|
---|
377 | }
|
---|
378 | break;
|
---|
379 | case VINF_PATM_DUPLICATE_FUNCTION:
|
---|
380 | STAM_COUNTER_INC(&pVM->vmm.s.StatGCRetPATMDuplicateFn);
|
---|
381 | break;
|
---|
382 | case VINF_PGM_CHANGE_MODE:
|
---|
383 | STAM_COUNTER_INC(&pVM->vmm.s.StatGCRetPGMChangeMode);
|
---|
384 | break;
|
---|
385 | case VINF_EM_RAW_EMULATE_INSTR_HLT:
|
---|
386 | STAM_COUNTER_INC(&pVM->vmm.s.StatGCRetEmulHlt);
|
---|
387 | break;
|
---|
388 | case VINF_EM_PENDING_REQUEST:
|
---|
389 | STAM_COUNTER_INC(&pVM->vmm.s.StatGCRetPendingRequest);
|
---|
390 | break;
|
---|
391 | default:
|
---|
392 | STAM_COUNTER_INC(&pVM->vmm.s.StatGCRetMisc);
|
---|
393 | break;
|
---|
394 | }
|
---|
395 | }
|
---|
396 | #endif /* VBOX_WITH_STATISTICS */
|
---|
397 |
|
---|
398 |
|
---|
399 | /**
|
---|
400 | * The Ring 0 entry point, called by the support library (SUP).
|
---|
401 | *
|
---|
402 | * @returns VBox status code.
|
---|
403 | * @param pVM The VM to operate on.
|
---|
404 | * @param uOperation Which operation to execute. (VMMR0OPERATION)
|
---|
405 | * @param pvArg Argument to the operation.
|
---|
406 | */
|
---|
407 | VMMR0DECL(int) VMMR0Entry(PVM pVM, unsigned /* make me an enum */ uOperation, void *pvArg)
|
---|
408 | {
|
---|
409 | switch (uOperation)
|
---|
410 | {
|
---|
411 | /*
|
---|
412 | * Switch to GC.
|
---|
413 | * These calls return whatever the GC returns.
|
---|
414 | */
|
---|
415 | case VMMR0_DO_RUN_GC:
|
---|
416 | {
|
---|
417 | /* Safety precaution as VMX disables the switcher. */
|
---|
418 | Assert(!pVM->vmm.s.fSwitcherDisabled);
|
---|
419 | if (pVM->vmm.s.fSwitcherDisabled)
|
---|
420 | return VERR_NOT_SUPPORTED;
|
---|
421 |
|
---|
422 | STAM_COUNTER_INC(&pVM->vmm.s.StatRunGC);
|
---|
423 | register int rc;
|
---|
424 | TMCpuTickResume(pVM);
|
---|
425 | pVM->vmm.s.iLastGCRc = rc = pVM->vmm.s.pfnR0HostToGuest(pVM);
|
---|
426 | TMCpuTickPause(pVM);
|
---|
427 |
|
---|
428 | #ifdef VBOX_WITH_STATISTICS
|
---|
429 | vmmR0RecordRC(pVM, rc);
|
---|
430 | #endif
|
---|
431 |
|
---|
432 | /*
|
---|
433 | * Check if there is an exit R0 action associated with the return code.
|
---|
434 | */
|
---|
435 | switch (rc)
|
---|
436 | {
|
---|
437 | /*
|
---|
438 | * Default - no action, just return.
|
---|
439 | */
|
---|
440 | default:
|
---|
441 | return rc;
|
---|
442 |
|
---|
443 | /*
|
---|
444 | * We'll let TRPM change the stack frame so our return is different.
|
---|
445 | * Just keep in mind that after the call, things have changed!
|
---|
446 | */
|
---|
447 | case VINF_EM_RAW_INTERRUPT:
|
---|
448 | case VINF_EM_RAW_INTERRUPT_HYPER:
|
---|
449 | TRPMR0SetupInterruptDispatcherFrame(pVM, (char*)&pVM - sizeof(pVM));
|
---|
450 | return rc;
|
---|
451 | }
|
---|
452 | /* Won't get here! */
|
---|
453 | break;
|
---|
454 | }
|
---|
455 |
|
---|
456 | /*
|
---|
457 | * Run guest code using the available hardware acceleration technology.
|
---|
458 | */
|
---|
459 | case VMMR0_HWACC_RUN_GUEST:
|
---|
460 | {
|
---|
461 | int rc;
|
---|
462 |
|
---|
463 | STAM_COUNTER_INC(&pVM->vmm.s.StatRunGC);
|
---|
464 | TMCpuTickResume(pVM);
|
---|
465 | rc = HWACCMR0Enable(pVM);
|
---|
466 | if (VBOX_SUCCESS(rc))
|
---|
467 | {
|
---|
468 | #ifdef DEBUG_NO_RING0_ASSERTIONS
|
---|
469 | g_pVMAssert = pVM;
|
---|
470 | #endif
|
---|
471 | rc = vmmR0CallHostSetJmp(&pVM->vmm.s.CallHostR0JmpBuf, HWACCMR0RunGuestCode, pVM); /* this may resume code. */
|
---|
472 | #ifdef DEBUG_NO_RING0_ASSERTIONS
|
---|
473 | g_pVMAssert = 0;
|
---|
474 | #endif
|
---|
475 | int rc2 = HWACCMR0Disable(pVM);
|
---|
476 | AssertRC(rc2);
|
---|
477 | }
|
---|
478 | TMCpuTickPause(pVM);
|
---|
479 | pVM->vmm.s.iLastGCRc = rc;
|
---|
480 |
|
---|
481 | #ifdef VBOX_WITH_STATISTICS
|
---|
482 | vmmR0RecordRC(pVM, rc);
|
---|
483 | #endif
|
---|
484 | /* No special action required for external interrupts, just return. */
|
---|
485 | return rc;
|
---|
486 | }
|
---|
487 |
|
---|
488 | /*
|
---|
489 | * Initialize the R0 part of a VM instance.
|
---|
490 | */
|
---|
491 | case VMMR0_DO_VMMR0_INIT:
|
---|
492 | return VMMR0Init(pVM, (unsigned)(uintptr_t)pvArg);
|
---|
493 |
|
---|
494 | /*
|
---|
495 | * Terminate the R0 part of a VM instance.
|
---|
496 | */
|
---|
497 | case VMMR0_DO_VMMR0_TERM:
|
---|
498 | return VMMR0Term(pVM);
|
---|
499 |
|
---|
500 | /*
|
---|
501 | * Setup the hardware accelerated raw-mode session.
|
---|
502 | */
|
---|
503 | case VMMR0_HWACC_SETUP_VM:
|
---|
504 | return HWACCMR0SetupVMX(pVM);
|
---|
505 |
|
---|
506 | /*
|
---|
507 | * Switch to GC to execute Hypervisor function.
|
---|
508 | */
|
---|
509 | case VMMR0_DO_CALL_HYPERVISOR:
|
---|
510 | {
|
---|
511 | /* Safety precaution as VMX disables the switcher. */
|
---|
512 | Assert(!pVM->vmm.s.fSwitcherDisabled);
|
---|
513 | if (pVM->vmm.s.fSwitcherDisabled)
|
---|
514 | return VERR_NOT_SUPPORTED;
|
---|
515 |
|
---|
516 | int rc = pVM->vmm.s.pfnR0HostToGuest(pVM);
|
---|
517 | return rc;
|
---|
518 | }
|
---|
519 |
|
---|
520 | #if !defined(__L4__) && !defined(__AMD64__) /** @todo Port this to L4. */ /** @todo fix logging and other services problems on AMD64. */
|
---|
521 | /*
|
---|
522 | * Services.
|
---|
523 | */
|
---|
524 | case VMMR0_DO_INTNET_OPEN:
|
---|
525 | case VMMR0_DO_INTNET_IF_CLOSE:
|
---|
526 | case VMMR0_DO_INTNET_IF_GET_RING3_BUFFER:
|
---|
527 | case VMMR0_DO_INTNET_IF_SET_PROMISCUOUS_MODE:
|
---|
528 | case VMMR0_DO_INTNET_IF_SEND:
|
---|
529 | case VMMR0_DO_INTNET_IF_WAIT:
|
---|
530 | {
|
---|
531 | /*
|
---|
532 | * Validate arguments a bit first.
|
---|
533 | */
|
---|
534 | if (!VALID_PTR(pvArg))
|
---|
535 | return VERR_INVALID_POINTER;
|
---|
536 | if (!VALID_PTR(pVM))
|
---|
537 | return VERR_INVALID_POINTER;
|
---|
538 | if (pVM->pVMHC != pVM)
|
---|
539 | return VERR_INVALID_POINTER;
|
---|
540 | if (!VALID_PTR(pVM->pSession))
|
---|
541 | return VERR_INVALID_POINTER;
|
---|
542 | if (!g_pIntNet)
|
---|
543 | return VERR_FILE_NOT_FOUND; ///@todo fix this status code!
|
---|
544 |
|
---|
545 | /*
|
---|
546 | * Unpack the arguments and call the service.
|
---|
547 | */
|
---|
548 | switch (uOperation)
|
---|
549 | {
|
---|
550 | case VMMR0_DO_INTNET_OPEN:
|
---|
551 | {
|
---|
552 | PINTNETOPENARGS pArgs = (PINTNETOPENARGS)pvArg;
|
---|
553 | return INTNETR0Open(g_pIntNet, pVM->pSession, &pArgs->szNetwork[0], pArgs->cbSend, pArgs->cbRecv, &pArgs->hIf);
|
---|
554 | }
|
---|
555 |
|
---|
556 | case VMMR0_DO_INTNET_IF_CLOSE:
|
---|
557 | {
|
---|
558 | PINTNETIFCLOSEARGS pArgs = (PINTNETIFCLOSEARGS)pvArg;
|
---|
559 | return INTNETR0IfClose(g_pIntNet, pArgs->hIf);
|
---|
560 | }
|
---|
561 |
|
---|
562 | case VMMR0_DO_INTNET_IF_GET_RING3_BUFFER:
|
---|
563 | {
|
---|
564 | PINTNETIFGETRING3BUFFERARGS pArgs = (PINTNETIFGETRING3BUFFERARGS)pvArg;
|
---|
565 | return INTNETR0IfGetRing3Buffer(g_pIntNet, pArgs->hIf, &pArgs->pRing3Buf);
|
---|
566 | }
|
---|
567 |
|
---|
568 | case VMMR0_DO_INTNET_IF_SET_PROMISCUOUS_MODE:
|
---|
569 | {
|
---|
570 | PINTNETIFSETPROMISCUOUSMODEARGS pArgs = (PINTNETIFSETPROMISCUOUSMODEARGS)pvArg;
|
---|
571 | return INTNETR0IfSetPromiscuousMode(g_pIntNet, pArgs->hIf, pArgs->fPromiscuous);
|
---|
572 | }
|
---|
573 |
|
---|
574 | case VMMR0_DO_INTNET_IF_SEND:
|
---|
575 | {
|
---|
576 | PINTNETIFSENDARGS pArgs = (PINTNETIFSENDARGS)pvArg;
|
---|
577 | return INTNETR0IfSend(g_pIntNet, pArgs->hIf, pArgs->pvFrame, pArgs->cbFrame);
|
---|
578 | }
|
---|
579 |
|
---|
580 | case VMMR0_DO_INTNET_IF_WAIT:
|
---|
581 | {
|
---|
582 | PINTNETIFWAITARGS pArgs = (PINTNETIFWAITARGS)pvArg;
|
---|
583 | return INTNETR0IfWait(g_pIntNet, pArgs->hIf, pArgs->cMillies);
|
---|
584 | }
|
---|
585 |
|
---|
586 | default:
|
---|
587 | return VERR_NOT_SUPPORTED;
|
---|
588 | }
|
---|
589 | }
|
---|
590 | #endif /* !__L4__ */
|
---|
591 |
|
---|
592 | #ifdef DEBUG
|
---|
593 | /*
|
---|
594 | * For testing purposes only.
|
---|
595 | */
|
---|
596 | case 0xdeadbeef:
|
---|
597 | {
|
---|
598 | LogCom(("VMMR0Entry: !debug testing! 0xdeadbeef!\n"));
|
---|
599 | #if 0
|
---|
600 | void *pv;
|
---|
601 | void *pvPhys;
|
---|
602 |
|
---|
603 | /* alloc cont memory */
|
---|
604 | int rc = SUPR0ContAlloc(pVM->pSession, 0x1fff, &pv, &pvPhys);
|
---|
605 | LogCom(("VMMR0Entry: ContAlloc: rc=%d pv=%p pvPhys=%p\n", rc, pv, pvPhys));
|
---|
606 | if (!VBOX_SUCCESS(rc))
|
---|
607 | return rc;
|
---|
608 | /* touch */
|
---|
609 | ((char*)pv)[0x1000] = ((char*)pv)[0] = 'f';
|
---|
610 | /* free */
|
---|
611 | rc = SUPR0ContFree(pVM->pSession, pv);
|
---|
612 | LogCom(("VMMR0Entry: ContFree: rc=%d\n", rc));
|
---|
613 | if (!VBOX_SUCCESS(rc))
|
---|
614 | return rc;
|
---|
615 | #endif
|
---|
616 | /* successful return - consistent with release builds. */
|
---|
617 | return VERR_NOT_SUPPORTED;
|
---|
618 | }
|
---|
619 | #endif
|
---|
620 |
|
---|
621 | default:
|
---|
622 | /*
|
---|
623 | * We're returning VERR_NOT_SUPPORT here so we've got something else
|
---|
624 | * than -1 which the interrupt gate glue code might return.
|
---|
625 | */
|
---|
626 | Log(("operation %#x is not supported\n", uOperation));
|
---|
627 | return VERR_NOT_SUPPORTED;
|
---|
628 | }
|
---|
629 | }
|
---|
630 |
|
---|
631 |
|
---|
632 | /**
|
---|
633 | * Internal R0 logger worker: Flush logger.
|
---|
634 | *
|
---|
635 | * @param pLogger The logger instance to flush.
|
---|
636 | * @remark This function must be exported!
|
---|
637 | */
|
---|
638 | VMMR0DECL(void) vmmR0LoggerFlush(PRTLOGGER pLogger)
|
---|
639 | {
|
---|
640 | /*
|
---|
641 | * Convert the pLogger into a VM handle and 'call' back to Ring-3.
|
---|
642 | * (This is a bit paranoid code.)
|
---|
643 | */
|
---|
644 | PVMMR0LOGGER pR0Logger = (PVMMR0LOGGER)((uintptr_t)pLogger - RT_OFFSETOF(VMMR0LOGGER, Logger));
|
---|
645 | if ( !VALID_PTR(pR0Logger)
|
---|
646 | || !VALID_PTR(pR0Logger + 1)
|
---|
647 | || !VALID_PTR(pLogger)
|
---|
648 | || pLogger->u32Magic != RTLOGGER_MAGIC)
|
---|
649 | {
|
---|
650 | LogCom(("vmmR0LoggerFlush: pLogger=%p!\n", pLogger));
|
---|
651 | return;
|
---|
652 | }
|
---|
653 |
|
---|
654 | PVM pVM = pR0Logger->pVM;
|
---|
655 | if ( !VALID_PTR(pVM)
|
---|
656 | || pVM->pVMHC != pVM)
|
---|
657 | {
|
---|
658 | LogCom(("vmmR0LoggerFlush: pVM=%p! pLogger=%p\n", pVM, pLogger));
|
---|
659 | return;
|
---|
660 | }
|
---|
661 |
|
---|
662 | /*
|
---|
663 | * Check that the jump buffer is armed.
|
---|
664 | */
|
---|
665 | #ifdef __X86__
|
---|
666 | if (!pVM->vmm.s.CallHostR0JmpBuf.eip)
|
---|
667 | #else
|
---|
668 | if (!pVM->vmm.s.CallHostR0JmpBuf.rip)
|
---|
669 | #endif
|
---|
670 | {
|
---|
671 | LogCom(("vmmR0LoggerFlush: Jump buffer isn't armed!\n"));
|
---|
672 | pLogger->offScratch = 0;
|
---|
673 | return;
|
---|
674 | }
|
---|
675 |
|
---|
676 | VMMR0CallHost(pVM, VMMCALLHOST_VMM_LOGGER_FLUSH, 0);
|
---|
677 | }
|
---|
678 |
|
---|
679 | #ifdef DEBUG_NO_RING0_ASSERTIONS
|
---|
680 | /**
|
---|
681 | * Check if we really want to hit a breakpoint.
|
---|
682 | * Can jump back to ring-3 when the longjmp is armed.
|
---|
683 | */
|
---|
684 | DECLEXPORT(bool) RTCALL RTAssertDoBreakpoint()
|
---|
685 | {
|
---|
686 | if (g_pVMAssert)
|
---|
687 | {
|
---|
688 | g_pVMAssert->vmm.s.enmCallHostOperation = VMMCALLHOST_VMM_LOGGER_FLUSH;
|
---|
689 | g_pVMAssert->vmm.s.u64CallHostArg = 0;
|
---|
690 | g_pVMAssert->vmm.s.rcCallHost = VERR_INTERNAL_ERROR;
|
---|
691 | int rc = vmmR0CallHostLongJmp(&g_pVMAssert->vmm.s.CallHostR0JmpBuf, VERR_INTERNAL_ERROR);
|
---|
692 | if (rc == VINF_SUCCESS)
|
---|
693 | rc = g_pVMAssert->vmm.s.rcCallHost;
|
---|
694 | }
|
---|
695 |
|
---|
696 | return true;
|
---|
697 | }
|
---|
698 |
|
---|
699 |
|
---|
700 | #undef LOG_GROUP
|
---|
701 | #define LOG_GROUP LOG_GROUP_EM
|
---|
702 |
|
---|
703 | /** Runtime assert implementation for Native Win32 Ring-0. */
|
---|
704 | DECLEXPORT(void) RTCALL AssertMsg1(const char *pszExpr, unsigned uLine, const char *pszFile, const char *pszFunction)
|
---|
705 | {
|
---|
706 | Log(("\n!!Assertion Failed!!\n"
|
---|
707 | "Expression: %s\n"
|
---|
708 | "Location : %s(%d) %s\n",
|
---|
709 | pszExpr, pszFile, uLine, pszFunction));
|
---|
710 | }
|
---|
711 |
|
---|
712 | #endif
|
---|