1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
4 //*****************************************************************************
6 // Internal data access functionality.
9 //*****************************************************************************
15 #include <dacprivate.h>
17 //----------------------------------------------------------------------------
19 // LiveProcDataTarget.
21 //----------------------------------------------------------------------------
23 LiveProcDataTarget::LiveProcDataTarget(HANDLE process,
25 CLRDATA_ADDRESS baseAddressOfEngine)
28 m_processId = processId;
29 m_baseAddressOfEngine = baseAddressOfEngine;
33 LiveProcDataTarget::QueryInterface(
35 IN REFIID InterfaceId,
39 if (InterfaceId == IID_IUnknown ||
40 InterfaceId == IID_ICLRDataTarget)
42 *Interface = (ICLRDataTarget*)this;
43 // No need to refcount as this class is contained.
54 LiveProcDataTarget::AddRef(
58 // No need to refcount as this class is contained.
63 LiveProcDataTarget::Release(
67 SUPPORTS_DAC_HOST_ONLY;
68 // No need to refcount as this class is contained.
72 HRESULT STDMETHODCALLTYPE
73 LiveProcDataTarget::GetMachineType(
74 /* [out] */ ULONG32 *machine)
76 LIMITED_METHOD_CONTRACT;
78 #if defined(_TARGET_X86_)
79 *machine = IMAGE_FILE_MACHINE_I386;
80 #elif defined(_TARGET_AMD64_)
81 *machine = IMAGE_FILE_MACHINE_AMD64;
82 #elif defined(_TARGET_ARM_)
83 *machine = IMAGE_FILE_MACHINE_ARMNT;
85 PORTABILITY_ASSERT("Unknown Processor");
90 HRESULT STDMETHODCALLTYPE
91 LiveProcDataTarget::GetPointerSize(
92 /* [out] */ ULONG32 *size)
94 LIMITED_METHOD_CONTRACT;
96 *size = sizeof(void*);
100 HRESULT STDMETHODCALLTYPE
101 LiveProcDataTarget::GetImageBase(
102 /* [string][in] */ LPCWSTR name,
103 /* [out] */ CLRDATA_ADDRESS *base)
106 // The only image base that the access code cares
107 // about right now is the base of mscorwks.
110 if (wcscmp(name, MAIN_CLR_DLL_NAME_W))
112 return E_NOINTERFACE;
116 // If a base address was specified, use that
118 if (NULL != m_baseAddressOfEngine)
120 *base = m_baseAddressOfEngine;
125 // Our creator must have told us WHICH clr to work with.
130 HRESULT STDMETHODCALLTYPE
131 LiveProcDataTarget::ReadVirtual(
132 /* [in] */ CLRDATA_ADDRESS address,
133 /* [length_is][size_is][out] */ PBYTE buffer,
134 /* [in] */ ULONG32 request,
135 /* [optional][out] */ ULONG32 *done)
137 // ReadProcessMemory will fail if any part of the
138 // region to read does not have read access. This
139 // routine attempts to read the largest valid prefix
140 // so it has to break up reads on page boundaries.
142 HRESULT status = S_OK;
143 ULONG32 totalDone = 0;
149 // Calculate bytes to read and don't let read cross
151 readSize = GetOsPageSize() - (ULONG32)(address & (GetOsPageSize() - 1));
152 readSize = min(request, readSize);
154 if (!ReadProcessMemory(m_process, (PVOID)(ULONG_PTR)address,
155 buffer, readSize, &read))
159 // If we haven't read anything indicate failure.
165 totalDone += (ULONG32)read;
168 request -= (ULONG32)read;
175 HRESULT STDMETHODCALLTYPE
176 LiveProcDataTarget::WriteVirtual(
177 /* [in] */ CLRDATA_ADDRESS address,
178 /* [size_is][in] */ PBYTE buffer,
179 /* [in] */ ULONG32 request,
180 /* [optional][out] */ ULONG32 *done)
182 // Not necessary yet.
186 HRESULT STDMETHODCALLTYPE
187 LiveProcDataTarget::GetTLSValue(
188 /* [in] */ ULONG32 threadID,
189 /* [in] */ ULONG32 index,
190 /* [out] */ CLRDATA_ADDRESS* value)
193 // Not necessary yet.
197 HRESULT STDMETHODCALLTYPE
198 LiveProcDataTarget::SetTLSValue(
199 /* [in] */ ULONG32 threadID,
200 /* [in] */ ULONG32 index,
201 /* [in] */ CLRDATA_ADDRESS value)
203 // Not necessary yet.
207 HRESULT STDMETHODCALLTYPE
208 LiveProcDataTarget::GetCurrentThreadID(
209 /* [out] */ ULONG32* threadID)
212 // Not necessary yet.
216 HRESULT STDMETHODCALLTYPE
217 LiveProcDataTarget::GetThreadContext(
218 /* [in] */ ULONG32 threadID,
219 /* [in] */ ULONG32 contextFlags,
220 /* [in] */ ULONG32 contextSize,
221 /* [out, size_is(contextSize)] */ PBYTE context)
223 // Not necessary yet.
227 HRESULT STDMETHODCALLTYPE
228 LiveProcDataTarget::SetThreadContext(
229 /* [in] */ ULONG32 threadID,
230 /* [in] */ ULONG32 contextSize,
231 /* [out, size_is(contextSize)] */ PBYTE context)
233 // Not necessary yet.
237 HRESULT STDMETHODCALLTYPE
238 LiveProcDataTarget::Request(
239 /* [in] */ ULONG32 reqCode,
240 /* [in] */ ULONG32 inBufferSize,
241 /* [size_is][in] */ BYTE *inBuffer,
242 /* [in] */ ULONG32 outBufferSize,
243 /* [size_is][out] */ BYTE *outBuffer)