<AutoInitializedAssemblies Include="System.Private.TypeLoader" />
<AutoInitializedAssemblies Include="System.Private.Reflection.Execution" Condition="$(IlcDisableReflection) != 'true'" />
<AutoInitializedAssemblies Include="System.Private.DisabledReflection" Condition="$(IlcDisableReflection) == 'true'" />
- <AutoInitializedAssemblies Include="System.Private.Interop" />
</ItemGroup>
<ItemGroup>
public static partial class StartupCodeHelpers
{
/// <summary>
- /// Initial module array allocation used when adding modules dynamically.
- /// </summary>
- private const int InitialModuleCount = 8;
-
- /// <summary>
/// Table of logical modules. Only the first s_moduleCount elements of the array are in use.
/// </summary>
private static TypeManagerHandle[] s_modules;
// We are now at a stage where we can use GC statics - publish the list of modules
// so that the eager constructors can access it.
- if (s_modules != null)
- {
- for (int i = 0; i < modules.Length; i++)
- {
- AddModule(modules[i]);
- }
- }
- else
- {
- s_modules = modules;
- s_moduleCount = modules.Length;
- }
+ s_modules = modules;
+ s_moduleCount = modules.Length;
// These two loops look funny but it's important to initialize the global tables before running
// the first class constructor to prevent them calling into another uninitialized module
return s_moduleCount;
}
- private static void AddModule(TypeManagerHandle newModuleHandle)
- {
- if (s_moduleCount >= s_modules!.Length)
- {
- // Reallocate logical module array
- int newModuleLength = 2 * s_moduleCount;
- if (newModuleLength < InitialModuleCount)
- {
- newModuleLength = InitialModuleCount;
- }
-
- TypeManagerHandle[] newModules = new TypeManagerHandle[newModuleLength];
- for (int copyIndex = 0; copyIndex < s_moduleCount; copyIndex++)
- {
- newModules[copyIndex] = s_modules[copyIndex];
- }
- s_modules = newModules;
- }
-
- s_modules[s_moduleCount] = newModuleHandle;
- s_moduleCount++;
- }
-
private static unsafe TypeManagerHandle[] CreateTypeManagers(IntPtr osModule, IntPtr* pModuleHeaders, int count, IntPtr* pClasslibFunctions, int nClasslibFunctions)
{
// Count the number of modules so we can allocate an array to hold the TypeManager objects.
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System;
+using Internal.Runtime.Augments;
+
+namespace Internal.Runtime.TypeLoader
+{
+ partial struct ExternalReferencesTable
+ {
+ private IntPtr _elements;
+ private uint _elementsCount;
+
+ private unsafe bool Initialize(TypeManagerHandle typeManager, ReflectionMapBlob blobId)
+ {
+ byte* pBlob;
+ uint cbBlob;
+
+ if (!RuntimeAugments.FindBlob(typeManager, (int)blobId, (IntPtr)(void*)&pBlob, (IntPtr)(void*)&cbBlob))
+ {
+ _elements = IntPtr.Zero;
+ _elementsCount = 0;
+ return false;
+ }
+
+ _elements = (IntPtr)pBlob;
+ _elementsCount = (uint)(cbBlob / sizeof(uint));
+
+ return true;
+ }
+
+ public bool IsInitialized() { return _elements != IntPtr.Zero; }
+
+ /// <summary>
+ /// Initialize ExternalReferencesTable using the CommonFixupsTable metadata blob on a given module.
+ /// </summary>
+ /// <param name="module">Module handle is used to locate the CommonFixupsTable blob</param>
+ /// <returns>true when the CommonFixupsTable blob was found in the given module, false when not</returns>
+ public bool InitializeCommonFixupsTable(TypeManagerHandle module)
+ {
+ return Initialize(module, ReflectionMapBlob.CommonFixupsTable);
+ }
+
+ public unsafe IntPtr GetIntPtrFromIndex(uint index)
+ {
+ return GetAddressFromIndex(index);
+ }
+
+ public unsafe IntPtr GetFunctionPointerFromIndex(uint index)
+ {
+ return GetAddressFromIndex(index);
+ }
+
+ public RuntimeTypeHandle GetRuntimeTypeHandleFromIndex(uint index)
+ {
+ return RuntimeAugments.CreateRuntimeTypeHandle(GetIntPtrFromIndex(index));
+ }
+
+ public IntPtr GetGenericDictionaryFromIndex(uint index)
+ {
+ return GetIntPtrFromIndex(index);
+ }
+
+ public unsafe IntPtr GetAddressFromIndex(uint index)
+ {
+ if (index >= _elementsCount)
+ throw new BadImageFormatException();
+
+ if (MethodTable.SupportsRelativePointers)
+ {
+ int* pRelPtr32 = &((int*)_elements)[index];
+ return (IntPtr)((byte*)pRelPtr32 + *pRelPtr32);
+ }
+
+ return (IntPtr)(((void**)_elements)[index]);
+ }
+ }
+}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System;
-using Internal.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-namespace Internal.Runtime.Augments
-{
- [CLSCompliant(false)]
- [System.Runtime.CompilerServices.ReflectionBlocked]
- public abstract class InteropCallbacks
- {
- public abstract IntPtr GetForwardDelegateCreationStub(RuntimeTypeHandle delegateTypeHandle);
-
- public abstract IntPtr GetDelegateMarshallingStub(RuntimeTypeHandle delegateTypeHandle, bool openStaticDelegate);
-
- public abstract bool TryGetStructUnmarshalStub(RuntimeTypeHandle structureTypeHandle, out IntPtr unmarshalStub);
-
- public abstract IntPtr GetStructUnmarshalStub(RuntimeTypeHandle structureTypeHandle);
-
- public abstract bool TryGetStructMarshalStub(RuntimeTypeHandle structureTypeHandle, out IntPtr marshalStub);
-
- public abstract IntPtr GetStructMarshalStub(RuntimeTypeHandle structureTypeHandle);
-
- public abstract bool TryGetDestroyStructureStub(RuntimeTypeHandle structureTypeHandle, out IntPtr destroyStructureStub, out bool hasInvalidLayout);
-
- public abstract IntPtr GetDestroyStructureStub(RuntimeTypeHandle structureTypeHandle, out bool hasInvalidLayout);
-
- public abstract bool TryGetStructFieldOffset(RuntimeTypeHandle structureTypeHandle, string fieldName, out bool structExists, out uint offset);
-
- public abstract uint GetStructFieldOffset(RuntimeTypeHandle structureTypeHandle, string fieldName);
-
- public abstract bool TryGetStructUnsafeStructSize(RuntimeTypeHandle structureTypeHandle, out int size);
-
- public abstract int GetStructUnsafeStructSize(RuntimeTypeHandle structureTypeHandle);
- }
-}
}
[CLSCompliant(false)]
- public static void InitializeInteropLookups(InteropCallbacks callbacks)
- {
- s_interopCallbacks = callbacks;
- }
-
- [CLSCompliant(false)]
public static void InitializeStackTraceMetadataSupport(StackTraceMetadataCallbacks callbacks)
{
s_stackTraceMetadataCallbacks = callbacks;
functionPointer = delegateObj.m_functionPointer;
}
+ // Low level method that returns the loaded modules as array. ReadOnlySpan returning overload
+ // cannot be used early during startup.
public static int GetLoadedModules(TypeManagerHandle[] resultArray)
{
return Internal.Runtime.CompilerHelpers.StartupCodeHelpers.GetLoadedModules(resultArray);
}
+ public static ReadOnlySpan<TypeManagerHandle> GetLoadedModules()
+ {
+ return Internal.Runtime.CompilerHelpers.StartupCodeHelpers.GetLoadedModules();
+ }
+
public static IntPtr GetOSModuleFromPointer(IntPtr pointerVal)
{
return RuntimeImports.RhGetOSModuleFromPointer(pointerVal);
}
}
- internal static InteropCallbacks InteropCallbacks
- {
- get
- {
- InteropCallbacks callbacks = s_interopCallbacks;
- Debug.Assert(callbacks != null);
- return callbacks;
- }
- }
-
internal static StackTraceMetadataCallbacks StackTraceCallbacksIfAvailable
{
get
private static volatile ReflectionExecutionDomainCallbacks s_reflectionExecutionDomainCallbacks;
private static TypeLoaderCallbacks s_typeLoaderCallbacks;
- private static InteropCallbacks s_interopCallbacks;
public static void ReportUnhandledException(Exception exception)
{
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
+
using System;
+using System.Runtime;
using Internal.Runtime.Augments;
-using Internal.NativeFormat;
using Internal.Runtime.TypeLoader;
-using Internal.Reflection.Execution;
+using Internal.NativeFormat;
using System.Runtime.InteropServices;
namespace Internal.Runtime.CompilerHelpers
{
- internal partial class RuntimeInteropData
+ internal static class RuntimeInteropData
{
- public override IntPtr GetForwardDelegateCreationStub(RuntimeTypeHandle delegateTypeHandle)
+ public static uint GetStructFieldOffset(RuntimeTypeHandle structureTypeHandle, string fieldName)
+ {
+ if (TryGetStructFieldOffset(structureTypeHandle, fieldName, out bool structExists, out uint offset))
+ {
+ return offset;
+ }
+
+ // if we can find the struct but couldn't find its field, throw Argument Exception
+ if (structExists)
+ {
+ throw new ArgumentException(SR.Format(SR.Argument_OffsetOfFieldNotFound, RuntimeAugments.GetLastResortString(structureTypeHandle)), nameof(fieldName));
+ }
+
+ throw new MissingInteropDataException(SR.StructMarshalling_MissingInteropData, Type.GetTypeFromHandle(structureTypeHandle));
+ }
+
+ public static int GetStructUnsafeStructSize(RuntimeTypeHandle structureTypeHandle)
+ {
+ if (TryGetStructUnsafeStructSize(structureTypeHandle, out int size))
+ {
+ return size;
+ }
+
+ // IsBlittable() checks whether the type contains GC references. It is approximate check with false positives.
+ // This fallback path will return incorrect answer for types that do not contain GC references, but that are
+ // not actually blittable; e.g. for types with bool fields.
+ if (structureTypeHandle.IsBlittable() && structureTypeHandle.IsValueType())
+ {
+ return structureTypeHandle.GetValueTypeSize();
+ }
+
+ throw new MissingInteropDataException(SR.StructMarshalling_MissingInteropData, Type.GetTypeFromHandle(structureTypeHandle));
+ }
+
+ public static IntPtr GetStructUnmarshalStub(RuntimeTypeHandle structureTypeHandle)
+ {
+ if (TryGetStructUnmarshalStub(structureTypeHandle, out IntPtr stub))
+ {
+ return stub;
+ }
+
+ throw new MissingInteropDataException(SR.StructMarshalling_MissingInteropData, Type.GetTypeFromHandle(structureTypeHandle));
+ }
+
+ public static IntPtr GetStructMarshalStub(RuntimeTypeHandle structureTypeHandle)
+ {
+ if (TryGetStructMarshalStub(structureTypeHandle, out IntPtr stub))
+ {
+ return stub;
+ }
+
+ throw new MissingInteropDataException(SR.StructMarshalling_MissingInteropData, Type.GetTypeFromHandle(structureTypeHandle));
+ }
+
+ public static IntPtr GetDestroyStructureStub(RuntimeTypeHandle structureTypeHandle, out bool hasInvalidLayout)
+ {
+ if (TryGetDestroyStructureStub(structureTypeHandle, out IntPtr stub, out hasInvalidLayout))
+ {
+ return stub;
+ }
+
+ throw new MissingInteropDataException(SR.StructMarshalling_MissingInteropData, Type.GetTypeFromHandle(structureTypeHandle));
+ }
+
+
+ public static IntPtr GetForwardDelegateCreationStub(RuntimeTypeHandle delegateTypeHandle)
{
GetMarshallersForDelegate(delegateTypeHandle, out _, out _, out IntPtr delegateCreationStub);
if (delegateCreationStub == IntPtr.Zero)
return delegateCreationStub;
}
- public override IntPtr GetDelegateMarshallingStub(RuntimeTypeHandle delegateTypeHandle, bool openStaticDelegate)
+ public static IntPtr GetDelegateMarshallingStub(RuntimeTypeHandle delegateTypeHandle, bool openStaticDelegate)
{
GetMarshallersForDelegate(delegateTypeHandle, out IntPtr openStub, out IntPtr closedStub, out _);
IntPtr pStub = openStaticDelegate ? openStub : closedStub;
}
#region "Struct Data"
- public override bool TryGetStructUnmarshalStub(RuntimeTypeHandle structureTypeHandle, out IntPtr unmarshalStub)
+ public static bool TryGetStructUnmarshalStub(RuntimeTypeHandle structureTypeHandle, out IntPtr unmarshalStub)
=> TryGetMarshallersForStruct(structureTypeHandle, out _, out unmarshalStub, out _, out _, out _);
- public override bool TryGetStructMarshalStub(RuntimeTypeHandle structureTypeHandle, out IntPtr marshalStub)
+ public static bool TryGetStructMarshalStub(RuntimeTypeHandle structureTypeHandle, out IntPtr marshalStub)
=> TryGetMarshallersForStruct(structureTypeHandle, out marshalStub, out _, out _, out _, out _);
- public override bool TryGetDestroyStructureStub(RuntimeTypeHandle structureTypeHandle, out IntPtr destroyStub, out bool hasInvalidLayout)
+ public static bool TryGetDestroyStructureStub(RuntimeTypeHandle structureTypeHandle, out IntPtr destroyStub, out bool hasInvalidLayout)
=> TryGetMarshallersForStruct(structureTypeHandle, out _, out _, out destroyStub, out hasInvalidLayout, out _);
- public override bool TryGetStructUnsafeStructSize(RuntimeTypeHandle structureTypeHandle, out int size)
+ public static bool TryGetStructUnsafeStructSize(RuntimeTypeHandle structureTypeHandle, out int size)
=> TryGetMarshallersForStruct(structureTypeHandle, out _, out _, out _, out _, out size);
- public override bool TryGetStructFieldOffset(RuntimeTypeHandle structureTypeHandle, string fieldName, out bool structExists, out uint offset)
+ public static bool TryGetStructFieldOffset(RuntimeTypeHandle structureTypeHandle, string fieldName, out bool structExists, out uint offset)
{
NativeParser entryParser;
structExists = false;
}
#endregion
- private static unsafe bool TryGetNativeReaderForBlob(NativeFormatModuleInfo module, ReflectionMapBlob blob, out NativeReader reader)
+ private static unsafe bool TryGetNativeReaderForBlob(TypeManagerHandle module, ReflectionMapBlob blob, out NativeReader reader)
{
byte* pBlob;
uint cbBlob;
- if (module.TryFindBlob((int)blob, out pBlob, out cbBlob))
+ if (RuntimeImports.RhFindBlob(module, (uint)blob, &pBlob, &cbBlob))
{
reader = new NativeReader(pBlob, cbBlob);
return true;
closedStub = IntPtr.Zero;
delegateCreationStub = IntPtr.Zero;
- foreach (NativeFormatModuleInfo module in ModuleList.EnumerateModules())
+ foreach (TypeManagerHandle module in RuntimeAugments.GetLoadedModules())
{
NativeReader delegateMapReader;
if (TryGetNativeReaderForBlob(module, ReflectionMapBlob.DelegateMarshallingStubMap, out delegateMapReader))
int structHashcode = structTypeHandle.GetHashCode();
externalReferences = default(ExternalReferencesTable);
entryParser = default(NativeParser);
- foreach (NativeFormatModuleInfo module in ModuleList.EnumerateModules())
+ foreach (TypeManagerHandle module in RuntimeAugments.GetLoadedModules())
{
NativeReader structMapReader;
if (TryGetNativeReaderForBlob(module, ReflectionMapBlob.StructMarshallingStubMap, out structMapReader))
{
public partial class StartupCodeHelpers
{
+ /// <summary>
+ /// Return the registered logical modules; optionally copy them into an array.
+ /// </summary>
+ internal static ReadOnlySpan<TypeManagerHandle> GetLoadedModules()
+ => s_modules.AsSpan(0, s_moduleCount);
+
internal static unsafe void InitializeCommandLineArgsW(int argc, char** argv)
{
string[] args = new string[argc];
<Compile Include="$(CompilerCommonPath)\Internal\Runtime\ModuleHeaders.cs">
<Link>Internal\Runtime\ModuleHeaders.cs</Link>
</Compile>
+ <Compile Include="$(CompilerCommonPath)\Internal\Runtime\MetadataBlob.cs">
+ <Link>MetadataBlob.cs</Link>
+ </Compile>
</ItemGroup>
<ItemGroup>
<Compile Include="$(CompilerCommonPath)\Internal\NativeFormat\NativeFormatReader.cs">
<Link>Common\src\Internal\NativeFormat\NativeFormatReader.cs</Link>
</Compile>
+ <Compile Include="$(CompilerCommonPath)\Internal\NativeFormat\NativeFormatReader.String.cs">
+ <Link>Common\src\Internal\NativeFormat\NativeFormatReader.String.cs</Link>
+ </Compile>
+ <Compile Include="$(AotCommonPath)\Internal\Runtime\TypeLoader\ExternalReferencesTable.cs">
+ <Link>Common\src\Internal\Runtime\TypeLoader\ExternalReferencesTable.cs</Link>
+ </Compile>
<Compile Include="Internal\Runtime\ThreadStatics.cs" />
<Compile Include="Internal\Runtime\CompilerHelpers\StartupCode\StartupCodeHelpers.Extensions.cs" />
<Compile Include="Internal\Runtime\CompilerHelpers\ArrayHelpers.cs" />
<Compile Include="Internal\Runtime\CompilerHelpers\InteropHelpers.cs" />
<Compile Include="Internal\Runtime\CompilerHelpers\LdTokenHelpers.cs" />
+ <Compile Include="Internal\Runtime\CompilerHelpers\RuntimeInteropData.cs" />
<Compile Include="Internal\Runtime\CompilerHelpers\SynchronizedMethodHelpers.cs" />
<Compile Include="Internal\Runtime\CompilerHelpers\TypedReferenceHelpers.cs" />
</ItemGroup>
<Compile Include="Internal\Runtime\Augments\RuntimeAugments.cs" />
<Compile Include="Internal\Runtime\Augments\ReflectionExecutionDomainCallbacks.cs" />
<Compile Include="Internal\Runtime\Augments\TypeLoaderCallbacks.cs" />
- <Compile Include="Internal\Runtime\Augments\InteropCallbacks.cs" />
<Compile Include="Internal\Runtime\Augments\StackTraceMetadataCallbacks.cs" />
<Compile Include="Internal\Runtime\Augments\DynamicDelegateAugments.cs" />
</ItemGroup>
<Compile Include="System\Runtime\InteropServices\PInvokeMarshal.cs" />
<Compile Include="System\Runtime\InteropServices\Marshal.NativeAot.cs" />
<Compile Include="System\Runtime\InteropServices\Marshal.Com.cs" Condition="'$(FeatureCominterop)' == 'true'" />
+ <Compile Include="System\Runtime\InteropServices\MissingInteropDataException.cs" />
<Compile Include="System\Runtime\InteropServices\MemoryMarshal.NativeAot.cs" />
<Compile Include="System\Runtime\InteropServices\SafeHandle.NativeAot.cs" />
<Compile Include="System\Runtime\InteropServices\UnsafeGCHandle.cs" />
using System.Text;
using Internal.Runtime.Augments;
+using Internal.Runtime.CompilerHelpers;
namespace System.Runtime.InteropServices
{
internal static int SizeOfHelper(Type t, bool throwIfNotMarshalable)
{
Debug.Assert(throwIfNotMarshalable);
- return RuntimeAugments.InteropCallbacks.GetStructUnsafeStructSize(t.TypeHandle);
+ return RuntimeInteropData.GetStructUnsafeStructSize(t.TypeHandle);
}
[EditorBrowsable(EditorBrowsableState.Never)]
if (t.TypeHandle.IsGenericTypeDefinition())
throw new ArgumentException(SR.Argument_NeedNonGenericType, nameof(t));
- return new IntPtr(RuntimeAugments.InteropCallbacks.GetStructFieldOffset(t.TypeHandle, fieldName));
+ return new IntPtr(RuntimeInteropData.GetStructFieldOffset(t.TypeHandle, fieldName));
}
private static void PtrToStructureHelper(IntPtr ptr, object structure, bool allowValueClasses)
IntPtr unmarshalStub;
if (structureTypeHandle.IsBlittable())
{
- if (!RuntimeAugments.InteropCallbacks.TryGetStructUnmarshalStub(structureTypeHandle, out unmarshalStub))
+ if (!RuntimeInteropData.TryGetStructUnmarshalStub(structureTypeHandle, out unmarshalStub))
{
unmarshalStub = IntPtr.Zero;
}
}
else
{
- unmarshalStub = RuntimeAugments.InteropCallbacks.GetStructUnmarshalStub(structureTypeHandle);
+ unmarshalStub = RuntimeInteropData.GetStructUnmarshalStub(structureTypeHandle);
}
if (unmarshalStub != IntPtr.Zero)
}
else
{
- nuint size = (nuint)RuntimeAugments.InteropCallbacks.GetStructUnsafeStructSize(structureTypeHandle);
+ nuint size = (nuint)RuntimeInteropData.GetStructUnsafeStructSize(structureTypeHandle);
Buffer.Memmove(ref structure.GetRawData(), ref *(byte*)ptr, size);
}
return;
}
- IntPtr destroyStructureStub = RuntimeAugments.InteropCallbacks.GetDestroyStructureStub(structureTypeHandle, out bool hasInvalidLayout);
+ IntPtr destroyStructureStub = RuntimeInteropData.GetDestroyStructureStub(structureTypeHandle, out bool hasInvalidLayout);
if (hasInvalidLayout)
throw new ArgumentException(SR.Format(SR.Argument_MustHaveLayoutOrBeBlittable, structureTypeHandle.LastResortToString));
// DestroyStructureStub == IntPtr.Zero means its fields don't need to be destroyed
IntPtr marshalStub;
if (structureTypeHandle.IsBlittable())
{
- if (!RuntimeAugments.InteropCallbacks.TryGetStructMarshalStub(structureTypeHandle, out marshalStub))
+ if (!RuntimeInteropData.TryGetStructMarshalStub(structureTypeHandle, out marshalStub))
{
marshalStub = IntPtr.Zero;
}
}
else
{
- marshalStub = RuntimeAugments.InteropCallbacks.GetStructMarshalStub(structureTypeHandle);
+ marshalStub = RuntimeInteropData.GetStructMarshalStub(structureTypeHandle);
}
if (marshalStub != IntPtr.Zero)
}
else
{
- nuint size = (nuint)RuntimeAugments.InteropCallbacks.GetStructUnsafeStructSize(structureTypeHandle);
+ nuint size = (nuint)RuntimeInteropData.GetStructUnsafeStructSize(structureTypeHandle);
Buffer.Memmove(ref *(byte*)ptr, ref structure.GetRawData(), size);
}
//
bool openStaticDelegate = del.GetRawFunctionPointerForOpenStaticDelegate() != IntPtr.Zero;
- IntPtr pTarget = RuntimeAugments.InteropCallbacks.GetDelegateMarshallingStub(del.GetTypeHandle(), openStaticDelegate);
+ IntPtr pTarget = RuntimeInteropData.GetDelegateMarshallingStub(del.GetTypeHandle(), openStaticDelegate);
Debug.Assert(pTarget != IntPtr.Zero);
RuntimeAugments.SetThunkData(s_thunkPoolHeap, delegateThunk.Thunk, delegateThunk.ContextData, pTarget);
// We need to create the delegate that points to the invoke method of a
// NativeFunctionPointerWrapper derived class
//
- IntPtr pDelegateCreationStub = RuntimeAugments.InteropCallbacks.GetForwardDelegateCreationStub(delegateType);
+ IntPtr pDelegateCreationStub = RuntimeInteropData.GetForwardDelegateCreationStub(delegateType);
Debug.Assert(pDelegateCreationStub != IntPtr.Zero);
return ((delegate*<IntPtr, Delegate>)pDelegateCreationStub)(ptr);
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-using System;
-using System.Runtime;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-using Internal.Runtime.Augments;
-
-namespace Internal.Runtime.CompilerHelpers
-{
- /// <summary>
- /// Container class to run specific class constructors in a defined order. Since we can't
- /// directly invoke class constructors in C#, they're renamed Initialize.
- /// </summary>
- public static class LibraryInitializer
- {
- public static void InitializeLibrary()
- {
- RuntimeAugments.InitializeInteropLookups(new RuntimeInteropData());
- }
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-
-
-using System;
-using Internal.Runtime.Augments;
-using Internal.NativeFormat;
-using Internal.Runtime.TypeLoader;
-using Internal.Reflection.Execution;
-using System.Runtime.InteropServices;
-
-namespace Internal.Runtime.CompilerHelpers
-{
- internal partial class RuntimeInteropData : InteropCallbacks
- {
- public override uint GetStructFieldOffset(RuntimeTypeHandle structureTypeHandle, string fieldName)
- {
- if (TryGetStructFieldOffset(structureTypeHandle, fieldName, out bool structExists, out uint offset))
- {
- return offset;
- }
-
- // if we can find the struct but couldn't find its field, throw Argument Exception
- if (structExists)
- {
- throw new ArgumentException(SR.Format(SR.Argument_OffsetOfFieldNotFound, RuntimeAugments.GetLastResortString(structureTypeHandle)), nameof(fieldName));
- }
-
- throw new MissingInteropDataException(SR.StructMarshalling_MissingInteropData, Type.GetTypeFromHandle(structureTypeHandle));
- }
-
- public override int GetStructUnsafeStructSize(RuntimeTypeHandle structureTypeHandle)
- {
- if (TryGetStructUnsafeStructSize(structureTypeHandle, out int size))
- {
- return size;
- }
-
- // IsBlittable() checks whether the type contains GC references. It is approximate check with false positives.
- // This fallback path will return incorrect answer for types that do not contain GC references, but that are
- // not actually blittable; e.g. for types with bool fields.
- if (structureTypeHandle.IsBlittable() && structureTypeHandle.IsValueType())
- {
- return structureTypeHandle.GetValueTypeSize();
- }
-
- throw new MissingInteropDataException(SR.StructMarshalling_MissingInteropData, Type.GetTypeFromHandle(structureTypeHandle));
- }
-
- public override IntPtr GetStructUnmarshalStub(RuntimeTypeHandle structureTypeHandle)
- {
- if (TryGetStructUnmarshalStub(structureTypeHandle, out IntPtr stub))
- {
- return stub;
- }
-
- throw new MissingInteropDataException(SR.StructMarshalling_MissingInteropData, Type.GetTypeFromHandle(structureTypeHandle));
- }
-
- public override IntPtr GetStructMarshalStub(RuntimeTypeHandle structureTypeHandle)
- {
- if (TryGetStructMarshalStub(structureTypeHandle, out IntPtr stub))
- {
- return stub;
- }
-
- throw new MissingInteropDataException(SR.StructMarshalling_MissingInteropData, Type.GetTypeFromHandle(structureTypeHandle));
- }
-
- public override IntPtr GetDestroyStructureStub(RuntimeTypeHandle structureTypeHandle, out bool hasInvalidLayout)
- {
- if (TryGetDestroyStructureStub(structureTypeHandle, out IntPtr stub, out hasInvalidLayout))
- {
- return stub;
- }
-
- throw new MissingInteropDataException(SR.StructMarshalling_MissingInteropData, Type.GetTypeFromHandle(structureTypeHandle));
- }
- }
-}
+++ /dev/null
-<?xml version="1.0" encoding="utf-8"?>
-<root>
- <!--
- Microsoft ResX Schema
-
- Version 2.0
-
- The primary goals of this format is to allow a simple XML format
- that is mostly human readable. The generation and parsing of the
- various data types are done through the TypeConverter classes
- associated with the data types.
-
- Example:
-
- ... ado.net/XML headers & schema ...
- <resheader name="resmimetype">text/microsoft-resx</resheader>
- <resheader name="version">2.0</resheader>
- <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
- <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
- <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
- <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
- <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
- <value>[base64 mime encoded serialized .NET Framework object]</value>
- </data>
- <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
- <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
- <comment>This is a comment</comment>
- </data>
-
- There are any number of "resheader" rows that contain simple
- name/value pairs.
-
- Each data row contains a name, and value. The row also contains a
- type or mimetype. Type corresponds to a .NET class that support
- text/value conversion through the TypeConverter architecture.
- Classes that don't support this are serialized and stored with the
- mimetype set.
-
- The mimetype is used for serialized objects, and tells the
- ResXResourceReader how to depersist the object. This is currently not
- extensible. For a given mimetype the value must be set accordingly:
-
- Note - application/x-microsoft.net.object.binary.base64 is the format
- that the ResXResourceWriter will generate, however the reader can
- read any of the formats listed below.
-
- mimetype: application/x-microsoft.net.object.binary.base64
- value : The object must be serialized with
- : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
- : and then encoded with base64 encoding.
-
- mimetype: application/x-microsoft.net.object.soap.base64
- value : The object must be serialized with
- : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
- : and then encoded with base64 encoding.
-
- mimetype: application/x-microsoft.net.object.bytearray.base64
- value : The object must be serialized into a byte array
- : using a System.ComponentModel.TypeConverter
- : and then encoded with base64 encoding.
- -->
- <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
- <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
- <xsd:element name="root" msdata:IsDataSet="true">
- <xsd:complexType>
- <xsd:choice maxOccurs="unbounded">
- <xsd:element name="metadata">
- <xsd:complexType>
- <xsd:sequence>
- <xsd:element name="value" type="xsd:string" minOccurs="0" />
- </xsd:sequence>
- <xsd:attribute name="name" use="required" type="xsd:string" />
- <xsd:attribute name="type" type="xsd:string" />
- <xsd:attribute name="mimetype" type="xsd:string" />
- <xsd:attribute ref="xml:space" />
- </xsd:complexType>
- </xsd:element>
- <xsd:element name="assembly">
- <xsd:complexType>
- <xsd:attribute name="alias" type="xsd:string" />
- <xsd:attribute name="name" type="xsd:string" />
- </xsd:complexType>
- </xsd:element>
- <xsd:element name="data">
- <xsd:complexType>
- <xsd:sequence>
- <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
- <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
- </xsd:sequence>
- <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
- <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
- <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
- <xsd:attribute ref="xml:space" />
- </xsd:complexType>
- </xsd:element>
- <xsd:element name="resheader">
- <xsd:complexType>
- <xsd:sequence>
- <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
- </xsd:sequence>
- <xsd:attribute name="name" type="xsd:string" use="required" />
- </xsd:complexType>
- </xsd:element>
- </xsd:choice>
- </xsd:complexType>
- </xsd:element>
- </xsd:schema>
- <resheader name="resmimetype">
- <value>text/microsoft-resx</value>
- </resheader>
- <resheader name="version">
- <value>2.0</value>
- </resheader>
- <resheader name="reader">
- <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
- </resheader>
- <resheader name="writer">
- <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
- </resheader>
- <data name="StructMarshalling_MissingInteropData" xml:space="preserve">
- <value>{0} is missing structure marshalling data. To enable structure marshalling data, add a MarshalStructure directive to the application rd.xml file. For more information, please visit http://go.microsoft.com/fwlink/?LinkID=393965</value>
- </data>
- <data name="DelegateMarshalling_MissingInteropData" xml:space="preserve">
- <value>{0} is missing delegate marshalling data. To enable delegate marshalling data, add a MarshalDelegate directive to the application rd.xml file. For more information, please visit http://go.microsoft.com/fwlink/?LinkID=393965</value>
- </data>
- <data name="Argument_OffsetOfFieldNotFound" xml:space="preserve">
- <value>Field passed in is not a marshaled member of the type '{0}'.</value>
- </data>
-</root>
\ No newline at end of file
+++ /dev/null
-<Project Sdk="Microsoft.NET.Sdk">
- <ItemGroup>
- <ProjectReference Include="..\..\System.Private.CoreLib\src\System.Private.CoreLib.csproj" />
- <ProjectReference Include="..\..\System.Private.TypeLoader\src\System.Private.TypeLoader.csproj" />
- </ItemGroup>
-
- <PropertyGroup>
- <NativeFormatCommonPath>$(CompilerCommonPath)\Internal\NativeFormat</NativeFormatCommonPath>
- </PropertyGroup>
- <ItemGroup>
- <Compile Include="$(NativeFormatCommonPath)\NativeFormatReader.cs" />
- <Compile Include="$(NativeFormatCommonPath)\NativeFormatReader.Primitives.cs" />
- <Compile Include="$(NativeFormatCommonPath)\NativeFormatReader.String.cs" />
- </ItemGroup>
-
- <ItemGroup>
- <Compile Include="Internal\Runtime\CompilerHelpers\LibraryInitializer.cs"/>
- <Compile Include="System\Runtime\InteropServices\MissingInteropDataException.cs" />
- <Compile Include="Internal\Runtime\CompilerHelpers\RuntimeInteropData.cs"/>
- <Compile Include="Internal\Runtime\CompilerHelpers\RuntimeInteropData.NativeAot.cs"/>
- <Compile Include="$(CompilerCommonPath)\Internal\Runtime\InteropConstants.cs">
- <Link>Internal\Runtime\InteropConstants.cs</Link>
- </Compile>
- </ItemGroup>
-
- <ItemGroup>
- <Compile Include="$(CompilerCommonPath)\Internal\Runtime\MetadataBlob.cs">
- <Link>MetadataBlob.cs</Link>
- </Compile>
- <Compile Include="$(AotCommonPath)\System\Runtime\CompilerServices\__BlockReflectionAttribute.cs">
- <Link>System\Runtime\CompilerServices\__BlockReflectionAttribute.cs</Link>
- </Compile>
- <Compile Include="$(LibrariesProjectRoot)\System.Private.CoreLib\src\System\SR.cs" />
- </ItemGroup>
-</Project>
<ItemGroup>
<ProjectReference Include="..\..\System.Private.CoreLib\src\System.Private.CoreLib.csproj" />
<ProjectReference Include="..\..\System.Private.Reflection.Metadata\src\System.Private.Reflection.Metadata.csproj" />
- <ProjectReference Include="..\..\System.Private.Interop\src\System.Private.Interop.csproj" />
<ProjectReference Include="..\..\System.Private.TypeLoader\src\System.Private.TypeLoader.csproj" />
<ProjectReference Include="..\..\System.Private.Reflection.Core\src\System.Private.Reflection.Core.csproj" />
</ItemGroup>
namespace Internal.Runtime.TypeLoader
{
- public struct ExternalReferencesTable
+ public partial struct ExternalReferencesTable
{
- private IntPtr _elements;
- private uint _elementsCount;
- private TypeManagerHandle _moduleHandle;
-
- public bool IsInitialized() { return !_moduleHandle.IsNull; }
-
private unsafe bool Initialize(NativeFormatModuleInfo module, ReflectionMapBlob blobId)
{
- _moduleHandle = module.Handle;
-
byte* pBlob;
uint cbBlob;
if (!module.TryFindBlob(blobId, out pBlob, out cbBlob))
// and we'll not be able to support this for CppCodegen.
throw new PlatformNotSupportedException();
}
-
- public unsafe IntPtr GetIntPtrFromIndex(uint index)
- {
- return GetAddressFromIndex(index);
- }
-
- public unsafe IntPtr GetFunctionPointerFromIndex(uint index)
- {
- return GetAddressFromIndex(index);
- }
-
- public RuntimeTypeHandle GetRuntimeTypeHandleFromIndex(uint index)
- {
- return RuntimeAugments.CreateRuntimeTypeHandle(GetIntPtrFromIndex(index));
- }
-
- public IntPtr GetGenericDictionaryFromIndex(uint index)
- {
- return GetIntPtrFromIndex(index);
- }
-
- public unsafe IntPtr GetAddressFromIndex(uint index)
- {
- if (index >= _elementsCount)
- throw new BadImageFormatException();
-
- // TODO: indirection through IAT
- if (MethodTable.SupportsRelativePointers)
- {
- int* pRelPtr32 = &((int*)_elements)[index];
- return (IntPtr)((byte*)pRelPtr32 + *pRelPtr32);
- }
-
- return (IntPtr)(((void**)_elements)[index]);
- }
}
}
<Compile Include="Internal\Reflection\Execution\AssemblyBinderImplementation.cs" />
<Compile Include="$(CompilerCommonPath)\Internal\Metadata\NativeFormat\MetadataTypeHashingAlgorithms.cs" />
<Compile Include="$(CompilerCommonPath)\TypeSystem\Common\TypeHashingAlgorithms.cs" />
- <Compile Include="Internal\Runtime\TypeLoader\ExternalReferencesTable.cs" />
+ <Compile Include="$(AotCommonPath)\Internal\Runtime\TypeLoader\ExternalReferencesTable.cs" />
+ <Compile Include="Internal\Runtime\TypeLoader\ExternalReferencesTable.NativeFormatModuleInfo.cs" />
<Compile Include="Internal\Runtime\TypeLoader\FixupCellMetadataResolver.cs" />
<Compile Include="Internal\Runtime\TypeLoader\GenericDictionary.cs" />
<Compile Include="Internal\Runtime\TypeLoader\GenericDictionaryCell.cs" />
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Private.DisabledReflection", "System.Private.DisabledReflection\src\System.Private.DisabledReflection.csproj", "{ADA691AE-4E1F-4212-97E6-51A27EFCE7E4}"
EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Private.Interop", "System.Private.Interop\src\System.Private.Interop.csproj", "{BAF9BBDF-0DFA-4E0D-AB3C-F07657B9EBB0}"
-EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Private.Reflection.Core", "System.Private.Reflection.Core\src\System.Private.Reflection.Core.csproj", "{6147AF1A-5054-492A-9309-FA868A184414}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "System.Private.Reflection.Execution", "System.Private.Reflection.Execution\src\System.Private.Reflection.Execution.csproj", "{7498DD7C-76C1-4912-AF72-DA84E05B568F}"
<ReproResponseLines Include="--initassembly:System.Private.StackTraceMetadata" />
<ReproResponseLines Include="--initassembly:System.Private.TypeLoader" />
<ReproResponseLines Include="--initassembly:System.Private.Reflection.Execution" />
- <ReproResponseLines Include="--initassembly:System.Private.Interop" />
<ReproResponseLines Include="--directpinvokelist:$(RuntimeBinDir)build\WindowsAPIs.txt" />
<ReproResponseLines Include="--directpinvoke:System.Globalization.Native" />
<ReproResponseLines Include="--stacktracedata" />
<data name="ArgumentOutOfRange_NotGreaterThanBufferLength" xml:space="preserve">
<value>Must not be greater than the length of the buffer.</value>
</data>
+ <data name="StructMarshalling_MissingInteropData" xml:space="preserve">
+ <value>{0} is missing structure marshalling data. To enable structure marshalling data, add a MarshalStructure directive to the application rd.xml file. For more information, please visit http://go.microsoft.com/fwlink/?LinkID=393965</value>
+ </data>
+ <data name="DelegateMarshalling_MissingInteropData" xml:space="preserve">
+ <value>{0} is missing delegate marshalling data. To enable delegate marshalling data, add a MarshalDelegate directive to the application rd.xml file. For more information, please visit http://go.microsoft.com/fwlink/?LinkID=393965</value>
+ </data>
</root>
\ No newline at end of file