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