1 | /* $Id: MMAll.cpp 45618 2013-04-18 18:41:07Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * MM - Memory Manager - Any Context.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2012 Oracle Corporation
|
---|
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 |
|
---|
18 |
|
---|
19 | /*******************************************************************************
|
---|
20 | * Header Files *
|
---|
21 | *******************************************************************************/
|
---|
22 | #define LOG_GROUP LOG_GROUP_MM_HYPER
|
---|
23 | #include <VBox/vmm/mm.h>
|
---|
24 | #include <VBox/vmm/vmm.h>
|
---|
25 | #include "MMInternal.h"
|
---|
26 | #include <VBox/vmm/vm.h>
|
---|
27 | #include <VBox/log.h>
|
---|
28 | #include <iprt/assert.h>
|
---|
29 | #include <iprt/string.h>
|
---|
30 |
|
---|
31 |
|
---|
32 |
|
---|
33 | /**
|
---|
34 | * Lookup a host context ring-3 address.
|
---|
35 | *
|
---|
36 | * @returns Pointer to the corresponding lookup record.
|
---|
37 | * @returns NULL on failure.
|
---|
38 | * @param pVM Pointer to the VM.
|
---|
39 | * @param R3Ptr The host context ring-3 address to lookup.
|
---|
40 | * @param poff Where to store the offset into the HMA memory chunk.
|
---|
41 | */
|
---|
42 | DECLINLINE(PMMLOOKUPHYPER) mmHyperLookupR3(PVM pVM, RTR3PTR R3Ptr, uint32_t *poff)
|
---|
43 | {
|
---|
44 | /** @todo cache last lookup, this stuff ain't cheap! */
|
---|
45 | PMMLOOKUPHYPER pLookup = (PMMLOOKUPHYPER)((uint8_t *)pVM->mm.s.CTX_SUFF(pHyperHeap) + pVM->mm.s.offLookupHyper);
|
---|
46 | for (;;)
|
---|
47 | {
|
---|
48 | switch (pLookup->enmType)
|
---|
49 | {
|
---|
50 | case MMLOOKUPHYPERTYPE_LOCKED:
|
---|
51 | {
|
---|
52 | const RTR3UINTPTR off = (RTR3UINTPTR)R3Ptr - (RTR3UINTPTR)pLookup->u.Locked.pvR3;
|
---|
53 | if (off < pLookup->cb)
|
---|
54 | {
|
---|
55 | *poff = off;
|
---|
56 | return pLookup;
|
---|
57 | }
|
---|
58 | break;
|
---|
59 | }
|
---|
60 |
|
---|
61 | case MMLOOKUPHYPERTYPE_HCPHYS:
|
---|
62 | {
|
---|
63 | const RTR3UINTPTR off = (RTR3UINTPTR)R3Ptr - (RTR3UINTPTR)pLookup->u.HCPhys.pvR3;
|
---|
64 | if (off < pLookup->cb)
|
---|
65 | {
|
---|
66 | *poff = off;
|
---|
67 | return pLookup;
|
---|
68 | }
|
---|
69 | break;
|
---|
70 | }
|
---|
71 |
|
---|
72 | case MMLOOKUPHYPERTYPE_GCPHYS: /* (for now we'll not allow these kind of conversions) */
|
---|
73 | case MMLOOKUPHYPERTYPE_MMIO2:
|
---|
74 | case MMLOOKUPHYPERTYPE_DYNAMIC:
|
---|
75 | break;
|
---|
76 |
|
---|
77 | default:
|
---|
78 | AssertMsgFailed(("enmType=%d\n", pLookup->enmType));
|
---|
79 | break;
|
---|
80 | }
|
---|
81 |
|
---|
82 | /* next */
|
---|
83 | if (pLookup->offNext == (int32_t)NIL_OFFSET)
|
---|
84 | break;
|
---|
85 | pLookup = (PMMLOOKUPHYPER)((uint8_t *)pLookup + pLookup->offNext);
|
---|
86 | }
|
---|
87 |
|
---|
88 | AssertMsgFailed(("R3Ptr=%RHv is not inside the hypervisor memory area!\n", R3Ptr));
|
---|
89 | return NULL;
|
---|
90 | }
|
---|
91 |
|
---|
92 |
|
---|
93 | /**
|
---|
94 | * Lookup a host context ring-0 address.
|
---|
95 | *
|
---|
96 | * @returns Pointer to the corresponding lookup record.
|
---|
97 | * @returns NULL on failure.
|
---|
98 | * @param pVM Pointer to the VM.
|
---|
99 | * @param R0Ptr The host context ring-0 address to lookup.
|
---|
100 | * @param poff Where to store the offset into the HMA memory chunk.
|
---|
101 | */
|
---|
102 | DECLINLINE(PMMLOOKUPHYPER) mmHyperLookupR0(PVM pVM, RTR0PTR R0Ptr, uint32_t *poff)
|
---|
103 | {
|
---|
104 | AssertCompile(sizeof(RTR0PTR) == sizeof(RTR3PTR));
|
---|
105 |
|
---|
106 | /** @todo cache last lookup, this stuff ain't cheap! */
|
---|
107 | PMMLOOKUPHYPER pLookup = (PMMLOOKUPHYPER)((uint8_t *)pVM->mm.s.CTX_SUFF(pHyperHeap) + pVM->mm.s.offLookupHyper);
|
---|
108 | for (;;)
|
---|
109 | {
|
---|
110 | switch (pLookup->enmType)
|
---|
111 | {
|
---|
112 | case MMLOOKUPHYPERTYPE_LOCKED:
|
---|
113 | {
|
---|
114 | const RTR0UINTPTR off = (RTR0UINTPTR)R0Ptr - (RTR0UINTPTR)pLookup->u.Locked.pvR0;
|
---|
115 | if (off < pLookup->cb && pLookup->u.Locked.pvR0)
|
---|
116 | {
|
---|
117 | *poff = off;
|
---|
118 | return pLookup;
|
---|
119 | }
|
---|
120 | break;
|
---|
121 | }
|
---|
122 |
|
---|
123 | case MMLOOKUPHYPERTYPE_HCPHYS:
|
---|
124 | {
|
---|
125 | const RTR0UINTPTR off = (RTR0UINTPTR)R0Ptr - (RTR0UINTPTR)pLookup->u.HCPhys.pvR0;
|
---|
126 | if (off < pLookup->cb && pLookup->u.HCPhys.pvR0)
|
---|
127 | {
|
---|
128 | *poff = off;
|
---|
129 | return pLookup;
|
---|
130 | }
|
---|
131 | break;
|
---|
132 | }
|
---|
133 |
|
---|
134 | case MMLOOKUPHYPERTYPE_GCPHYS: /* (for now we'll not allow these kind of conversions) */
|
---|
135 | case MMLOOKUPHYPERTYPE_MMIO2:
|
---|
136 | case MMLOOKUPHYPERTYPE_DYNAMIC:
|
---|
137 | break;
|
---|
138 |
|
---|
139 | default:
|
---|
140 | AssertMsgFailed(("enmType=%d\n", pLookup->enmType));
|
---|
141 | break;
|
---|
142 | }
|
---|
143 |
|
---|
144 | /* next */
|
---|
145 | if (pLookup->offNext == (int32_t)NIL_OFFSET)
|
---|
146 | break;
|
---|
147 | pLookup = (PMMLOOKUPHYPER)((uint8_t *)pLookup + pLookup->offNext);
|
---|
148 | }
|
---|
149 |
|
---|
150 | AssertMsgFailed(("R0Ptr=%RHv is not inside the hypervisor memory area!\n", R0Ptr));
|
---|
151 | return NULL;
|
---|
152 | }
|
---|
153 |
|
---|
154 |
|
---|
155 | /**
|
---|
156 | * Lookup a raw-mode context address.
|
---|
157 | *
|
---|
158 | * @returns Pointer to the corresponding lookup record.
|
---|
159 | * @returns NULL on failure.
|
---|
160 | * @param pVM Pointer to the VM.
|
---|
161 | * @param RCPtr The raw-mode context address to lookup.
|
---|
162 | * @param poff Where to store the offset into the HMA memory chunk.
|
---|
163 | */
|
---|
164 | DECLINLINE(PMMLOOKUPHYPER) mmHyperLookupRC(PVM pVM, RTRCPTR RCPtr, uint32_t *poff)
|
---|
165 | {
|
---|
166 | /** @todo cache last lookup this stuff ain't cheap! */
|
---|
167 | unsigned offRC = (RTRCUINTPTR)RCPtr - (RTGCUINTPTR)pVM->mm.s.pvHyperAreaGC;
|
---|
168 | PMMLOOKUPHYPER pLookup = (PMMLOOKUPHYPER)((uint8_t *)pVM->mm.s.CTX_SUFF(pHyperHeap) + pVM->mm.s.offLookupHyper);
|
---|
169 | for (;;)
|
---|
170 | {
|
---|
171 | const uint32_t off = offRC - pLookup->off;
|
---|
172 | if (off < pLookup->cb)
|
---|
173 | {
|
---|
174 | switch (pLookup->enmType)
|
---|
175 | {
|
---|
176 | case MMLOOKUPHYPERTYPE_LOCKED:
|
---|
177 | case MMLOOKUPHYPERTYPE_HCPHYS:
|
---|
178 | *poff = off;
|
---|
179 | return pLookup;
|
---|
180 | default:
|
---|
181 | break;
|
---|
182 | }
|
---|
183 | AssertMsgFailed(("enmType=%d\n", pLookup->enmType));
|
---|
184 | *poff = 0; /* shut up gcc */
|
---|
185 | return NULL;
|
---|
186 | }
|
---|
187 |
|
---|
188 | /* next */
|
---|
189 | if (pLookup->offNext == (int32_t)NIL_OFFSET)
|
---|
190 | break;
|
---|
191 | pLookup = (PMMLOOKUPHYPER)((uint8_t *)pLookup + pLookup->offNext);
|
---|
192 | }
|
---|
193 |
|
---|
194 | AssertMsgFailed(("RCPtr=%RRv is not inside the hypervisor memory area!\n", RCPtr));
|
---|
195 | *poff = 0; /* shut up gcc */
|
---|
196 | return NULL;
|
---|
197 | }
|
---|
198 |
|
---|
199 |
|
---|
200 | /**
|
---|
201 | * Lookup a current context address.
|
---|
202 | *
|
---|
203 | * @returns Pointer to the corresponding lookup record.
|
---|
204 | * @returns NULL on failure.
|
---|
205 | * @param pVM Pointer to the VM.
|
---|
206 | * @param pv The current context address to lookup.
|
---|
207 | * @param poff Where to store the offset into the HMA memory chunk.
|
---|
208 | */
|
---|
209 | DECLINLINE(PMMLOOKUPHYPER) mmHyperLookupCC(PVM pVM, void *pv, uint32_t *poff)
|
---|
210 | {
|
---|
211 | #ifdef IN_RC
|
---|
212 | return mmHyperLookupRC(pVM, (RTRCPTR)pv, poff);
|
---|
213 | #elif defined(IN_RING0)
|
---|
214 | return mmHyperLookupR0(pVM, pv, poff);
|
---|
215 | #else
|
---|
216 | return mmHyperLookupR3(pVM, pv, poff);
|
---|
217 | #endif
|
---|
218 | }
|
---|
219 |
|
---|
220 |
|
---|
221 | /**
|
---|
222 | * Calculate the host context ring-3 address of an offset into the HMA memory chunk.
|
---|
223 | *
|
---|
224 | * @returns the host context ring-3 address.
|
---|
225 | * @param pLookup The HMA lookup record.
|
---|
226 | * @param off The offset into the HMA memory chunk.
|
---|
227 | */
|
---|
228 | DECLINLINE(RTR3PTR) mmHyperLookupCalcR3(PMMLOOKUPHYPER pLookup, uint32_t off)
|
---|
229 | {
|
---|
230 | switch (pLookup->enmType)
|
---|
231 | {
|
---|
232 | case MMLOOKUPHYPERTYPE_LOCKED:
|
---|
233 | return (RTR3PTR)((RTR3UINTPTR)pLookup->u.Locked.pvR3 + off);
|
---|
234 | case MMLOOKUPHYPERTYPE_HCPHYS:
|
---|
235 | return (RTR3PTR)((RTR3UINTPTR)pLookup->u.HCPhys.pvR3 + off);
|
---|
236 | default:
|
---|
237 | AssertMsgFailed(("enmType=%d\n", pLookup->enmType));
|
---|
238 | return NIL_RTR3PTR;
|
---|
239 | }
|
---|
240 | }
|
---|
241 |
|
---|
242 |
|
---|
243 | /**
|
---|
244 | * Calculate the host context ring-0 address of an offset into the HMA memory chunk.
|
---|
245 | *
|
---|
246 | * @returns the host context ring-0 address.
|
---|
247 | * @param pVM Pointer to the VM.
|
---|
248 | * @param pLookup The HMA lookup record.
|
---|
249 | * @param off The offset into the HMA memory chunk.
|
---|
250 | */
|
---|
251 | DECLINLINE(RTR0PTR) mmHyperLookupCalcR0(PVM pVM, PMMLOOKUPHYPER pLookup, uint32_t off)
|
---|
252 | {
|
---|
253 | switch (pLookup->enmType)
|
---|
254 | {
|
---|
255 | case MMLOOKUPHYPERTYPE_LOCKED:
|
---|
256 | if (pLookup->u.Locked.pvR0)
|
---|
257 | return (RTR0PTR)((RTR0UINTPTR)pLookup->u.Locked.pvR0 + off);
|
---|
258 | #ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
|
---|
259 | AssertMsg(!HMIsEnabled(pVM), ("%s\n", R3STRING(pLookup->pszDesc)));
|
---|
260 | #else
|
---|
261 | AssertMsgFailed(("%s\n", R3STRING(pLookup->pszDesc))); NOREF(pVM);
|
---|
262 | #endif
|
---|
263 | return NIL_RTR0PTR;
|
---|
264 |
|
---|
265 | case MMLOOKUPHYPERTYPE_HCPHYS:
|
---|
266 | if (pLookup->u.HCPhys.pvR0)
|
---|
267 | return (RTR0PTR)((RTR0UINTPTR)pLookup->u.HCPhys.pvR0 + off);
|
---|
268 | AssertMsgFailed(("%s\n", R3STRING(pLookup->pszDesc)));
|
---|
269 | return NIL_RTR0PTR;
|
---|
270 |
|
---|
271 | default:
|
---|
272 | AssertMsgFailed(("enmType=%d\n", pLookup->enmType));
|
---|
273 | return NIL_RTR0PTR;
|
---|
274 | }
|
---|
275 | }
|
---|
276 |
|
---|
277 |
|
---|
278 | /**
|
---|
279 | * Calculate the raw-mode context address of an offset into the HMA memory chunk.
|
---|
280 | *
|
---|
281 | * @returns the raw-mode context base address.
|
---|
282 | * @param pVM Pointer to the VM.
|
---|
283 | * @param pLookup The HMA lookup record.
|
---|
284 | * @param off The offset into the HMA memory chunk.
|
---|
285 | */
|
---|
286 | DECLINLINE(RTRCPTR) mmHyperLookupCalcRC(PVM pVM, PMMLOOKUPHYPER pLookup, uint32_t off)
|
---|
287 | {
|
---|
288 | return (RTRCPTR)((RTRCUINTPTR)pVM->mm.s.pvHyperAreaGC + pLookup->off + off);
|
---|
289 | }
|
---|
290 |
|
---|
291 |
|
---|
292 | /**
|
---|
293 | * Calculate the guest context address of an offset into the HMA memory chunk.
|
---|
294 | *
|
---|
295 | * @returns the guest context base address.
|
---|
296 | * @param pVM Pointer to the VM.
|
---|
297 | * @param pLookup The HMA lookup record.
|
---|
298 | * @param off The offset into the HMA memory chunk.
|
---|
299 | */
|
---|
300 | DECLINLINE(void *) mmHyperLookupCalcCC(PVM pVM, PMMLOOKUPHYPER pLookup, uint32_t off)
|
---|
301 | {
|
---|
302 | #ifdef IN_RC
|
---|
303 | return (void *)mmHyperLookupCalcRC(pVM, pLookup, off);
|
---|
304 | #elif defined(IN_RING0)
|
---|
305 | return mmHyperLookupCalcR0(pVM, pLookup, off);
|
---|
306 | #else
|
---|
307 | NOREF(pVM);
|
---|
308 | return mmHyperLookupCalcR3(pLookup, off);
|
---|
309 | #endif
|
---|
310 | }
|
---|
311 |
|
---|
312 |
|
---|
313 | /**
|
---|
314 | * Converts a ring-0 host context address in the Hypervisor memory region to a ring-3 host context address.
|
---|
315 | *
|
---|
316 | * @returns ring-3 host context address.
|
---|
317 | * @param pVM Pointer to the VM.
|
---|
318 | * @param R0Ptr The ring-0 host context address.
|
---|
319 | * You'll be damned if this is not in the HMA! :-)
|
---|
320 | * @thread The Emulation Thread.
|
---|
321 | */
|
---|
322 | VMMDECL(RTR3PTR) MMHyperR0ToR3(PVM pVM, RTR0PTR R0Ptr)
|
---|
323 | {
|
---|
324 | uint32_t off;
|
---|
325 | PMMLOOKUPHYPER pLookup = mmHyperLookupR0(pVM, R0Ptr, &off);
|
---|
326 | if (pLookup)
|
---|
327 | return mmHyperLookupCalcR3(pLookup, off);
|
---|
328 | return NIL_RTR3PTR;
|
---|
329 | }
|
---|
330 |
|
---|
331 |
|
---|
332 | /**
|
---|
333 | * Converts a ring-0 host context address in the Hypervisor memory region to a raw-mode context address.
|
---|
334 | *
|
---|
335 | * @returns raw-mode context address.
|
---|
336 | * @param pVM Pointer to the VM.
|
---|
337 | * @param R0Ptr The ring-0 host context address.
|
---|
338 | * You'll be damned if this is not in the HMA! :-)
|
---|
339 | * @thread The Emulation Thread.
|
---|
340 | */
|
---|
341 | VMMDECL(RTRCPTR) MMHyperR0ToRC(PVM pVM, RTR0PTR R0Ptr)
|
---|
342 | {
|
---|
343 | uint32_t off;
|
---|
344 | PMMLOOKUPHYPER pLookup = mmHyperLookupR0(pVM, R0Ptr, &off);
|
---|
345 | if (pLookup)
|
---|
346 | return mmHyperLookupCalcRC(pVM, pLookup, off);
|
---|
347 | return NIL_RTRCPTR;
|
---|
348 | }
|
---|
349 |
|
---|
350 |
|
---|
351 | #ifndef IN_RING0
|
---|
352 | /**
|
---|
353 | * Converts a ring-0 host context address in the Hypervisor memory region to a current context address.
|
---|
354 | *
|
---|
355 | * @returns current context address.
|
---|
356 | * @param pVM Pointer to the VM.
|
---|
357 | * @param R0Ptr The ring-0 host context address.
|
---|
358 | * You'll be damned if this is not in the HMA! :-)
|
---|
359 | * @thread The Emulation Thread.
|
---|
360 | */
|
---|
361 | VMMDECL(void *) MMHyperR0ToCC(PVM pVM, RTR0PTR R0Ptr)
|
---|
362 | {
|
---|
363 | uint32_t off;
|
---|
364 | PMMLOOKUPHYPER pLookup = mmHyperLookupR0(pVM, R0Ptr, &off);
|
---|
365 | if (pLookup)
|
---|
366 | return mmHyperLookupCalcCC(pVM, pLookup, off);
|
---|
367 | return NULL;
|
---|
368 | }
|
---|
369 | #endif
|
---|
370 |
|
---|
371 |
|
---|
372 | /**
|
---|
373 | * Converts a ring-3 host context address in the Hypervisor memory region to a ring-0 host context address.
|
---|
374 | *
|
---|
375 | * @returns ring-0 host context address.
|
---|
376 | * @param pVM Pointer to the VM.
|
---|
377 | * @param R3Ptr The ring-3 host context address.
|
---|
378 | * You'll be damned if this is not in the HMA! :-)
|
---|
379 | * @thread The Emulation Thread.
|
---|
380 | */
|
---|
381 | VMMDECL(RTR0PTR) MMHyperR3ToR0(PVM pVM, RTR3PTR R3Ptr)
|
---|
382 | {
|
---|
383 | uint32_t off;
|
---|
384 | PMMLOOKUPHYPER pLookup = mmHyperLookupR3(pVM, R3Ptr, &off);
|
---|
385 | if (pLookup)
|
---|
386 | return mmHyperLookupCalcR0(pVM, pLookup, off);
|
---|
387 | AssertMsgFailed(("R3Ptr=%p is not inside the hypervisor memory area!\n", R3Ptr));
|
---|
388 | return NIL_RTR0PTR;
|
---|
389 | }
|
---|
390 |
|
---|
391 |
|
---|
392 | /**
|
---|
393 | * Converts a ring-3 host context address in the Hypervisor memory region to a guest context address.
|
---|
394 | *
|
---|
395 | * @returns guest context address.
|
---|
396 | * @param pVM Pointer to the VM.
|
---|
397 | * @param R3Ptr The ring-3 host context address.
|
---|
398 | * You'll be damned if this is not in the HMA! :-)
|
---|
399 | * @thread The Emulation Thread.
|
---|
400 | */
|
---|
401 | VMMDECL(RTRCPTR) MMHyperR3ToRC(PVM pVM, RTR3PTR R3Ptr)
|
---|
402 | {
|
---|
403 | uint32_t off;
|
---|
404 | PMMLOOKUPHYPER pLookup = mmHyperLookupR3(pVM, R3Ptr, &off);
|
---|
405 | if (pLookup)
|
---|
406 | return mmHyperLookupCalcRC(pVM, pLookup, off);
|
---|
407 | AssertMsgFailed(("R3Ptr=%p is not inside the hypervisor memory area!\n", R3Ptr));
|
---|
408 | return NIL_RTRCPTR;
|
---|
409 | }
|
---|
410 |
|
---|
411 |
|
---|
412 | #ifndef IN_RING3
|
---|
413 | /**
|
---|
414 | * Converts a ring-3 host context address in the Hypervisor memory region to a current context address.
|
---|
415 | *
|
---|
416 | * @returns current context address.
|
---|
417 | * @param pVM Pointer to the VM.
|
---|
418 | * @param R3Ptr The ring-3 host context address.
|
---|
419 | * You'll be damned if this is not in the HMA! :-)
|
---|
420 | * @thread The Emulation Thread.
|
---|
421 | */
|
---|
422 | VMMDECL(void *) MMHyperR3ToCC(PVM pVM, RTR3PTR R3Ptr)
|
---|
423 | {
|
---|
424 | uint32_t off;
|
---|
425 | PMMLOOKUPHYPER pLookup = mmHyperLookupR3(pVM, R3Ptr, &off);
|
---|
426 | if (pLookup)
|
---|
427 | return mmHyperLookupCalcCC(pVM, pLookup, off);
|
---|
428 | return NULL;
|
---|
429 | }
|
---|
430 | #endif
|
---|
431 |
|
---|
432 |
|
---|
433 | /**
|
---|
434 | * Converts a raw-mode context address in the Hypervisor memory region to a ring-3 context address.
|
---|
435 | *
|
---|
436 | * @returns ring-3 host context address.
|
---|
437 | * @param pVM Pointer to the VM.
|
---|
438 | * @param GCPtr The raw-mode context address.
|
---|
439 | * You'll be damned if this is not in the HMA! :-)
|
---|
440 | * @thread The Emulation Thread.
|
---|
441 | */
|
---|
442 | VMMDECL(RTR3PTR) MMHyperRCToR3(PVM pVM, RTRCPTR RCPtr)
|
---|
443 | {
|
---|
444 | uint32_t off;
|
---|
445 | PMMLOOKUPHYPER pLookup = mmHyperLookupRC(pVM, RCPtr, &off);
|
---|
446 | if (pLookup)
|
---|
447 | return mmHyperLookupCalcR3(pLookup, off);
|
---|
448 | return NIL_RTR3PTR;
|
---|
449 | }
|
---|
450 |
|
---|
451 |
|
---|
452 | /**
|
---|
453 | * Converts a raw-mode context address in the Hypervisor memory region to a ring-0 host context address.
|
---|
454 | *
|
---|
455 | * @returns ring-0 host context address.
|
---|
456 | * @param pVM Pointer to the VM.
|
---|
457 | * @param RCPtr The raw-mode context address.
|
---|
458 | * You'll be damned if this is not in the HMA! :-)
|
---|
459 | * @thread The Emulation Thread.
|
---|
460 | */
|
---|
461 | VMMDECL(RTR0PTR) MMHyperRCToR0(PVM pVM, RTRCPTR RCPtr)
|
---|
462 | {
|
---|
463 | uint32_t off;
|
---|
464 | PMMLOOKUPHYPER pLookup = mmHyperLookupRC(pVM, RCPtr, &off);
|
---|
465 | if (pLookup)
|
---|
466 | return mmHyperLookupCalcR0(pVM, pLookup, off);
|
---|
467 | return NIL_RTR0PTR;
|
---|
468 | }
|
---|
469 |
|
---|
470 | #ifndef IN_RC
|
---|
471 | /**
|
---|
472 | * Converts a raw-mode context address in the Hypervisor memory region to a current context address.
|
---|
473 | *
|
---|
474 | * @returns current context address.
|
---|
475 | * @param pVM Pointer to the VM.
|
---|
476 | * @param RCPtr The raw-mode host context address.
|
---|
477 | * You'll be damned if this is not in the HMA! :-)
|
---|
478 | * @thread The Emulation Thread.
|
---|
479 | */
|
---|
480 | VMMDECL(void *) MMHyperRCToCC(PVM pVM, RTRCPTR RCPtr)
|
---|
481 | {
|
---|
482 | uint32_t off;
|
---|
483 | PMMLOOKUPHYPER pLookup = mmHyperLookupRC(pVM, RCPtr, &off);
|
---|
484 | if (pLookup)
|
---|
485 | return mmHyperLookupCalcCC(pVM, pLookup, off);
|
---|
486 | return NULL;
|
---|
487 | }
|
---|
488 | #endif
|
---|
489 |
|
---|
490 | #ifndef IN_RING3
|
---|
491 | /**
|
---|
492 | * Converts a current context address in the Hypervisor memory region to a ring-3 host context address.
|
---|
493 | *
|
---|
494 | * @returns ring-3 host context address.
|
---|
495 | * @param pVM Pointer to the VM.
|
---|
496 | * @param pv The current context address.
|
---|
497 | * You'll be damned if this is not in the HMA! :-)
|
---|
498 | * @thread The Emulation Thread.
|
---|
499 | */
|
---|
500 | VMMDECL(RTR3PTR) MMHyperCCToR3(PVM pVM, void *pv)
|
---|
501 | {
|
---|
502 | uint32_t off;
|
---|
503 | PMMLOOKUPHYPER pLookup = mmHyperLookupCC(pVM, pv, &off);
|
---|
504 | if (pLookup)
|
---|
505 | return mmHyperLookupCalcR3(pLookup, off);
|
---|
506 | return NIL_RTR3PTR;
|
---|
507 | }
|
---|
508 | #endif
|
---|
509 |
|
---|
510 | #ifndef IN_RING0
|
---|
511 | /**
|
---|
512 | * Converts a current context address in the Hypervisor memory region to a ring-0 host context address.
|
---|
513 | *
|
---|
514 | * @returns ring-0 host context address.
|
---|
515 | * @param pVM Pointer to the VM.
|
---|
516 | * @param pv The current context address.
|
---|
517 | * You'll be damned if this is not in the HMA! :-)
|
---|
518 | * @thread The Emulation Thread.
|
---|
519 | */
|
---|
520 | VMMDECL(RTR0PTR) MMHyperCCToR0(PVM pVM, void *pv)
|
---|
521 | {
|
---|
522 | uint32_t off;
|
---|
523 | PMMLOOKUPHYPER pLookup = mmHyperLookupCC(pVM, pv, &off);
|
---|
524 | if (pLookup)
|
---|
525 | return mmHyperLookupCalcR0(pVM, pLookup, off);
|
---|
526 | return NIL_RTR0PTR;
|
---|
527 | }
|
---|
528 | #endif
|
---|
529 |
|
---|
530 |
|
---|
531 | #ifndef IN_RC
|
---|
532 | /**
|
---|
533 | * Converts a current context address in the Hypervisor memory region to a raw-mode context address.
|
---|
534 | *
|
---|
535 | * @returns guest context address.
|
---|
536 | * @param pVM Pointer to the VM.
|
---|
537 | * @param pv The current context address.
|
---|
538 | * You'll be damned if this is not in the HMA! :-)
|
---|
539 | * @thread The Emulation Thread.
|
---|
540 | */
|
---|
541 | VMMDECL(RTRCPTR) MMHyperCCToRC(PVM pVM, void *pv)
|
---|
542 | {
|
---|
543 | uint32_t off;
|
---|
544 | PMMLOOKUPHYPER pLookup = mmHyperLookupCC(pVM, pv, &off);
|
---|
545 | if (pLookup)
|
---|
546 | return mmHyperLookupCalcRC(pVM, pLookup, off);
|
---|
547 | return NIL_RTRCPTR;
|
---|
548 | }
|
---|
549 | #endif
|
---|
550 |
|
---|
551 |
|
---|
552 | /**
|
---|
553 | * Gets the string name of a memory tag.
|
---|
554 | *
|
---|
555 | * @returns name of enmTag.
|
---|
556 | * @param enmTag The tag.
|
---|
557 | */
|
---|
558 | const char *mmGetTagName(MMTAG enmTag)
|
---|
559 | {
|
---|
560 | switch (enmTag)
|
---|
561 | {
|
---|
562 | #define TAG2STR(tag) case MM_TAG_##tag: return #tag
|
---|
563 |
|
---|
564 | TAG2STR(CFGM);
|
---|
565 | TAG2STR(CFGM_BYTES);
|
---|
566 | TAG2STR(CFGM_STRING);
|
---|
567 | TAG2STR(CFGM_USER);
|
---|
568 |
|
---|
569 | TAG2STR(CSAM);
|
---|
570 | TAG2STR(CSAM_PATCH);
|
---|
571 |
|
---|
572 | TAG2STR(DBGF);
|
---|
573 | TAG2STR(DBGF_AS);
|
---|
574 | TAG2STR(DBGF_INFO);
|
---|
575 | TAG2STR(DBGF_LINE);
|
---|
576 | TAG2STR(DBGF_LINE_DUP);
|
---|
577 | TAG2STR(DBGF_MODULE);
|
---|
578 | TAG2STR(DBGF_OS);
|
---|
579 | TAG2STR(DBGF_REG);
|
---|
580 | TAG2STR(DBGF_STACK);
|
---|
581 | TAG2STR(DBGF_SYMBOL);
|
---|
582 | TAG2STR(DBGF_SYMBOL_DUP);
|
---|
583 |
|
---|
584 | TAG2STR(EM);
|
---|
585 |
|
---|
586 | TAG2STR(IOM);
|
---|
587 | TAG2STR(IOM_STATS);
|
---|
588 |
|
---|
589 | TAG2STR(MM);
|
---|
590 | TAG2STR(MM_LOOKUP_GUEST);
|
---|
591 | TAG2STR(MM_LOOKUP_PHYS);
|
---|
592 | TAG2STR(MM_LOOKUP_VIRT);
|
---|
593 | TAG2STR(MM_PAGE);
|
---|
594 |
|
---|
595 | TAG2STR(PARAV);
|
---|
596 |
|
---|
597 | TAG2STR(PATM);
|
---|
598 | TAG2STR(PATM_PATCH);
|
---|
599 |
|
---|
600 | TAG2STR(PDM);
|
---|
601 | TAG2STR(PDM_DEVICE);
|
---|
602 | TAG2STR(PDM_DEVICE_DESC);
|
---|
603 | TAG2STR(PDM_DEVICE_USER);
|
---|
604 | TAG2STR(PDM_DRIVER);
|
---|
605 | TAG2STR(PDM_DRIVER_DESC);
|
---|
606 | TAG2STR(PDM_DRIVER_USER);
|
---|
607 | TAG2STR(PDM_USB);
|
---|
608 | TAG2STR(PDM_USB_DESC);
|
---|
609 | TAG2STR(PDM_USB_USER);
|
---|
610 | TAG2STR(PDM_LUN);
|
---|
611 | TAG2STR(PDM_QUEUE);
|
---|
612 | TAG2STR(PDM_THREAD);
|
---|
613 | TAG2STR(PDM_ASYNC_COMPLETION);
|
---|
614 | #ifdef VBOX_WITH_NETSHAPER
|
---|
615 | TAG2STR(PDM_NET_SHAPER);
|
---|
616 | #endif /* VBOX_WITH_NETSHAPER */
|
---|
617 |
|
---|
618 | TAG2STR(PGM);
|
---|
619 | TAG2STR(PGM_CHUNK_MAPPING);
|
---|
620 | TAG2STR(PGM_HANDLERS);
|
---|
621 | TAG2STR(PGM_MAPPINGS);
|
---|
622 | TAG2STR(PGM_PHYS);
|
---|
623 | TAG2STR(PGM_POOL);
|
---|
624 |
|
---|
625 | TAG2STR(REM);
|
---|
626 |
|
---|
627 | TAG2STR(SELM);
|
---|
628 |
|
---|
629 | TAG2STR(SSM);
|
---|
630 |
|
---|
631 | TAG2STR(STAM);
|
---|
632 |
|
---|
633 | TAG2STR(TM);
|
---|
634 |
|
---|
635 | TAG2STR(TRPM);
|
---|
636 |
|
---|
637 | TAG2STR(VM);
|
---|
638 | TAG2STR(VM_REQ);
|
---|
639 |
|
---|
640 | TAG2STR(VMM);
|
---|
641 |
|
---|
642 | TAG2STR(HM);
|
---|
643 |
|
---|
644 | #undef TAG2STR
|
---|
645 |
|
---|
646 | default:
|
---|
647 | {
|
---|
648 | AssertMsgFailed(("Unknown tag %d! forgot to add it to the switch?\n", enmTag));
|
---|
649 | #ifdef IN_RING3
|
---|
650 | static char sz[48];
|
---|
651 | RTStrPrintf(sz, sizeof(sz), "%d", enmTag);
|
---|
652 | return sz;
|
---|
653 | #else
|
---|
654 | return "unknown tag!";
|
---|
655 | #endif
|
---|
656 | }
|
---|
657 | }
|
---|
658 | }
|
---|
659 |
|
---|