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//*****************************************************************************
5// DacDbiImpl.inl
6//
7
8//
9// Inline functions for DacDbiImpl.h
10//
11//*****************************************************************************
12
13#ifndef _DACDBI_IMPL_INL_
14#define _DACDBI_IMPL_INL_
15
16#include "dacdbiimpl.h"
17
18//---------------------------------------------------------------------------------------
19// Helper to write a structure to the target
20//
21// Arguments:
22// T - type of structure to read.
23// pRemotePtr - remote pointer into target (dest).
24// pLocalBuffer - local buffer to write (Src).
25//
26// Return Value:
27// Throws on error.
28//
29// Notes:
30// This just does a raw Byte copy into the Target, but does not do any Marshalling.
31// This fails if any part of the buffer can't be written.
32//
33//
34//---------------------------------------------------------------------------------------
35template<typename T>
36void DacDbiInterfaceImpl::SafeWriteStructOrThrow(CORDB_ADDRESS pRemotePtr, const T * pLocalBuffer)
37{
38 HRESULT hr = m_pMutableTarget->WriteVirtual(pRemotePtr,
39 (BYTE *)(pLocalBuffer), sizeof(T));
40
41 if (FAILED(hr))
42 {
43 ThrowHR(hr);
44 }
45}
46
47//---------------------------------------------------------------------------------------
48// Helper to read a structure from the target process
49//
50// Arguments:
51// T - type of structure to read
52// pRemotePtr - remote pointer into the target process (src)
53// pLocalBuffer - local buffer to store the structure (dest)
54//
55// Notes:
56// This just does a raw Byte copy into the Target, but does not do any Marshalling.
57// This fails if any part of the buffer can't be written.
58//
59
60template<typename T>
61void DacDbiInterfaceImpl::SafeReadStructOrThrow(CORDB_ADDRESS pRemotePtr, T * pLocalBuffer)
62{
63 ULONG32 cbRead = 0;
64
65 HRESULT hr = m_pTarget->ReadVirtual(pRemotePtr,
66 reinterpret_cast<BYTE *>(pLocalBuffer), sizeof(T), &cbRead);
67
68 if (FAILED(hr))
69 {
70 ThrowHR(CORDBG_E_READVIRTUAL_FAILURE);
71 }
72
73 if (cbRead != sizeof(T))
74 {
75 ThrowWin32(ERROR_PARTIAL_COPY);
76 }
77}
78
79#endif // _DACDBI_IMPL_INL_
80