// 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.Versioning;
namespace System.Runtime.CompilerServices
{
//
// Subsetted clone of System.Runtime.CompilerServices.Unsafe for internal runtime use.
// Keep in sync with https://github.com/dotnet/corefx/tree/master/src/System.Runtime.CompilerServices.Unsafe.
//
///
/// Contains generic, low-level functionality for manipulating pointers.
///
internal static unsafe class Unsafe
{
///
/// Returns a pointer to the given by-ref parameter.
///
[NonVersionable]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void* AsPointer(ref T value)
{
// The body of this function will be replaced by the EE with unsafe code!!!
// See getILIntrinsicImplementationForUnsafe for how this happens.
throw new InvalidOperationException();
}
///
/// Returns the size of an object of the given type parameter.
///
[NonVersionable]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int SizeOf()
{
// The body of this function will be replaced by the EE with unsafe code that just returns sizeof !!T
// See getILIntrinsicImplementationForUnsafe for how this happens.
throw new InvalidOperationException();
}
///
/// Reinterprets the given reference as a reference to a value of type .
///
[NonVersionable]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ref TTo As(ref TFrom source)
{
// The body of this function will be replaced by the EE with unsafe code!!!
// See getILIntrinsicImplementationForUnsafe for how this happens.
throw new InvalidOperationException();
}
///
/// Adds an element offset to the given reference.
///
[NonVersionable]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ref T Add(ref T source, int elementOffset)
{
// The body of this function will be replaced by the EE with unsafe code!!!
// See getILIntrinsicImplementationForUnsafe for how this happens.
typeof(T).ToString(); // Type used by the actual method body
throw new InvalidOperationException();
}
///
/// Determines whether the specified references point to the same location.
///
[NonVersionable]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool AreSame(ref T left, ref T right)
{
// The body of this function will be replaced by the EE with unsafe code!!!
// See getILIntrinsicImplementationForUnsafe for how this happens.
throw new InvalidOperationException();
}
///
/// Initializes a block of memory at the given location with a given initial value
/// without assuming architecture dependent alignment of the address.
///
[NonVersionable]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void InitBlockUnaligned(ref byte startAddress, byte value, uint byteCount)
{
// The body of this function will be replaced by the EE with unsafe code!!!
// See getILIntrinsicImplementationForUnsafe for how this happens.
throw new InvalidOperationException();
}
}
}