diff --git a/pykd/context.cpp b/pykd/context.cpp index 5246be7..67781e4 100644 --- a/pykd/context.cpp +++ b/pykd/context.cpp @@ -6,6 +6,7 @@ #include "context.h" #include "stkframe.h" +#include "dbgmem.h" ///////////////////////////////////////////////////////////////////////////////// @@ -228,7 +229,8 @@ ContextPtr ThreadContext::getWow64Context( IDebugClient4 *client ) ULONG64 cpuAreaAddress; ULONG readedBytes; hres = - ptrContext->m_dataSpaces->ReadVirtual( + readVirtual( + ptrContext->m_dataSpaces, teb64Address + teb64ToTlsOffset + (sizeof(ULONG64) * WOW64_TLS_CPURESERVED), &cpuAreaAddress, sizeof(cpuAreaAddress), @@ -242,7 +244,8 @@ ContextPtr ThreadContext::getWow64Context( IDebugClient4 *client ) static const ULONG cpuAreaToWow64ContextOffset = sizeof(ULONG); WOW64_CONTEXT Context = {0}; hres = - ptrContext->m_dataSpaces->ReadVirtual( + readVirtual( + ptrContext->m_dataSpaces, cpuAreaAddress + cpuAreaToWow64ContextOffset, &Context, sizeof(Context), diff --git a/pykd/dbgmem.cpp b/pykd/dbgmem.cpp index 234f72b..c2d7dee 100644 --- a/pykd/dbgmem.cpp +++ b/pykd/dbgmem.cpp @@ -107,22 +107,51 @@ bool isVaValid( ULONG64 addr ) ///////////////////////////////////////////////////////////////////////////////////// +HRESULT readVirtual( + IDebugDataSpaces4 *dbgDataSpace, + ULONG64 address, + PVOID buffer, + ULONG length, + PULONG readed +) +{ + HRESULT hres; + + CComQIPtr<IDebugControl4> dbgControl(dbgDataSpace); + + address = addr64( dbgControl, address); + + { + // workitem/10473 workaround + ULONG64 nextAddress; + hres = + dbgDataSpace->GetNextDifferentlyValidOffsetVirtual( + address, + &nextAddress); + DBG_UNREFERENCED_LOCAL_VARIABLE(nextAddress); + } + + hres = dbgDataSpace->ReadVirtual( address, buffer, length, readed ); + + return hres; +} + +///////////////////////////////////////////////////////////////////////////////////// + void readMemory( IDebugDataSpaces4* dbgDataSpace, ULONG64 address, PVOID buffer, ULONG length, bool phyAddr = FALSE ) { HRESULT hres; - CComQIPtr<IDebugControl4> dbgControl(dbgDataSpace); - if ( phyAddr == false ) { - hres = dbgDataSpace->ReadVirtual( addr64( dbgControl, address), buffer, length, NULL ); - } + hres = readVirtual( dbgDataSpace, address, buffer, length, NULL ); + } else { hres = dbgDataSpace->ReadPhysical( address, buffer, length, NULL ); - } - + } + if ( FAILED( hres ) ) throw MemoryException( address, phyAddr ); } diff --git a/pykd/dbgmem.h b/pykd/dbgmem.h index a1b5070..bb8cde3 100644 --- a/pykd/dbgmem.h +++ b/pykd/dbgmem.h @@ -12,6 +12,16 @@ isVaValid( ULONG64 addr ); /////////////////////////////////////////////////////////////////////////////////// +HRESULT readVirtual( + IDebugDataSpaces4 *dbgDataSpace, + ULONG64 address, + PVOID buffer, + ULONG length, + PULONG readed +); + +/////////////////////////////////////////////////////////////////////////////////// + void readMemory( IDebugDataSpaces4* dbgDataSpace, ULONG64 address, PVOID buffer, ULONG length, bool phyAddr = FALSE );