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