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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
// 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.
// QCALL.CPP
//
#include "common.h"
//
// Helpers for returning managed string from QCall
//
void QCall::StringHandleOnStack::Set(const SString& value)
{
STANDARD_VM_CONTRACT;
GCX_COOP();
Set(StringObject::NewString(value));
}
void QCall::StringHandleOnStack::Set(LPCWSTR pwzValue)
{
STANDARD_VM_CONTRACT;
GCX_COOP();
Set(StringObject::NewString(pwzValue));
}
void QCall::StringHandleOnStack::Set(LPCUTF8 pszValue)
{
STANDARD_VM_CONTRACT;
GCX_COOP();
Set(StringObject::NewString(pszValue));
}
//
// Helpers for returning common managed types from QCall
//
void QCall::ObjectHandleOnStack::SetByteArray(const BYTE * p, COUNT_T length)
{
STANDARD_VM_CONTRACT;
GCX_COOP();
BASEARRAYREF arr = (BASEARRAYREF) AllocatePrimitiveArray(ELEMENT_TYPE_U1, length);
memcpyNoGCRefs(arr->GetDataPtr(), p, length * sizeof(BYTE));
Set(arr);
}
void QCall::ObjectHandleOnStack::SetIntPtrArray(const PVOID * p, COUNT_T length)
{
STANDARD_VM_CONTRACT;
GCX_COOP();
BASEARRAYREF arr = (BASEARRAYREF) AllocatePrimitiveArray(ELEMENT_TYPE_I, length);
memcpyNoGCRefs(arr->GetDataPtr(), p, length * sizeof(PVOID));
Set(arr);
}
void QCall::ObjectHandleOnStack::SetGuidArray(const GUID * p, COUNT_T length)
{
STANDARD_VM_CONTRACT;
GCX_COOP();
TypeHandle typeHandle = MscorlibBinder::GetClass(CLASS__GUID);
BASEARRAYREF arr = (BASEARRAYREF) AllocateValueSzArray(typeHandle, length);
memcpyNoGCRefs(arr->GetDataPtr(), p, length * sizeof(GUID));
Set(arr);
}
//
// Helpers for passing an AppDomain to a QCall
//
#ifdef _DEBUG
//---------------------------------------------------------------------------------------
//
// Verify that the AppDomain being passed from the BCL is valid for use in a QCall. Note: some additional
// checks are in System.AppDomain.GetNativeHandle()
//
void QCall::AppDomainHandle::VerifyDomainHandle() const
{
LIMITED_METHOD_CONTRACT;
// System.AppDomain.GetNativeHandle() should ensure that we're not calling through with a null AppDomain pointer.
_ASSERTE(m_pAppDomain);
// QCalls should only be made with pointers to the current domain
_ASSERTE(GetAppDomain() == m_pAppDomain);
// We should not have a QCall made on an invalid AppDomain. Once unload a domain, we won't let anyone else
// in and any threads that are already in will be unwound.
_ASSERTE(SystemDomain::GetAppDomainAtIndex(m_pAppDomain->GetIndex()) != NULL);
}
#endif // _DEBUG
|