forked from nanoframework/nf-interpreter
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCLR_RT_HeapBlock_Delegate.cpp
More file actions
88 lines (71 loc) · 2.15 KB
/
CLR_RT_HeapBlock_Delegate.cpp
File metadata and controls
88 lines (71 loc) · 2.15 KB
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
//
// Copyright (c) .NET Foundation and Contributors
// Portions Copyright (c) Microsoft Corporation. All rights reserved.
// See LICENSE file in the project root for full license information.
//
#include "Core.h"
////////////////////////////////////////////////////////////////////////////////////////////////////
HRESULT CLR_RT_HeapBlock_Delegate::CreateInstance(
CLR_RT_HeapBlock &reference,
const CLR_RT_MethodDef_Index &ftn,
CLR_RT_StackFrame *call)
{
NATIVE_PROFILE_CLR_CORE();
NANOCLR_HEADER();
reference.SetObjectReference(nullptr);
CLR_UINT32 length = 0;
#if defined(NANOCLR_DELEGATE_PRESERVE_STACK)
if (call)
{
NANOCLR_FOREACH_NODE_BACKWARD__DIRECT(CLR_RT_StackFrame, ptr, call)
{
length++;
}
NANOCLR_FOREACH_NODE_BACKWARD_END();
}
//
// Limit depth to three callers.
//
if (length > 3)
length = 3;
#else
(void)call;
#endif
CLR_UINT32 totLength = (CLR_UINT32)(sizeof(CLR_RT_HeapBlock_Delegate) + length * sizeof(CLR_RT_MethodDef_Index));
CLR_RT_HeapBlock_Delegate *dlg = (CLR_RT_HeapBlock_Delegate *)g_CLR_RT_ExecutionEngine.ExtractHeapBytesForObjects(
DATATYPE_DELEGATE_HEAD,
0,
totLength);
CHECK_ALLOCATION(dlg);
reference.SetObjectReference(dlg);
dlg->ClearData();
dlg->m_cls.Clear();
dlg->m_ftn = ftn;
#if defined(NANOCLR_DELEGATE_PRESERVE_STACK)
dlg->m_numOfStackFrames = length;
#endif
dlg->m_object.SetObjectReference(nullptr);
dlg->m_genericTypeSpec.Clear();
#if defined(NANOCLR_APPDOMAINS)
dlg->m_appDomain = g_CLR_RT_ExecutionEngine.GetCurrentAppDomain();
#endif
#if defined(NANOCLR_DELEGATE_PRESERVE_STACK)
if (call)
{
CLR_RT_MethodDef_Index *callStack = dlg->GetStackFrames();
NANOCLR_FOREACH_NODE_BACKWARD__DIRECT(CLR_RT_StackFrame, ptr, call)
{
if (length-- == 0)
break;
*callStack++ = ptr->m_call;
}
NANOCLR_FOREACH_NODE_BACKWARD_END();
}
#endif
NANOCLR_NOCLEANUP();
}
void CLR_RT_HeapBlock_Delegate::Relocate()
{
NATIVE_PROFILE_CLR_CORE();
m_object.Relocate__HeapBlock();
}