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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
// 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.
// Internal.Reflection.Execution
// -------------------------------------------------
// Why does this exist?:
// Unlike the desktop, RH uses Internal.Reflection.Core for
// "classic reflection" emulation as well as LMR, using
// the Internal.Reflection.Core.Execution contract.
//
// Internal.Reflection.Core.Execution has an abstract model
// for an "execution engine" - this contract provides the
// concrete implementation of this model for Redhawk.
//
//
// Implemented by:
// Reflection.Execution.dll on RH
// N/A on desktop:
//
// Consumed by:
// Redhawk app's directly via an under-the-hood ILTransform.
// System.Private.CoreLib.dll, via a callback (see Internal.System.Runtime.Augment)
//
using global::System;
using global::System.Collections.Generic;
using global::System.Reflection;
using global::System.Reflection.Runtime.General;
using global::Internal.Runtime.Augments;
using global::Internal.Reflection.Core;
using global::Internal.Reflection.Core.Execution;
using global::Internal.Metadata.NativeFormat;
using Debug = System.Diagnostics.Debug;
namespace Internal.Reflection.Execution
{
public static class ReflectionExecution
{
/// <summary>
/// Eager initialization of runtime reflection support. As part of ExecutionEnvironmentImplementation
/// initialization it enumerates the modules and registers the ones containing EmbeddedMetadata reflection blobs
/// in its _moduleToMetadataReader map.
/// </summary>
internal static void Initialize()
{
// Initialize Reflection.Core's one and only ExecutionDomain.
ExecutionEnvironmentImplementation executionEnvironment = new ExecutionEnvironmentImplementation();
ReflectionDomainSetupImplementation setup = new ReflectionDomainSetupImplementation(executionEnvironment);
ReflectionCoreExecution.InitializeExecutionDomain(setup, executionEnvironment);
// Initialize our two communication with System.Private.CoreLib.
ExecutionDomain executionDomain = ReflectionCoreExecution.ExecutionDomain;
ReflectionExecutionDomainCallbacksImplementation runtimeCallbacks = new ReflectionExecutionDomainCallbacksImplementation(executionDomain, executionEnvironment);
RuntimeAugments.Initialize(runtimeCallbacks);
DefaultAssemblyNamesForGetType =
new String[]
{
AssemblyBinder.DefaultAssemblyNameForGetType,
};
ExecutionEnvironment = executionEnvironment;
}
//
// This entry is targeted by the ILTransformer to implement Type.GetType()'s ability to detect the calling assembly and use it as
// a default assembly name.
//
public static Type GetType(string typeName, string callingAssemblyName, bool throwOnError, bool ignoreCase)
{
return ExtensibleGetType(typeName, callingAssemblyName, null, null, throwOnError: throwOnError, ignoreCase: ignoreCase);
}
//
// This entry is targeted by the ILTransformer to implement Type.GetType()'s ability to detect the calling assembly and use it as
// a default assembly name.
//
public static Type ExtensibleGetType(string typeName, string callingAssemblyName, Func<AssemblyName, Assembly> assemblyResolver, Func<Assembly, string, bool, Type> typeResolver, bool throwOnError, bool ignoreCase)
{
LowLevelListWithIList<String> defaultAssemblies = new LowLevelListWithIList<String>();
defaultAssemblies.Add(callingAssemblyName);
defaultAssemblies.AddRange(DefaultAssemblyNamesForGetType);
return ReflectionCoreExecution.ExecutionDomain.GetType(typeName, assemblyResolver, typeResolver, throwOnError, ignoreCase, defaultAssemblies);
}
public static bool TryGetMethodMetadataFromStartAddress(IntPtr methodStartAddress, out MetadataReader reader, out TypeDefinitionHandle typeHandle, out MethodHandle methodHandle)
{
reader = null;
typeHandle = default(TypeDefinitionHandle);
methodHandle = default(MethodHandle);
RuntimeTypeHandle declaringTypeHandle = default(RuntimeTypeHandle);
if (!ExecutionEnvironment.TryGetMethodForStartAddress(methodStartAddress,
ref declaringTypeHandle, out QMethodDefinition qMethodDefinition))
return false;
if (!qMethodDefinition.IsNativeFormatMetadataBased)
return false;
if (!ExecutionEnvironment.TryGetMetadataForNamedType(declaringTypeHandle, out QTypeDefinition qTypeDefinition))
return false;
Debug.Assert(qTypeDefinition.IsNativeFormatMetadataBased);
Debug.Assert(qTypeDefinition.NativeFormatReader == qMethodDefinition.NativeFormatReader);
reader = qTypeDefinition.NativeFormatReader;
typeHandle = qTypeDefinition.NativeFormatHandle;
methodHandle = qMethodDefinition.NativeFormatHandle;
return true;
}
internal static ExecutionEnvironmentImplementation ExecutionEnvironment { get; private set; }
internal static IList<string> DefaultAssemblyNamesForGetType;
}
}
|