1 | /* $Id: MMInternal.h 93554 2022-02-02 22:57:02Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * MM - Internal header file.
|
---|
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 | #ifndef VMM_INCLUDED_SRC_include_MMInternal_h
|
---|
19 | #define VMM_INCLUDED_SRC_include_MMInternal_h
|
---|
20 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
21 | # pragma once
|
---|
22 | #endif
|
---|
23 |
|
---|
24 | #include <VBox/cdefs.h>
|
---|
25 | #include <VBox/types.h>
|
---|
26 | #include <VBox/sup.h>
|
---|
27 | #include <VBox/vmm/stam.h>
|
---|
28 | #include <VBox/vmm/pdmcritsect.h>
|
---|
29 | #include <iprt/assert.h>
|
---|
30 | #include <iprt/avl.h>
|
---|
31 | #include <iprt/critsect.h>
|
---|
32 |
|
---|
33 |
|
---|
34 |
|
---|
35 | /** @defgroup grp_mm_int Internals
|
---|
36 | * @ingroup grp_mm
|
---|
37 | * @internal
|
---|
38 | * @{
|
---|
39 | */
|
---|
40 |
|
---|
41 |
|
---|
42 | /** @name MMR3Heap - VM Ring-3 Heap Internals
|
---|
43 | * @{
|
---|
44 | */
|
---|
45 |
|
---|
46 | /** @def MMR3HEAP_SIZE_ALIGNMENT
|
---|
47 | * The allocation size alignment of the MMR3Heap.
|
---|
48 | */
|
---|
49 | #define MMR3HEAP_SIZE_ALIGNMENT 16
|
---|
50 |
|
---|
51 | /** @def MMR3HEAP_WITH_STATISTICS
|
---|
52 | * Enable MMR3Heap statistics.
|
---|
53 | */
|
---|
54 | #if !defined(MMR3HEAP_WITH_STATISTICS) && defined(VBOX_WITH_STATISTICS)
|
---|
55 | # define MMR3HEAP_WITH_STATISTICS
|
---|
56 | #endif
|
---|
57 |
|
---|
58 | /**
|
---|
59 | * Heap statistics record.
|
---|
60 | * There is one global and one per allocation tag.
|
---|
61 | */
|
---|
62 | typedef struct MMHEAPSTAT
|
---|
63 | {
|
---|
64 | /** Core avl node, key is the tag. */
|
---|
65 | AVLULNODECORE Core;
|
---|
66 | /** Pointer to the heap the memory belongs to. */
|
---|
67 | struct MMHEAP *pHeap;
|
---|
68 | #ifdef MMR3HEAP_WITH_STATISTICS
|
---|
69 | /** Number of bytes currently allocated. */
|
---|
70 | size_t cbCurAllocated;
|
---|
71 | /** Number of allocation. */
|
---|
72 | uint64_t cAllocations;
|
---|
73 | /** Number of reallocations. */
|
---|
74 | uint64_t cReallocations;
|
---|
75 | /** Number of frees. */
|
---|
76 | uint64_t cFrees;
|
---|
77 | /** Failures. */
|
---|
78 | uint64_t cFailures;
|
---|
79 | /** Number of bytes allocated (sum). */
|
---|
80 | uint64_t cbAllocated;
|
---|
81 | /** Number of bytes freed. */
|
---|
82 | uint64_t cbFreed;
|
---|
83 | #endif
|
---|
84 | } MMHEAPSTAT;
|
---|
85 | #if defined(MMR3HEAP_WITH_STATISTICS) && defined(IN_RING3)
|
---|
86 | AssertCompileMemberAlignment(MMHEAPSTAT, cAllocations, 8);
|
---|
87 | AssertCompileSizeAlignment(MMHEAPSTAT, 8);
|
---|
88 | #endif
|
---|
89 | /** Pointer to heap statistics record. */
|
---|
90 | typedef MMHEAPSTAT *PMMHEAPSTAT;
|
---|
91 |
|
---|
92 |
|
---|
93 |
|
---|
94 |
|
---|
95 | /**
|
---|
96 | * Additional heap block header for relating allocations to the VM.
|
---|
97 | */
|
---|
98 | typedef struct MMHEAPHDR
|
---|
99 | {
|
---|
100 | /** Pointer to the next record. */
|
---|
101 | struct MMHEAPHDR *pNext;
|
---|
102 | /** Pointer to the previous record. */
|
---|
103 | struct MMHEAPHDR *pPrev;
|
---|
104 | /** Pointer to the heap statistics record.
|
---|
105 | * (Where the a PVM can be found.) */
|
---|
106 | PMMHEAPSTAT pStat;
|
---|
107 | /** Size of the allocation (including this header). */
|
---|
108 | size_t cbSize;
|
---|
109 | } MMHEAPHDR;
|
---|
110 | /** Pointer to MM heap header. */
|
---|
111 | typedef MMHEAPHDR *PMMHEAPHDR;
|
---|
112 |
|
---|
113 |
|
---|
114 | /** MM Heap structure. */
|
---|
115 | typedef struct MMHEAP
|
---|
116 | {
|
---|
117 | /** Lock protecting the heap. */
|
---|
118 | RTCRITSECT Lock;
|
---|
119 | /** Heap block list head. */
|
---|
120 | PMMHEAPHDR pHead;
|
---|
121 | /** Heap block list tail. */
|
---|
122 | PMMHEAPHDR pTail;
|
---|
123 | /** Heap per tag statistics tree. */
|
---|
124 | PAVLULNODECORE pStatTree;
|
---|
125 | /** The VM handle. */
|
---|
126 | PUVM pUVM;
|
---|
127 | /** Heap global statistics. */
|
---|
128 | MMHEAPSTAT Stat;
|
---|
129 | } MMHEAP;
|
---|
130 | /** Pointer to MM Heap structure. */
|
---|
131 | typedef MMHEAP *PMMHEAP;
|
---|
132 |
|
---|
133 | /** @} */
|
---|
134 |
|
---|
135 |
|
---|
136 | /** @name MMUkHeap - VM User-kernel Heap Internals
|
---|
137 | * @{
|
---|
138 | */
|
---|
139 |
|
---|
140 | /** @def MMUKHEAP_SIZE_ALIGNMENT
|
---|
141 | * The allocation size alignment of the MMR3UkHeap.
|
---|
142 | */
|
---|
143 | #define MMUKHEAP_SIZE_ALIGNMENT 16
|
---|
144 |
|
---|
145 | /** @def MMUKHEAP_WITH_STATISTICS
|
---|
146 | * Enable MMUkHeap statistics.
|
---|
147 | */
|
---|
148 | #if !defined(MMUKHEAP_WITH_STATISTICS) && defined(VBOX_WITH_STATISTICS)
|
---|
149 | # define MMUKHEAP_WITH_STATISTICS
|
---|
150 | #endif
|
---|
151 |
|
---|
152 |
|
---|
153 | /**
|
---|
154 | * Heap statistics record.
|
---|
155 | * There is one global and one per allocation tag.
|
---|
156 | */
|
---|
157 | typedef struct MMUKHEAPSTAT
|
---|
158 | {
|
---|
159 | /** Core avl node, key is the tag. */
|
---|
160 | AVLULNODECORE Core;
|
---|
161 | /** Number of allocation. */
|
---|
162 | uint64_t cAllocations;
|
---|
163 | /** Number of reallocations. */
|
---|
164 | uint64_t cReallocations;
|
---|
165 | /** Number of frees. */
|
---|
166 | uint64_t cFrees;
|
---|
167 | /** Failures. */
|
---|
168 | uint64_t cFailures;
|
---|
169 | /** Number of bytes allocated (sum). */
|
---|
170 | uint64_t cbAllocated;
|
---|
171 | /** Number of bytes freed. */
|
---|
172 | uint64_t cbFreed;
|
---|
173 | /** Number of bytes currently allocated. */
|
---|
174 | size_t cbCurAllocated;
|
---|
175 | } MMUKHEAPSTAT;
|
---|
176 | #ifdef IN_RING3
|
---|
177 | AssertCompileMemberAlignment(MMUKHEAPSTAT, cAllocations, 8);
|
---|
178 | #endif
|
---|
179 | /** Pointer to heap statistics record. */
|
---|
180 | typedef MMUKHEAPSTAT *PMMUKHEAPSTAT;
|
---|
181 |
|
---|
182 | /**
|
---|
183 | * Sub heap tracking record.
|
---|
184 | */
|
---|
185 | typedef struct MMUKHEAPSUB
|
---|
186 | {
|
---|
187 | /** Pointer to the next sub-heap. */
|
---|
188 | struct MMUKHEAPSUB *pNext;
|
---|
189 | /** The base address of the sub-heap. */
|
---|
190 | void *pv;
|
---|
191 | /** The size of the sub-heap. */
|
---|
192 | size_t cb;
|
---|
193 | /** The handle of the simple block pointer. */
|
---|
194 | RTHEAPSIMPLE hSimple;
|
---|
195 | /** The ring-0 address corresponding to MMUKHEAPSUB::pv. */
|
---|
196 | RTR0PTR pvR0;
|
---|
197 | } MMUKHEAPSUB;
|
---|
198 | /** Pointer to a sub-heap tracking record. */
|
---|
199 | typedef MMUKHEAPSUB *PMMUKHEAPSUB;
|
---|
200 |
|
---|
201 |
|
---|
202 | /** MM User-kernel Heap structure. */
|
---|
203 | typedef struct MMUKHEAP
|
---|
204 | {
|
---|
205 | /** Lock protecting the heap. */
|
---|
206 | RTCRITSECT Lock;
|
---|
207 | /** Head of the sub-heap LIFO. */
|
---|
208 | PMMUKHEAPSUB pSubHeapHead;
|
---|
209 | /** Heap per tag statistics tree. */
|
---|
210 | PAVLULNODECORE pStatTree;
|
---|
211 | /** The VM handle. */
|
---|
212 | PUVM pUVM;
|
---|
213 | #if HC_ARCH_BITS == 32
|
---|
214 | /** Aligning the statistics on an 8 byte boundary (for uint64_t and STAM). */
|
---|
215 | void *pvAlignment;
|
---|
216 | #endif
|
---|
217 | /** Heap global statistics. */
|
---|
218 | MMUKHEAPSTAT Stat;
|
---|
219 | } MMUKHEAP;
|
---|
220 | #ifdef IN_RING3
|
---|
221 | AssertCompileMemberAlignment(MMUKHEAP, Stat, 8);
|
---|
222 | #endif
|
---|
223 | /** Pointer to MM Heap structure. */
|
---|
224 | typedef MMUKHEAP *PMMUKHEAP;
|
---|
225 |
|
---|
226 | /** @} */
|
---|
227 |
|
---|
228 |
|
---|
229 |
|
---|
230 | /** @name Hypervisor Heap Internals
|
---|
231 | * @{
|
---|
232 | */
|
---|
233 |
|
---|
234 | /** @def MMHYPER_HEAP_FREE_DELAY
|
---|
235 | * If defined, it indicates the number of frees that should be delayed.
|
---|
236 | */
|
---|
237 | #if defined(DOXYGEN_RUNNING)
|
---|
238 | # define MMHYPER_HEAP_FREE_DELAY 64
|
---|
239 | #endif
|
---|
240 |
|
---|
241 | /** @def MMHYPER_HEAP_FREE_POISON
|
---|
242 | * If defined, it indicates that freed memory should be poisoned
|
---|
243 | * with the value it has.
|
---|
244 | */
|
---|
245 | #if defined(VBOX_STRICT) || defined(DOXYGEN_RUNNING)
|
---|
246 | # define MMHYPER_HEAP_FREE_POISON 0xcb
|
---|
247 | #endif
|
---|
248 |
|
---|
249 | /** @def MMHYPER_HEAP_STRICT
|
---|
250 | * Enables a bunch of assertions in the heap code. */
|
---|
251 | #if defined(VBOX_STRICT) || defined(DOXYGEN_RUNNING)
|
---|
252 | # define MMHYPER_HEAP_STRICT 1
|
---|
253 | # if 0 || defined(DOXYGEN_RUNNING)
|
---|
254 | /** @def MMHYPER_HEAP_STRICT_FENCE
|
---|
255 | * Enables tail fence. */
|
---|
256 | # define MMHYPER_HEAP_STRICT_FENCE
|
---|
257 | /** @def MMHYPER_HEAP_STRICT_FENCE_SIZE
|
---|
258 | * The fence size in bytes. */
|
---|
259 | # define MMHYPER_HEAP_STRICT_FENCE_SIZE 256
|
---|
260 | /** @def MMHYPER_HEAP_STRICT_FENCE_U32
|
---|
261 | * The fence filler. */
|
---|
262 | # define MMHYPER_HEAP_STRICT_FENCE_U32 UINT32_C(0xdeadbeef)
|
---|
263 | # endif
|
---|
264 | #endif
|
---|
265 |
|
---|
266 | /**
|
---|
267 | * Hypervisor heap statistics record.
|
---|
268 | * There is one global and one per allocation tag.
|
---|
269 | */
|
---|
270 | typedef struct MMHYPERSTAT
|
---|
271 | {
|
---|
272 | /** Core avl node, key is the tag.
|
---|
273 | * @todo The type is wrong! Get your lazy a$$ over and create that offsetted uint32_t version we need here! */
|
---|
274 | AVLOGCPHYSNODECORE Core;
|
---|
275 | /** Aligning the 64-bit fields on a 64-bit line. */
|
---|
276 | uint32_t u32Padding0;
|
---|
277 | /** Indicator for whether these statistics are registered with STAM or not. */
|
---|
278 | bool fRegistered;
|
---|
279 | /** Number of allocation. */
|
---|
280 | uint64_t cAllocations;
|
---|
281 | /** Number of frees. */
|
---|
282 | uint64_t cFrees;
|
---|
283 | /** Failures. */
|
---|
284 | uint64_t cFailures;
|
---|
285 | /** Number of bytes allocated (sum). */
|
---|
286 | uint64_t cbAllocated;
|
---|
287 | /** Number of bytes freed (sum). */
|
---|
288 | uint64_t cbFreed;
|
---|
289 | /** Number of bytes currently allocated. */
|
---|
290 | uint32_t cbCurAllocated;
|
---|
291 | /** Max number of bytes allocated. */
|
---|
292 | uint32_t cbMaxAllocated;
|
---|
293 | } MMHYPERSTAT;
|
---|
294 | AssertCompileMemberAlignment(MMHYPERSTAT, cAllocations, 8);
|
---|
295 | /** Pointer to hypervisor heap statistics record. */
|
---|
296 | typedef MMHYPERSTAT *PMMHYPERSTAT;
|
---|
297 |
|
---|
298 | /**
|
---|
299 | * Hypervisor heap chunk.
|
---|
300 | */
|
---|
301 | typedef struct MMHYPERCHUNK
|
---|
302 | {
|
---|
303 | /** Previous block in the list of all blocks.
|
---|
304 | * This is relative to the start of the heap. */
|
---|
305 | uint32_t offNext;
|
---|
306 | /** Offset to the previous block relative to this one. */
|
---|
307 | int32_t offPrev;
|
---|
308 | /** The statistics record this allocation belongs to (self relative). */
|
---|
309 | int32_t offStat;
|
---|
310 | /** Offset to the heap block (self relative). */
|
---|
311 | int32_t offHeap;
|
---|
312 | } MMHYPERCHUNK;
|
---|
313 | /** Pointer to a hypervisor heap chunk. */
|
---|
314 | typedef MMHYPERCHUNK *PMMHYPERCHUNK;
|
---|
315 |
|
---|
316 |
|
---|
317 | /**
|
---|
318 | * Hypervisor heap chunk.
|
---|
319 | */
|
---|
320 | typedef struct MMHYPERCHUNKFREE
|
---|
321 | {
|
---|
322 | /** Main list. */
|
---|
323 | MMHYPERCHUNK core;
|
---|
324 | /** Offset of the next chunk in the list of free nodes. */
|
---|
325 | uint32_t offNext;
|
---|
326 | /** Offset of the previous chunk in the list of free nodes. */
|
---|
327 | int32_t offPrev;
|
---|
328 | /** Size of the block. */
|
---|
329 | uint32_t cb;
|
---|
330 | } MMHYPERCHUNKFREE;
|
---|
331 | /** Pointer to a free hypervisor heap chunk. */
|
---|
332 | typedef MMHYPERCHUNKFREE *PMMHYPERCHUNKFREE;
|
---|
333 |
|
---|
334 |
|
---|
335 | /**
|
---|
336 | * The hypervisor heap.
|
---|
337 | */
|
---|
338 | typedef struct MMHYPERHEAP
|
---|
339 | {
|
---|
340 | /** The typical magic (MMHYPERHEAP_MAGIC). */
|
---|
341 | uint32_t u32Magic;
|
---|
342 | /** The heap size. (This structure is not included!) */
|
---|
343 | uint32_t cbHeap;
|
---|
344 | /** Lock protecting the heap. */
|
---|
345 | PDMCRITSECT Lock;
|
---|
346 | /** The HC ring-3 address of the heap. */
|
---|
347 | R3PTRTYPE(uint8_t *) pbHeapR3;
|
---|
348 | /** The HC ring-3 address of the shared VM structure. */
|
---|
349 | PVMR3 pVMR3;
|
---|
350 | /** The HC ring-0 address of the heap. */
|
---|
351 | R0PTRTYPE(uint8_t *) pbHeapR0;
|
---|
352 | /** The HC ring-0 address of the shared VM structure. */
|
---|
353 | PVMR0 pVMR0;
|
---|
354 | /** The RC address of the heap. */
|
---|
355 | RCPTRTYPE(uint8_t *) pbHeapRC;
|
---|
356 | /** The RC address of the shared VM structure. */
|
---|
357 | PVMRC pVMRC;
|
---|
358 | /** The amount of free memory in the heap. */
|
---|
359 | uint32_t cbFree;
|
---|
360 | /** Offset of the first free chunk in the heap.
|
---|
361 | * The offset is relative to the start of the heap. */
|
---|
362 | uint32_t offFreeHead;
|
---|
363 | /** Offset of the last free chunk in the heap.
|
---|
364 | * The offset is relative to the start of the heap. */
|
---|
365 | uint32_t offFreeTail;
|
---|
366 | /** Offset of the first page aligned block in the heap.
|
---|
367 | * The offset is equal to cbHeap initially. */
|
---|
368 | uint32_t offPageAligned;
|
---|
369 | /** Tree of hypervisor heap statistics. */
|
---|
370 | AVLOGCPHYSTREE HyperHeapStatTree;
|
---|
371 | #ifdef MMHYPER_HEAP_FREE_DELAY
|
---|
372 | /** Where to insert the next free. */
|
---|
373 | uint32_t iDelayedFree;
|
---|
374 | /** Array of delayed frees. Circular. Offsets relative to this structure. */
|
---|
375 | struct
|
---|
376 | {
|
---|
377 | /** The free caller address. */
|
---|
378 | RTUINTPTR uCaller;
|
---|
379 | /** The offset of the freed chunk. */
|
---|
380 | uint32_t offChunk;
|
---|
381 | } aDelayedFrees[MMHYPER_HEAP_FREE_DELAY];
|
---|
382 | #else
|
---|
383 | /** Padding the structure to a 64-bit aligned size. */
|
---|
384 | uint32_t u32Padding0;
|
---|
385 | #endif
|
---|
386 | /** The heap physical pages. */
|
---|
387 | R3PTRTYPE(PSUPPAGE) paPages;
|
---|
388 | #if HC_ARCH_BITS == 32
|
---|
389 | /** Padding the structure to a 64-bit aligned size. */
|
---|
390 | uint32_t u32Padding1;
|
---|
391 | #endif
|
---|
392 | } MMHYPERHEAP;
|
---|
393 | /** Pointer to the hypervisor heap. */
|
---|
394 | typedef MMHYPERHEAP *PMMHYPERHEAP;
|
---|
395 |
|
---|
396 | /** Magic value for MMHYPERHEAP. (C. S. Lewis) */
|
---|
397 | #define MMHYPERHEAP_MAGIC UINT32_C(0x18981129)
|
---|
398 |
|
---|
399 |
|
---|
400 | /**
|
---|
401 | * Hypervisor heap minimum alignment (16 bytes).
|
---|
402 | */
|
---|
403 | #define MMHYPER_HEAP_ALIGN_MIN 16
|
---|
404 |
|
---|
405 | /**
|
---|
406 | * The aligned size of the MMHYPERHEAP structure.
|
---|
407 | */
|
---|
408 | #define MMYPERHEAP_HDR_SIZE RT_ALIGN_Z(sizeof(MMHYPERHEAP), MMHYPER_HEAP_ALIGN_MIN * 4)
|
---|
409 |
|
---|
410 | /** @name Hypervisor heap chunk flags.
|
---|
411 | * The flags are put in the first bits of the MMHYPERCHUNK::offPrev member.
|
---|
412 | * These bits aren't used anyway because of the chunk minimal alignment (16 bytes).
|
---|
413 | * @{ */
|
---|
414 | /** The chunk is free. (The code ASSUMES this is 0!) */
|
---|
415 | #define MMHYPERCHUNK_FLAGS_FREE 0x0
|
---|
416 | /** The chunk is in use. */
|
---|
417 | #define MMHYPERCHUNK_FLAGS_USED 0x1
|
---|
418 | /** The type mask. */
|
---|
419 | #define MMHYPERCHUNK_FLAGS_TYPE_MASK 0x1
|
---|
420 | /** The flag mask */
|
---|
421 | #define MMHYPERCHUNK_FLAGS_MASK 0x1
|
---|
422 |
|
---|
423 | /** Checks if the chunk is free. */
|
---|
424 | #define MMHYPERCHUNK_ISFREE(pChunk) ( (((pChunk)->offPrev) & MMHYPERCHUNK_FLAGS_TYPE_MASK) == MMHYPERCHUNK_FLAGS_FREE )
|
---|
425 | /** Checks if the chunk is used. */
|
---|
426 | #define MMHYPERCHUNK_ISUSED(pChunk) ( (((pChunk)->offPrev) & MMHYPERCHUNK_FLAGS_TYPE_MASK) == MMHYPERCHUNK_FLAGS_USED )
|
---|
427 | /** Toggles FREE/USED flag of a chunk. */
|
---|
428 | #define MMHYPERCHUNK_SET_TYPE(pChunk, type) do { (pChunk)->offPrev = ((pChunk)->offPrev & ~MMHYPERCHUNK_FLAGS_TYPE_MASK) | ((type) & MMHYPERCHUNK_FLAGS_TYPE_MASK); } while (0)
|
---|
429 |
|
---|
430 | /** Gets the prev offset without the flags. */
|
---|
431 | #define MMHYPERCHUNK_GET_OFFPREV(pChunk) ((int32_t)((pChunk)->offPrev & ~MMHYPERCHUNK_FLAGS_MASK))
|
---|
432 | /** Sets the prev offset without changing the flags. */
|
---|
433 | #define MMHYPERCHUNK_SET_OFFPREV(pChunk, off) do { (pChunk)->offPrev = (off) | ((pChunk)->offPrev & MMHYPERCHUNK_FLAGS_MASK); } while (0)
|
---|
434 | #if 0
|
---|
435 | /** Clears one or more flags. */
|
---|
436 | #define MMHYPERCHUNK_FLAGS_OP_CLEAR(pChunk, fFlags) do { ((pChunk)->offPrev) &= ~((fFlags) & MMHYPERCHUNK_FLAGS_MASK); } while (0)
|
---|
437 | /** Sets one or more flags. */
|
---|
438 | #define MMHYPERCHUNK_FLAGS_OP_SET(pChunk, fFlags) do { ((pChunk)->offPrev) |= ((fFlags) & MMHYPERCHUNK_FLAGS_MASK); } while (0)
|
---|
439 | /** Checks if one is set. */
|
---|
440 | #define MMHYPERCHUNK_FLAGS_OP_ISSET(pChunk, fFlag) (!!(((pChunk)->offPrev) & ((fFlag) & MMHYPERCHUNK_FLAGS_MASK)))
|
---|
441 | #endif
|
---|
442 | /** @} */
|
---|
443 |
|
---|
444 | /** @} */
|
---|
445 |
|
---|
446 | /**
|
---|
447 | * Hypervisor memory mapping type.
|
---|
448 | */
|
---|
449 | typedef enum MMLOOKUPHYPERTYPE
|
---|
450 | {
|
---|
451 | /** Invalid record. This is used for record which are incomplete. */
|
---|
452 | MMLOOKUPHYPERTYPE_INVALID = 0,
|
---|
453 | /** Mapping of locked memory. */
|
---|
454 | MMLOOKUPHYPERTYPE_LOCKED,
|
---|
455 | /** Mapping of contiguous HC physical memory. */
|
---|
456 | MMLOOKUPHYPERTYPE_HCPHYS,
|
---|
457 | /** Mapping of contiguous GC physical memory. */
|
---|
458 | MMLOOKUPHYPERTYPE_GCPHYS,
|
---|
459 | /** Mapping of MMIO2 memory. */
|
---|
460 | MMLOOKUPHYPERTYPE_MMIO2,
|
---|
461 | /** Dynamic mapping area (MMR3HyperReserve).
|
---|
462 | * A conversion will require to check what's in the page table for the pages. */
|
---|
463 | MMLOOKUPHYPERTYPE_DYNAMIC
|
---|
464 | } MMLOOKUPHYPERTYPE;
|
---|
465 |
|
---|
466 | /**
|
---|
467 | * Lookup record for the hypervisor memory area.
|
---|
468 | */
|
---|
469 | typedef struct MMLOOKUPHYPER
|
---|
470 | {
|
---|
471 | /** Byte offset from the start of this record to the next.
|
---|
472 | * If the value is NIL_OFFSET the chain is terminated. */
|
---|
473 | int32_t offNext;
|
---|
474 | /** Offset into the hypervisor memory area. */
|
---|
475 | uint32_t off;
|
---|
476 | /** Size of this part. */
|
---|
477 | uint32_t cb;
|
---|
478 | /** Locking type. */
|
---|
479 | MMLOOKUPHYPERTYPE enmType;
|
---|
480 | /** Type specific data */
|
---|
481 | union
|
---|
482 | {
|
---|
483 | /** Locked memory. */
|
---|
484 | struct
|
---|
485 | {
|
---|
486 | /** Host context ring-3 pointer. */
|
---|
487 | R3PTRTYPE(void *) pvR3;
|
---|
488 | /** Host context ring-0 pointer. Optional. */
|
---|
489 | RTR0PTR pvR0;
|
---|
490 | /** Pointer to an array containing the physical address of each page
|
---|
491 | * (HOST_PAGE_SIZE). */
|
---|
492 | R3PTRTYPE(PRTHCPHYS) paHCPhysPages;
|
---|
493 | } Locked;
|
---|
494 |
|
---|
495 | /** Contiguous physical memory. */
|
---|
496 | struct
|
---|
497 | {
|
---|
498 | /** Host context ring-3 pointer. */
|
---|
499 | R3PTRTYPE(void *) pvR3;
|
---|
500 | /** Host context ring-0 pointer. Optional. */
|
---|
501 | RTR0PTR pvR0;
|
---|
502 | /** HC physical address corresponding to pvR3/pvR0. */
|
---|
503 | RTHCPHYS HCPhys;
|
---|
504 | } HCPhys;
|
---|
505 |
|
---|
506 | /** Contiguous guest physical memory. */
|
---|
507 | struct
|
---|
508 | {
|
---|
509 | /** The memory address (Guest Context). */
|
---|
510 | RTGCPHYS GCPhys;
|
---|
511 | } GCPhys;
|
---|
512 |
|
---|
513 | /** MMIO2 memory. */
|
---|
514 | struct
|
---|
515 | {
|
---|
516 | /** The device instance owning the MMIO2 region. */
|
---|
517 | PPDMDEVINSR3 pDevIns;
|
---|
518 | /** The sub-device number. */
|
---|
519 | uint32_t iSubDev;
|
---|
520 | /** The region number. */
|
---|
521 | uint32_t iRegion;
|
---|
522 | #if HC_ARCH_BITS == 32
|
---|
523 | /** Alignment padding. */
|
---|
524 | uint32_t uPadding;
|
---|
525 | #endif
|
---|
526 | /** The offset into the MMIO2 region. */
|
---|
527 | RTGCPHYS off;
|
---|
528 | } MMIO2;
|
---|
529 | } u;
|
---|
530 | /** Description. */
|
---|
531 | R3PTRTYPE(const char *) pszDesc;
|
---|
532 | } MMLOOKUPHYPER;
|
---|
533 | /** Pointer to a hypervisor memory lookup record. */
|
---|
534 | typedef MMLOOKUPHYPER *PMMLOOKUPHYPER;
|
---|
535 |
|
---|
536 |
|
---|
537 | /**
|
---|
538 | * Converts a MM pointer into a VM pointer.
|
---|
539 | * @returns Pointer to the VM structure the MM is part of.
|
---|
540 | * @param pMM Pointer to MM instance data.
|
---|
541 | */
|
---|
542 | #define MM2VM(pMM) ( (PVM)((uint8_t *)pMM - pMM->offVM) )
|
---|
543 |
|
---|
544 |
|
---|
545 | /**
|
---|
546 | * MM Data (part of VM)
|
---|
547 | */
|
---|
548 | typedef struct MM
|
---|
549 | {
|
---|
550 | /** Offset to the VM structure.
|
---|
551 | * See MM2VM(). */
|
---|
552 | RTINT offVM;
|
---|
553 |
|
---|
554 | /** Set if MMR3InitPaging has been called. */
|
---|
555 | bool fDoneMMR3InitPaging;
|
---|
556 | /** Set if PGM has been initialized and we can safely call PGMR3Map(). */
|
---|
557 | bool fPGMInitialized;
|
---|
558 | #if GC_ARCH_BITS == 64 || HC_ARCH_BITS == 64
|
---|
559 | uint32_t u32Padding1; /**< alignment padding. */
|
---|
560 | #endif
|
---|
561 |
|
---|
562 | /** Lookup list for the Hypervisor Memory Area.
|
---|
563 | * The offset is relative to the start of the heap.
|
---|
564 | * Use pHyperHeapR3, pHyperHeapR0 or pHypeRHeapRC to calculate the address.
|
---|
565 | */
|
---|
566 | RTUINT offLookupHyper;
|
---|
567 |
|
---|
568 | /** The offset of the next static mapping in the Hypervisor Memory Area. */
|
---|
569 | RTUINT offHyperNextStatic;
|
---|
570 | /** The size of the HMA.
|
---|
571 | * Starts at 12MB and will be fixed late in the init process. */
|
---|
572 | RTUINT cbHyperArea;
|
---|
573 |
|
---|
574 | /** Guest address of the Hypervisor Memory Area.
|
---|
575 | * @remarks It's still a bit open whether this should be change to RTRCPTR or
|
---|
576 | * remain a RTGCPTR. */
|
---|
577 | RTGCPTR pvHyperAreaGC;
|
---|
578 |
|
---|
579 | /** The hypervisor heap (GC Ptr). */
|
---|
580 | RCPTRTYPE(PMMHYPERHEAP) pHyperHeapRC;
|
---|
581 | #if HC_ARCH_BITS == 64 && GC_ARCH_BITS == 64
|
---|
582 | uint32_t u32Padding2;
|
---|
583 | #endif
|
---|
584 |
|
---|
585 | /** The hypervisor heap (R0 Ptr). */
|
---|
586 | R0PTRTYPE(PMMHYPERHEAP) pHyperHeapR0;
|
---|
587 |
|
---|
588 | /** The hypervisor heap (R3 Ptr). */
|
---|
589 | R3PTRTYPE(PMMHYPERHEAP) pHyperHeapR3;
|
---|
590 |
|
---|
591 | /** Pointer to the dummy page.
|
---|
592 | * The dummy page is a paranoia thingy used for instance for pure MMIO RAM ranges
|
---|
593 | * to make sure any bugs will not harm whatever the system stores in the first
|
---|
594 | * physical page. */
|
---|
595 | R3PTRTYPE(void *) pvDummyPage;
|
---|
596 | /** Physical address of the dummy page. */
|
---|
597 | RTHCPHYS HCPhysDummyPage;
|
---|
598 |
|
---|
599 | /** Size of the base RAM in bytes. (The CFGM RamSize value.) */
|
---|
600 | uint64_t cbRamBase;
|
---|
601 | /** Number of bytes of RAM above 4GB, starting at address 4GB. */
|
---|
602 | uint64_t cbRamAbove4GB;
|
---|
603 | /** Size of the below 4GB RAM hole. */
|
---|
604 | uint32_t cbRamHole;
|
---|
605 | /** Number of bytes of RAM below 4GB, starting at address 0. */
|
---|
606 | uint32_t cbRamBelow4GB;
|
---|
607 | /** The number of base RAM pages that PGM has reserved (GMM).
|
---|
608 | * @remarks Shadow ROMs will be counted twice (RAM+ROM), so it won't be 1:1 with
|
---|
609 | * what the guest sees. */
|
---|
610 | uint64_t cBasePages;
|
---|
611 | /** The number of handy pages that PGM has reserved (GMM).
|
---|
612 | * These are kept out of cBasePages and thus out of the saved state. */
|
---|
613 | uint32_t cHandyPages;
|
---|
614 | /** The number of shadow pages PGM has reserved (GMM). */
|
---|
615 | uint32_t cShadowPages;
|
---|
616 | /** The number of fixed pages we've reserved (GMM). */
|
---|
617 | uint32_t cFixedPages;
|
---|
618 | /** Padding. */
|
---|
619 | uint32_t u32Padding0;
|
---|
620 | } MM;
|
---|
621 | /** Pointer to MM Data (part of VM). */
|
---|
622 | typedef MM *PMM;
|
---|
623 |
|
---|
624 |
|
---|
625 | /**
|
---|
626 | * MM data kept in the UVM.
|
---|
627 | */
|
---|
628 | typedef struct MMUSERPERVM
|
---|
629 | {
|
---|
630 | /** Pointer to the MM R3 Heap. */
|
---|
631 | R3PTRTYPE(PMMHEAP) pHeap;
|
---|
632 | } MMUSERPERVM;
|
---|
633 | /** Pointer to the MM data kept in the UVM. */
|
---|
634 | typedef MMUSERPERVM *PMMUSERPERVM;
|
---|
635 |
|
---|
636 |
|
---|
637 | RT_C_DECLS_BEGIN
|
---|
638 |
|
---|
639 | int mmR3UpdateReservation(PVM pVM);
|
---|
640 |
|
---|
641 | int mmR3HeapCreateU(PUVM pUVM, PMMHEAP *ppHeap);
|
---|
642 | void mmR3HeapDestroy(PMMHEAP pHeap);
|
---|
643 |
|
---|
644 | int mmR3HyperInit(PVM pVM);
|
---|
645 | int mmR3HyperTerm(PVM pVM);
|
---|
646 | int mmR3HyperInitPaging(PVM pVM);
|
---|
647 |
|
---|
648 | const char *mmGetTagName(MMTAG enmTag);
|
---|
649 |
|
---|
650 | RT_C_DECLS_END
|
---|
651 |
|
---|
652 | /** @} */
|
---|
653 |
|
---|
654 | #endif /* !VMM_INCLUDED_SRC_include_MMInternal_h */
|
---|
655 |
|
---|