1 | /* $Id: MMAll.cpp 9212 2008-05-29 09:38:38Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * MM - Memory Monitor(/Manager) - Any Context.
|
---|
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_MM_HYPER
|
---|
27 | #include <VBox/mm.h>
|
---|
28 | #include "MMInternal.h"
|
---|
29 | #include <VBox/vm.h>
|
---|
30 | #include <VBox/log.h>
|
---|
31 | #include <iprt/assert.h>
|
---|
32 |
|
---|
33 |
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * Lookup a host context ring-3 address.
|
---|
37 | *
|
---|
38 | * @returns Pointer to the corresponding lookup record.
|
---|
39 | * @returns NULL on failure.
|
---|
40 | * @param pVM The VM handle.
|
---|
41 | * @param R3Ptr The host context ring-3 address to lookup.
|
---|
42 | * @param poff Where to store the offset into the HMA memory chunk.
|
---|
43 | */
|
---|
44 | DECLINLINE(PMMLOOKUPHYPER) mmHyperLookupR3(PVM pVM, RTR3PTR R3Ptr, uint32_t *poff)
|
---|
45 | {
|
---|
46 | /** @todo cache last lookup this stuff ain't cheap! */
|
---|
47 | PMMLOOKUPHYPER pLookup = (PMMLOOKUPHYPER)((char*)CTXSUFF(pVM->mm.s.pHyperHeap) + pVM->mm.s.offLookupHyper);
|
---|
48 | for (;;)
|
---|
49 | {
|
---|
50 | switch (pLookup->enmType)
|
---|
51 | {
|
---|
52 | case MMLOOKUPHYPERTYPE_LOCKED:
|
---|
53 | {
|
---|
54 | const uint32_t off = (RTR3UINTPTR)R3Ptr - (RTR3UINTPTR)pLookup->u.Locked.pvHC;
|
---|
55 | if (off < pLookup->cb)
|
---|
56 | {
|
---|
57 | *poff = off;
|
---|
58 | return pLookup;
|
---|
59 | }
|
---|
60 | break;
|
---|
61 | }
|
---|
62 |
|
---|
63 | case MMLOOKUPHYPERTYPE_HCPHYS:
|
---|
64 | {
|
---|
65 | const uint32_t off = (RTR3UINTPTR)R3Ptr - (RTR3UINTPTR)pLookup->u.HCPhys.pvHC;
|
---|
66 | if (off < pLookup->cb)
|
---|
67 | {
|
---|
68 | *poff = off;
|
---|
69 | return pLookup;
|
---|
70 | }
|
---|
71 | break;
|
---|
72 | }
|
---|
73 |
|
---|
74 | case MMLOOKUPHYPERTYPE_GCPHYS: /* (for now we'll not allow these kind of conversions) */
|
---|
75 | case MMLOOKUPHYPERTYPE_MMIO2:
|
---|
76 | case MMLOOKUPHYPERTYPE_DYNAMIC:
|
---|
77 | break;
|
---|
78 |
|
---|
79 | default:
|
---|
80 | AssertMsgFailed(("enmType=%d\n", pLookup->enmType));
|
---|
81 | break;
|
---|
82 | }
|
---|
83 |
|
---|
84 | /* next */
|
---|
85 | if (pLookup->offNext == (int32_t)NIL_OFFSET)
|
---|
86 | break;
|
---|
87 | pLookup = (PMMLOOKUPHYPER)((char *)pLookup + pLookup->offNext);
|
---|
88 | }
|
---|
89 |
|
---|
90 | AssertMsgFailed(("R3Ptr=%p is not inside the hypervisor memory area!\n", R3Ptr));
|
---|
91 | return NULL;
|
---|
92 | }
|
---|
93 |
|
---|
94 |
|
---|
95 | /**
|
---|
96 | * Lookup a host context ring-0 address.
|
---|
97 | *
|
---|
98 | * @returns Pointer to the corresponding lookup record.
|
---|
99 | * @returns NULL on failure.
|
---|
100 | * @param pVM The VM handle.
|
---|
101 | * @param R0Ptr The host context ring-0 address to lookup.
|
---|
102 | * @param poff Where to store the offset into the HMA memory chunk.
|
---|
103 | */
|
---|
104 | DECLINLINE(PMMLOOKUPHYPER) mmHyperLookupR0(PVM pVM, RTR0PTR R0Ptr, uint32_t *poff)
|
---|
105 | {
|
---|
106 | AssertCompile(sizeof(RTR0PTR) == sizeof(RTR3PTR));
|
---|
107 |
|
---|
108 | /*
|
---|
109 | * Translate Ring-0 VM addresses into Ring-3 VM addresses before feeding it to mmHyperLookupR3.
|
---|
110 | */
|
---|
111 | /** @todo fix this properly; the ring 0 pVM address differs from the R3 one. (#1865) */
|
---|
112 | RTR0UINTPTR offVM = (RTR0UINTPTR)R0Ptr - (RTR0UINTPTR)pVM->pVMR0;
|
---|
113 | RTR3PTR R3Ptr = offVM < sizeof(*pVM)
|
---|
114 | ? (RTR3PTR)((RTR3UINTPTR)pVM->pVMR3 + offVM)
|
---|
115 | : (RTR3PTR)R0Ptr;
|
---|
116 |
|
---|
117 | return mmHyperLookupR3(pVM, R3Ptr, poff);
|
---|
118 | }
|
---|
119 |
|
---|
120 |
|
---|
121 | /**
|
---|
122 | * Lookup a guest context address.
|
---|
123 | *
|
---|
124 | * @returns Pointer to the corresponding lookup record.
|
---|
125 | * @returns NULL on failure.
|
---|
126 | * @param pVM The VM handle.
|
---|
127 | * @param GCPtr The guest context address to lookup.
|
---|
128 | * @param poff Where to store the offset into the HMA memory chunk.
|
---|
129 | */
|
---|
130 | DECLINLINE(PMMLOOKUPHYPER) mmHyperLookupGC(PVM pVM, RTGCPTR GCPtr, uint32_t *poff)
|
---|
131 | {
|
---|
132 | /** @todo cache last lookup this stuff ain't cheap! */
|
---|
133 | unsigned offGC = (RTGCUINTPTR)GCPtr - (RTGCUINTPTR)pVM->mm.s.pvHyperAreaGC;
|
---|
134 | PMMLOOKUPHYPER pLookup = (PMMLOOKUPHYPER)((char*)CTXSUFF(pVM->mm.s.pHyperHeap) + pVM->mm.s.offLookupHyper);
|
---|
135 | for (;;)
|
---|
136 | {
|
---|
137 | const uint32_t off = offGC - pLookup->off;
|
---|
138 | if (off < pLookup->cb)
|
---|
139 | {
|
---|
140 | switch (pLookup->enmType)
|
---|
141 | {
|
---|
142 | case MMLOOKUPHYPERTYPE_LOCKED:
|
---|
143 | case MMLOOKUPHYPERTYPE_HCPHYS:
|
---|
144 | *poff = off;
|
---|
145 | return pLookup;
|
---|
146 | default:
|
---|
147 | break;
|
---|
148 | }
|
---|
149 | AssertMsgFailed(("enmType=%d\n", pLookup->enmType));
|
---|
150 | return NULL;
|
---|
151 | }
|
---|
152 |
|
---|
153 | /* next */
|
---|
154 | if (pLookup->offNext == (int32_t)NIL_OFFSET)
|
---|
155 | break;
|
---|
156 | pLookup = (PMMLOOKUPHYPER)((char *)pLookup + pLookup->offNext);
|
---|
157 | }
|
---|
158 |
|
---|
159 | AssertMsgFailed(("GCPtr=%p is not inside the hypervisor memory area!\n", GCPtr));
|
---|
160 | return NULL;
|
---|
161 | }
|
---|
162 |
|
---|
163 |
|
---|
164 | /**
|
---|
165 | * Lookup a current context address.
|
---|
166 | *
|
---|
167 | * @returns Pointer to the corresponding lookup record.
|
---|
168 | * @returns NULL on failure.
|
---|
169 | * @param pVM The VM handle.
|
---|
170 | * @param pv The current context address to lookup.
|
---|
171 | * @param poff Where to store the offset into the HMA memory chunk.
|
---|
172 | */
|
---|
173 | DECLINLINE(PMMLOOKUPHYPER) mmHyperLookupCC(PVM pVM, void *pv, uint32_t *poff)
|
---|
174 | {
|
---|
175 | #ifdef IN_GC
|
---|
176 | return mmHyperLookupGC(pVM, (RTGCPTR)pv, poff);
|
---|
177 | #elif defined(IN_RING0)
|
---|
178 | return mmHyperLookupR0(pVM, pv, poff);
|
---|
179 | #else
|
---|
180 | return mmHyperLookupR3(pVM, pv, poff);
|
---|
181 | #endif
|
---|
182 | }
|
---|
183 |
|
---|
184 |
|
---|
185 | /**
|
---|
186 | * Calculate the host context ring-3 address of an offset into the HMA memory chunk.
|
---|
187 | *
|
---|
188 | * @returns the host context ring-3 address.
|
---|
189 | * @param pLookup The HMA lookup record.
|
---|
190 | * @param off The offset into the HMA memory chunk.
|
---|
191 | */
|
---|
192 | DECLINLINE(RTR3PTR) mmHyperLookupCalcR3(PMMLOOKUPHYPER pLookup, uint32_t off)
|
---|
193 | {
|
---|
194 | switch (pLookup->enmType)
|
---|
195 | {
|
---|
196 | case MMLOOKUPHYPERTYPE_LOCKED:
|
---|
197 | return (RTR3PTR)((RTR3UINTPTR)pLookup->u.Locked.pvHC + off);
|
---|
198 | case MMLOOKUPHYPERTYPE_HCPHYS:
|
---|
199 | return (RTR3PTR)((RTR3UINTPTR)pLookup->u.HCPhys.pvHC + off);
|
---|
200 | default:
|
---|
201 | AssertMsgFailed(("enmType=%d\n", pLookup->enmType));
|
---|
202 | return NIL_RTR3PTR;
|
---|
203 | }
|
---|
204 | }
|
---|
205 |
|
---|
206 |
|
---|
207 | /**
|
---|
208 | * Calculate the host context ring-0 address of an offset into the HMA memory chunk.
|
---|
209 | *
|
---|
210 | * @returns the host context ring-0 address.
|
---|
211 | * @param pLookup The HMA lookup record.
|
---|
212 | * @param off The offset into the HMA memory chunk.
|
---|
213 | */
|
---|
214 | DECLINLINE(RTR0PTR) mmHyperLookupCalcR0(PMMLOOKUPHYPER pLookup, uint32_t off)
|
---|
215 | {
|
---|
216 | switch (pLookup->enmType)
|
---|
217 | {
|
---|
218 | case MMLOOKUPHYPERTYPE_LOCKED:
|
---|
219 | if (pLookup->u.Locked.pvR0)
|
---|
220 | return (RTR0PTR)((RTR0UINTPTR)pLookup->u.Locked.pvR0 + off);
|
---|
221 | return (RTR0PTR)((RTR3UINTPTR)pLookup->u.Locked.pvHC + off);
|
---|
222 | case MMLOOKUPHYPERTYPE_HCPHYS:
|
---|
223 | return (RTR0PTR)((RTR3UINTPTR)pLookup->u.HCPhys.pvHC + off);
|
---|
224 | default:
|
---|
225 | AssertMsgFailed(("enmType=%d\n", pLookup->enmType));
|
---|
226 | return NIL_RTR0PTR;
|
---|
227 | }
|
---|
228 | }
|
---|
229 |
|
---|
230 |
|
---|
231 | /**
|
---|
232 | * Calculate the guest context address of an offset into the HMA memory chunk.
|
---|
233 | *
|
---|
234 | * @returns the guest context base address.
|
---|
235 | * @param pVM The the VM handle.
|
---|
236 | * @param pLookup The HMA lookup record.
|
---|
237 | * @param off The offset into the HMA memory chunk.
|
---|
238 | */
|
---|
239 | DECLINLINE(RTGCPTR) mmHyperLookupCalcGC(PVM pVM, PMMLOOKUPHYPER pLookup, uint32_t off)
|
---|
240 | {
|
---|
241 | return (RTGCPTR)((RTGCUINTPTR)pVM->mm.s.pvHyperAreaGC + pLookup->off + off);
|
---|
242 | }
|
---|
243 |
|
---|
244 |
|
---|
245 | /**
|
---|
246 | * Calculate the guest context address of an offset into the HMA memory chunk.
|
---|
247 | *
|
---|
248 | * @returns the guest context base address.
|
---|
249 | * @param pVM The the VM handle.
|
---|
250 | * @param pLookup The HMA lookup record.
|
---|
251 | * @param off The offset into the HMA memory chunk.
|
---|
252 | */
|
---|
253 | DECLINLINE(void *) mmHyperLookupCalcCC(PVM pVM, PMMLOOKUPHYPER pLookup, uint32_t off)
|
---|
254 | {
|
---|
255 | #ifdef IN_GC
|
---|
256 | return (void *)mmHyperLookupCalcGC(pVM, pLookup, off);
|
---|
257 | #elif defined(IN_RING0)
|
---|
258 | return mmHyperLookupCalcR0(pLookup, off);
|
---|
259 | #else
|
---|
260 | return mmHyperLookupCalcR3(pLookup, off);
|
---|
261 | #endif
|
---|
262 | }
|
---|
263 |
|
---|
264 |
|
---|
265 | /**
|
---|
266 | * Converts a ring-0 host context address in the Hypervisor memory region to a ring-3 host context address.
|
---|
267 | *
|
---|
268 | * @returns ring-3 host context address.
|
---|
269 | * @param pVM The VM to operate on.
|
---|
270 | * @param R0Ptr The ring-0 host context address.
|
---|
271 | * You'll be damned if this is not in the HMA! :-)
|
---|
272 | * @thread The Emulation Thread.
|
---|
273 | */
|
---|
274 | MMDECL(RTR3PTR) MMHyperR0ToR3(PVM pVM, RTR0PTR R0Ptr)
|
---|
275 | {
|
---|
276 | uint32_t off;
|
---|
277 | PMMLOOKUPHYPER pLookup = mmHyperLookupR0(pVM, R0Ptr, &off);
|
---|
278 | if (pLookup)
|
---|
279 | return mmHyperLookupCalcR3(pLookup, off);
|
---|
280 | return NIL_RTR3PTR;
|
---|
281 | }
|
---|
282 |
|
---|
283 |
|
---|
284 | /**
|
---|
285 | * Converts a ring-0 host context address in the Hypervisor memory region to a guest context address.
|
---|
286 | *
|
---|
287 | * @returns guest context address.
|
---|
288 | * @param pVM The VM to operate on.
|
---|
289 | * @param R0Ptr The ring-0 host context address.
|
---|
290 | * You'll be damned if this is not in the HMA! :-)
|
---|
291 | * @thread The Emulation Thread.
|
---|
292 | */
|
---|
293 | MMDECL(RTGCPTR) MMHyperR0ToGC(PVM pVM, RTR0PTR R0Ptr)
|
---|
294 | {
|
---|
295 | uint32_t off;
|
---|
296 | PMMLOOKUPHYPER pLookup = mmHyperLookupR0(pVM, R0Ptr, &off);
|
---|
297 | if (pLookup)
|
---|
298 | return mmHyperLookupCalcGC(pVM, pLookup, off);
|
---|
299 | return NIL_RTGCPTR;
|
---|
300 | }
|
---|
301 |
|
---|
302 |
|
---|
303 | #ifndef IN_RING0
|
---|
304 | /**
|
---|
305 | * Converts a ring-0 host context address in the Hypervisor memory region to a current context address.
|
---|
306 | *
|
---|
307 | * @returns current context address.
|
---|
308 | * @param pVM The VM to operate on.
|
---|
309 | * @param R0Ptr The ring-0 host context address.
|
---|
310 | * You'll be damned if this is not in the HMA! :-)
|
---|
311 | * @thread The Emulation Thread.
|
---|
312 | */
|
---|
313 | MMDECL(void *) MMHyperR0ToCC(PVM pVM, RTR0PTR R0Ptr)
|
---|
314 | {
|
---|
315 | uint32_t off;
|
---|
316 | PMMLOOKUPHYPER pLookup = mmHyperLookupR0(pVM, R0Ptr, &off);
|
---|
317 | if (pLookup)
|
---|
318 | return mmHyperLookupCalcCC(pVM, pLookup, off);
|
---|
319 | return NULL;
|
---|
320 | }
|
---|
321 | #endif
|
---|
322 |
|
---|
323 |
|
---|
324 | /**
|
---|
325 | * Converts a ring-3 host context address in the Hypervisor memory region to a ring-0 host context address.
|
---|
326 | *
|
---|
327 | * @returns ring-0 host context address.
|
---|
328 | * @param pVM The VM to operate on.
|
---|
329 | * @param R3Ptr The ring-3 host context address.
|
---|
330 | * You'll be damned if this is not in the HMA! :-)
|
---|
331 | * @thread The Emulation Thread.
|
---|
332 | */
|
---|
333 | MMDECL(RTR0PTR) MMHyperR3ToR0(PVM pVM, RTR3PTR R3Ptr)
|
---|
334 | {
|
---|
335 | uint32_t off;
|
---|
336 | PMMLOOKUPHYPER pLookup = mmHyperLookupR3(pVM, R3Ptr, &off);
|
---|
337 | if (pLookup)
|
---|
338 | return mmHyperLookupCalcR0(pLookup, off);
|
---|
339 | AssertMsgFailed(("R3Ptr=%p is not inside the hypervisor memory area!\n", R3Ptr));
|
---|
340 | return NIL_RTR0PTR;
|
---|
341 | }
|
---|
342 |
|
---|
343 |
|
---|
344 | /**
|
---|
345 | * Converts a ring-3 host context address in the Hypervisor memory region to a guest context address.
|
---|
346 | *
|
---|
347 | * @returns guest context address.
|
---|
348 | * @param pVM The VM to operate on.
|
---|
349 | * @param R3Ptr The ring-3 host context address.
|
---|
350 | * You'll be damned if this is not in the HMA! :-)
|
---|
351 | * @thread The Emulation Thread.
|
---|
352 | */
|
---|
353 | MMDECL(RTGCPTR) MMHyperR3ToGC(PVM pVM, RTR3PTR R3Ptr)
|
---|
354 | {
|
---|
355 | uint32_t off;
|
---|
356 | PMMLOOKUPHYPER pLookup = mmHyperLookupR3(pVM, R3Ptr, &off);
|
---|
357 | if (pLookup)
|
---|
358 | return mmHyperLookupCalcGC(pVM, pLookup, off);
|
---|
359 | AssertMsgFailed(("R3Ptr=%p is not inside the hypervisor memory area!\n", R3Ptr));
|
---|
360 | return NIL_RTGCPTR;
|
---|
361 | }
|
---|
362 |
|
---|
363 |
|
---|
364 | /**
|
---|
365 | * Converts a ring-3 host context address in the Hypervisor memory region to a current context address.
|
---|
366 | *
|
---|
367 | * @returns current context address.
|
---|
368 | * @param pVM The VM to operate on.
|
---|
369 | * @param R3Ptr The ring-3 host context address.
|
---|
370 | * You'll be damned if this is not in the HMA! :-)
|
---|
371 | * @thread The Emulation Thread.
|
---|
372 | */
|
---|
373 | #ifndef IN_RING3
|
---|
374 | MMDECL(void *) MMHyperR3ToCC(PVM pVM, RTR3PTR R3Ptr)
|
---|
375 | {
|
---|
376 | uint32_t off;
|
---|
377 | PMMLOOKUPHYPER pLookup = mmHyperLookupR3(pVM, R3Ptr, &off);
|
---|
378 | if (pLookup)
|
---|
379 | return mmHyperLookupCalcCC(pVM, pLookup, off);
|
---|
380 | return NULL;
|
---|
381 | }
|
---|
382 | #endif
|
---|
383 |
|
---|
384 |
|
---|
385 | /**
|
---|
386 | * Converts a guest context address in the Hypervisor memory region to a ring-3 context address.
|
---|
387 | *
|
---|
388 | * @returns ring-3 host context address.
|
---|
389 | * @param pVM The VM to operate on.
|
---|
390 | * @param GCPtr The guest context address.
|
---|
391 | * You'll be damned if this is not in the HMA! :-)
|
---|
392 | * @thread The Emulation Thread.
|
---|
393 | */
|
---|
394 | MMDECL(RTR3PTR) MMHyperGCToR3(PVM pVM, RTGCPTR GCPtr)
|
---|
395 | {
|
---|
396 | uint32_t off;
|
---|
397 | PMMLOOKUPHYPER pLookup = mmHyperLookupGC(pVM, GCPtr, &off);
|
---|
398 | if (pLookup)
|
---|
399 | return mmHyperLookupCalcR3(pLookup, off);
|
---|
400 | return NIL_RTR3PTR;
|
---|
401 | }
|
---|
402 |
|
---|
403 |
|
---|
404 | /**
|
---|
405 | * Converts a guest context address in the Hypervisor memory region to a ring-0 host context address.
|
---|
406 | *
|
---|
407 | * @returns ring-0 host context address.
|
---|
408 | * @param pVM The VM to operate on.
|
---|
409 | * @param GCPtr The guest context address.
|
---|
410 | * You'll be damned if this is not in the HMA! :-)
|
---|
411 | * @thread The Emulation Thread.
|
---|
412 | */
|
---|
413 | MMDECL(RTR0PTR) MMHyperGCToR0(PVM pVM, RTGCPTR GCPtr)
|
---|
414 | {
|
---|
415 | uint32_t off;
|
---|
416 | PMMLOOKUPHYPER pLookup = mmHyperLookupGC(pVM, GCPtr, &off);
|
---|
417 | if (pLookup)
|
---|
418 | return mmHyperLookupCalcR0(pLookup, off);
|
---|
419 | return NIL_RTR0PTR;
|
---|
420 | }
|
---|
421 |
|
---|
422 |
|
---|
423 | /**
|
---|
424 | * Converts a guest context address in the Hypervisor memory region to a current context address.
|
---|
425 | *
|
---|
426 | * @returns current context address.
|
---|
427 | * @param pVM The VM to operate on.
|
---|
428 | * @param GCPtr The guest host context address.
|
---|
429 | * You'll be damned if this is not in the HMA! :-)
|
---|
430 | * @thread The Emulation Thread.
|
---|
431 | */
|
---|
432 | #ifndef IN_GC
|
---|
433 | MMDECL(void *) MMHyperGCToCC(PVM pVM, RTGCPTR GCPtr)
|
---|
434 | {
|
---|
435 | uint32_t off;
|
---|
436 | PMMLOOKUPHYPER pLookup = mmHyperLookupGC(pVM, GCPtr, &off);
|
---|
437 | if (pLookup)
|
---|
438 | return mmHyperLookupCalcCC(pVM, pLookup, off);
|
---|
439 | return NULL;
|
---|
440 | }
|
---|
441 | #endif
|
---|
442 |
|
---|
443 |
|
---|
444 |
|
---|
445 | /**
|
---|
446 | * Converts a current context address in the Hypervisor memory region to a ring-3 host context address.
|
---|
447 | *
|
---|
448 | * @returns ring-3 host context address.
|
---|
449 | * @param pVM The VM to operate on.
|
---|
450 | * @param pv The current context address.
|
---|
451 | * You'll be damned if this is not in the HMA! :-)
|
---|
452 | * @thread The Emulation Thread.
|
---|
453 | */
|
---|
454 | #ifndef IN_RING3
|
---|
455 | MMDECL(RTR3PTR) MMHyperCCToR3(PVM pVM, void *pv)
|
---|
456 | {
|
---|
457 | uint32_t off;
|
---|
458 | PMMLOOKUPHYPER pLookup = mmHyperLookupCC(pVM, pv, &off);
|
---|
459 | if (pLookup)
|
---|
460 | return mmHyperLookupCalcR3(pLookup, off);
|
---|
461 | return NIL_RTR3PTR;
|
---|
462 | }
|
---|
463 | #endif
|
---|
464 |
|
---|
465 | /**
|
---|
466 | * Converts a current context address in the Hypervisor memory region to a ring-0 host context address.
|
---|
467 | *
|
---|
468 | * @returns ring-0 host context address.
|
---|
469 | * @param pVM The VM to operate on.
|
---|
470 | * @param pv The current context address.
|
---|
471 | * You'll be damned if this is not in the HMA! :-)
|
---|
472 | * @thread The Emulation Thread.
|
---|
473 | */
|
---|
474 | #ifndef IN_RING0
|
---|
475 | MMDECL(RTR0PTR) MMHyperCCToR0(PVM pVM, void *pv)
|
---|
476 | {
|
---|
477 | uint32_t off;
|
---|
478 | PMMLOOKUPHYPER pLookup = mmHyperLookupCC(pVM, pv, &off);
|
---|
479 | if (pLookup)
|
---|
480 | return mmHyperLookupCalcR0(pLookup, off);
|
---|
481 | return NIL_RTR0PTR;
|
---|
482 | }
|
---|
483 | #endif
|
---|
484 |
|
---|
485 |
|
---|
486 | /**
|
---|
487 | * Converts a current context address in the Hypervisor memory region to a guest context address.
|
---|
488 | *
|
---|
489 | * @returns guest context address.
|
---|
490 | * @param pVM The VM to operate on.
|
---|
491 | * @param pv The current context address.
|
---|
492 | * You'll be damned if this is not in the HMA! :-)
|
---|
493 | * @thread The Emulation Thread.
|
---|
494 | */
|
---|
495 | #ifndef IN_GC
|
---|
496 | MMDECL(RCPTRTYPE(void *)) MMHyperCCToGC(PVM pVM, void *pv)
|
---|
497 | {
|
---|
498 | uint32_t off;
|
---|
499 | PMMLOOKUPHYPER pLookup = mmHyperLookupCC(pVM, pv, &off);
|
---|
500 | if (pLookup)
|
---|
501 | return mmHyperLookupCalcGC(pVM, pLookup, off);
|
---|
502 | return NIL_RTGCPTR;
|
---|
503 | }
|
---|
504 | #endif
|
---|
505 |
|
---|
506 |
|
---|
507 |
|
---|
508 | /**
|
---|
509 | * Converts a HC address in the Hypervisor memory region to a GC address.
|
---|
510 | * The memory must have been allocated with MMGCHyperAlloc() or MMR3HyperAlloc().
|
---|
511 | *
|
---|
512 | * @returns GC address.
|
---|
513 | * @param pVM The VM to operate on.
|
---|
514 | * @param HCPtr The host context address.
|
---|
515 | * You'll be damed if this is not in the hypervisor region! :-)
|
---|
516 | * @deprecated
|
---|
517 | */
|
---|
518 | MMDECL(RCPTRTYPE(void *)) MMHyperHC2GC(PVM pVM, RTHCPTR HCPtr)
|
---|
519 | {
|
---|
520 | PMMLOOKUPHYPER pLookup = (PMMLOOKUPHYPER)((char*)CTXSUFF(pVM->mm.s.pHyperHeap) + pVM->mm.s.offLookupHyper);
|
---|
521 | for (;;)
|
---|
522 | {
|
---|
523 | switch (pLookup->enmType)
|
---|
524 | {
|
---|
525 | case MMLOOKUPHYPERTYPE_LOCKED:
|
---|
526 | {
|
---|
527 | unsigned off = (RTHCUINTPTR)HCPtr - (RTHCUINTPTR)pLookup->u.Locked.pvHC;
|
---|
528 | if (off < pLookup->cb)
|
---|
529 | return (RCPTRTYPE(void *))((RTGCUINTPTR)pVM->mm.s.pvHyperAreaGC + pLookup->off + off);
|
---|
530 | break;
|
---|
531 | }
|
---|
532 |
|
---|
533 | case MMLOOKUPHYPERTYPE_HCPHYS:
|
---|
534 | {
|
---|
535 | unsigned off = (RTHCUINTPTR)HCPtr - (RTHCUINTPTR)pLookup->u.HCPhys.pvHC;
|
---|
536 | if (off < pLookup->cb)
|
---|
537 | return (RCPTRTYPE(void *))((RTGCUINTPTR)pVM->mm.s.pvHyperAreaGC + pLookup->off + off);
|
---|
538 | break;
|
---|
539 | }
|
---|
540 |
|
---|
541 | case MMLOOKUPHYPERTYPE_GCPHYS: /* (for now we'll not allow these kind of conversions) */
|
---|
542 | case MMLOOKUPHYPERTYPE_MMIO2:
|
---|
543 | case MMLOOKUPHYPERTYPE_DYNAMIC:
|
---|
544 | break;
|
---|
545 |
|
---|
546 | default:
|
---|
547 | AssertMsgFailed(("enmType=%d\n", pLookup->enmType));
|
---|
548 | break;
|
---|
549 | }
|
---|
550 |
|
---|
551 | /* next */
|
---|
552 | if ((unsigned)pLookup->offNext == NIL_OFFSET)
|
---|
553 | break;
|
---|
554 | pLookup = (PMMLOOKUPHYPER)((char *)pLookup + pLookup->offNext);
|
---|
555 | }
|
---|
556 |
|
---|
557 | AssertMsgFailed(("HCPtr=%p is not inside the hypervisor memory area!\n", HCPtr));
|
---|
558 | return (RCPTRTYPE(void *))0;
|
---|
559 | }
|
---|
560 |
|
---|
561 |
|
---|
562 | /**
|
---|
563 | * Converts a GC address in the Hypervisor memory region to a HC address.
|
---|
564 | * The memory must have been allocated with MMHyperAlloc().
|
---|
565 | *
|
---|
566 | * @returns HC address.
|
---|
567 | * @param pVM The VM to operate on.
|
---|
568 | * @param GCPtr The guest context address.
|
---|
569 | * You'll be damed if this is not in the hypervisor region! :-)
|
---|
570 | * @deprecated
|
---|
571 | */
|
---|
572 | MMDECL(RTHCPTR) MMHyperGC2HC(PVM pVM, RCPTRTYPE(void *) GCPtr)
|
---|
573 | {
|
---|
574 | unsigned offGC = (RTGCUINTPTR)GCPtr - (RTGCUINTPTR)pVM->mm.s.pvHyperAreaGC;
|
---|
575 | PMMLOOKUPHYPER pLookup = (PMMLOOKUPHYPER)((char*)CTXSUFF(pVM->mm.s.pHyperHeap) + pVM->mm.s.offLookupHyper);
|
---|
576 | for (;;)
|
---|
577 | {
|
---|
578 | unsigned off = offGC - pLookup->off;
|
---|
579 | if (off < pLookup->cb)
|
---|
580 | {
|
---|
581 | switch (pLookup->enmType)
|
---|
582 | {
|
---|
583 | case MMLOOKUPHYPERTYPE_LOCKED:
|
---|
584 | return (RTHCPTR)((RTHCUINTPTR)pLookup->u.Locked.pvHC + off);
|
---|
585 | case MMLOOKUPHYPERTYPE_HCPHYS:
|
---|
586 | return (RTHCPTR)((RTHCUINTPTR)pLookup->u.HCPhys.pvHC + off);
|
---|
587 | default:
|
---|
588 | break;
|
---|
589 | }
|
---|
590 | AssertMsgFailed(("enmType=%d\n", pLookup->enmType));
|
---|
591 | return (RTHCPTR)0;
|
---|
592 | }
|
---|
593 |
|
---|
594 | /* next */
|
---|
595 | if ((unsigned)pLookup->offNext == NIL_OFFSET)
|
---|
596 | break;
|
---|
597 | pLookup = (PMMLOOKUPHYPER)((char *)pLookup + pLookup->offNext);
|
---|
598 | }
|
---|
599 |
|
---|
600 | AssertMsgFailed(("GCPtr=%p is not inside the hypervisor memory area!\n", GCPtr));
|
---|
601 | return (RTHCPTR)0;
|
---|
602 | }
|
---|
603 |
|
---|
604 |
|
---|
605 | #ifdef IN_GC
|
---|
606 | /**
|
---|
607 | * Converts a current context address in the Hypervisor memory region to a HC address.
|
---|
608 | * The memory must have been allocated with MMGCHyperAlloc() or MMR3HyperAlloc().
|
---|
609 | *
|
---|
610 | * @returns HC address.
|
---|
611 | * @param pVM The VM to operate on.
|
---|
612 | * @param Ptr The current context address.
|
---|
613 | * @deprecated
|
---|
614 | */
|
---|
615 | MMDECL(RTHCPTR) MMHyper2HC(PVM pVM, uintptr_t Ptr)
|
---|
616 | {
|
---|
617 | return MMHyperGC2HC(pVM, (RCPTRTYPE(void *))Ptr);
|
---|
618 | }
|
---|
619 |
|
---|
620 | #else /* !IN_GC */
|
---|
621 |
|
---|
622 | /**
|
---|
623 | * Converts a current context address in the Hypervisor memory region to a GC address.
|
---|
624 | * The memory must have been allocated with MMHyperAlloc().
|
---|
625 | *
|
---|
626 | * @returns HC address.
|
---|
627 | * @param pVM The VM to operate on.
|
---|
628 | * @param Ptr The current context address.
|
---|
629 | * @thread The Emulation Thread.
|
---|
630 | * @deprecated
|
---|
631 | */
|
---|
632 | MMDECL(RCPTRTYPE(void *)) MMHyper2GC(PVM pVM, uintptr_t Ptr)
|
---|
633 | {
|
---|
634 | return MMHyperHC2GC(pVM, (RTHCPTR)Ptr);
|
---|
635 | }
|
---|
636 |
|
---|
637 | #endif /* !IN_GC */
|
---|