summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKoundinya Veluri <kouvel@microsoft.com>2015-09-03 22:06:56 -0700
committerKoundinya Veluri <kouvel@microsoft.com>2015-09-09 13:12:36 -0700
commit2f042a1212137e558fca716dbb92197f7a770e55 (patch)
tree1c081af67ef569a8b328e65e73098ee4f4475228 /src
parent508454cc76e1bd35c07521ebfc73617c00c5bcb3 (diff)
downloadcoreclr-2f042a1212137e558fca716dbb92197f7a770e55.tar.gz
coreclr-2f042a1212137e558fca716dbb92197f7a770e55.tar.bz2
coreclr-2f042a1212137e558fca716dbb92197f7a770e55.zip
Add AssemblyExtensions.TryGetRawMetadata to the System.Reflection.Metadata namespace.
This patch contains has the necessary changes in coreclr and mscorlib. Tests will be added separately, once the new API is published and can be consumed. Part of dotnet/corefx#2768
Diffstat (limited to 'src')
-rw-r--r--src/mscorlib/model.xml3
-rw-r--r--src/mscorlib/mscorlib.shared.sources.props4
-rw-r--r--src/mscorlib/src/System/Reflection/Metadata/AssemblyExtensions.cs37
-rw-r--r--src/vm/assemblynative.cpp26
-rw-r--r--src/vm/assemblynative.hpp2
-rw-r--r--src/vm/ecalllist.h10
6 files changed, 82 insertions, 0 deletions
diff --git a/src/mscorlib/model.xml b/src/mscorlib/model.xml
index 4d169f8ae8..8136c81cba 100644
--- a/src/mscorlib/model.xml
+++ b/src/mscorlib/model.xml
@@ -1021,6 +1021,9 @@
<Member Name="SetProfileOptimizationRoot(System.String)" />
<Member Name="StartProfileOptimization(System.String)" />
</Type>
+ <Type Name="System.Reflection.Metadata.AssemblyExtensions">
+ <Member Name="TryGetRawMetadata(System.Reflection.Assembly,System.Byte*@,System.Int32@)"/>
+ </Type>
<Type Status="ApiFxInternal" Name="System.Runtime.Versioning.BinaryCompatibility">
<Member Status="ApiFxInternal" MemberType="Property" Name="TargetsAtLeast_Phone_V7_1" />
<Member Status="ApiFxInternal" MemberType="Property" Name="TargetsAtLeast_Phone_V8_0" />
diff --git a/src/mscorlib/mscorlib.shared.sources.props b/src/mscorlib/mscorlib.shared.sources.props
index a4b0511dc5..5dc14a4958 100644
--- a/src/mscorlib/mscorlib.shared.sources.props
+++ b/src/mscorlib/mscorlib.shared.sources.props
@@ -677,6 +677,9 @@
<ReflectionEmitSources Include="$(BclSourcesRoot)\System\Reflection\Emit\XXXOnTypeBuilderInstantiation.cs" />
<ReflectionEmitSources Include="$(BclSourcesRoot)\System\Reflection\Emit\UnmanagedMarshal.cs" />
</ItemGroup>
+ <ItemGroup Condition="'$(FeatureCoreclr)' == 'true'">
+ <ReflectionMetadataSources Include="$(BclSourcesRoot)\System\Reflection\Metadata\AssemblyExtensions.cs" />
+ </ItemGroup>
<ItemGroup>
<GlobalizationSources Include="$(BclSourcesRoot)\System\Globalization\DateTimeFormat.cs" />
<GlobalizationSources Include="$(BclSourcesRoot)\System\Globalization\DateTimeParse.cs" />
@@ -1307,6 +1310,7 @@
<MscorlibSources Include="@(SerializationFormattersSources)" ><Visible>true</Visible></MscorlibSources>
<MscorlibSources Include="@(SerializationFormattersBinarySources)" ><Visible>true</Visible></MscorlibSources>
<MscorlibSources Include="@(ReflectionEmitSources)" ><Visible>true</Visible></MscorlibSources>
+ <MscorlibSources Include="@(ReflectionMetadataSources)" ><Visible>true</Visible></MscorlibSources>
<MscorlibSources Include="@(ConfigurationAssembliesSources)" ><Visible>true</Visible></MscorlibSources>
<MscorlibSources Include="@(SecCryptographySources)" ><Visible>true</Visible></MscorlibSources>
<MscorlibSources Include="@(SecPublickeySources)" ><Visible>true</Visible></MscorlibSources>
diff --git a/src/mscorlib/src/System/Reflection/Metadata/AssemblyExtensions.cs b/src/mscorlib/src/System/Reflection/Metadata/AssemblyExtensions.cs
new file mode 100644
index 0000000000..64c0e5cb23
--- /dev/null
+++ b/src/mscorlib/src/System/Reflection/Metadata/AssemblyExtensions.cs
@@ -0,0 +1,37 @@
+// Copyright (c) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using System.Security;
+
+namespace System.Reflection.Metadata
+{
+ public static class AssemblyExtensions
+ {
+ [DllImport(JitHelpers.QCall)]
+ [SuppressUnmanagedCodeSecurity]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ private unsafe static extern bool InternalTryGetRawMetadata(RuntimeAssembly assembly, ref byte* blob, ref int length);
+
+ // Retrieves the metadata section of the assembly, for use with System.Reflection.Metadata.MetadataReader.
+ // - Returns false upon failure. Metadata might not be available for some assemblies, such as AssemblyBuilder, .NET
+ // native images, etc.
+ // - Callers should not write to the metadata blob
+ // - The metadata blob pointer will remain valid as long as the AssemblyLoadContext with which the assembly is
+ // associated, is alive. The caller is responsible for keeping the assembly object alive while accessing the
+ // metadata blob.
+ [CLSCompliant(false)] // out byte* blob
+ public unsafe static bool TryGetRawMetadata(this Assembly assembly, out byte* blob, out int length)
+ {
+ if (assembly == null)
+ {
+ throw new ArgumentNullException("assembly");
+ }
+
+ blob = null;
+ length = 0;
+ return InternalTryGetRawMetadata((RuntimeAssembly)assembly, ref blob, ref length);
+ }
+ }
+}
diff --git a/src/vm/assemblynative.cpp b/src/vm/assemblynative.cpp
index 40df0068c5..5b4e0c5347 100644
--- a/src/vm/assemblynative.cpp
+++ b/src/vm/assemblynative.cpp
@@ -2614,3 +2614,29 @@ INT_PTR QCALLTYPE AssemblyNative::GetLoadContextForAssembly(QCall::AssemblyHandl
return ptrManagedAssemblyLoadContext;
}
#endif // defined(FEATURE_HOST_ASSEMBLY_RESOLVER)
+
+// static
+BOOL QCALLTYPE AssemblyNative::InternalTryGetRawMetadata(
+ QCall::AssemblyHandle assembly,
+ UINT8 **blobRef,
+ INT32 *lengthRef)
+{
+ QCALL_CONTRACT;
+
+ PTR_CVOID metadata = nullptr;
+
+ BEGIN_QCALL;
+
+ _ASSERTE(assembly != nullptr);
+ _ASSERTE(blobRef != nullptr);
+ _ASSERTE(lengthRef != nullptr);
+
+ static_assert_no_msg(sizeof(*lengthRef) == sizeof(COUNT_T));
+ metadata = assembly->GetFile()->GetLoadedMetadata(reinterpret_cast<COUNT_T *>(lengthRef));
+ *blobRef = reinterpret_cast<UINT8 *>(const_cast<PTR_VOID>(metadata));
+ _ASSERTE(*lengthRef >= 0);
+
+ END_QCALL;
+
+ return metadata != nullptr;
+}
diff --git a/src/vm/assemblynative.hpp b/src/vm/assemblynative.hpp
index 91637105c9..f4ca12ee68 100644
--- a/src/vm/assemblynative.hpp
+++ b/src/vm/assemblynative.hpp
@@ -282,6 +282,8 @@ public:
static void QCALLTYPE LoadFromStream(INT_PTR ptrNativeAssemblyLoadContext, INT_PTR ptrAssemblyArray, INT32 cbAssemblyArrayLength, INT_PTR ptrSymbolArray, INT32 cbSymbolArrayLength, QCall::ObjectHandleOnStack retLoadedAssembly);
static Assembly* LoadFromPEImage(CLRPrivBinderAssemblyLoadContext* pBinderContext, PEImage *pILImage, PEImage *pNIImage);
static INT_PTR QCALLTYPE GetLoadContextForAssembly(QCall::AssemblyHandle pAssembly);
+
+ static BOOL QCALLTYPE InternalTryGetRawMetadata(QCall::AssemblyHandle assembly, UINT8 **blobRef, INT32 *lengthRef);
};
#endif
diff --git a/src/vm/ecalllist.h b/src/vm/ecalllist.h
index c35168f4b5..b6bd8eeaf5 100644
--- a/src/vm/ecalllist.h
+++ b/src/vm/ecalllist.h
@@ -1156,6 +1156,12 @@ FCFuncStart(gAssemblyFuncs)
FCFuncEnd()
+#ifdef FEATURE_CORECLR
+FCFuncStart(gAssemblyExtensionsFuncs)
+ QCFuncElement("InternalTryGetRawMetadata", AssemblyNative::InternalTryGetRawMetadata)
+FCFuncEnd()
+#endif
+
#if defined(FEATURE_HOST_ASSEMBLY_RESOLVER)
FCFuncStart(gAssemblyLoadContextFuncs)
QCFuncElement("InitializeAssemblyLoadContext", AssemblyNative::InitializeAssemblyLoadContext)
@@ -2148,6 +2154,10 @@ FCClassElement("AssemblyBuilder", "System.Reflection.Emit", gAssemblyBuilderFunc
FCClassElement("AssemblyEvidenceFactory", "System.Security.Policy", gAssemblyEvidenceFactoryFuncs)
#endif // FEATURE_CAS_POLICY
+#ifdef FEATURE_CORECLR
+FCClassElement("AssemblyExtensions", "System.Reflection.Metadata", gAssemblyExtensionsFuncs)
+#endif
+
#if defined(FEATURE_HOST_ASSEMBLY_RESOLVER)
FCClassElement("AssemblyLoadContext", "System.Runtime.Loader", gAssemblyLoadContextFuncs)
#endif // defined(FEATURE_HOST_ASSEMBLY_RESOLVER)