summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike McLaughlin <mikem@microsoft.com>2019-05-29 23:39:31 -0700
committerGitHub <noreply@github.com>2019-05-29 23:39:31 -0700
commite46ae5921c510309f252af21c2a88d341e4e15ab (patch)
tree53b273bfed5e8310d50b38daf2067a77f3589b2f /src
parentcc1f8ab68e645cd46601b1df50ff644dfffc4dae (diff)
downloadcoreclr-e46ae5921c510309f252af21c2a88d341e4e15ab.tar.gz
coreclr-e46ae5921c510309f252af21c2a88d341e4e15ab.tar.bz2
coreclr-e46ae5921c510309f252af21c2a88d341e4e15ab.zip
Use /proc/<pid>/mem to read memory in remote DBI data target. It makes the test case run at (#24844)
least 4 to 5 times faster than before. Fallback to old transport ReadMemory if /proc/<pid>/mem can't be opened. This happens on attach because of permissions/access, but works fine on the launch (the most important case).
Diffstat (limited to 'src')
-rw-r--r--src/debug/di/shimremotedatatarget.cpp35
-rw-r--r--src/dlls/mscordac/mscordac_unixexports.src3
-rw-r--r--src/pal/inc/pal.h5
-rw-r--r--src/pal/src/cruntime/file.cpp12
4 files changed, 46 insertions, 9 deletions
diff --git a/src/debug/di/shimremotedatatarget.cpp b/src/debug/di/shimremotedatatarget.cpp
index 7e6b8375ee..aaf8523b60 100644
--- a/src/debug/di/shimremotedatatarget.cpp
+++ b/src/debug/di/shimremotedatatarget.cpp
@@ -20,7 +20,6 @@
#include "dbgtransportsession.h"
#include "dbgtransportmanager.h"
-
class ShimRemoteDataTarget : public ShimDataTarget
{
public:
@@ -69,6 +68,7 @@ public:
private:
DbgTransportTarget * m_pProxy;
DbgTransportSession * m_pTransport;
+ int m_fd; // /proc/<pid>/mem handle
};
@@ -103,6 +103,10 @@ ShimRemoteDataTarget::ShimRemoteDataTarget(DWORD processId,
m_fpContinueStatusChanged = NULL;
m_pContinueStatusChangedUserData = NULL;
+
+ char memPath[128];
+ _snprintf_s(memPath, sizeof(memPath), sizeof(memPath), "/proc/%lu/mem", m_processId);
+ m_fd = _open(memPath, 0); // O_RDONLY
}
//---------------------------------------------------------------------------------------
@@ -127,11 +131,15 @@ ShimRemoteDataTarget::~ShimRemoteDataTarget()
void ShimRemoteDataTarget::Dispose()
{
+ if (m_fd != -1)
+ {
+ _close(m_fd);
+ m_fd = -1;
+ }
if (m_pTransport != NULL)
{
m_pProxy->ReleaseTransport(m_pTransport);
}
-
m_pTransport = NULL;
m_hr = CORDBG_E_OBJECT_NEUTERED;
}
@@ -244,7 +252,7 @@ ShimRemoteDataTarget::GetPlatform(
// impl of interface method ICorDebugDataTarget::ReadVirtual
HRESULT STDMETHODCALLTYPE
-ShimRemoteDataTarget::ReadVirtual(
+ShimRemoteDataTarget::ReadVirtual(
CORDB_ADDRESS address,
PBYTE pBuffer,
ULONG32 cbRequestSize,
@@ -252,13 +260,24 @@ ShimRemoteDataTarget::ReadVirtual(
{
ReturnFailureIfStateNotOk();
- HRESULT hr = E_FAIL;
- hr = m_pTransport->ReadMemory(reinterpret_cast<BYTE *>(CORDB_ADDRESS_TO_PTR(address)),
- pBuffer,
- cbRequestSize);
+ size_t read = cbRequestSize;
+ HRESULT hr = S_OK;
+
+ if (m_fd != -1)
+ {
+ read = _pread(m_fd, pBuffer, cbRequestSize, (ULONG64)address);
+ if (read == -1)
+ {
+ hr = E_FAIL;
+ }
+ }
+ else
+ {
+ hr = m_pTransport->ReadMemory(reinterpret_cast<BYTE *>(CORDB_ADDRESS_TO_PTR(address)), pBuffer, cbRequestSize);
+ }
if (pcbRead != NULL)
{
- *pcbRead = (SUCCEEDED(hr) ? cbRequestSize : 0);
+ *pcbRead = (SUCCEEDED(hr) ? read : 0);
}
return hr;
}
diff --git a/src/dlls/mscordac/mscordac_unixexports.src b/src/dlls/mscordac/mscordac_unixexports.src
index eb5d4ea7d9..71c6b313be 100644
--- a/src/dlls/mscordac/mscordac_unixexports.src
+++ b/src/dlls/mscordac/mscordac_unixexports.src
@@ -65,6 +65,9 @@ nativeStringResourceTable_mscorrc_debug
#PAL_wcscspn
#PAL_wcscat
#PAL_wcsstr
+#PAL__open
+#PAL__pread
+#PAL__close
#_wcsicmp
#_stricmp
diff --git a/src/pal/inc/pal.h b/src/pal/inc/pal.h
index bcb4e8ce8f..884b737d15 100644
--- a/src/pal/inc/pal.h
+++ b/src/pal/inc/pal.h
@@ -4138,6 +4138,7 @@ PAL_GetCurrentThreadAffinitySet(SIZE_T size, UINT_PTR* data);
#define _strdup PAL__strdup
#define _getcwd PAL__getcwd
#define _open PAL__open
+#define _pread PAL__pread
#define _close PAL__close
#define _wcstoui64 PAL__wcstoui64
#define _flushall PAL__flushall
@@ -4507,7 +4508,9 @@ PALIMPORT char * __cdecl ctime(const time_t *);
#endif // !PAL_STDCPP_COMPAT
PALIMPORT int __cdecl _open_osfhandle(INT_PTR, int);
-PALIMPORT int __cdecl _close(int);
+PALIMPORT DLLEXPORT int __cdecl _open(const char *szPath, int nFlags, ...);
+PALIMPORT DLLEXPORT size_t __cdecl _pread(int fd, void *buf, size_t nbytes, ULONG64 offset);
+PALIMPORT DLLEXPORT int __cdecl _close(int);
PALIMPORT DLLEXPORT int __cdecl _flushall();
#ifdef PAL_STDCPP_COMPAT
diff --git a/src/pal/src/cruntime/file.cpp b/src/pal/src/cruntime/file.cpp
index 0eb2cea151..c54e3e0418 100644
--- a/src/pal/src/cruntime/file.cpp
+++ b/src/pal/src/cruntime/file.cpp
@@ -453,6 +453,18 @@ PAL_FILE * __cdecl PAL_get_stderr(int caller)
return &PAL_Stderr;
}
+/*++
+
+Function:
+
+ PAL_pread
+
+See msdn for more details.
+--*/
+size_t __cdecl PAL__pread(int fd, void *buf, size_t nbytes, ULONG64 offset)
+{
+ return pread(fd, buf, nbytes, offset);
+}
/*++