VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMAll/MMAll.cpp@ 93628

Last change on this file since 93628 was 93626, checked in by vboxsync, 3 years ago

VMM/MMHyper: Removed unused code. [build fix] bugref:10093

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 9.3 KB
Line 
1/* $Id: MMAll.cpp 93626 2022-02-06 18:04:51Z vboxsync $ */
2/** @file
3 * MM - Memory Manager - Any Context.
4 */
5
6/*
7 * Copyright (C) 2006-2022 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/vmcc.h>
27#include <VBox/vmm/hm.h>
28#include <VBox/log.h>
29#include <iprt/assert.h>
30#include <iprt/string.h>
31
32
33
34/**
35 * Lookup a host context ring-3 address.
36 *
37 * @returns Pointer to the corresponding lookup record.
38 * @returns NULL on failure.
39 * @param pVM The cross context VM structure.
40 * @param R3Ptr The host context ring-3 address to lookup.
41 * @param poff Where to store the offset into the HMA memory chunk.
42 */
43DECLINLINE(PMMLOOKUPHYPER) mmHyperLookupR3(PVM pVM, RTR3PTR R3Ptr, uint32_t *poff)
44{
45 /** @todo cache last lookup, this stuff ain't cheap! */
46 PMMLOOKUPHYPER pLookup = (PMMLOOKUPHYPER)((uint8_t *)pVM->mm.s.CTX_SUFF(pHyperHeap) + pVM->mm.s.offLookupHyper);
47 for (;;)
48 {
49 switch (pLookup->enmType)
50 {
51 case MMLOOKUPHYPERTYPE_LOCKED:
52 {
53 const RTR3UINTPTR off = (RTR3UINTPTR)R3Ptr - (RTR3UINTPTR)pLookup->u.Locked.pvR3;
54 if (off < pLookup->cb)
55 {
56 *poff = off;
57 return pLookup;
58 }
59 break;
60 }
61
62 case MMLOOKUPHYPERTYPE_HCPHYS:
63 {
64 const RTR3UINTPTR off = (RTR3UINTPTR)R3Ptr - (RTR3UINTPTR)pLookup->u.HCPhys.pvR3;
65 if (off < pLookup->cb)
66 {
67 *poff = off;
68 return pLookup;
69 }
70 break;
71 }
72
73 case MMLOOKUPHYPERTYPE_GCPHYS: /* (for now we'll not allow these kind of conversions) */
74 case MMLOOKUPHYPERTYPE_MMIO2:
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)((uint8_t *)pLookup + pLookup->offNext);
87 }
88
89 AssertMsgFailed(("R3Ptr=%RHv is not inside the hypervisor memory area!\n", R3Ptr));
90 return NULL;
91}
92
93
94#ifdef IN_RING3
95/**
96 * Lookup a current context address.
97 *
98 * @returns Pointer to the corresponding lookup record.
99 * @returns NULL on failure.
100 * @param pVM The cross context VM structure.
101 * @param pv The current context address to lookup.
102 * @param poff Where to store the offset into the HMA memory chunk.
103 */
104DECLINLINE(PMMLOOKUPHYPER) mmHyperLookupCC(PVM pVM, void *pv, uint32_t *poff)
105{
106 return mmHyperLookupR3(pVM, pv, poff);
107}
108#endif
109
110
111#ifdef IN_RING3
112/**
113 * Calculate the host context ring-3 address of an offset into the HMA memory chunk.
114 *
115 * @returns the host context ring-3 address.
116 * @param pLookup The HMA lookup record.
117 * @param off The offset into the HMA memory chunk.
118 */
119DECLINLINE(RTR3PTR) mmHyperLookupCalcR3(PMMLOOKUPHYPER pLookup, uint32_t off)
120{
121 switch (pLookup->enmType)
122 {
123 case MMLOOKUPHYPERTYPE_LOCKED:
124 return (RTR3PTR)((RTR3UINTPTR)pLookup->u.Locked.pvR3 + off);
125 case MMLOOKUPHYPERTYPE_HCPHYS:
126 return (RTR3PTR)((RTR3UINTPTR)pLookup->u.HCPhys.pvR3 + off);
127 default:
128 AssertMsgFailed(("enmType=%d\n", pLookup->enmType));
129 return NIL_RTR3PTR;
130 }
131}
132#endif
133
134
135/**
136 * Calculate the host context ring-0 address of an offset into the HMA memory chunk.
137 *
138 * @returns the host context ring-0 address.
139 * @param pVM The cross context VM structure.
140 * @param pLookup The HMA lookup record.
141 * @param off The offset into the HMA memory chunk.
142 */
143DECLINLINE(RTR0PTR) mmHyperLookupCalcR0(PVM pVM, PMMLOOKUPHYPER pLookup, uint32_t off)
144{
145 switch (pLookup->enmType)
146 {
147 case MMLOOKUPHYPERTYPE_LOCKED:
148 if (pLookup->u.Locked.pvR0)
149 return (RTR0PTR)((RTR0UINTPTR)pLookup->u.Locked.pvR0 + off);
150#ifdef IN_RING3
151 AssertMsg(SUPR3IsDriverless(), ("%s\n", R3STRING(pLookup->pszDesc)));
152#else
153 AssertMsgFailed(("%s\n", R3STRING(pLookup->pszDesc)));
154#endif
155 NOREF(pVM);
156 return NIL_RTR0PTR;
157
158 case MMLOOKUPHYPERTYPE_HCPHYS:
159 if (pLookup->u.HCPhys.pvR0)
160 return (RTR0PTR)((RTR0UINTPTR)pLookup->u.HCPhys.pvR0 + off);
161#ifdef IN_RING3
162 AssertMsg(SUPR3IsDriverless(), ("%s\n", R3STRING(pLookup->pszDesc)));
163#else
164 AssertMsgFailed(("%s\n", R3STRING(pLookup->pszDesc)));
165#endif
166 return NIL_RTR0PTR;
167
168 default:
169 AssertMsgFailed(("enmType=%d\n", pLookup->enmType));
170 return NIL_RTR0PTR;
171 }
172}
173
174
175/**
176 * Converts a ring-3 host context address in the Hypervisor memory region to a ring-0 host context address.
177 *
178 * @returns ring-0 host context address.
179 * @param pVM The cross context VM structure.
180 * @param R3Ptr The ring-3 host context address.
181 * You'll be damned if this is not in the HMA! :-)
182 * @thread The Emulation Thread.
183 */
184VMMDECL(RTR0PTR) MMHyperR3ToR0(PVM pVM, RTR3PTR R3Ptr)
185{
186 uint32_t off;
187 PMMLOOKUPHYPER pLookup = mmHyperLookupR3(pVM, R3Ptr, &off);
188 if (pLookup)
189 return mmHyperLookupCalcR0(pVM, pLookup, off);
190 AssertMsgFailed(("R3Ptr=%p is not inside the hypervisor memory area!\n", R3Ptr));
191 return NIL_RTR0PTR;
192}
193
194
195#ifdef IN_RING0
196/**
197 * Converts a ring-3 host context address in the Hypervisor memory region to a current context address.
198 *
199 * @returns current context address.
200 * @param pVM The cross context VM structure.
201 * @param R3Ptr The ring-3 host context address.
202 * You'll be damned if this is not in the HMA! :-)
203 * @thread The Emulation Thread.
204 */
205VMMDECL(void *) MMHyperR3ToCC(PVM pVM, RTR3PTR R3Ptr)
206{
207 uint32_t off;
208 PMMLOOKUPHYPER pLookup = mmHyperLookupR3(pVM, R3Ptr, &off);
209 if (pLookup)
210 return mmHyperLookupCalcR0(pVM, pLookup, off);
211 return NULL;
212}
213#endif
214
215
216/**
217 * Gets the string name of a memory tag.
218 *
219 * @returns name of enmTag.
220 * @param enmTag The tag.
221 */
222const char *mmGetTagName(MMTAG enmTag)
223{
224 switch (enmTag)
225 {
226 #define TAG2STR(tag) case MM_TAG_##tag: return #tag
227
228 TAG2STR(CFGM);
229 TAG2STR(CFGM_BYTES);
230 TAG2STR(CFGM_STRING);
231 TAG2STR(CFGM_USER);
232
233 TAG2STR(CPUM_CTX);
234 TAG2STR(CPUM_CPUID);
235 TAG2STR(CPUM_MSRS);
236
237 TAG2STR(CSAM);
238 TAG2STR(CSAM_PATCH);
239
240 TAG2STR(DBGF);
241 TAG2STR(DBGF_AS);
242 TAG2STR(DBGF_FLOWTRACE);
243 TAG2STR(DBGF_INFO);
244 TAG2STR(DBGF_LINE);
245 TAG2STR(DBGF_LINE_DUP);
246 TAG2STR(DBGF_MODULE);
247 TAG2STR(DBGF_OS);
248 TAG2STR(DBGF_REG);
249 TAG2STR(DBGF_STACK);
250 TAG2STR(DBGF_SYMBOL);
251 TAG2STR(DBGF_SYMBOL_DUP);
252 TAG2STR(DBGF_TYPE);
253 TAG2STR(DBGF_TRACER);
254
255 TAG2STR(EM);
256
257 TAG2STR(IEM);
258
259 TAG2STR(IOM);
260 TAG2STR(IOM_STATS);
261
262 TAG2STR(MM);
263 TAG2STR(MM_LOOKUP_GUEST);
264 TAG2STR(MM_LOOKUP_PHYS);
265 TAG2STR(MM_LOOKUP_VIRT);
266 TAG2STR(MM_PAGE);
267
268 TAG2STR(PARAV);
269
270 TAG2STR(PATM);
271 TAG2STR(PATM_PATCH);
272
273 TAG2STR(PDM);
274 TAG2STR(PDM_DEVICE);
275 TAG2STR(PDM_DEVICE_DESC);
276 TAG2STR(PDM_DEVICE_USER);
277 TAG2STR(PDM_DRIVER);
278 TAG2STR(PDM_DRIVER_DESC);
279 TAG2STR(PDM_DRIVER_USER);
280 TAG2STR(PDM_USB);
281 TAG2STR(PDM_USB_DESC);
282 TAG2STR(PDM_USB_USER);
283 TAG2STR(PDM_LUN);
284 TAG2STR(PDM_QUEUE);
285 TAG2STR(PDM_THREAD);
286 TAG2STR(PDM_ASYNC_COMPLETION);
287#ifdef VBOX_WITH_NETSHAPER
288 TAG2STR(PDM_NET_SHAPER);
289#endif /* VBOX_WITH_NETSHAPER */
290
291 TAG2STR(PGM);
292 TAG2STR(PGM_CHUNK_MAPPING);
293 TAG2STR(PGM_HANDLERS);
294 TAG2STR(PGM_HANDLER_TYPES);
295 TAG2STR(PGM_MAPPINGS);
296 TAG2STR(PGM_PHYS);
297 TAG2STR(PGM_POOL);
298
299 TAG2STR(REM);
300
301 TAG2STR(SELM);
302
303 TAG2STR(SSM);
304
305 TAG2STR(STAM);
306
307 TAG2STR(TM);
308
309 TAG2STR(TRPM);
310
311 TAG2STR(VM);
312 TAG2STR(VM_REQ);
313
314 TAG2STR(VMM);
315
316 TAG2STR(HM);
317
318 #undef TAG2STR
319
320 default:
321 {
322 AssertMsgFailed(("Unknown tag %d! forgot to add it to the switch?\n", enmTag));
323#ifdef IN_RING3
324 static char sz[48];
325 RTStrPrintf(sz, sizeof(sz), "%d", enmTag);
326 return sz;
327#else
328 return "unknown tag!";
329#endif
330 }
331 }
332}
333
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette