<Compile Include="$(BclSourcesRoot)\System\Runtime\InteropServices\NativeLibrary.cs" />
<Compile Include="$(BclSourcesRoot)\System\Runtime\Loader\AssemblyDependencyResolver.cs" />
<Compile Include="$(BclSourcesRoot)\System\Runtime\Loader\AssemblyLoadContext.CoreCLR.cs" />
- <Compile Include="$(BclSourcesRoot)\System\Runtime\Serialization\FormatterServices.cs" />
<Compile Include="$(BclSourcesRoot)\System\Runtime\Versioning\CompatibilitySwitch.cs" />
<Compile Include="$(BclSourcesRoot)\System\RuntimeArgumentHandle.cs" />
<Compile Include="$(BclSourcesRoot)\System\RuntimeHandles.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\ReferenceAssemblyAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\RuntimeCompatibilityAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\RuntimeFeature.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\RuntimeHelpers.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\RuntimeWrappedException.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\SpecialNameAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\StateMachineAttribute.cs" />
--- /dev/null
+// 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.
+
+using System.Runtime.Serialization;
+
+namespace System.Runtime.CompilerServices
+{
+ public static partial class RuntimeHelpers
+ {
+ public delegate void TryCode(object userData);
+
+ public delegate void CleanupCode(object userData, bool exceptionThrown);
+
+ /// <summary>
+ /// GetSubArray helper method for the compiler to slice an array using a range.
+ /// </summary>
+ public static T[] GetSubArray<T>(T[] array, Range range)
+ {
+ Type elementType = array.GetType().GetElementType();
+ Span<T> source = array.AsSpan(range);
+
+ if (elementType.IsValueType)
+ {
+ return source.ToArray();
+ }
+ else
+ {
+ T[] newArray = (T[])Array.CreateInstance(elementType, source.Length);
+ source.CopyTo(newArray);
+ return newArray;
+ }
+ }
+
+ public static object GetUninitializedObject(Type type)
+ {
+ if (type is null)
+ {
+ throw new ArgumentNullException(nameof(type), SR.ArgumentNull_Type);
+ }
+
+ if (!type.IsRuntimeImplemented())
+ {
+ throw new SerializationException(SR.Format(SR.Serialization_InvalidType, type.ToString()));
+ }
+
+ return GetUninitializedObjectInternal(type);
+ }
+
+ public static void PrepareContractedDelegate(Delegate d)
+ {
+ }
+
+ public static void ProbeForSufficientStack()
+ {
+ }
+
+ public static void PrepareConstrainedRegions()
+ {
+ }
+
+ public static void PrepareConstrainedRegionsNoOP()
+ {
+ }
+ }
+}
\ No newline at end of file
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-////////////////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////////////////
-//
-// RuntimeHelpers
-// This class defines a set of static methods that provide support for compilers.
-//
-//
+using System.Diagnostics;
+using System.Runtime.InteropServices;
+using Internal.Runtime.CompilerServices;
namespace System.Runtime.CompilerServices
{
- using System;
- using System.Diagnostics;
- using System.Security;
- using System.Runtime;
- using System.Runtime.CompilerServices;
- using System.Runtime.InteropServices;
- using System.Runtime.ConstrainedExecution;
- using System.Runtime.Serialization;
- using System.Threading;
- using System.Runtime.Versioning;
- using Internal.Runtime.CompilerServices;
-
- public static class RuntimeHelpers
+ public static partial class RuntimeHelpers
{
- // Exposed here as a more appropriate place than on FormatterServices itself,
- // which is a high level reflection heavy type.
- public static object GetUninitializedObject(Type type)
- {
- return FormatterServices.GetUninitializedObject(type);
- }
-
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public static extern void InitializeArray(Array array, RuntimeFieldHandle fldHandle);
}
}
- public static void PrepareContractedDelegate(Delegate d) { }
-
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public static extern void PrepareDelegate(Delegate d);
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public static extern bool TryEnsureSufficientExecutionStack();
- public static void ProbeForSufficientStack()
- {
- }
-
- // This method is a marker placed immediately before a try clause to mark the corresponding catch and finally blocks as
- // constrained. There's no code here other than the probe because most of the work is done at JIT time when we spot a call to this routine.
- public static void PrepareConstrainedRegions()
- {
- ProbeForSufficientStack();
- }
-
- // When we detect a CER with no calls, we can point the JIT to this non-probing version instead
- // as we don't need to probe.
- public static void PrepareConstrainedRegionsNoOP()
- {
- }
-
- public delegate void TryCode(object userData);
-
- public delegate void CleanupCode(object userData, bool exceptionThrown);
-
[MethodImplAttribute(MethodImplOptions.InternalCall)]
public static extern void ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, object userData);
throw new InvalidOperationException();
}
- /// <summary>
- /// GetSubArray helper method for the compiler to slice an array using a range.
- /// </summary>
- public static T[] GetSubArray<T>(T[] array, Range range)
- {
- Type elementType = array.GetType().GetElementType();
- Span<T> source = array.AsSpan(range);
-
- if (elementType.IsValueType)
- {
- return source.ToArray();
- }
- else
- {
- T[] newArray = (T[])Array.CreateInstance(elementType, source.Length);
- source.CopyTo(newArray);
- return newArray;
- }
- }
-
// Returns true iff the object has a component size;
// i.e., is variable length like System.String or Array.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
// Ideally this would just be a single dereference:
// mov tmp, qword ptr [rax] ; rax = obj ref, tmp = MethodTable* pointer
}
+
+ [MethodImplAttribute(MethodImplOptions.InternalCall)]
+ private static extern object GetUninitializedObjectInternal(Type type);
+
}
}
+++ /dev/null
-// 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.
-
-/*============================================================
-**
-**
-**
-** Purpose: Provides some static methods to aid with the implementation
-** of a Formatter for Serialization.
-**
-**
-============================================================*/
-
-using System;
-using System.Reflection;
-using System.Collections;
-using System.Collections.Generic;
-using System.Security;
-using System.Runtime.CompilerServices;
-using System.Runtime.Versioning;
-using System.Threading;
-using System.IO;
-using System.Text;
-using System.Globalization;
-using System.Diagnostics;
-
-namespace System.Runtime.Serialization
-{
- // This class duplicates a class on CoreFX. We are keeping it here -- just this one method --
- // as it was widely invoked by reflection to workaround it being missing in .NET Core 1.0
- internal static class FormatterServices
- {
- // Gets a new instance of the object. The entire object is initalized to 0 and no
- // constructors have been run. **THIS MEANS THAT THE OBJECT MAY NOT BE IN A STATE
- // CONSISTENT WITH ITS INTERNAL REQUIREMENTS** This method should only be used for
- // deserialization when the user intends to immediately populate all fields. This method
- // will not create an unitialized string because it is non-sensical to create an empty
- // instance of an immutable type.
- //
- public static object GetUninitializedObject(Type type)
- {
- if ((object)type == null)
- {
- throw new ArgumentNullException(nameof(type));
- }
-
- if (!(type is RuntimeType))
- {
- throw new SerializationException(SR.Format(SR.Serialization_InvalidType, type));
- }
-
- return nativeGetUninitializedObject((RuntimeType)type);
- }
-
- [MethodImplAttribute(MethodImplOptions.InternalCall)]
- private static extern object nativeGetUninitializedObject(RuntimeType type);
- }
-}
-
-
-
-
-
FCFuncElementSig("FailFast", &gsig_SM_Str_Exception_Str_RetVoid, SystemNative::FailFastWithExceptionAndSource)
FCFuncEnd()
-FCFuncStart(gSerializationFuncs)
- FCFuncElement("nativeGetUninitializedObject", ReflectionSerialization::GetUninitializedObject)
-FCFuncEnd()
-
FCFuncStart(gExceptionFuncs)
FCFuncElement("IsImmutableAgileException", ExceptionNative::IsImmutableAgileException)
FCFuncElement("nIsTransient", ExceptionNative::IsTransient)
FCFuncElement("Equals", ObjectNative::Equals)
FCFuncElement("EnsureSufficientExecutionStack", ReflectionInvocation::EnsureSufficientExecutionStack)
FCFuncElement("TryEnsureSufficientExecutionStack", ReflectionInvocation::TryEnsureSufficientExecutionStack)
+ FCFuncElement("GetUninitializedObjectInternal", ReflectionSerialization::GetUninitializedObject)
FCFuncEnd()
FCFuncStart(gContextSynchronizationFuncs)
#endif // FEATURE_PERFTRACING
FCClassElement("Exception", "System", gExceptionFuncs)
FCClassElement("FileLoadException", "System.IO", gFileLoadExceptionFuncs)
-FCClassElement("FormatterServices", "System.Runtime.Serialization", gSerializationFuncs)
FCClassElement("GC", "System", gGCInterfaceFuncs)
FCClassElement("GCHandle", "System.Runtime.InteropServices", gGCHandleFuncs)
FCClassElement("GCSettings", "System.Runtime", gGCSettingsFuncs)
HELPER_METHOD_FRAME_BEGIN_RET_NOPOLL();
- if (objType == NULL) {
- COMPlusThrowArgumentNull(W("type"), W("ArgumentNull_Type"));
- }
-
TypeHandle type = objType->GetType();
// Don't allow arrays, pointers, byrefs or function pointers.