summaryrefslogtreecommitdiff
path: root/src/debug/daccess/dacdbiimpl.inl
blob: c9deae7feee19a2f11e1990b99ca14bdf272bf16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
//*****************************************************************************
// DacDbiImpl.inl
// 

//
// Inline functions for DacDbiImpl.h
//
//*****************************************************************************

#ifndef _DACDBI_IMPL_INL_
#define _DACDBI_IMPL_INL_

#include "dacdbiimpl.h"

//---------------------------------------------------------------------------------------
// Helper to write a structure to the target
//
// Arguments:
//    T - type of structure to read.
//    pRemotePtr - remote pointer into target (dest).
//    pLocalBuffer - local buffer to write (Src). 
//
// Return Value:
//    Throws on error.
//
// Notes:
//    This just does a raw Byte copy into the Target, but does not do any Marshalling. 
//    This fails if any part of the buffer can't be written. 
//
//
//---------------------------------------------------------------------------------------
template<typename T>
void DacDbiInterfaceImpl::SafeWriteStructOrThrow(CORDB_ADDRESS pRemotePtr, const T * pLocalBuffer)
{
    HRESULT hr = m_pMutableTarget->WriteVirtual(pRemotePtr, 
        (BYTE *)(pLocalBuffer), sizeof(T));
    
    if (FAILED(hr))
    {
        ThrowHR(hr);
    }
}

//---------------------------------------------------------------------------------------
// Helper to read a structure from the target process
//
// Arguments:
//    T            - type of structure to read
//    pRemotePtr   - remote pointer into the target process (src)
//    pLocalBuffer - local buffer to store the structure (dest)
//
// Notes:
//    This just does a raw Byte copy into the Target, but does not do any Marshalling. 
//    This fails if any part of the buffer can't be written. 
//

template<typename T>
void DacDbiInterfaceImpl::SafeReadStructOrThrow(CORDB_ADDRESS pRemotePtr, T * pLocalBuffer)
{
    ULONG32 cbRead = 0;

    HRESULT hr = m_pTarget->ReadVirtual(pRemotePtr, 
        reinterpret_cast<BYTE *>(pLocalBuffer), sizeof(T), &cbRead);
    
    if (FAILED(hr))
    {
        ThrowHR(CORDBG_E_READVIRTUAL_FAILURE);
    }
    
    if (cbRead != sizeof(T))
    {
        ThrowWin32(ERROR_PARTIAL_COPY);
    }
}

#endif // _DACDBI_IMPL_INL_