VirtualBox

source: vbox/trunk/include/VBox/pgm.h@ 6791

Last change on this file since 6791 was 6546, checked in by vboxsync, 17 years ago

VBOX_WITH_NEW_PHYS_CODE changes mostly realted to REM. Killed a warning in cpu-exec.c.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 68.8 KB
Line 
1/** @file
2 * PGM - Page Monitor/Monitor.
3 */
4
5/*
6 * Copyright (C) 2006-2007 innotek GmbH
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26#ifndef ___VBox_pgm_h
27#define ___VBox_pgm_h
28
29#include <VBox/cdefs.h>
30#include <VBox/types.h>
31#include <VBox/sup.h>
32#include <VBox/cpum.h>
33#include <VBox/vmapi.h>
34
35__BEGIN_DECLS
36
37/** @defgroup grp_pgm The Page Monitor/Manager API
38 * @{
39 */
40
41/** Chunk size for dynamically allocated physical memory. */
42#define PGM_DYNAMIC_CHUNK_SIZE (1*1024*1024)
43/** Shift GC physical address by 20 bits to get the offset into the pvHCChunkHC array. */
44#define PGM_DYNAMIC_CHUNK_SHIFT 20
45/** Dynamic chunk offset mask. */
46#define PGM_DYNAMIC_CHUNK_OFFSET_MASK 0xfffff
47/** Dynamic chunk base mask. */
48#define PGM_DYNAMIC_CHUNK_BASE_MASK (~(RTGCPHYS)PGM_DYNAMIC_CHUNK_OFFSET_MASK)
49
50
51/** Page flags used for PGMHyperSetPageFlags
52 * @deprecated
53 * @{ */
54#define PGMPAGE_READ 1
55#define PGMPAGE_WRITE 2
56#define PGMPAGE_USER 4
57#define PGMPAGE_SYSTEM 8
58#define PGMPAGE_NOTPRESENT 16
59/** @} */
60
61
62/**
63 * FNPGMRELOCATE callback mode.
64 */
65typedef enum PGMRELOCATECALL
66{
67 /** The callback is for checking if the suggested address is suitable. */
68 PGMRELOCATECALL_SUGGEST = 1,
69 /** The callback is for executing the relocation. */
70 PGMRELOCATECALL_RELOCATE
71} PGMRELOCATECALL;
72
73
74/**
75 * Callback function which will be called when PGM is trying to find
76 * a new location for the mapping.
77 *
78 * The callback is called in two modes, 1) the check mode and 2) the relocate mode.
79 * In 1) the callback should say if it objects to a suggested new location. If it
80 * accepts the new location, it is called again for doing it's relocation.
81 *
82 *
83 * @returns true if the location is ok.
84 * @returns false if another location should be found.
85 * @param GCPtrOld The old virtual address.
86 * @param GCPtrNew The new virtual address.
87 * @param enmMode Used to indicate the callback mode.
88 * @param pvUser User argument.
89 * @remark The return value is no a failure indicator, it's an acceptance
90 * indicator. Relocation can not fail!
91 */
92typedef DECLCALLBACK(bool) FNPGMRELOCATE(PVM pVM, RTGCPTR GCPtrOld, RTGCPTR GCPtrNew, PGMRELOCATECALL enmMode, void *pvUser);
93/** Pointer to a relocation callback function. */
94typedef FNPGMRELOCATE *PFNPGMRELOCATE;
95
96
97/**
98 * Physical page access handler type.
99 */
100typedef enum PGMPHYSHANDLERTYPE
101{
102 /** MMIO range. Pages are not present, all access is done in interpreter or recompiler. */
103 PGMPHYSHANDLERTYPE_MMIO = 1,
104 /** Handle all normal page faults for a physical page range. */
105 PGMPHYSHANDLERTYPE_PHYSICAL,
106 /** Handler all write access to a physical page range. */
107 PGMPHYSHANDLERTYPE_PHYSICAL_WRITE,
108 /** Handler all access to a physical page range. */
109 PGMPHYSHANDLERTYPE_PHYSICAL_ALL
110
111} PGMPHYSHANDLERTYPE;
112
113/**
114 * \#PF Handler callback for physical access handler ranges (MMIO among others) in GC.
115 *
116 * @returns VBox status code (appropriate for GC return).
117 * @param pVM VM Handle.
118 * @param uErrorCode CPU Error code.
119 * @param pRegFrame Trap register frame.
120 * NULL on DMA and other non CPU access.
121 * @param pvFault The fault address (cr2).
122 * @param GCPhysFault The GC physical address corresponding to pvFault.
123 * @param pvUser User argument.
124 */
125typedef DECLCALLBACK(int) FNPGMGCPHYSHANDLER(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, RTGCPHYS GCPhysFault, void *pvUser);
126/** Pointer to PGM access callback. */
127typedef FNPGMGCPHYSHANDLER *PFNPGMGCPHYSHANDLER;
128
129/**
130 * \#PF Handler callback for physical access handler ranges (MMIO among others) in R0.
131 *
132 * @returns VBox status code (appropriate for GC return).
133 * @param pVM VM Handle.
134 * @param uErrorCode CPU Error code.
135 * @param pRegFrame Trap register frame.
136 * NULL on DMA and other non CPU access.
137 * @param pvFault The fault address (cr2).
138 * @param GCPhysFault The GC physical address corresponding to pvFault.
139 * @param pvUser User argument.
140 */
141typedef DECLCALLBACK(int) FNPGMR0PHYSHANDLER(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, RTGCPHYS GCPhysFault, void *pvUser);
142/** Pointer to PGM access callback. */
143typedef FNPGMR0PHYSHANDLER *PFNPGMR0PHYSHANDLER;
144
145/**
146 * Guest Access type
147 */
148typedef enum PGMACCESSTYPE
149{
150 /** Read access. */
151 PGMACCESSTYPE_READ = 1,
152 /** Write access. */
153 PGMACCESSTYPE_WRITE
154} PGMACCESSTYPE;
155
156/**
157 * \#PF Handler callback for physical access handler ranges (MMIO among others) in HC.
158 *
159 * The handler can not raise any faults, it's mainly for monitoring write access
160 * to certain pages.
161 *
162 * @returns VINF_SUCCESS if the handler have carried out the operation.
163 * @returns VINF_PGM_HANDLER_DO_DEFAULT if the caller should carry out the access operation.
164 * @param pVM VM Handle.
165 * @param GCPhys The physical address the guest is writing to.
166 * @param pvPhys The HC mapping of that address.
167 * @param pvBuf What the guest is reading/writing.
168 * @param cbBuf How much it's reading/writing.
169 * @param enmAccessType The access type.
170 * @param pvUser User argument.
171 */
172typedef DECLCALLBACK(int) FNPGMR3PHYSHANDLER(PVM pVM, RTGCPHYS GCPhys, void *pvPhys, void *pvBuf, size_t cbBuf, PGMACCESSTYPE enmAccessType, void *pvUser);
173/** Pointer to PGM access callback. */
174typedef FNPGMR3PHYSHANDLER *PFNPGMR3PHYSHANDLER;
175
176
177/**
178 * Virtual access handler type.
179 */
180typedef enum PGMVIRTHANDLERTYPE
181{
182 /** Natural traps only. */
183 PGMVIRTHANDLERTYPE_NORMAL = 1,
184 /** Write access handled. */
185 PGMVIRTHANDLERTYPE_WRITE,
186 /** All access handled. */
187 PGMVIRTHANDLERTYPE_ALL,
188 /** By eip - Natural traps only. */
189 PGMVIRTHANDLERTYPE_EIP,
190 /** Hypervisor write access handled.
191 * This is used to catch the guest trying to write to LDT, TSS and any other
192 * system structure which the brain dead intel guys let unprivilegde code find. */
193 PGMVIRTHANDLERTYPE_HYPERVISOR
194
195} PGMVIRTHANDLERTYPE;
196
197/**
198 * \#PF Handler callback for virtual access handler ranges.
199 *
200 * Important to realize that a physical page in a range can have aliases, and
201 * for ALL and WRITE handlers these will also trigger.
202 *
203 * @returns VBox status code (appropriate for GC return).
204 * @param pVM VM Handle.
205 * @param uErrorCode CPU Error code.
206 * @param pRegFrame Trap register frame.
207 * @param pvFault The fault address (cr2).
208 * @param pvRange The base address of the handled virtual range.
209 * @param offRange The offset of the access into this range.
210 * (If it's a EIP range this's the EIP, if not it's pvFault.)
211 */
212typedef DECLCALLBACK(int) FNPGMGCVIRTHANDLER(PVM pVM, RTGCUINT uErrorCode, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault, RTGCPTR pvRange, uintptr_t offRange);
213/** Pointer to PGM access callback. */
214typedef FNPGMGCVIRTHANDLER *PFNPGMGCVIRTHANDLER;
215
216/**
217 * \#PF Handler callback for virtual access handler ranges.
218 *
219 * Important to realize that a physical page in a range can have aliases, and
220 * for ALL and WRITE handlers these will also trigger.
221 *
222 * @returns VINF_SUCCESS if the handler have carried out the operation.
223 * @returns VINF_PGM_HANDLER_DO_DEFAULT if the caller should carry out the access operation.
224 * @param pVM VM Handle.
225 * @param GCPtr The virtual address the guest is writing to. (not correct if it's an alias!)
226 * @param pvPtr The HC mapping of that address.
227 * @param pvBuf What the guest is reading/writing.
228 * @param cbBuf How much it's reading/writing.
229 * @param enmAccessType The access type.
230 * @param pvUser User argument.
231 */
232typedef DECLCALLBACK(int) FNPGMHCVIRTHANDLER(PVM pVM, RTGCPTR GCPtr, void *pvPtr, void *pvBuf, size_t cbBuf, PGMACCESSTYPE enmAccessType, void *pvUser);
233/** Pointer to PGM access callback. */
234typedef FNPGMHCVIRTHANDLER *PFNPGMHCVIRTHANDLER;
235
236
237/**
238 * \#PF Handler callback for invalidation of virtual access handler ranges.
239 *
240 * @param pVM VM Handle.
241 * @param GCPtr The virtual address the guest has changed.
242 */
243typedef DECLCALLBACK(int) FNPGMHCVIRTINVALIDATE(PVM pVM, RTGCPTR GCPtr);
244/** Pointer to PGM invalidation callback. */
245typedef FNPGMHCVIRTINVALIDATE *PFNPGMHCVIRTINVALIDATE;
246
247/**
248 * Paging mode.
249 */
250typedef enum PGMMODE
251{
252 /** The usual invalid value. */
253 PGMMODE_INVALID = 0,
254 /** Real mode. */
255 PGMMODE_REAL,
256 /** Protected mode, no paging. */
257 PGMMODE_PROTECTED,
258 /** 32-bit paging. */
259 PGMMODE_32_BIT,
260 /** PAE paging. */
261 PGMMODE_PAE,
262 /** PAE paging with NX enabled. */
263 PGMMODE_PAE_NX,
264 /** 64-bit AMD paging (long mode). */
265 PGMMODE_AMD64,
266 /** 64-bit AMD paging (long mode) with NX enabled. */
267 PGMMODE_AMD64_NX,
268 /** The max number of modes */
269 PGMMODE_MAX,
270 /** 32bit hackishness. */
271 PGMMODE_32BIT_HACK = 0x7fffffff
272} PGMMODE;
273
274
275/**
276 * Gets the current CR3 register value for the shadow memory context.
277 * @returns CR3 value.
278 * @param pVM The VM handle.
279 */
280PGMDECL(uint32_t) PGMGetHyperCR3(PVM pVM);
281
282/**
283 * Gets the CR3 register value for the 32-Bit shadow memory context.
284 * @returns CR3 value.
285 * @param pVM The VM handle.
286 */
287PGMDECL(uint32_t) PGMGetHyper32BitCR3(PVM pVM);
288
289/**
290 * Gets the CR3 register value for the PAE shadow memory context.
291 * @returns CR3 value.
292 * @param pVM The VM handle.
293 */
294PGMDECL(uint32_t) PGMGetHyperPaeCR3(PVM pVM);
295
296/**
297 * Gets the CR3 register value for the AMD64 shadow memory context.
298 * @returns CR3 value.
299 * @param pVM The VM handle.
300 */
301PGMDECL(uint32_t) PGMGetHyperAmd64CR3(PVM pVM);
302
303/**
304 * Gets the current CR3 register value for the HC intermediate memory context.
305 * @returns CR3 value.
306 * @param pVM The VM handle.
307 */
308PGMDECL(uint32_t) PGMGetInterHCCR3(PVM pVM);
309
310/**
311 * Gets the current CR3 register value for the GC intermediate memory context.
312 * @returns CR3 value.
313 * @param pVM The VM handle.
314 */
315PGMDECL(uint32_t) PGMGetInterGCCR3(PVM pVM);
316
317/**
318 * Gets the CR3 register value for the 32-Bit intermediate memory context.
319 * @returns CR3 value.
320 * @param pVM The VM handle.
321 */
322PGMDECL(uint32_t) PGMGetInter32BitCR3(PVM pVM);
323
324/**
325 * Gets the CR3 register value for the PAE intermediate memory context.
326 * @returns CR3 value.
327 * @param pVM The VM handle.
328 */
329PGMDECL(uint32_t) PGMGetInterPaeCR3(PVM pVM);
330
331/**
332 * Gets the CR3 register value for the AMD64 intermediate memory context.
333 * @returns CR3 value.
334 * @param pVM The VM handle.
335 */
336PGMDECL(uint32_t) PGMGetInterAmd64CR3(PVM pVM);
337
338/**
339 * \#PF Handler.
340 *
341 * @returns VBox status code (appropriate for GC return).
342 * @param pVM VM Handle.
343 * @param uErr The trap error code.
344 * @param pRegFrame Trap register frame.
345 * @param pvFault The fault address.
346 */
347PGMDECL(int) PGMTrap0eHandler(PVM pVM, RTGCUINT uErr, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault);
348
349/**
350 * Prefetch a page/set of pages.
351 *
352 * Typically used to sync commonly used pages before entering raw mode
353 * after a CR3 reload.
354 *
355 * @returns VBox status code suitable for scheduling.
356 * @retval VINF_SUCCESS on success.
357 * @retval VINF_PGM_SYNC_CR3 if we're out of shadow pages or something like that.
358 * @param pVM VM handle.
359 * @param GCPtrPage Page to prefetch.
360 */
361PGMDECL(int) PGMPrefetchPage(PVM pVM, RTGCPTR GCPtrPage);
362
363/**
364 * Verifies a range of pages for read or write access.
365 *
366 * Supports handling of pages marked for dirty bit tracking and CSAM.
367 *
368 * @returns VBox status code.
369 * @param pVM VM handle.
370 * @param Addr Guest virtual address to check.
371 * @param cbSize Access size.
372 * @param fAccess Access type (r/w, user/supervisor (X86_PTE_*).
373 */
374PGMDECL(int) PGMVerifyAccess(PVM pVM, RTGCUINTPTR Addr, uint32_t cbSize, uint32_t fAccess);
375
376/**
377 * Verifies a range of pages for read or write access
378 *
379 * Only checks the guest's page tables
380 *
381 * @returns VBox status code.
382 * @param pVM VM handle.
383 * @param Addr Guest virtual address to check
384 * @param cbSize Access size
385 * @param fAccess Access type (r/w, user/supervisor (X86_PTE_*))
386 */
387PGMDECL(int) PGMIsValidAccess(PVM pVM, RTGCUINTPTR Addr, uint32_t cbSize, uint32_t fAccess);
388
389/**
390 * Executes an instruction using the interpreter.
391 *
392 * @returns VBox status code (appropriate for trap handling and GC return).
393 * @param pVM VM handle.
394 * @param pRegFrame Register frame.
395 * @param pvFault Fault address.
396 */
397PGMDECL(int) PGMInterpretInstruction(PVM pVM, PCPUMCTXCORE pRegFrame, RTGCPTR pvFault);
398
399/**
400 * Maps a range of physical pages at a given virtual address
401 * in the guest context.
402 *
403 * The GC virtual address range must be within an existing mapping.
404 *
405 * @returns VBox status code.
406 * @param pVM The virtual machine.
407 * @param GCPtr Where to map the page(s). Must be page aligned.
408 * @param HCPhys Start of the range of physical pages. Must be page aligned.
409 * @param cbPages Number of bytes to map. Must be page aligned.
410 * @param fFlags Page flags (X86_PTE_*).
411 */
412PGMDECL(int) PGMMap(PVM pVM, RTGCUINTPTR GCPtr, RTHCPHYS HCPhys, uint32_t cbPages, unsigned fFlags);
413
414/**
415 * Sets (replaces) the page flags for a range of pages in a mapping.
416 *
417 * The pages must be mapped pages, it's not possible to change the flags of
418 * Guest OS pages.
419 *
420 * @returns VBox status.
421 * @param pVM VM handle.
422 * @param GCPtr Virtual address of the first page in the range.
423 * @param cb Size (in bytes) of the range to apply the modification to.
424 * @param fFlags Page flags X86_PTE_*, excluding the page mask of course.
425 */
426PGMDECL(int) PGMMapSetPage(PVM pVM, RTGCPTR GCPtr, uint64_t cb, uint64_t fFlags);
427
428/**
429 * Modify page flags for a range of pages in a mapping.
430 *
431 * The existing flags are ANDed with the fMask and ORed with the fFlags.
432 *
433 * @returns VBox status code.
434 * @param pVM VM handle.
435 * @param GCPtr Virtual address of the first page in the range.
436 * @param cb Size (in bytes) of the range to apply the modification to.
437 * @param fFlags The OR mask - page flags X86_PTE_*, excluding the page mask of course.
438 * @param fMask The AND mask - page flags X86_PTE_*.
439 * Be very CAREFUL when ~'ing constants which could be 32-bit!
440 */
441PGMDECL(int) PGMMapModifyPage(PVM pVM, RTGCPTR GCPtr, size_t cb, uint64_t fFlags, uint64_t fMask);
442
443/**
444 * Gets effective page information (from the VMM page directory).
445 *
446 * @returns VBox status.
447 * @param pVM VM Handle.
448 * @param GCPtr Guest Context virtual address of the page.
449 * @param pfFlags Where to store the flags. These are X86_PTE_*.
450 * @param pHCPhys Where to store the HC physical address of the page.
451 * This is page aligned.
452 * @remark You should use PGMMapGetPage() for pages in a mapping.
453 */
454PGMDECL(int) PGMShwGetPage(PVM pVM, RTGCPTR GCPtr, uint64_t *pfFlags, PRTHCPHYS pHCPhys);
455
456/**
457 * Sets (replaces) the page flags for a range of pages in the shadow context.
458 *
459 * @returns VBox status.
460 * @param pVM VM handle.
461 * @param GCPtr The address of the first page.
462 * @param cb The size of the range in bytes.
463 * @param fFlags Page flags X86_PTE_*, excluding the page mask of course.
464 * @remark You must use PGMMapSetPage() for pages in a mapping.
465 */
466PGMDECL(int) PGMShwSetPage(PVM pVM, RTGCPTR GCPtr, size_t cb, uint64_t fFlags);
467
468/**
469 * Modify page flags for a range of pages in the shadow context.
470 *
471 * The existing flags are ANDed with the fMask and ORed with the fFlags.
472 *
473 * @returns VBox status code.
474 * @param pVM VM handle.
475 * @param GCPtr Virtual address of the first page in the range.
476 * @param cb Size (in bytes) of the range to apply the modification to.
477 * @param fFlags The OR mask - page flags X86_PTE_*, excluding the page mask of course.
478 * @param fMask The AND mask - page flags X86_PTE_*.
479 * Be very CAREFUL when ~'ing constants which could be 32-bit!
480 * @remark You must use PGMMapModifyPage() for pages in a mapping.
481 */
482PGMDECL(int) PGMShwModifyPage(PVM pVM, RTGCPTR GCPtr, size_t cb, uint64_t fFlags, uint64_t fMask);
483
484/**
485 * Gets effective Guest OS page information.
486 *
487 * When GCPtr is in a big page, the function will return as if it was a normal
488 * 4KB page. If the need for distinguishing between big and normal page becomes
489 * necessary at a later point, a PGMGstGetPageEx() will be created for that
490 * purpose.
491 *
492 * @returns VBox status.
493 * @param pVM VM Handle.
494 * @param GCPtr Guest Context virtual address of the page.
495 * @param pfFlags Where to store the flags. These are X86_PTE_*, even for big pages.
496 * @param pGCPhys Where to store the GC physical address of the page.
497 * This is page aligned. The fact that the
498 */
499PGMDECL(int) PGMGstGetPage(PVM pVM, RTGCPTR GCPtr, uint64_t *pfFlags, PRTGCPHYS pGCPhys);
500
501/**
502 * Checks if the page is present.
503 *
504 * @returns true if the page is present.
505 * @returns false if the page is not present.
506 * @param pVM The VM handle.
507 * @param GCPtr Address within the page.
508 */
509PGMDECL(bool) PGMGstIsPagePresent(PVM pVM, RTGCPTR GCPtr);
510
511/**
512 * Sets (replaces) the page flags for a range of pages in the guest's tables.
513 *
514 * @returns VBox status.
515 * @param pVM VM handle.
516 * @param GCPtr The address of the first page.
517 * @param cb The size of the range in bytes.
518 * @param fFlags Page flags X86_PTE_*, excluding the page mask of course.
519 */
520PGMDECL(int) PGMGstSetPage(PVM pVM, RTGCPTR GCPtr, size_t cb, uint64_t fFlags);
521
522/**
523 * Modify page flags for a range of pages in the guest's tables
524 *
525 * The existing flags are ANDed with the fMask and ORed with the fFlags.
526 *
527 * @returns VBox status code.
528 * @param pVM VM handle.
529 * @param GCPtr Virtual address of the first page in the range.
530 * @param cb Size (in bytes) of the range to apply the modification to.
531 * @param fFlags The OR mask - page flags X86_PTE_*, excluding the page mask of course.
532 * @param fMask The AND mask - page flags X86_PTE_*, excluding the page mask of course.
533 * Be very CAREFUL when ~'ing constants which could be 32-bit!
534 */
535PGMDECL(int) PGMGstModifyPage(PVM pVM, RTGCPTR GCPtr, size_t cb, uint64_t fFlags, uint64_t fMask);
536
537/**
538 * Performs and schedules necessary updates following a CR3 load or reload.
539 *
540 * This will normally involve mapping the guest PD or nPDPTR
541 *
542 * @returns VBox status code.
543 * @retval VINF_PGM_SYNC_CR3 if monitoring requires a CR3 sync. This can
544 * safely be ignored and overridden since the FF will be set too then.
545 * @param pVM VM handle.
546 * @param cr3 The new cr3.
547 * @param fGlobal Indicates whether this is a global flush or not.
548 */
549PGMDECL(int) PGMFlushTLB(PVM pVM, uint32_t cr3, bool fGlobal);
550
551/**
552 * Synchronize the paging structures.
553 *
554 * This function is called in response to the VM_FF_PGM_SYNC_CR3 and
555 * VM_FF_PGM_SYNC_CR3_NONGLOBAL. Those two force action flags are set
556 * in several places, most importantly whenever the CR3 is loaded.
557 *
558 * @returns VBox status code.
559 * @param pVM The virtual machine.
560 * @param cr0 Guest context CR0 register
561 * @param cr3 Guest context CR3 register
562 * @param cr4 Guest context CR4 register
563 * @param fGlobal Including global page directories or not
564 */
565PGMDECL(int) PGMSyncCR3(PVM pVM, uint32_t cr0, uint32_t cr3, uint32_t cr4, bool fGlobal);
566
567/**
568 * Called whenever CR0 or CR4 in a way which may change
569 * the paging mode.
570 *
571 * @returns VBox status code fit for scheduling in GC and R0.
572 * @retval VINF_SUCCESS if the was no change, or it was successfully dealt with.
573 * @retval VINF_PGM_CHANGE_MODE if we're in GC or R0 and the mode changes.
574 * @param pVM VM handle.
575 * @param cr0 The new cr0.
576 * @param cr4 The new cr4.
577 * @param efer The new extended feature enable register.
578 */
579PGMDECL(int) PGMChangeMode(PVM pVM, uint32_t cr0, uint32_t cr4, uint64_t efer);
580
581/**
582 * Gets the current guest paging mode.
583 *
584 * If you just need the CPU mode (real/protected/long), use CPUMGetGuestMode().
585 *
586 * @returns The current paging mode.
587 * @param pVM The VM handle.
588 */
589PGMDECL(PGMMODE) PGMGetGuestMode(PVM pVM);
590
591/**
592 * Gets the current shadow paging mode.
593 *
594 * @returns The current paging mode.
595 * @param pVM The VM handle.
596 */
597PGMDECL(PGMMODE) PGMGetShadowMode(PVM pVM);
598
599/**
600 * Get mode name.
601 *
602 * @returns read-only name string.
603 * @param enmMode The mode which name is desired.
604 */
605PGMDECL(const char *) PGMGetModeName(PGMMODE enmMode);
606
607/**
608 * Register a access handler for a physical range.
609 *
610 * @returns VBox status code.
611 * @param pVM VM Handle.
612 * @param enmType Handler type. Any of the PGMPHYSHANDLERTYPE_PHYSICAL* enums.
613 * @param GCPhys Start physical address.
614 * @param GCPhysLast Last physical address. (inclusive)
615 * @param pfnHandlerR3 The R3 handler.
616 * @param pvUserR3 User argument to the R3 handler.
617 * @param pfnHandlerR0 The R0 handler.
618 * @param pvUserR0 User argument to the R0 handler.
619 * @param pfnHandlerGC The GC handler.
620 * @param pvUserGC User argument to the GC handler.
621 * This must be a GC pointer because it will be relocated!
622 * @param pszDesc Pointer to description string. This must not be freed.
623 */
624PGMDECL(int) PGMHandlerPhysicalRegisterEx(PVM pVM, PGMPHYSHANDLERTYPE enmType, RTGCPHYS GCPhys, RTGCPHYS GCPhysLast,
625 R3PTRTYPE(PFNPGMR3PHYSHANDLER) pfnHandlerR3, RTR3PTR pvUserR3,
626 R0PTRTYPE(PFNPGMR0PHYSHANDLER) pfnHandlerR0, RTR0PTR pvUserR0,
627 GCPTRTYPE(PFNPGMGCPHYSHANDLER) pfnHandlerGC, RTGCPTR pvUserGC,
628 R3PTRTYPE(const char *) pszDesc);
629
630/**
631 * Modify a physical page access handler.
632 *
633 * Modification can only be done to the range it self, not the type or anything else.
634 *
635 * @returns VBox status code.
636 * For all return codes other than VERR_PGM_HANDLER_NOT_FOUND and VINF_SUCCESS the range is deregistered
637 * and a new registration must be performed!
638 * @param pVM VM handle.
639 * @param GCPhysCurrent Current location.
640 * @param GCPhys New location.
641 * @param GCPhysLast New last location.
642 */
643PGMDECL(int) PGMHandlerPhysicalModify(PVM pVM, RTGCPHYS GCPhysCurrent, RTGCPHYS GCPhys, RTGCPHYS GCPhysLast);
644
645/**
646 * Register a physical page access handler.
647 *
648 * @returns VBox status code.
649 * @param pVM VM Handle.
650 * @param GCPhys Start physical address earlier passed to PGMR3HandlerPhysicalRegister().
651 */
652PGMDECL(int) PGMHandlerPhysicalDeregister(PVM pVM, RTGCPHYS GCPhys);
653
654/**
655 * Changes the callbacks associated with a physical access handler.
656 *
657 * @returns VBox status code.
658 * @param pVM VM Handle.
659 * @param GCPhys Start physical address.
660 * @param pfnHandlerR3 The R3 handler.
661 * @param pvUserR3 User argument to the R3 handler.
662 * @param pfnHandlerR0 The R0 handler.
663 * @param pvUserR0 User argument to the R0 handler.
664 * @param pfnHandlerGC The GC handler.
665 * @param pvUserGC User argument to the GC handler.
666 * This must be a GC pointer because it will be relocated!
667 * @param pszDesc Pointer to description string. This must not be freed.
668 */
669PGMDECL(int) PGMHandlerPhysicalChangeCallbacks(PVM pVM, RTGCPHYS GCPhys,
670 R3PTRTYPE(PFNPGMR3PHYSHANDLER) pfnHandlerR3, RTR3PTR pvUserR3,
671 R0PTRTYPE(PFNPGMR0PHYSHANDLER) pfnHandlerR0, RTR0PTR pvUserR0,
672 GCPTRTYPE(PFNPGMGCPHYSHANDLER) pfnHandlerGC, RTGCPTR pvUserGC,
673 R3PTRTYPE(const char *) pszDesc);
674
675/**
676 * Splitts a physical access handler in two.
677 *
678 * @returns VBox status code.
679 * @param pVM VM Handle.
680 * @param GCPhys Start physical address of the handler.
681 * @param GCPhysSplit The split address.
682 */
683PGMDECL(int) PGMHandlerPhysicalSplit(PVM pVM, RTGCPHYS GCPhys, RTGCPHYS GCPhysSplit);
684
685/**
686 * Joins up two adjacent physical access handlers which has the same callbacks.
687 *
688 * @returns VBox status code.
689 * @param pVM VM Handle.
690 * @param GCPhys1 Start physical address of the first handler.
691 * @param GCPhys2 Start physical address of the second handler.
692 */
693PGMDECL(int) PGMHandlerPhysicalJoin(PVM pVM, RTGCPHYS GCPhys1, RTGCPHYS GCPhys2);
694
695/**
696 * Temporarily turns off the access monitoring of a page within a monitored
697 * physical write/all page access handler region.
698 *
699 * Use this when no further #PFs are required for that page. Be aware that
700 * a page directory sync might reset the flags, and turn on access monitoring
701 * for the page.
702 *
703 * The caller must do required page table modifications.
704 *
705 * @returns VBox status code.
706 * @param pVM VM Handle
707 * @param GCPhys Start physical address earlier passed to PGMR3HandlerPhysicalRegister().
708 * @param GCPhysPage Physical address of the page to turn off access monitoring for.
709 */
710PGMDECL(int) PGMHandlerPhysicalPageTempOff(PVM pVM, RTGCPHYS GCPhys, RTGCPHYS GCPhysPage);
711
712
713/**
714 * Resets any modifications to individual pages in a physical
715 * page access handler region.
716 *
717 * This is used in pair with PGMHandlerPhysicalModify().
718 *
719 * @returns VBox status code.
720 * @param pVM VM Handle
721 * @param GCPhys Start physical address earlier passed to PGMR3HandlerPhysicalRegister().
722 */
723PGMDECL(int) PGMHandlerPhysicalReset(PVM pVM, RTGCPHYS GCPhys);
724
725/**
726 * Turns access monitoring of a page within a monitored
727 * physical write/all page access handler region back on.
728 *
729 * The caller must do required page table modifications.
730 *
731 * @returns VBox status code.
732 * @param pVM VM Handle
733 * @param GCPhys Start physical address earlier passed to PGMR3HandlerPhysicalRegister().
734 * @param GCPhysPage Physical address of the page to turn on access monitoring for.
735 */
736PGMDECL(int) PGMHandlerPhysicalPageReset(PVM pVM, RTGCPHYS GCPhys, RTGCPHYS GCPhysPage);
737
738/**
739 * Checks if a physical range is handled
740 *
741 * @returns boolean.
742 * @param pVM VM Handle
743 * @param GCPhys Start physical address earlier passed to PGMR3HandlerPhysicalRegister().
744 */
745PGMDECL(bool) PGMHandlerPhysicalIsRegistered(PVM pVM, RTGCPHYS GCPhys);
746
747/**
748 * Checks if Address Gate 20 is enabled or not.
749 *
750 * @returns true if enabled.
751 * @returns false if disabled.
752 * @param pVM VM handle.
753 */
754PGMDECL(bool) PGMPhysIsA20Enabled(PVM pVM);
755
756/**
757 * Validates a GC physical address.
758 *
759 * @returns true if valid.
760 * @returns false if invalid.
761 * @param pVM The VM handle.
762 * @param GCPhys The physical address to validate.
763 */
764PGMDECL(bool) PGMPhysIsGCPhysValid(PVM pVM, RTGCPHYS GCPhys);
765
766/**
767 * Checks if a GC physical address is a normal page,
768 * i.e. not ROM, MMIO or reserved.
769 *
770 * @returns true if normal.
771 * @returns false if invalid, ROM, MMIO or reserved page.
772 * @param pVM The VM handle.
773 * @param GCPhys The physical address to check.
774 */
775PGMDECL(bool) PGMPhysIsGCPhysNormal(PVM pVM, RTGCPHYS GCPhys);
776
777/**
778 * Converts a GC physical address to a HC physical address.
779 *
780 * @returns VINF_SUCCESS on success.
781 * @returns VERR_PGM_PHYS_PAGE_RESERVED it it's a valid GC physical
782 * page but has no physical backing.
783 * @returns VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS if it's not a valid
784 * GC physical address.
785 * @param pVM The VM handle.
786 * @param GCPhys The GC physical address to convert.
787 * @param pHCPhys Where to store the HC physical address on success.
788 */
789PGMDECL(int) PGMPhysGCPhys2HCPhys(PVM pVM, RTGCPHYS GCPhys, PRTHCPHYS pHCPhys);
790
791/**
792 * Converts a guest pointer to a GC physical address.
793 *
794 * This uses the current CR3/CR0/CR4 of the guest.
795 *
796 * @returns VBox status code.
797 * @param pVM The VM Handle
798 * @param GCPtr The guest pointer to convert.
799 * @param pGCPhys Where to store the GC physical address.
800 */
801PGMDECL(int) PGMPhysGCPtr2GCPhys(PVM pVM, RTGCPTR GCPtr, PRTGCPHYS pGCPhys);
802
803/**
804 * Converts a guest pointer to a HC physical address.
805 *
806 * This uses the current CR3/CR0/CR4 of the guest.
807 *
808 * @returns VBox status code.
809 * @param pVM The VM Handle
810 * @param GCPtr The guest pointer to convert.
811 * @param pHCPhys Where to store the HC physical address.
812 */
813PGMDECL(int) PGMPhysGCPtr2HCPhys(PVM pVM, RTGCPTR GCPtr, PRTHCPHYS pHCPhys);
814
815
816/**
817 * Invalidates the GC page mapping TLB.
818 *
819 * @param pVM The VM handle.
820 */
821PDMDECL(void) PGMPhysInvalidatePageGCMapTLB(PVM pVM);
822
823/**
824 * Invalidates the ring-0 page mapping TLB.
825 *
826 * @param pVM The VM handle.
827 */
828PDMDECL(void) PGMPhysInvalidatePageR0MapTLB(PVM pVM);
829
830/**
831 * Invalidates the ring-3 page mapping TLB.
832 *
833 * @param pVM The VM handle.
834 */
835PDMDECL(void) PGMPhysInvalidatePageR3MapTLB(PVM pVM);
836
837/**
838 * Page mapping lock.
839 *
840 * @remarks This doesn't work in structures shared between
841 * ring-3, ring-0 and/or GC.
842 */
843typedef struct PGMPAGEMAPLOCK
844{
845 /** @todo see PGMPhysIsPageMappingLockValid for possibly incorrect assumptions */
846#ifdef IN_GC
847 /** Just a dummy for the time being. */
848 uint32_t u32Dummy;
849#else
850 /** Pointer to the PGMPAGE. */
851 void *pvPage;
852 /** Pointer to the PGMCHUNKR3MAP. */
853 void *pvMap;
854#endif
855} PGMPAGEMAPLOCK;
856/** Pointer to a page mapping lock. */
857typedef PGMPAGEMAPLOCK *PPGMPAGEMAPLOCK;
858
859/**
860 * Requests the mapping of a guest page into the current context.
861 *
862 * This API should only be used for very short term, as it will consume
863 * scarse resources (R0 and GC) in the mapping cache. When you're done
864 * with the page, call PGMPhysReleasePageMappingLock() ASAP to release it.
865 *
866 * This API will assume your intention is to write to the page, and will
867 * therefore replace shared and zero pages. If you do not intend to modify
868 * the page, use the PGMPhysGCPhys2CCPtrReadOnly() API.
869 *
870 * @returns VBox status code.
871 * @retval VINF_SUCCESS on success.
872 * @retval VERR_PGM_PHYS_PAGE_RESERVED it it's a valid page but has no physical backing.
873 * @retval VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS if it's not a valid physical address.
874 *
875 * @param pVM The VM handle.
876 * @param GCPhys The guest physical address of the page that should be mapped.
877 * @param ppv Where to store the address corresponding to GCPhys.
878 * @param pLock Where to store the lock information that PGMPhysReleasePageMappingLock needs.
879 *
880 * @remark Avoid calling this API from within critical sections (other than
881 * the PGM one) because of the deadlock risk.
882 * @thread Any thread.
883 */
884PGMDECL(int) PGMPhysGCPhys2CCPtr(PVM pVM, RTGCPHYS GCPhys, void **ppv, PPGMPAGEMAPLOCK pLock);
885
886/**
887 * Requests the mapping of a guest page into the current context.
888 *
889 * This API should only be used for very short term, as it will consume
890 * scarse resources (R0 and GC) in the mapping cache. When you're done
891 * with the page, call PGMPhysReleasePageMappingLock() ASAP to release it.
892 *
893 * @returns VBox status code.
894 * @retval VINF_SUCCESS on success.
895 * @retval VERR_PGM_PHYS_PAGE_RESERVED it it's a valid page but has no physical backing.
896 * @retval VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS if it's not a valid physical address.
897 *
898 * @param pVM The VM handle.
899 * @param GCPhys The guest physical address of the page that should be mapped.
900 * @param ppv Where to store the address corresponding to GCPhys.
901 * @param pLock Where to store the lock information that PGMPhysReleasePageMappingLock needs.
902 *
903 * @remark Avoid calling this API from within critical sections (other than
904 * the PGM one) because of the deadlock risk.
905 * @thread Any thread.
906 */
907PGMDECL(int) PGMPhysGCPhys2CCPtrReadOnly(PVM pVM, RTGCPHYS GCPhys, void const **ppv, PPGMPAGEMAPLOCK pLock);
908
909/**
910 * Requests the mapping of a guest page given by virtual address into the current context.
911 *
912 * This API should only be used for very short term, as it will consume
913 * scarse resources (R0 and GC) in the mapping cache. When you're done
914 * with the page, call PGMPhysReleasePageMappingLock() ASAP to release it.
915 *
916 * This API will assume your intention is to write to the page, and will
917 * therefore replace shared and zero pages. If you do not intend to modify
918 * the page, use the PGMPhysGCPtr2CCPtrReadOnly() API.
919 *
920 * @returns VBox status code.
921 * @retval VINF_SUCCESS on success.
922 * @retval VERR_PAGE_TABLE_NOT_PRESENT if the page directory for the virtual address isn't present.
923 * @retval VERR_PAGE_NOT_PRESENT if the page at the virtual address isn't present.
924 * @retval VERR_PGM_PHYS_PAGE_RESERVED it it's a valid page but has no physical backing.
925 * @retval VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS if it's not a valid physical address.
926 *
927 * @param pVM The VM handle.
928 * @param GCPhys The guest physical address of the page that should be mapped.
929 * @param ppv Where to store the address corresponding to GCPhys.
930 * @param pLock Where to store the lock information that PGMPhysReleasePageMappingLock needs.
931 *
932 * @remark Avoid calling this API from within critical sections (other than
933 * the PGM one) because of the deadlock risk.
934 * @thread EMT
935 */
936PGMDECL(int) PGMPhysGCPtr2CCPtr(PVM pVM, RTGCPTR GCPtr, void **ppv, PPGMPAGEMAPLOCK pLock);
937
938/**
939 * Requests the mapping of a guest page given by virtual address into the current context.
940 *
941 * This API should only be used for very short term, as it will consume
942 * scarse resources (R0 and GC) in the mapping cache. When you're done
943 * with the page, call PGMPhysReleasePageMappingLock() ASAP to release it.
944 *
945 * @returns VBox status code.
946 * @retval VINF_SUCCESS on success.
947 * @retval VERR_PAGE_TABLE_NOT_PRESENT if the page directory for the virtual address isn't present.
948 * @retval VERR_PAGE_NOT_PRESENT if the page at the virtual address isn't present.
949 * @retval VERR_PGM_PHYS_PAGE_RESERVED it it's a valid page but has no physical backing.
950 * @retval VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS if it's not a valid physical address.
951 *
952 * @param pVM The VM handle.
953 * @param GCPhys The guest physical address of the page that should be mapped.
954 * @param ppv Where to store the address corresponding to GCPhys.
955 * @param pLock Where to store the lock information that PGMPhysReleasePageMappingLock needs.
956 *
957 * @remark Avoid calling this API from within critical sections (other than
958 * the PGM one) because of the deadlock risk.
959 * @thread EMT
960 */
961PGMDECL(int) PGMPhysGCPtr2CCPtrReadOnly(PVM pVM, RTGCPTR GCPtr, void const **ppv, PPGMPAGEMAPLOCK pLock);
962
963/**
964 * Release the mapping of a guest page.
965 *
966 * This is the counter part of PGMPhysGCPhys2CCPtr, PGMPhysGCPhys2CCPtrReadOnly
967 * PGMPhysGCPtr2CCPtr and PGMPhysGCPtr2CCPtrReadOnly.
968 *
969 * @param pVM The VM handle.
970 * @param pLock The lock structure initialized by the mapping function.
971 */
972PGMDECL(void) PGMPhysReleasePageMappingLock(PVM pVM, PPGMPAGEMAPLOCK pLock);
973
974
975/**
976 * Checks if the lock structure is valid
977 *
978 * @param pVM The VM handle.
979 * @param pLock The lock structure initialized by the mapping function.
980 */
981DECLINLINE(bool) PGMPhysIsPageMappingLockValid(PVM pVM, PPGMPAGEMAPLOCK pLock)
982{
983 /** @todo -> complete/change this */
984#ifdef IN_GC
985 return !!(pLock->u32Dummy);
986#else
987 return !!(pLock->pvPage);
988#endif
989}
990
991/**
992 * Converts a GC physical address to a HC pointer.
993 *
994 * @returns VINF_SUCCESS on success.
995 * @returns VERR_PGM_PHYS_PAGE_RESERVED it it's a valid GC physical
996 * page but has no physical backing.
997 * @returns VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS if it's not a valid
998 * GC physical address.
999 * @param pVM The VM handle.
1000 * @param GCPhys The GC physical address to convert.
1001 * @param cbRange Physical range
1002 * @param pHCPtr Where to store the HC pointer on success.
1003 *
1004 * @remark Do *not* assume this mapping will be around forever!
1005 */
1006PGMDECL(int) PGMPhysGCPhys2HCPtr(PVM pVM, RTGCPHYS GCPhys, RTUINT cbRange, PRTHCPTR pHCPtr);
1007
1008/**
1009 * Converts a guest pointer to a HC pointer.
1010 *
1011 * This uses the current CR3/CR0/CR4 of the guest.
1012 *
1013 * @returns VBox status code.
1014 * @param pVM The VM Handle
1015 * @param GCPtr The guest pointer to convert.
1016 * @param pHCPtr Where to store the HC virtual address.
1017 *
1018 * @remark Do *not* assume this mapping will be around forever!
1019 */
1020PGMDECL(int) PGMPhysGCPtr2HCPtr(PVM pVM, RTGCPTR GCPtr, PRTHCPTR pHCPtr);
1021
1022/**
1023 * Converts a guest virtual address to a HC pointer by specfied CR3 and flags.
1024 *
1025 * @returns VBox status code.
1026 * @param pVM The VM Handle
1027 * @param GCPtr The guest pointer to convert.
1028 * @param cr3 The guest CR3.
1029 * @param fFlags Flags used for interpreting the PD correctly: X86_CR4_PSE and X86_CR4_PAE
1030 * @param pHCPtr Where to store the HC pointer.
1031 *
1032 * @remark Do *not* assume this mapping will be around forever!
1033 * @remark This function is used by the REM at a time where PGM could
1034 * potentially not be in sync. It could also be used by a
1035 * future DBGF API to cpu state independent conversions.
1036 */
1037PGMDECL(int) PGMPhysGCPtr2HCPtrByGstCR3(PVM pVM, RTGCPTR GCPtr, uint32_t cr3, unsigned fFlags, PRTHCPTR pHCPtr);
1038
1039/**
1040 * Read physical memory.
1041 *
1042 * This API respects access handlers and MMIO. Use PGMPhysReadGCPhys() if you
1043 * want to ignore those.
1044 *
1045 * @param pVM VM Handle.
1046 * @param GCPhys Physical address start reading from.
1047 * @param pvBuf Where to put the read bits.
1048 * @param cbRead How many bytes to read.
1049 */
1050PGMDECL(void) PGMPhysRead(PVM pVM, RTGCPHYS GCPhys, void *pvBuf, size_t cbRead);
1051
1052/**
1053 * Write to physical memory.
1054 *
1055 * This API respects access handlers and MMIO. Use PGMPhysReadGCPhys() if you
1056 * want to ignore those.
1057 *
1058 * @param pVM VM Handle.
1059 * @param GCPhys Physical address to write to.
1060 * @param pvBuf What to write.
1061 * @param cbWrite How many bytes to write.
1062 */
1063PGMDECL(void) PGMPhysWrite(PVM pVM, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite);
1064
1065
1066#ifndef IN_GC /* Only ring 0 & 3. */
1067
1068/**
1069 * Read from guest physical memory by GC physical address, bypassing
1070 * MMIO and access handlers.
1071 *
1072 * @returns VBox status.
1073 * @param pVM VM handle.
1074 * @param pvDst The destination address.
1075 * @param GCPhysSrc The source address (GC physical address).
1076 * @param cb The number of bytes to read.
1077 */
1078PGMDECL(int) PGMPhysReadGCPhys(PVM pVM, void *pvDst, RTGCPHYS GCPhysSrc, size_t cb);
1079
1080/**
1081 * Write to guest physical memory referenced by GC pointer.
1082 * Write memory to GC physical address in guest physical memory.
1083 *
1084 * This will bypass MMIO and access handlers.
1085 *
1086 * @returns VBox status.
1087 * @param pVM VM handle.
1088 * @param GCPhysDst The GC physical address of the destination.
1089 * @param pvSrc The source buffer.
1090 * @param cb The number of bytes to write.
1091 */
1092PGMDECL(int) PGMPhysWriteGCPhys(PVM pVM, RTGCPHYS GCPhysDst, const void *pvSrc, size_t cb);
1093
1094/**
1095 * Read from guest physical memory referenced by GC pointer.
1096 *
1097 * This function uses the current CR3/CR0/CR4 of the guest and will
1098 * bypass access handlers and not set any accessed bits.
1099 *
1100 * @returns VBox status.
1101 * @param pVM VM handle.
1102 * @param pvDst The destination address.
1103 * @param GCPtrSrc The source address (GC pointer).
1104 * @param cb The number of bytes to read.
1105 */
1106PGMDECL(int) PGMPhysReadGCPtr(PVM pVM, void *pvDst, RTGCPTR GCPtrSrc, size_t cb);
1107
1108/**
1109 * Write to guest physical memory referenced by GC pointer.
1110 *
1111 * This function uses the current CR3/CR0/CR4 of the guest and will
1112 * bypass access handlers and not set dirty or accessed bits.
1113 *
1114 * @returns VBox status.
1115 * @param pVM VM handle.
1116 * @param GCPtrDst The destination address (GC pointer).
1117 * @param pvSrc The source address.
1118 * @param cb The number of bytes to write.
1119 */
1120PGMDECL(int) PGMPhysWriteGCPtr(PVM pVM, RTGCPTR GCPtrDst, const void *pvSrc, size_t cb);
1121
1122/**
1123 * Read from guest physical memory referenced by GC pointer.
1124 *
1125 * This function uses the current CR3/CR0/CR4 of the guest and will
1126 * respect access handlers and set accessed bits.
1127 *
1128 * @returns VBox status.
1129 * @param pVM VM handle.
1130 * @param pvDst The destination address.
1131 * @param GCPtrSrc The source address (GC pointer).
1132 * @param cb The number of bytes to read.
1133 */
1134PGMDECL(int) PGMPhysReadGCPtrSafe(PVM pVM, void *pvDst, RTGCPTR GCPtrSrc, size_t cb);
1135
1136/**
1137 * Write to guest physical memory referenced by GC pointer.
1138 *
1139 * This function uses the current CR3/CR0/CR4 of the guest and will
1140 * respect access handlers and set dirty and accessed bits.
1141 *
1142 * @returns VBox status.
1143 * @param pVM VM handle.
1144 * @param GCPtrDst The destination address (GC pointer).
1145 * @param pvSrc The source address.
1146 * @param cb The number of bytes to write.
1147 */
1148PGMDECL(int) PGMPhysWriteGCPtrSafe(PVM pVM, RTGCPTR GCPtrDst, const void *pvSrc, size_t cb);
1149
1150/**
1151 * Write to guest physical memory referenced by GC pointer and update the PTE.
1152 *
1153 * This function uses the current CR3/CR0/CR4 of the guest and will
1154 * bypass access handlers and set any dirty and accessed bits in the PTE.
1155 *
1156 * If you don't want to set the dirty bit, use PGMR3PhysWriteGCPtr().
1157 *
1158 * @returns VBox status.
1159 * @param pVM VM handle.
1160 * @param GCPtrDst The destination address (GC pointer).
1161 * @param pvSrc The source address.
1162 * @param cb The number of bytes to write.
1163 */
1164PGMDECL(int) PGMPhysWriteGCPtrDirty(PVM pVM, RTGCPTR GCPtrDst, const void *pvSrc, size_t cb);
1165
1166/**
1167 * Emulation of the invlpg instruction (HC only actually).
1168 *
1169 * @returns VBox status code.
1170 * @param pVM VM handle.
1171 * @param GCPtrPage Page to invalidate.
1172 * @remark ASSUMES the page table entry or page directory is
1173 * valid. Fairly safe, but there could be edge cases!
1174 * @todo Flush page or page directory only if necessary!
1175 */
1176PGMDECL(int) PGMInvalidatePage(PVM pVM, RTGCPTR GCPtrPage);
1177
1178#endif /* !IN_GC */
1179
1180/**
1181 * Performs a read of guest virtual memory for instruction emulation.
1182 *
1183 * This will check permissions, raise exceptions and update the access bits.
1184 *
1185 * The current implementation will bypass all access handlers. It may later be
1186 * changed to at least respect MMIO.
1187 *
1188 *
1189 * @returns VBox status code suitable to scheduling.
1190 * @retval VINF_SUCCESS if the read was performed successfully.
1191 * @retval VINF_EM_RAW_GUEST_TRAP if an exception was raised but not dispatched yet.
1192 * @retval VINF_TRPM_XCPT_DISPATCHED if an exception was raised and dispatched.
1193 *
1194 * @param pVM The VM handle.
1195 * @param pCtxCore The context core.
1196 * @param pvDst Where to put the bytes we've read.
1197 * @param GCPtrSrc The source address.
1198 * @param cb The number of bytes to read. Not more than a page.
1199 *
1200 * @remark This function will dynamically map physical pages in GC. This may unmap
1201 * mappings done by the caller. Be careful!
1202 */
1203PGMDECL(int) PGMPhysInterpretedRead(PVM pVM, PCPUMCTXCORE pCtxCore, void *pvDst, RTGCUINTPTR GCPtrSrc, size_t cb);
1204
1205#ifdef VBOX_STRICT
1206/**
1207 * Asserts that the handlers+guest-page-tables == ramrange-flags and
1208 * that the physical addresses associated with virtual handlers are correct.
1209 *
1210 * @returns Number of mismatches.
1211 * @param pVM The VM handle.
1212 */
1213PGMDECL(unsigned) PGMAssertHandlerAndFlagsInSync(PVM pVM);
1214
1215/**
1216 * Asserts that there are no mapping conflicts.
1217 *
1218 * @returns Number of conflicts.
1219 * @param pVM The VM Handle.
1220 */
1221PGMDECL(unsigned) PGMAssertNoMappingConflicts(PVM pVM);
1222
1223/**
1224 * Asserts that everything related to the guest CR3 is correctly shadowed.
1225 *
1226 * This will call PGMAssertNoMappingConflicts() and PGMAssertHandlerAndFlagsInSync(),
1227 * and assert the correctness of the guest CR3 mapping before asserting that the
1228 * shadow page tables is in sync with the guest page tables.
1229 *
1230 * @returns Number of conflicts.
1231 * @param pVM The VM Handle.
1232 * @param cr3 The current guest CR3 register value.
1233 * @param cr4 The current guest CR4 register value.
1234 */
1235PGMDECL(unsigned) PGMAssertCR3(PVM pVM, uint32_t cr3, uint32_t cr4);
1236#endif /* VBOX_STRICT */
1237
1238
1239#ifdef IN_GC
1240
1241/** @defgroup grp_pgm_gc The PGM Guest Context API
1242 * @ingroup grp_pgm
1243 * @{
1244 */
1245
1246/**
1247 * Temporarily maps one guest page specified by GC physical address.
1248 * These pages must have a physical mapping in HC, i.e. they cannot be MMIO pages.
1249 *
1250 * Be WARNED that the dynamic page mapping area is small, 8 pages, thus the space is
1251 * reused after 8 mappings (or perhaps a few more if you score with the cache).
1252 *
1253 * @returns VBox status.
1254 * @param pVM VM handle.
1255 * @param GCPhys GC Physical address of the page.
1256 * @param ppv Where to store the address of the mapping.
1257 */
1258PGMGCDECL(int) PGMGCDynMapGCPage(PVM pVM, RTGCPHYS GCPhys, void **ppv);
1259
1260/**
1261 * Temporarily maps one guest page specified by unaligned GC physical address.
1262 * These pages must have a physical mapping in HC, i.e. they cannot be MMIO pages.
1263 *
1264 * Be WARNED that the dynamic page mapping area is small, 8 pages, thus the space is
1265 * reused after 8 mappings (or perhaps a few more if you score with the cache).
1266 *
1267 * The caller is aware that only the speicifed page is mapped and that really bad things
1268 * will happen if writing beyond the page!
1269 *
1270 * @returns VBox status.
1271 * @param pVM VM handle.
1272 * @param GCPhys GC Physical address within the page to be mapped.
1273 * @param ppv Where to store the address of the mapping address corresponding to GCPhys.
1274 */
1275PGMGCDECL(int) PGMGCDynMapGCPageEx(PVM pVM, RTGCPHYS GCPhys, void **ppv);
1276
1277/**
1278 * Temporarily maps one host page specified by HC physical address.
1279 *
1280 * Be WARNED that the dynamic page mapping area is small, 8 pages, thus the space is
1281 * reused after 8 mappings (or perhaps a few more if you score with the cache).
1282 *
1283 * @returns VBox status.
1284 * @param pVM VM handle.
1285 * @param HCPhys HC Physical address of the page.
1286 * @param ppv Where to store the address of the mapping.
1287 */
1288PGMGCDECL(int) PGMGCDynMapHCPage(PVM pVM, RTHCPHYS HCPhys, void **ppv);
1289
1290/**
1291 * Syncs a guest os page table.
1292 *
1293 * @returns VBox status code.
1294 * @param pVM VM handle.
1295 * @param iPD Page directory index.
1296 * @param pPDSrc Source page directory (i.e. Guest OS page directory).
1297 * Assume this is a temporary mapping.
1298 */
1299PGMGCDECL(int) PGMGCSyncPT(PVM pVM, unsigned iPD, PVBOXPD pPDSrc);
1300
1301/**
1302 * Emulation of the invlpg instruction.
1303 *
1304 * @returns VBox status code.
1305 * @param pVM VM handle.
1306 * @param GCPtrPage Page to invalidate.
1307 */
1308PGMGCDECL(int) PGMGCInvalidatePage(PVM pVM, RTGCPTR GCPtrPage);
1309
1310/** @} */
1311#endif
1312
1313
1314#ifdef IN_RING0
1315/** @defgroup grp_pgm_r0 The PGM Host Context Ring-0 API
1316 * @ingroup grp_pgm
1317 * @{
1318 */
1319/**
1320 * Worker function for PGMR3PhysAllocateHandyPages and pgmPhysEnsureHandyPage.
1321 *
1322 * @returns The following VBox status codes.
1323 * @retval VINF_SUCCESS on success. FF cleared.
1324 * @retval VINF_EM_NO_MEMORY if we're out of memory. The FF is set in this case.
1325 *
1326 * @param pVM The VM handle.
1327 *
1328 * @remarks Must be called from within the PGM critical section.
1329 */
1330PGMR0DECL(int) PGMR0PhysAllocateHandyPages(PVM pVM);
1331
1332/** @} */
1333#endif
1334
1335
1336
1337#ifdef IN_RING3
1338/** @defgroup grp_pgm_r3 The PGM Host Context Ring-3 API
1339 * @ingroup grp_pgm
1340 * @{
1341 */
1342/**
1343 * Initiates the paging of VM.
1344 *
1345 * @returns VBox status code.
1346 * @param pVM Pointer to VM structure.
1347 */
1348PGMR3DECL(int) PGMR3Init(PVM pVM);
1349
1350/**
1351 * Init the PGM bits that rely on VMMR0 and MM to be fully initialized.
1352 *
1353 * The dynamic mapping area will also be allocated and initialized at this
1354 * time. We could allocate it during PGMR3Init of course, but the mapping
1355 * wouldn't be allocated at that time preventing us from setting up the
1356 * page table entries with the dummy page.
1357 *
1358 * @returns VBox status code.
1359 * @param pVM VM handle.
1360 */
1361PGMR3DECL(int) PGMR3InitDynMap(PVM pVM);
1362
1363/**
1364 * Ring-3 init finalizing.
1365 *
1366 * @returns VBox status code.
1367 * @param pVM The VM handle.
1368 */
1369PGMR3DECL(int) PGMR3InitFinalize(PVM pVM);
1370
1371/**
1372 * Applies relocations to data and code managed by this
1373 * component. This function will be called at init and
1374 * whenever the VMM need to relocate it self inside the GC.
1375 *
1376 * @param pVM The VM.
1377 * @param offDelta Relocation delta relative to old location.
1378 */
1379PGMR3DECL(void) PGMR3Relocate(PVM pVM, RTGCINTPTR offDelta);
1380
1381/**
1382 * The VM is being reset.
1383 *
1384 * For the PGM component this means that any PD write monitors
1385 * needs to be removed.
1386 *
1387 * @param pVM VM handle.
1388 */
1389PGMR3DECL(void) PGMR3Reset(PVM pVM);
1390
1391/**
1392 * Terminates the PGM.
1393 *
1394 * @returns VBox status code.
1395 * @param pVM Pointer to VM structure.
1396 */
1397PGMR3DECL(int) PGMR3Term(PVM pVM);
1398
1399/**
1400 * Serivce a VMMCALLHOST_PGM_LOCK call.
1401 *
1402 * @returns VBox status code.
1403 * @param pVM The VM handle.
1404 */
1405PDMR3DECL(int) PGMR3LockCall(PVM pVM);
1406
1407/**
1408 * Inform PGM if we want all mappings to be put into the shadow page table. (necessary for e.g. VMX)
1409 *
1410 * @returns VBox status code.
1411 * @param pVM VM handle.
1412 * @param fEnable Enable or disable shadow mappings
1413 */
1414PGMR3DECL(int) PGMR3ChangeShwPDMappings(PVM pVM, bool fEnable);
1415
1416#ifndef VBOX_WITH_NEW_PHYS_CODE
1417/**
1418 * Allocate missing physical pages for an existing guest RAM range.
1419 *
1420 * @returns VBox status.
1421 * @param pVM The VM handle.
1422 * @param GCPhys GC physical address of the RAM range. (page aligned)
1423 */
1424PGMR3DECL(int) PGM3PhysGrowRange(PVM pVM, RTGCPHYS GCPhys);
1425#endif /* !VBOX_WITH_NEW_PHYS_CODE */
1426
1427/**
1428 * Interface that the MMR3RamRegister(), MMR3RomRegister() and MMIO handler
1429 * registration APIs calls to inform PGM about memory registrations.
1430 *
1431 * It registers the physical memory range with PGM. MM is responsible
1432 * for the toplevel things - allocation and locking - while PGM is taking
1433 * care of all the details and implements the physical address space virtualization.
1434 *
1435 * @returns VBox status.
1436 * @param pVM The VM handle.
1437 * @param pvRam HC virtual address of the RAM range. (page aligned)
1438 * @param GCPhys GC physical address of the RAM range. (page aligned)
1439 * @param cb Size of the RAM range. (page aligned)
1440 * @param fFlags Flags, MM_RAM_*.
1441 * @param paPages Pointer an array of physical page descriptors.
1442 * @param pszDesc Description string.
1443 */
1444PGMR3DECL(int) PGMR3PhysRegister(PVM pVM, void *pvRam, RTGCPHYS GCPhys, size_t cb, unsigned fFlags, const SUPPAGE *paPages, const char *pszDesc);
1445
1446#ifndef VBOX_WITH_NEW_PHYS_CODE
1447/**
1448 * Register a chunk of a the physical memory range with PGM. MM is responsible
1449 * for the toplevel things - allocation and locking - while PGM is taking
1450 * care of all the details and implements the physical address space virtualization.
1451 *
1452 * @returns VBox status.
1453 * @param pVM The VM handle.
1454 * @param pvRam HC virtual address of the RAM range. (page aligned)
1455 * @param GCPhys GC physical address of the RAM range. (page aligned)
1456 * @param cb Size of the RAM range. (page aligned)
1457 * @param fFlags Flags, MM_RAM_*.
1458 * @param paPages Pointer an array of physical page descriptors.
1459 * @param pszDesc Description string.
1460 */
1461PGMR3DECL(int) PGMR3PhysRegisterChunk(PVM pVM, void *pvRam, RTGCPHYS GCPhys, size_t cb, unsigned fFlags, const SUPPAGE *paPages, const char *pszDesc);
1462#endif /* !VBOX_WITH_NEW_PHYS_CODE */
1463
1464/**
1465 * Interface MMIO handler relocation calls.
1466 *
1467 * It relocates an existing physical memory range with PGM.
1468 *
1469 * @returns VBox status.
1470 * @param pVM The VM handle.
1471 * @param GCPhysOld Previous GC physical address of the RAM range. (page aligned)
1472 * @param GCPhysNew New GC physical address of the RAM range. (page aligned)
1473 * @param cb Size of the RAM range. (page aligned)
1474 */
1475PGMR3DECL(int) PGMR3PhysRelocate(PVM pVM, RTGCPHYS GCPhysOld, RTGCPHYS GCPhysNew, size_t cb);
1476
1477/**
1478 * Interface MMR3RomRegister() and MMR3PhysReserve calls to update the
1479 * flags of existing RAM ranges.
1480 *
1481 * @returns VBox status.
1482 * @param pVM The VM handle.
1483 * @param GCPhys GC physical address of the RAM range. (page aligned)
1484 * @param cb Size of the RAM range. (page aligned)
1485 * @param fFlags The Or flags, MM_RAM_* #defines.
1486 * @param fMask The and mask for the flags.
1487 */
1488PGMR3DECL(int) PGMR3PhysSetFlags(PVM pVM, RTGCPHYS GCPhys, size_t cb, unsigned fFlags, unsigned fMask);
1489
1490/**
1491 * Sets the Address Gate 20 state.
1492 *
1493 * @param pVM VM handle.
1494 * @param fEnable True if the gate should be enabled.
1495 * False if the gate should be disabled.
1496 */
1497PGMDECL(void) PGMR3PhysSetA20(PVM pVM, bool fEnable);
1498
1499/**
1500 * Creates a page table based mapping in GC.
1501 *
1502 * @returns VBox status code.
1503 * @param pVM VM Handle.
1504 * @param GCPtr Virtual Address. (Page table aligned!)
1505 * @param cb Size of the range. Must be a 4MB aligned!
1506 * @param pfnRelocate Relocation callback function.
1507 * @param pvUser User argument to the callback.
1508 * @param pszDesc Pointer to description string. This must not be freed.
1509 */
1510PGMR3DECL(int) PGMR3MapPT(PVM pVM, RTGCPTR GCPtr, size_t cb, PFNPGMRELOCATE pfnRelocate, void *pvUser, const char *pszDesc);
1511
1512/**
1513 * Removes a page table based mapping.
1514 *
1515 * @returns VBox status code.
1516 * @param pVM VM Handle.
1517 * @param GCPtr Virtual Address. (Page table aligned!)
1518 */
1519PGMR3DECL(int) PGMR3UnmapPT(PVM pVM, RTGCPTR GCPtr);
1520
1521/**
1522 * Gets the size of the current guest mappings if they were to be
1523 * put next to oneanother.
1524 *
1525 * @returns VBox status code.
1526 * @param pVM The VM.
1527 * @param pcb Where to store the size.
1528 */
1529PGMR3DECL(int) PGMR3MappingsSize(PVM pVM, size_t *pcb);
1530
1531/**
1532 * Fixes the guest context mappings in a range reserved from the Guest OS.
1533 *
1534 * @returns VBox status code.
1535 * @param pVM The VM.
1536 * @param GCPtrBase The address of the reserved range of guest memory.
1537 * @param cb The size of the range starting at GCPtrBase.
1538 */
1539PGMR3DECL(int) PGMR3MappingsFix(PVM pVM, RTGCPTR GCPtrBase, size_t cb);
1540
1541/**
1542 * Unfixes the mappings.
1543 * After calling this function mapping conflict detection will be enabled.
1544 *
1545 * @returns VBox status code.
1546 * @param pVM The VM.
1547 */
1548PGMR3DECL(int) PGMR3MappingsUnfix(PVM pVM);
1549
1550/**
1551 * Map pages into the intermediate context (switcher code).
1552 * These pages are mapped at both the give virtual address and at
1553 * the physical address (for identity mapping).
1554 *
1555 * @returns VBox status code.
1556 * @param pVM The virtual machine.
1557 * @param Addr Intermediate context address of the mapping.
1558 * @param HCPhys Start of the range of physical pages. This must be entriely below 4GB!
1559 * @param cbPages Number of bytes to map.
1560 *
1561 * @remark This API shall not be used to anything but mapping the switcher code.
1562 */
1563PGMR3DECL(int) PGMR3MapIntermediate(PVM pVM, RTUINTPTR Addr, RTHCPHYS HCPhys, unsigned cbPages);
1564
1565/**
1566 * Checks guest PD for conflicts with VMM GC mappings.
1567 *
1568 * @returns true if conflict detected.
1569 * @returns false if not.
1570 * @param pVM The virtual machine.
1571 * @param cr3 Guest context CR3 register.
1572 * @param fRawR0 Whether RawR0 is enabled or not.
1573 */
1574PGMR3DECL(bool) PGMR3MapHasConflicts(PVM pVM, uint32_t cr3, bool fRawR0);
1575
1576/**
1577 * Read memory from the guest mappings.
1578 *
1579 * This will use the page tables associated with the mappings to
1580 * read the memory. This means that not all kind of memory is readable
1581 * since we don't necessarily know how to convert that physical address
1582 * to a HC virtual one.
1583 *
1584 * @returns VBox status.
1585 * @param pVM VM handle.
1586 * @param pvDst The destination address (HC of course).
1587 * @param GCPtrSrc The source address (GC virtual address).
1588 * @param cb Number of bytes to read.
1589 */
1590PGMR3DECL(int) PGMR3MapRead(PVM pVM, void *pvDst, RTGCPTR GCPtrSrc, size_t cb);
1591
1592/**
1593 * Register a access handler for a physical range.
1594 *
1595 * @returns VBox status code.
1596 * @param pVM VM handle.
1597 * @param enmType Handler type. Any of the PGMPHYSHANDLERTYPE_PHYSICAL* enums.
1598 * @param GCPhys Start physical address.
1599 * @param GCPhysLast Last physical address. (inclusive)
1600 * @param pfnHandlerR3 The R3 handler.
1601 * @param pvUserR3 User argument to the R3 handler.
1602 * @param pszModR0 The R0 handler module. NULL means default R0 module.
1603 * @param pszHandlerR0 The R0 handler symbol name.
1604 * @param pvUserR0 User argument to the R0 handler.
1605 * @param pszModGC The GC handler module. NULL means default GC module.
1606 * @param pszHandlerGC The GC handler symbol name.
1607 * @param pvUserGC User argument to the GC handler.
1608 * This must be a GC pointer because it will be relocated!
1609 * @param pszDesc Pointer to description string. This must not be freed.
1610 */
1611PGMR3DECL(int) PGMR3HandlerPhysicalRegister(PVM pVM, PGMPHYSHANDLERTYPE enmType, RTGCPHYS GCPhys, RTGCPHYS GCPhysLast,
1612 PFNPGMR3PHYSHANDLER pfnHandlerR3, void *pvUserR3,
1613 const char *pszModR0, const char *pszHandlerR0, RTR0PTR pvUserR0,
1614 const char *pszModGC, const char *pszHandlerGC, RTGCPTR pvUserGC, const char *pszDesc);
1615
1616/**
1617 * Register an access handler for a virtual range.
1618 *
1619 * @returns VBox status code.
1620 * @param pVM VM handle.
1621 * @param enmType Handler type. Any of the PGMVIRTHANDLERTYPE_* enums.
1622 * @param GCPtr Start address.
1623 * @param GCPtrLast Last address. (inclusive)
1624 * @param pfnInvalidateHC The HC invalidate callback (can be 0)
1625 * @param pfnHandlerHC The HC handler.
1626 * @param pfnHandlerGC The GC handler.
1627 * @param pszDesc Pointer to description string. This must not be freed.
1628 */
1629PGMDECL(int) PGMHandlerVirtualRegisterEx(PVM pVM, PGMVIRTHANDLERTYPE enmType, RTGCPTR GCPtr, RTGCPTR GCPtrLast,
1630 PFNPGMHCVIRTINVALIDATE pfnInvalidateHC,
1631 PFNPGMHCVIRTHANDLER pfnHandlerHC, RTGCPTR pfnHandlerGC,
1632 R3PTRTYPE(const char *) pszDesc);
1633
1634/**
1635 * Register a access handler for a virtual range.
1636 *
1637 * @returns VBox status code.
1638 * @param pVM VM handle.
1639 * @param enmType Handler type. Any of the PGMVIRTHANDLERTYPE_* enums.
1640 * @param GCPtr Start address.
1641 * @param GCPtrLast Last address. (inclusive)
1642 * @param pfnInvalidateHC The HC invalidate callback (can be 0)
1643 * @param pfnHandlerHC The HC handler.
1644 * @param pszHandlerGC The GC handler symbol name.
1645 * @param pszModGC The GC handler module.
1646 * @param pszDesc Pointer to description string. This must not be freed.
1647 */
1648PGMR3DECL(int) PGMR3HandlerVirtualRegister(PVM pVM, PGMVIRTHANDLERTYPE enmType, RTGCPTR GCPtr, RTGCPTR GCPtrLast,
1649 PFNPGMHCVIRTINVALIDATE pfnInvalidateHC,
1650 PFNPGMHCVIRTHANDLER pfnHandlerHC,
1651 const char *pszHandlerGC, const char *pszModGC, const char *pszDesc);
1652
1653/**
1654 * Modify the page invalidation callback handler for a registered virtual range
1655 * (add more when needed)
1656 *
1657 * @returns VBox status code.
1658 * @param pVM VM handle.
1659 * @param GCPtr Start address.
1660 * @param pfnInvalidateHC The HC invalidate callback (can be 0)
1661 */
1662PGMDECL(int) PGMHandlerVirtualChangeInvalidateCallback(PVM pVM, RTGCPTR GCPtr, PFNPGMHCVIRTINVALIDATE pfnInvalidateHC);
1663
1664
1665/**
1666 * Deregister an access handler for a virtual range.
1667 *
1668 * @returns VBox status code.
1669 * @param pVM VM handle.
1670 * @param GCPtr Start address.
1671 */
1672PGMDECL(int) PGMHandlerVirtualDeregister(PVM pVM, RTGCPTR GCPtr);
1673
1674/**
1675 * Grows the shadow page pool.
1676 *
1677 * I.e. adds more pages to it, assuming that hasn't reached cMaxPages yet.
1678 *
1679 * @returns VBox status code.
1680 * @param pVM The VM handle.
1681 */
1682PDMR3DECL(int) PGMR3PoolGrow(PVM pVM);
1683
1684#ifdef ___VBox_dbgf_h /** @todo fix this! */
1685/**
1686 * Dumps a page table hierarchy use only physical addresses and cr4/lm flags.
1687 *
1688 * @returns VBox status code (VINF_SUCCESS).
1689 * @param pVM The VM handle.
1690 * @param cr3 The root of the hierarchy.
1691 * @param cr4 The cr4, only PAE and PSE is currently used.
1692 * @param fLongMode Set if long mode, false if not long mode.
1693 * @param cMaxDepth Number of levels to dump.
1694 * @param pHlp Pointer to the output functions.
1695 */
1696PGMR3DECL(int) PGMR3DumpHierarchyHC(PVM pVM, uint32_t cr3, uint32_t cr4, bool fLongMode, unsigned cMaxDepth, PCDBGFINFOHLP pHlp);
1697#endif
1698
1699/**
1700 * Dumps a 32-bit guest page directory and page tables.
1701 *
1702 * @returns VBox status code (VINF_SUCCESS).
1703 * @param pVM The VM handle.
1704 * @param cr3 The root of the hierarchy.
1705 * @param cr4 The CR4, PSE is currently used.
1706 * @param PhysSearch Address to search for.
1707 */
1708PGMR3DECL(int) PGMR3DumpHierarchyGC(PVM pVM, uint32_t cr3, uint32_t cr4, RTGCPHYS PhysSearch);
1709
1710/**
1711 * Debug helper - Dumps the supplied page directory.
1712 *
1713 * @internal
1714 */
1715PGMR3DECL(void) PGMR3DumpPD(PVM pVM, PVBOXPD pPD);
1716
1717/**
1718 * Dumps the the PGM mappings..
1719 *
1720 * @param pVM VM handle.
1721 */
1722PGMR3DECL(void) PGMR3DumpMappings(PVM pVM);
1723
1724/** @todo r=bird: s/Byte/U8/ s/Word/U16/ s/Dword/U32/ to match other functions names and returned types. */
1725/**
1726 * Read physical memory. (one byte)
1727 *
1728 * This API respects access handlers and MMIO. Use PGMPhysReadGCPhys() if you
1729 * want to ignore those.
1730 *
1731 * @param pVM VM Handle.
1732 * @param GCPhys Physical address start reading from.
1733 */
1734PGMR3DECL(uint8_t) PGMR3PhysReadByte(PVM pVM, RTGCPHYS GCPhys);
1735
1736/**
1737 * Read physical memory. (one word)
1738 *
1739 * This API respects access handlers and MMIO. Use PGMPhysReadGCPhys() if you
1740 * want to ignore those.
1741 *
1742 * @param pVM VM Handle.
1743 * @param GCPhys Physical address start reading from.
1744 */
1745PGMR3DECL(uint16_t) PGMR3PhysReadWord(PVM pVM, RTGCPHYS GCPhys);
1746
1747/**
1748 * Read physical memory. (one dword)
1749 *
1750 * This API respects access handlers and MMIO. Use PGMPhysReadGCPhys() if you
1751 * want to ignore those.
1752 *
1753 * @param pVM VM Handle.
1754 * @param GCPhys Physical address start reading from.
1755 */
1756PGMR3DECL(uint32_t) PGMR3PhysReadDword(PVM pVM, RTGCPHYS GCPhys);
1757
1758/**
1759 * Write to physical memory. (one byte)
1760 *
1761 * This API respects access handlers and MMIO. Use PGMPhysReadGCPhys() if you
1762 * want to ignore those.
1763 *
1764 * @param pVM VM Handle.
1765 * @param GCPhys Physical address to write to.
1766 * @param val What to write.
1767 */
1768PGMR3DECL(void) PGMR3PhysWriteByte(PVM pVM, RTGCPHYS GCPhys, uint8_t val);
1769
1770/**
1771 * Write to physical memory. (one word)
1772 *
1773 * This API respects access handlers and MMIO. Use PGMPhysReadGCPhys() if you
1774 * want to ignore those.
1775 *
1776 * @param pVM VM Handle.
1777 * @param GCPhys Physical address to write to.
1778 * @param val What to write.
1779 */
1780PGMR3DECL(void) PGMR3PhysWriteWord(PVM pVM, RTGCPHYS GCPhys, uint16_t val);
1781
1782/**
1783 * Write to physical memory. (one dword)
1784 *
1785 * This API respects access handlers and MMIO. Use PGMPhysReadGCPhys() if you
1786 * want to ignore those.
1787 *
1788 * @param pVM VM Handle.
1789 * @param GCPhys Physical address to write to.
1790 * @param val What to write.
1791 */
1792PGMR3DECL(void) PGMR3PhysWriteDword(PVM pVM, RTGCPHYS GCPhys, uint32_t val);
1793
1794/**
1795 * For VMMCALLHOST_PGM_MAP_CHUNK, considered internal.
1796 *
1797 * @returns see pgmR3PhysChunkMap.
1798 * @param pVM The VM handle.
1799 * @param idChunk The chunk to map.
1800 */
1801PDMR3DECL(int) PGMR3PhysChunkMap(PVM pVM, uint32_t idChunk);
1802
1803/**
1804 * Invalidates the TLB for the ring-3 mapping cache.
1805 *
1806 * @param pVM The VM handle.
1807 */
1808PGMR3DECL(void) PGMR3PhysChunkInvalidateTLB(PVM pVM);
1809
1810/**
1811 * Response to VM_FF_PGM_NEED_HANDY_PAGES and VMMCALLHOST_PGM_ALLOCATE_HANDY_PAGES.
1812 *
1813 * @returns VBox status code.
1814 * @retval VINF_SUCCESS on success. FF cleared.
1815 * @retval VINF_EM_NO_MEMORY if we're out of memory. The FF is not cleared in this case.
1816 *
1817 * @param pVM The VM handle.
1818 */
1819PDMR3DECL(int) PGMR3PhysAllocateHandyPages(PVM pVM);
1820
1821/**
1822 * Perform an integrity check on the PGM component.
1823 *
1824 * @returns VINF_SUCCESS if everything is fine.
1825 * @returns VBox error status after asserting on integrity breach.
1826 * @param pVM The VM handle.
1827 */
1828PDMR3DECL(int) PGMR3CheckIntegrity(PVM pVM);
1829
1830/**
1831 * Converts a HC pointer to a GC physical address.
1832 *
1833 * Only for the debugger.
1834 *
1835 * @returns VBox status code.
1836 * @retval VINF_SUCCESS on success, *pGCPhys is set.
1837 * @retval VERR_INVALID_POINTER if the pointer is not within the GC physical memory.
1838 *
1839 * @param pVM The VM handle.
1840 * @param HCPtr The HC pointer to convert.
1841 * @param pGCPhys Where to store the GC physical address on success.
1842 */
1843PGMR3DECL(int) PGMR3DbgHCPtr2GCPhys(PVM pVM, RTHCPTR HCPtr, PRTGCPHYS pGCPhys);
1844
1845/**
1846 * Converts a HC pointer to a GC physical address.
1847 *
1848 * @returns VBox status code.
1849 * @retval VINF_SUCCESS on success, *pHCPhys is set.
1850 * @retval VERR_PGM_PHYS_PAGE_RESERVED it it's a valid GC physical page but has no physical backing.
1851 * @retval VERR_INVALID_POINTER if the pointer is not within the GC physical memory.
1852 *
1853 * @param pVM The VM handle.
1854 * @param HCPtr The HC pointer to convert.
1855 * @param pHCPhys Where to store the HC physical address on success.
1856 */
1857PGMR3DECL(int) PGMR3DbgHCPtr2HCPhys(PVM pVM, RTHCPTR HCPtr, PRTHCPHYS pHCPhys);
1858
1859/**
1860 * Converts a HC physical address to a GC physical address.
1861 *
1862 * Only for the debugger.
1863 *
1864 * @returns VBox status code
1865 * @retval VINF_SUCCESS on success, *pGCPhys is set.
1866 * @retval VERR_INVALID_POINTER if the HC physical address is not within the GC physical memory.
1867 *
1868 * @param pVM The VM handle.
1869 * @param HCPhys The HC physical address to convert.
1870 * @param pGCPhys Where to store the GC physical address on success.
1871 */
1872PGMR3DECL(int) PGMR3DbgHCPhys2GCPhys(PVM pVM, RTHCPHYS HCPhys, PRTGCPHYS pGCPhys);
1873
1874/**
1875 * Scans guest physical memory for a byte string.
1876 *
1877 * Only for the debugger.
1878 *
1879 * @returns VBox status codes:
1880 * @retval VINF_SUCCESS and *pGCPtrHit on success.
1881 * @retval VERR_DBGF_MEM_NOT_FOUND if not found.
1882 * @retval VERR_INVALID_POINTER if any of the pointer arguments are invalid.
1883 * @retval VERR_INVALID_ARGUMENT if any other arguments are invalid.
1884 *
1885 * @param pVM Pointer to the shared VM structure.
1886 * @param GCPhys Where to start searching.
1887 * @param cbRange The number of bytes to search. Max 256 bytes.
1888 * @param pabNeedle The byte string to search for.
1889 * @param cbNeedle The length of the byte string.
1890 * @param pGCPhysHit Where to store the address of the first occurence on success.
1891 */
1892PDMR3DECL(int) PGMR3DbgScanPhysical(PVM pVM, RTGCPHYS GCPhys, RTGCPHYS cbRange, const uint8_t *pabNeedle, size_t cbNeedle, PRTGCPHYS pGCPhysHit);
1893
1894/**
1895 * Scans virtual memory for a byte string.
1896 *
1897 * Only for the debugger.
1898 *
1899 * @returns VBox status codes:
1900 * @retval VINF_SUCCESS and *pGCPtrHit on success.
1901 * @retval VERR_DBGF_MEM_NOT_FOUND if not found.
1902 * @retval VERR_INVALID_POINTER if any of the pointer arguments are invalid.
1903 * @retval VERR_INVALID_ARGUMENT if any other arguments are invalid.
1904 *
1905 * @param pVM Pointer to the shared VM structure.
1906 * @param GCPtr Where to start searching.
1907 * @param cbRange The number of bytes to search. Max 256 bytes.
1908 * @param pabNeedle The byte string to search for.
1909 * @param cbNeedle The length of the byte string.
1910 * @param pGCPtrHit Where to store the address of the first occurence on success.
1911 */
1912PDMR3DECL(int) PGMR3DbgScanVirtual(PVM pVM, RTGCUINTPTR GCPtr, RTGCUINTPTR cbRange, const uint8_t *pabNeedle, size_t cbNeedle, PRTGCUINTPTR pGCPhysHit);
1913
1914/** @} */
1915
1916#endif /* IN_RING3 */
1917
1918__END_DECLS
1919
1920/** @} */
1921#endif
1922
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