[23] | 1 | /* $Id: DBGFAddr.cpp 82968 2020-02-04 10:35:17Z vboxsync $ */
|
---|
[1] | 2 | /** @file
|
---|
[12677] | 3 | * DBGF - Debugger Facility, Mixed Address Methods.
|
---|
[1] | 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[82968] | 7 | * Copyright (C) 2006-2020 Oracle Corporation
|
---|
[1] | 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
|
---|
[5999] | 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.
|
---|
[1] | 16 | */
|
---|
| 17 |
|
---|
| 18 |
|
---|
[57358] | 19 | /*********************************************************************************************************************************
|
---|
| 20 | * Header Files *
|
---|
| 21 | *********************************************************************************************************************************/
|
---|
[1] | 22 | #define LOG_GROUP LOG_GROUP_DBGF
|
---|
[35346] | 23 | #include <VBox/vmm/dbgf.h>
|
---|
| 24 | #include <VBox/vmm/pgm.h>
|
---|
| 25 | #include <VBox/vmm/selm.h>
|
---|
| 26 | #include <VBox/vmm/mm.h>
|
---|
[45753] | 27 | #include <VBox/vmm/hm.h>
|
---|
[1] | 28 | #include "DBGFInternal.h"
|
---|
[35346] | 29 | #include <VBox/vmm/vm.h>
|
---|
[44399] | 30 | #include <VBox/vmm/uvm.h>
|
---|
| 31 |
|
---|
[19182] | 32 | #include <VBox/param.h>
|
---|
[1] | 33 | #include <VBox/err.h>
|
---|
| 34 | #include <VBox/log.h>
|
---|
| 35 |
|
---|
| 36 |
|
---|
| 37 |
|
---|
| 38 | /**
|
---|
[22112] | 39 | * Common worker for DBGFR3AddrFromSelOff and DBGFR3AddrFromSelInfoOff.
|
---|
| 40 | */
|
---|
| 41 | static int dbgfR3AddrFromSelInfoOffWorker(PDBGFADDRESS pAddress, PCDBGFSELINFO pSelInfo, RTUINTPTR off)
|
---|
| 42 | {
|
---|
| 43 | if (pSelInfo->fFlags & (DBGFSELINFO_FLAGS_INVALID | DBGFSELINFO_FLAGS_NOT_PRESENT))
|
---|
| 44 | return pSelInfo->fFlags & DBGFSELINFO_FLAGS_NOT_PRESENT
|
---|
| 45 | ? VERR_SELECTOR_NOT_PRESENT
|
---|
| 46 | : VERR_INVALID_SELECTOR;
|
---|
| 47 |
|
---|
| 48 | /** @todo This all goes voodoo in long mode. */
|
---|
| 49 | /* check limit. */
|
---|
| 50 | if (DBGFSelInfoIsExpandDown(pSelInfo))
|
---|
| 51 | {
|
---|
| 52 | if ( !pSelInfo->u.Raw.Gen.u1Granularity
|
---|
| 53 | && off > UINT32_C(0xffff))
|
---|
| 54 | return VERR_OUT_OF_SELECTOR_BOUNDS;
|
---|
| 55 | if (off <= pSelInfo->cbLimit)
|
---|
| 56 | return VERR_OUT_OF_SELECTOR_BOUNDS;
|
---|
| 57 | }
|
---|
| 58 | else if (off > pSelInfo->cbLimit)
|
---|
| 59 | return VERR_OUT_OF_SELECTOR_BOUNDS;
|
---|
| 60 |
|
---|
| 61 | pAddress->FlatPtr = pSelInfo->GCPtrBase + off;
|
---|
| 62 |
|
---|
| 63 | /** @todo fix all these selector tests! */
|
---|
| 64 | if ( !pSelInfo->GCPtrBase
|
---|
| 65 | && pSelInfo->u.Raw.Gen.u1Granularity
|
---|
| 66 | && pSelInfo->u.Raw.Gen.u1DefBig)
|
---|
| 67 | pAddress->fFlags = DBGFADDRESS_FLAGS_FLAT;
|
---|
| 68 | else if (pSelInfo->cbLimit <= UINT32_C(0xffff))
|
---|
| 69 | pAddress->fFlags = DBGFADDRESS_FLAGS_FAR16;
|
---|
| 70 | else if (pSelInfo->cbLimit <= UINT32_C(0xffffffff))
|
---|
| 71 | pAddress->fFlags = DBGFADDRESS_FLAGS_FAR32;
|
---|
| 72 | else
|
---|
| 73 | pAddress->fFlags = DBGFADDRESS_FLAGS_FAR64;
|
---|
| 74 |
|
---|
| 75 | return VINF_SUCCESS;
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 |
|
---|
| 79 | /**
|
---|
[1] | 80 | * Creates a mixed address from a Sel:off pair.
|
---|
| 81 | *
|
---|
| 82 | * @returns VBox status code.
|
---|
[44399] | 83 | * @param pUVM The user mode VM handle.
|
---|
| 84 | * @param idCpu The CPU ID.
|
---|
| 85 | * @param pAddress Where to store the mixed address.
|
---|
| 86 | * @param Sel The selector part.
|
---|
| 87 | * @param off The offset part.
|
---|
[1] | 88 | */
|
---|
[44399] | 89 | VMMR3DECL(int) DBGFR3AddrFromSelOff(PUVM pUVM, VMCPUID idCpu, PDBGFADDRESS pAddress, RTSEL Sel, RTUINTPTR off)
|
---|
[1] | 90 | {
|
---|
[44399] | 91 | UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
|
---|
| 92 | VM_ASSERT_VALID_EXT_RETURN(pUVM->pVM, VERR_INVALID_VM_HANDLE);
|
---|
| 93 | AssertReturn(idCpu < pUVM->cCpus, VERR_INVALID_PARAMETER);
|
---|
[19286] | 94 |
|
---|
[1] | 95 | pAddress->Sel = Sel;
|
---|
| 96 | pAddress->off = off;
|
---|
| 97 | if (Sel != DBGF_SEL_FLAT)
|
---|
| 98 | {
|
---|
[19334] | 99 | DBGFSELINFO SelInfo;
|
---|
[44399] | 100 | int rc = DBGFR3SelQueryInfo(pUVM, idCpu, Sel, DBGFSELQI_FLAGS_DT_GUEST | DBGFSELQI_FLAGS_DT_ADJ_64BIT_MODE, &SelInfo);
|
---|
[13816] | 101 | if (RT_FAILURE(rc))
|
---|
[1] | 102 | return rc;
|
---|
[22112] | 103 | rc = dbgfR3AddrFromSelInfoOffWorker(pAddress, &SelInfo, off);
|
---|
| 104 | if (RT_FAILURE(rc))
|
---|
| 105 | return rc;
|
---|
[1] | 106 | }
|
---|
| 107 | else
|
---|
| 108 | {
|
---|
| 109 | pAddress->FlatPtr = off;
|
---|
| 110 | pAddress->fFlags = DBGFADDRESS_FLAGS_FLAT;
|
---|
| 111 | }
|
---|
| 112 | pAddress->fFlags |= DBGFADDRESS_FLAGS_VALID;
|
---|
| 113 |
|
---|
| 114 | return VINF_SUCCESS;
|
---|
| 115 | }
|
---|
| 116 |
|
---|
| 117 |
|
---|
| 118 | /**
|
---|
[22112] | 119 | * Creates a mixed address from selector info and an offset into the segment
|
---|
| 120 | * described by it.
|
---|
| 121 | *
|
---|
| 122 | * @returns VBox status code.
|
---|
[44399] | 123 | * @param pUVM The user mode VM handle.
|
---|
| 124 | * @param pAddress Where to store the mixed address.
|
---|
| 125 | * @param pSelInfo The selector info.
|
---|
| 126 | * @param off The offset part.
|
---|
[22112] | 127 | */
|
---|
[44399] | 128 | VMMR3DECL(int) DBGFR3AddrFromSelInfoOff(PUVM pUVM, PDBGFADDRESS pAddress, PCDBGFSELINFO pSelInfo, RTUINTPTR off)
|
---|
[22112] | 129 | {
|
---|
[44399] | 130 | UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE);
|
---|
| 131 | VM_ASSERT_VALID_EXT_RETURN(pUVM->pVM, VERR_INVALID_VM_HANDLE);
|
---|
| 132 |
|
---|
[22112] | 133 | pAddress->Sel = pSelInfo->Sel;
|
---|
| 134 | pAddress->off = off;
|
---|
| 135 | int rc = dbgfR3AddrFromSelInfoOffWorker(pAddress, pSelInfo, off);
|
---|
| 136 | if (RT_FAILURE(rc))
|
---|
| 137 | return rc;
|
---|
[44399] | 138 |
|
---|
[22112] | 139 | pAddress->fFlags |= DBGFADDRESS_FLAGS_VALID;
|
---|
[44399] | 140 |
|
---|
[22112] | 141 | return VINF_SUCCESS;
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 |
|
---|
| 145 | /**
|
---|
[1] | 146 | * Creates a mixed address from a flat address.
|
---|
| 147 | *
|
---|
[19286] | 148 | * @returns pAddress.
|
---|
[44399] | 149 | * @param pUVM The user mode VM handle.
|
---|
| 150 | * @param pAddress Where to store the mixed address.
|
---|
| 151 | * @param FlatPtr The flat pointer.
|
---|
[1] | 152 | */
|
---|
[44399] | 153 | VMMR3DECL(PDBGFADDRESS) DBGFR3AddrFromFlat(PUVM pUVM, PDBGFADDRESS pAddress, RTGCUINTPTR FlatPtr)
|
---|
[1] | 154 | {
|
---|
[44399] | 155 | UVM_ASSERT_VALID_EXT_RETURN(pUVM, NULL);
|
---|
| 156 | VM_ASSERT_VALID_EXT_RETURN(pUVM->pVM, NULL);
|
---|
[1] | 157 | pAddress->Sel = DBGF_SEL_FLAT;
|
---|
| 158 | pAddress->off = FlatPtr;
|
---|
| 159 | pAddress->FlatPtr = FlatPtr;
|
---|
| 160 | pAddress->fFlags = DBGFADDRESS_FLAGS_FLAT | DBGFADDRESS_FLAGS_VALID;
|
---|
[8819] | 161 | return pAddress;
|
---|
[1] | 162 | }
|
---|
| 163 |
|
---|
| 164 |
|
---|
| 165 | /**
|
---|
[5667] | 166 | * Creates a mixed address from a guest physical address.
|
---|
| 167 | *
|
---|
[19286] | 168 | * @returns pAddress.
|
---|
[44399] | 169 | * @param pUVM The user mode VM handle.
|
---|
| 170 | * @param pAddress Where to store the mixed address.
|
---|
| 171 | * @param PhysAddr The guest physical address.
|
---|
[5667] | 172 | */
|
---|
[44399] | 173 | VMMR3DECL(PDBGFADDRESS) DBGFR3AddrFromPhys(PUVM pUVM, PDBGFADDRESS pAddress, RTGCPHYS PhysAddr)
|
---|
[5667] | 174 | {
|
---|
[44399] | 175 | UVM_ASSERT_VALID_EXT_RETURN(pUVM, NULL);
|
---|
[5667] | 176 | pAddress->Sel = DBGF_SEL_FLAT;
|
---|
| 177 | pAddress->off = PhysAddr;
|
---|
| 178 | pAddress->FlatPtr = PhysAddr;
|
---|
| 179 | pAddress->fFlags = DBGFADDRESS_FLAGS_PHYS | DBGFADDRESS_FLAGS_VALID;
|
---|
[19286] | 180 | return pAddress;
|
---|
[5667] | 181 | }
|
---|
| 182 |
|
---|
| 183 |
|
---|
| 184 | /**
|
---|
[73471] | 185 | * Creates a mixed address from a flat host ring-0 address.
|
---|
| 186 | *
|
---|
| 187 | * @returns pAddress
|
---|
| 188 | * @param pAddress Where to store the mixed address.
|
---|
| 189 | * @param R0Ptr The host ring-0 address.
|
---|
| 190 | */
|
---|
| 191 | VMMR3_INT_DECL(PDBGFADDRESS) DBGFR3AddrFromHostR0(PDBGFADDRESS pAddress, RTR0UINTPTR R0Ptr)
|
---|
| 192 | {
|
---|
| 193 | pAddress->FlatPtr = R0Ptr;
|
---|
| 194 | pAddress->off = R0Ptr;
|
---|
| 195 | pAddress->fFlags = DBGFADDRESS_FLAGS_RING0 | DBGFADDRESS_FLAGS_VALID;
|
---|
| 196 | pAddress->Sel = DBGF_SEL_FLAT;
|
---|
| 197 | return pAddress;
|
---|
| 198 | }
|
---|
| 199 |
|
---|
| 200 |
|
---|
| 201 | /**
|
---|
[1] | 202 | * Checks if the specified address is valid (checks the structure pointer too).
|
---|
| 203 | *
|
---|
| 204 | * @returns true if valid.
|
---|
| 205 | * @returns false if invalid.
|
---|
[44399] | 206 | * @param pUVM The user mode VM handle.
|
---|
| 207 | * @param pAddress The address to validate.
|
---|
[1] | 208 | */
|
---|
[44399] | 209 | VMMR3DECL(bool) DBGFR3AddrIsValid(PUVM pUVM, PCDBGFADDRESS pAddress)
|
---|
[1] | 210 | {
|
---|
[44399] | 211 | UVM_ASSERT_VALID_EXT_RETURN(pUVM, false);
|
---|
[1] | 212 | if (!VALID_PTR(pAddress))
|
---|
| 213 | return false;
|
---|
| 214 | if (!DBGFADDRESS_IS_VALID(pAddress))
|
---|
| 215 | return false;
|
---|
| 216 | /* more? */
|
---|
| 217 | return true;
|
---|
| 218 | }
|
---|
[12663] | 219 |
|
---|
[19182] | 220 |
|
---|
| 221 | /**
|
---|
| 222 | * Called on the EMT for the VCpu.
|
---|
| 223 | *
|
---|
| 224 | * @returns VBox status code.
|
---|
[58123] | 225 | * @param pVCpu The cross context virtual CPU structure.
|
---|
[19182] | 226 | * @param pAddress The address.
|
---|
| 227 | * @param pGCPhys Where to return the physical address.
|
---|
| 228 | */
|
---|
[64770] | 229 | static DECLCALLBACK(int) dbgfR3AddrToPhysOnVCpu(PVMCPU pVCpu, PCDBGFADDRESS pAddress, PRTGCPHYS pGCPhys)
|
---|
[19182] | 230 | {
|
---|
| 231 | VMCPU_ASSERT_EMT(pVCpu);
|
---|
| 232 | /* This is just a wrapper because we cannot pass FlatPtr thru VMR3ReqCall directly. */
|
---|
| 233 | return PGMGstGetPage(pVCpu, pAddress->FlatPtr, NULL, pGCPhys);
|
---|
| 234 | }
|
---|
| 235 |
|
---|
| 236 |
|
---|
| 237 | /**
|
---|
| 238 | * Converts an address to a guest physical address.
|
---|
| 239 | *
|
---|
| 240 | * @returns VBox status code.
|
---|
| 241 | * @retval VINF_SUCCESS
|
---|
| 242 | * @retval VERR_INVALID_PARAMETER if the address is invalid.
|
---|
| 243 | * @retval VERR_INVALID_STATE if the VM is being terminated or if the virtual
|
---|
| 244 | * CPU handle is invalid.
|
---|
| 245 | * @retval VERR_NOT_SUPPORTED is the type of address cannot be converted.
|
---|
| 246 | * @retval VERR_PAGE_NOT_PRESENT
|
---|
| 247 | * @retval VERR_PAGE_TABLE_NOT_PRESENT
|
---|
| 248 | * @retval VERR_PAGE_DIRECTORY_PTR_NOT_PRESENT
|
---|
| 249 | * @retval VERR_PAGE_MAP_LEVEL4_NOT_PRESENT
|
---|
| 250 | *
|
---|
[44399] | 251 | * @param pUVM The user mode VM handle.
|
---|
[19286] | 252 | * @param idCpu The ID of the CPU context to convert virtual
|
---|
| 253 | * addresses.
|
---|
[19182] | 254 | * @param pAddress The address.
|
---|
| 255 | * @param pGCPhys Where to return the physical address.
|
---|
| 256 | */
|
---|
[64770] | 257 | VMMR3DECL(int) DBGFR3AddrToPhys(PUVM pUVM, VMCPUID idCpu, PCDBGFADDRESS pAddress, PRTGCPHYS pGCPhys)
|
---|
[19182] | 258 | {
|
---|
| 259 | /*
|
---|
| 260 | * Parameter validation.
|
---|
| 261 | */
|
---|
| 262 | AssertPtr(pGCPhys);
|
---|
| 263 | *pGCPhys = NIL_RTGCPHYS;
|
---|
| 264 | AssertPtr(pAddress);
|
---|
| 265 | AssertReturn(DBGFADDRESS_IS_VALID(pAddress), VERR_INVALID_PARAMETER);
|
---|
[44399] | 266 | UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_STATE);
|
---|
| 267 | PVM pVM = pUVM->pVM;
|
---|
| 268 | VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE);
|
---|
| 269 | AssertReturn(idCpu < pUVM->cCpus, VERR_INVALID_PARAMETER);
|
---|
[19182] | 270 |
|
---|
| 271 | /*
|
---|
| 272 | * Convert by address type.
|
---|
| 273 | */
|
---|
| 274 | int rc;
|
---|
[80014] | 275 | if (pAddress->fFlags & DBGFADDRESS_FLAGS_PHYS)
|
---|
[19182] | 276 | {
|
---|
| 277 | *pGCPhys = pAddress->FlatPtr;
|
---|
| 278 | rc = VINF_SUCCESS;
|
---|
| 279 | }
|
---|
| 280 | else
|
---|
| 281 | {
|
---|
[19293] | 282 | PVMCPU pVCpu = VMMGetCpuById(pVM, idCpu);
|
---|
[19286] | 283 | if (VMCPU_IS_EMT(pVCpu))
|
---|
| 284 | rc = dbgfR3AddrToPhysOnVCpu(pVCpu, pAddress, pGCPhys);
|
---|
| 285 | else
|
---|
[44399] | 286 | rc = VMR3ReqPriorityCallWaitU(pUVM, pVCpu->idCpu,
|
---|
| 287 | (PFNRT)dbgfR3AddrToPhysOnVCpu, 3, pVCpu, pAddress, pGCPhys);
|
---|
[19182] | 288 | }
|
---|
| 289 | return rc;
|
---|
| 290 | }
|
---|
| 291 |
|
---|
| 292 |
|
---|
| 293 | /**
|
---|
| 294 | * Converts an address to a host physical address.
|
---|
| 295 | *
|
---|
| 296 | * @returns VBox status code.
|
---|
| 297 | * @retval VINF_SUCCESS
|
---|
| 298 | * @retval VERR_INVALID_PARAMETER if the address is invalid.
|
---|
| 299 | * @retval VERR_INVALID_STATE if the VM is being terminated or if the virtual
|
---|
| 300 | * CPU handle is invalid.
|
---|
| 301 | * @retval VERR_NOT_SUPPORTED is the type of address cannot be converted.
|
---|
| 302 | * @retval VERR_PAGE_NOT_PRESENT
|
---|
| 303 | * @retval VERR_PAGE_TABLE_NOT_PRESENT
|
---|
| 304 | * @retval VERR_PAGE_DIRECTORY_PTR_NOT_PRESENT
|
---|
| 305 | * @retval VERR_PAGE_MAP_LEVEL4_NOT_PRESENT
|
---|
| 306 | * @retval VERR_PGM_PHYS_PAGE_RESERVED
|
---|
| 307 | * @retval VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS
|
---|
| 308 | *
|
---|
[44399] | 309 | * @param pUVM The user mode VM handle.
|
---|
[19286] | 310 | * @param idCpu The ID of the CPU context to convert virtual
|
---|
| 311 | * addresses.
|
---|
[19182] | 312 | * @param pAddress The address.
|
---|
| 313 | * @param pHCPhys Where to return the physical address.
|
---|
| 314 | */
|
---|
[44399] | 315 | VMMR3DECL(int) DBGFR3AddrToHostPhys(PUVM pUVM, VMCPUID idCpu, PDBGFADDRESS pAddress, PRTHCPHYS pHCPhys)
|
---|
[19182] | 316 | {
|
---|
| 317 | /*
|
---|
| 318 | * Parameter validation.
|
---|
| 319 | */
|
---|
| 320 | AssertPtr(pHCPhys);
|
---|
| 321 | *pHCPhys = NIL_RTHCPHYS;
|
---|
| 322 | AssertPtr(pAddress);
|
---|
| 323 | AssertReturn(DBGFADDRESS_IS_VALID(pAddress), VERR_INVALID_PARAMETER);
|
---|
[44399] | 324 | UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_STATE);
|
---|
| 325 | PVM pVM = pUVM->pVM;
|
---|
| 326 | VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE);
|
---|
| 327 | AssertReturn(idCpu < pUVM->cCpus, VERR_INVALID_PARAMETER);
|
---|
[19182] | 328 |
|
---|
| 329 | /*
|
---|
[80014] | 330 | * Convert it.
|
---|
[19182] | 331 | */
|
---|
[80014] | 332 | RTGCPHYS GCPhys;
|
---|
| 333 | int rc = DBGFR3AddrToPhys(pUVM, idCpu, pAddress, &GCPhys);
|
---|
| 334 | if (RT_SUCCESS(rc))
|
---|
| 335 | rc = PGMPhysGCPhys2HCPhys(pVM, pAddress->FlatPtr, pHCPhys);
|
---|
[19182] | 336 | return rc;
|
---|
| 337 | }
|
---|
| 338 |
|
---|
| 339 |
|
---|
| 340 | /**
|
---|
| 341 | * Called on the EMT for the VCpu.
|
---|
| 342 | *
|
---|
| 343 | * @returns VBox status code.
|
---|
[19286] | 344 | *
|
---|
[44399] | 345 | * @param pUVM The user mode VM handle.
|
---|
[19286] | 346 | * @param idCpu The ID of the CPU context.
|
---|
[19182] | 347 | * @param pAddress The address.
|
---|
| 348 | * @param fReadOnly Whether returning a read-only page is fine or not.
|
---|
| 349 | * @param ppvR3Ptr Where to return the address.
|
---|
| 350 | */
|
---|
[44399] | 351 | static DECLCALLBACK(int) dbgfR3AddrToVolatileR3PtrOnVCpu(PUVM pUVM, VMCPUID idCpu, PDBGFADDRESS pAddress, bool fReadOnly,
|
---|
| 352 | void **ppvR3Ptr)
|
---|
[19182] | 353 | {
|
---|
[44399] | 354 | PVM pVM = pUVM->pVM;
|
---|
| 355 | VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE);
|
---|
[19286] | 356 | Assert(idCpu == VMMGetCpuId(pVM));
|
---|
[19182] | 357 |
|
---|
[80014] | 358 | /*
|
---|
| 359 | * This is a tad ugly, but it gets the job done.
|
---|
| 360 | */
|
---|
[19182] | 361 | int rc;
|
---|
[80014] | 362 | PGMPAGEMAPLOCK Lock;
|
---|
| 363 | if (pAddress->fFlags & DBGFADDRESS_FLAGS_PHYS)
|
---|
[19182] | 364 | {
|
---|
[80014] | 365 | if (fReadOnly)
|
---|
| 366 | rc = PGMPhysGCPhys2CCPtrReadOnly(pVM, pAddress->FlatPtr, (void const **)ppvR3Ptr, &Lock);
|
---|
| 367 | else
|
---|
| 368 | rc = PGMPhysGCPhys2CCPtr(pVM, pAddress->FlatPtr, ppvR3Ptr, &Lock);
|
---|
[19182] | 369 | }
|
---|
| 370 | else
|
---|
| 371 | {
|
---|
[80014] | 372 | PVMCPU pVCpu = VMMGetCpuById(pVM, idCpu);
|
---|
| 373 | if (fReadOnly)
|
---|
| 374 | rc = PGMPhysGCPtr2CCPtrReadOnly(pVCpu, pAddress->FlatPtr, (void const **)ppvR3Ptr, &Lock);
|
---|
[19182] | 375 | else
|
---|
[80014] | 376 | rc = PGMPhysGCPtr2CCPtr(pVCpu, pAddress->FlatPtr, ppvR3Ptr, &Lock);
|
---|
[19182] | 377 | }
|
---|
[80014] | 378 | if (RT_SUCCESS(rc))
|
---|
| 379 | PGMPhysReleasePageMappingLock(pVM, &Lock);
|
---|
[19182] | 380 | return rc;
|
---|
| 381 | }
|
---|
| 382 |
|
---|
| 383 |
|
---|
| 384 |
|
---|
| 385 |
|
---|
| 386 | /**
|
---|
| 387 | * Converts an address to a volatile host virtual address.
|
---|
| 388 | *
|
---|
| 389 | * @returns VBox status code.
|
---|
| 390 | * @retval VINF_SUCCESS
|
---|
| 391 | * @retval VERR_INVALID_PARAMETER if the address is invalid.
|
---|
| 392 | * @retval VERR_INVALID_STATE if the VM is being terminated or if the virtual
|
---|
| 393 | * CPU handle is invalid.
|
---|
| 394 | * @retval VERR_NOT_SUPPORTED is the type of address cannot be converted.
|
---|
| 395 | * @retval VERR_PAGE_NOT_PRESENT
|
---|
| 396 | * @retval VERR_PAGE_TABLE_NOT_PRESENT
|
---|
| 397 | * @retval VERR_PAGE_DIRECTORY_PTR_NOT_PRESENT
|
---|
| 398 | * @retval VERR_PAGE_MAP_LEVEL4_NOT_PRESENT
|
---|
| 399 | * @retval VERR_PGM_PHYS_PAGE_RESERVED
|
---|
| 400 | * @retval VERR_PGM_INVALID_GC_PHYSICAL_ADDRESS
|
---|
| 401 | *
|
---|
[44399] | 402 | * @param pUVM The user mode VM handle.
|
---|
[19286] | 403 | * @param idCpu The ID of the CPU context to convert virtual
|
---|
| 404 | * addresses.
|
---|
[19182] | 405 | * @param pAddress The address.
|
---|
| 406 | * @param fReadOnly Whether returning a read-only page is fine or not.
|
---|
| 407 | * If set to thru the page may have to be made writable
|
---|
| 408 | * before we return.
|
---|
| 409 | * @param ppvR3Ptr Where to return the address.
|
---|
| 410 | */
|
---|
[44399] | 411 | VMMR3DECL(int) DBGFR3AddrToVolatileR3Ptr(PUVM pUVM, VMCPUID idCpu, PDBGFADDRESS pAddress, bool fReadOnly, void **ppvR3Ptr)
|
---|
[19182] | 412 | {
|
---|
| 413 | /*
|
---|
| 414 | * Parameter validation.
|
---|
| 415 | */
|
---|
| 416 | AssertPtr(ppvR3Ptr);
|
---|
| 417 | *ppvR3Ptr = NULL;
|
---|
| 418 | AssertPtr(pAddress);
|
---|
| 419 | AssertReturn(DBGFADDRESS_IS_VALID(pAddress), VERR_INVALID_PARAMETER);
|
---|
[44399] | 420 | UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_STATE);
|
---|
| 421 | AssertReturn(idCpu < pUVM->cCpus, VERR_INVALID_PARAMETER);
|
---|
[19182] | 422 |
|
---|
| 423 | /*
|
---|
| 424 | * Convert it.
|
---|
| 425 | */
|
---|
[44399] | 426 | return VMR3ReqPriorityCallWaitU(pUVM, idCpu, (PFNRT)dbgfR3AddrToVolatileR3PtrOnVCpu, 5,
|
---|
| 427 | pUVM, idCpu, pAddress, fReadOnly, ppvR3Ptr);
|
---|
[19182] | 428 | }
|
---|
| 429 |
|
---|
[19286] | 430 |
|
---|
| 431 | /**
|
---|
| 432 | * Adds an offset to an address.
|
---|
| 433 | *
|
---|
| 434 | * @returns pAddress.
|
---|
| 435 | *
|
---|
| 436 | * @param pAddress The address.
|
---|
| 437 | * @param uAddend How much to add.
|
---|
| 438 | *
|
---|
| 439 | * @remarks No address space or segment limit checks are performed,
|
---|
| 440 | */
|
---|
| 441 | VMMR3DECL(PDBGFADDRESS) DBGFR3AddrAdd(PDBGFADDRESS pAddress, RTGCUINTPTR uAddend)
|
---|
| 442 | {
|
---|
| 443 | /*
|
---|
| 444 | * Parameter validation.
|
---|
| 445 | */
|
---|
| 446 | AssertPtrReturn(pAddress, NULL);
|
---|
| 447 | AssertReturn(DBGFADDRESS_IS_VALID(pAddress), NULL);
|
---|
| 448 |
|
---|
| 449 | /*
|
---|
| 450 | * Add the stuff.
|
---|
| 451 | */
|
---|
| 452 | pAddress->off += uAddend;
|
---|
| 453 | pAddress->FlatPtr += uAddend;
|
---|
| 454 |
|
---|
| 455 | return pAddress;
|
---|
| 456 | }
|
---|
| 457 |
|
---|
| 458 |
|
---|
| 459 | /**
|
---|
| 460 | * Subtracts an offset from an address.
|
---|
| 461 | *
|
---|
| 462 | * @returns VINF_SUCCESS on success.
|
---|
| 463 | *
|
---|
| 464 | * @param pAddress The address.
|
---|
| 465 | * @param uSubtrahend How much to subtract.
|
---|
| 466 | *
|
---|
| 467 | * @remarks No address space or segment limit checks are performed,
|
---|
| 468 | */
|
---|
| 469 | VMMR3DECL(PDBGFADDRESS) DBGFR3AddrSub(PDBGFADDRESS pAddress, RTGCUINTPTR uSubtrahend)
|
---|
| 470 | {
|
---|
| 471 | /*
|
---|
| 472 | * Parameter validation.
|
---|
| 473 | */
|
---|
| 474 | AssertPtrReturn(pAddress, NULL);
|
---|
| 475 | AssertReturn(DBGFADDRESS_IS_VALID(pAddress), NULL);
|
---|
| 476 |
|
---|
| 477 | /*
|
---|
| 478 | * Add the stuff.
|
---|
| 479 | */
|
---|
| 480 | pAddress->off -= uSubtrahend;
|
---|
| 481 | pAddress->FlatPtr -= uSubtrahend;
|
---|
| 482 |
|
---|
| 483 | return pAddress;
|
---|
| 484 | }
|
---|
| 485 |
|
---|