diff --git a/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/ThrowHelpers.cs b/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/ThrowHelpers.cs
index 377fba25b43a36..3a1c5d2980492b 100644
--- a/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/ThrowHelpers.cs
+++ b/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/ThrowHelpers.cs
@@ -12,10 +12,12 @@ internal static unsafe partial class ThrowHelpers
{
[DoesNotReturn]
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "ExceptionNative_ThrowAmbiguousResolutionException")]
+ [RequiresUnsafe]
private static partial void ThrowAmbiguousResolutionException(MethodTable* targetType, MethodTable* interfaceType, void* methodDesc);
[DoesNotReturn]
[DebuggerHidden]
+ [RequiresUnsafe]
internal static void ThrowAmbiguousResolutionException(
void* method, // MethodDesc*
void* interfaceType, // MethodTable*
@@ -26,10 +28,12 @@ internal static void ThrowAmbiguousResolutionException(
[DoesNotReturn]
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "ExceptionNative_ThrowEntryPointNotFoundException")]
+ [RequiresUnsafe]
private static partial void ThrowEntryPointNotFoundException(MethodTable* targetType, MethodTable* interfaceType, void* methodDesc);
[DoesNotReturn]
[DebuggerHidden]
+ [RequiresUnsafe]
internal static void ThrowEntryPointNotFoundException(
void* method, // MethodDesc*
void* interfaceType, // MethodTable*
@@ -40,11 +44,13 @@ internal static void ThrowEntryPointNotFoundException(
[DoesNotReturn]
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "ExceptionNative_ThrowMethodAccessException")]
+ [RequiresUnsafe]
private static partial void ThrowMethodAccessExceptionInternal(void* caller, void* callee);
// implementation of CORINFO_HELP_METHOD_ACCESS_EXCEPTION
[DoesNotReturn]
[DebuggerHidden]
+ [RequiresUnsafe]
internal static void ThrowMethodAccessException(
void* caller, // MethodDesc*
void* callee) // MethodDesc*
@@ -54,11 +60,13 @@ internal static void ThrowMethodAccessException(
[DoesNotReturn]
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "ExceptionNative_ThrowFieldAccessException")]
+ [RequiresUnsafe]
private static partial void ThrowFieldAccessExceptionInternal(void* caller, void* callee);
// implementation of CORINFO_HELP_FIELD_ACCESS_EXCEPTION
[DoesNotReturn]
[DebuggerHidden]
+ [RequiresUnsafe]
internal static void ThrowFieldAccessException(
void* caller, // MethodDesc*
void* callee) // FieldDesc*
@@ -68,11 +76,13 @@ internal static void ThrowFieldAccessException(
[DoesNotReturn]
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "ExceptionNative_ThrowClassAccessException")]
+ [RequiresUnsafe]
private static partial void ThrowClassAccessExceptionInternal(void* caller, void* callee);
// implementation of CORINFO_HELP_CLASS_ACCESS_EXCEPTION
[DoesNotReturn]
[DebuggerHidden]
+ [RequiresUnsafe]
internal static void ThrowClassAccessException(
void* caller, // MethodDesc*
void* callee) // Type handle
diff --git a/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.PlatformNotSupported.cs b/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.PlatformNotSupported.cs
index bb8036686d83e6..aa4e64ee600887 100644
--- a/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.PlatformNotSupported.cs
+++ b/src/coreclr/System.Private.CoreLib/src/Internal/Runtime/InteropServices/ComActivator.PlatformNotSupported.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
using System;
+using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
namespace Internal.Runtime.InteropServices
@@ -13,6 +14,7 @@ internal static class ComActivator
///
/// Pointer to a instance
[UnmanagedCallersOnly]
+ [RequiresUnsafe]
private static unsafe int GetClassFactoryForTypeInternal(ComActivationContextInternal* pCxtInt)
=> throw new PlatformNotSupportedException();
@@ -21,6 +23,7 @@ private static unsafe int GetClassFactoryForTypeInternal(ComActivationContextInt
///
/// Pointer to a instance
[UnmanagedCallersOnly]
+ [RequiresUnsafe]
private static unsafe int RegisterClassForTypeInternal(ComActivationContextInternal* pCxtInt)
=> throw new PlatformNotSupportedException();
@@ -29,6 +32,7 @@ private static unsafe int RegisterClassForTypeInternal(ComActivationContextInter
///
/// Pointer to a instance
[UnmanagedCallersOnly]
+ [RequiresUnsafe]
private static unsafe int UnregisterClassForTypeInternal(ComActivationContextInternal* pCxtInt)
=> throw new PlatformNotSupportedException();
}
diff --git a/src/coreclr/System.Private.CoreLib/src/System/AppContext.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/AppContext.CoreCLR.cs
index 99073bb46d91ec..75b8b42cf51f65 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/AppContext.CoreCLR.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/AppContext.CoreCLR.cs
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
+using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@@ -9,6 +10,7 @@ namespace System
public static partial class AppContext
{
[UnmanagedCallersOnly]
+ [RequiresUnsafe]
private static unsafe void OnProcessExit(Exception* pException)
{
try
@@ -22,6 +24,7 @@ private static unsafe void OnProcessExit(Exception* pException)
}
[UnmanagedCallersOnly]
+ [RequiresUnsafe]
private static unsafe void OnUnhandledException(object* pException, Exception* pOutException)
{
try
@@ -35,6 +38,7 @@ private static unsafe void OnUnhandledException(object* pException, Exception* p
}
[UnmanagedCallersOnly]
+ [RequiresUnsafe]
internal static unsafe void OnFirstChanceException(Exception* pException, Exception* pOutException)
{
try
diff --git a/src/coreclr/System.Private.CoreLib/src/System/ArgIterator.cs b/src/coreclr/System.Private.CoreLib/src/System/ArgIterator.cs
index 7beb15f81ccc2a..f9d3d9d3ba3ebb 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/ArgIterator.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/ArgIterator.cs
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
+using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@@ -161,6 +162,7 @@ public ArgIterator(RuntimeArgumentHandle arglist)
}
[CLSCompliant(false)]
+ [RequiresUnsafe]
public unsafe ArgIterator(RuntimeArgumentHandle arglist, void* ptr)
{
throw new PlatformNotSupportedException(SR.PlatformNotSupported_ArgIterator); // https://github.com/dotnet/runtime/issues/7317
diff --git a/src/coreclr/System.Private.CoreLib/src/System/Array.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Array.CoreCLR.cs
index 3c7cea884d1d03..72193cc785dc83 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/Array.CoreCLR.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/Array.CoreCLR.cs
@@ -16,9 +16,11 @@ namespace System
public abstract partial class Array : ICloneable, IList, IStructuralComparable, IStructuralEquatable
{
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "Array_CreateInstance")]
+ [RequiresUnsafe]
private static unsafe partial void InternalCreate(QCallTypeHandle type, int rank, int* pLengths, int* pLowerBounds,
[MarshalAs(UnmanagedType.Bool)] bool fromArrayType, ObjectHandleOnStack retArray);
+ [RequiresUnsafe]
private static unsafe Array InternalCreate(RuntimeType elementType, int rank, int* pLengths, int* pLowerBounds)
{
Array? retArray = null;
@@ -27,6 +29,7 @@ private static unsafe Array InternalCreate(RuntimeType elementType, int rank, in
return retArray!;
}
+ [RequiresUnsafe]
private static unsafe Array InternalCreateFromArrayType(RuntimeType arrayType, int rank, int* pLengths, int* pLowerBounds)
{
Array? retArray = null;
@@ -36,12 +39,14 @@ private static unsafe Array InternalCreateFromArrayType(RuntimeType arrayType, i
}
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "Array_Ctor")]
+ [RequiresUnsafe]
private static unsafe partial void Ctor(MethodTable* pArrayMT, uint dwNumArgs, int* pArgList, ObjectHandleOnStack retArray);
// implementation of CORINFO_HELP_NEW_MDARR and CORINFO_HELP_NEW_MDARR_RARE.
[StackTraceHidden]
[DebuggerStepThrough]
[DebuggerHidden]
+ [RequiresUnsafe]
internal static unsafe Array Ctor(MethodTable* pArrayMT, uint dwNumArgs, int* pArgList)
{
Array? arr = null;
@@ -304,6 +309,7 @@ public int Rank
[MethodImpl(MethodImplOptions.InternalCall)]
internal extern CorElementType GetCorElementTypeOfElementType();
+ [RequiresUnsafe]
private unsafe MethodTable* ElementMethodTable => RuntimeHelpers.GetMethodTable(this)->GetArrayElementTypeHandle().AsMethodTable();
private unsafe bool IsValueOfElementType(object value)
@@ -350,8 +356,10 @@ internal sealed unsafe partial class ArrayInitializeCache : RuntimeType.IGeneric
internal readonly delegate*[ ConstructorEntrypoint;
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "Array_GetElementConstructorEntrypoint")]
+ [RequiresUnsafe]
private static partial delegate*][ GetElementConstructorEntrypoint(QCallTypeHandle arrayType);
+ [RequiresUnsafe]
private ArrayInitializeCache(delegate*][ constructorEntrypoint)
{
ConstructorEntrypoint = constructorEntrypoint;
diff --git a/src/coreclr/System.Private.CoreLib/src/System/Buffer.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Buffer.CoreCLR.cs
index 7f31868f6a0c8a..8764e418aaf5ae 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/Buffer.CoreCLR.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/Buffer.CoreCLR.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@@ -13,6 +14,7 @@ public partial class Buffer
private static extern void BulkMoveWithWriteBarrierInternal(ref byte destination, ref byte source, nuint byteCount);
// Used by ilmarshalers.cpp
+ [RequiresUnsafe]
internal static unsafe void Memcpy(byte* dest, byte* src, int len)
{
Debug.Assert(len >= 0, "Negative length in memcpy!");
@@ -20,6 +22,7 @@ internal static unsafe void Memcpy(byte* dest, byte* src, int len)
}
// Used by ilmarshalers.cpp
+ [RequiresUnsafe]
internal static unsafe void Memcpy(byte* pDest, int destIndex, byte[] src, int srcIndex, int len)
{
Debug.Assert((srcIndex >= 0) && (destIndex >= 0) && (len >= 0), "Index and length must be non-negative!");
diff --git a/src/coreclr/System.Private.CoreLib/src/System/Delegate.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Delegate.CoreCLR.cs
index 358dab7f43674d..8d822a08a6b42b 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/Delegate.CoreCLR.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/Delegate.CoreCLR.cs
@@ -483,9 +483,11 @@ private void DelegateConstruct(object target, IntPtr method)
private static partial void Construct(ObjectHandleOnStack _this, ObjectHandleOnStack target, IntPtr method);
[MethodImpl(MethodImplOptions.InternalCall)]
+ [RequiresUnsafe]
private static extern unsafe void* GetMulticastInvoke(MethodTable* pMT);
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "Delegate_GetMulticastInvokeSlow")]
+ [RequiresUnsafe]
private static unsafe partial void* GetMulticastInvokeSlow(MethodTable* pMT);
internal unsafe IntPtr GetMulticastInvoke()
@@ -503,6 +505,7 @@ internal unsafe IntPtr GetMulticastInvoke()
}
[MethodImpl(MethodImplOptions.InternalCall)]
+ [RequiresUnsafe]
private static extern unsafe void* GetInvokeMethod(MethodTable* pMT);
internal unsafe IntPtr GetInvokeMethod()
diff --git a/src/coreclr/System.Private.CoreLib/src/System/Environment.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Environment.CoreCLR.cs
index 1ecbcb87a4d026..4b4fb747ca049d 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/Environment.CoreCLR.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/Environment.CoreCLR.cs
@@ -87,6 +87,7 @@ private static void FailFast(ref StackCrawlMark mark, string? message, Exception
[DoesNotReturn]
private static partial void FailFast(StackCrawlMarkHandle mark, string? message, ObjectHandleOnStack exception, string? errorMessage);
+ [RequiresUnsafe]
private static unsafe string[] InitializeCommandLineArgs(char* exePath, int argc, char** argv) // invoked from VM
{
string[] commandLineArgs = new string[argc + 1];
@@ -107,6 +108,7 @@ private static unsafe string[] InitializeCommandLineArgs(char* exePath, int argc
internal static partial int GetProcessorCount();
[UnmanagedCallersOnly]
+ [RequiresUnsafe]
private static unsafe void GetResourceString(char* pKey, string* pResult, Exception* pException)
{
try
diff --git a/src/coreclr/System.Private.CoreLib/src/System/Exception.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Exception.CoreCLR.cs
index 312e2a755c4929..3c4c5623e76a9a 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/Exception.CoreCLR.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/Exception.CoreCLR.cs
@@ -115,6 +115,7 @@ internal void InternalPreserveStackTrace()
}
[UnmanagedCallersOnly]
+ [RequiresUnsafe]
private static unsafe void InternalPreserveStackTrace(Exception* pException, Exception* pOutException)
{
try
@@ -271,6 +272,7 @@ private bool CanSetRemoteStackTrace()
}
[UnmanagedCallersOnly]
+ [RequiresUnsafe]
internal static unsafe void CreateRuntimeWrappedException(object* pThrownObject, object* pResult, Exception* pException)
{
try
@@ -284,6 +286,7 @@ internal static unsafe void CreateRuntimeWrappedException(object* pThrownObject,
}
[UnmanagedCallersOnly]
+ [RequiresUnsafe]
internal static unsafe void CreateTypeInitializationException(char* pTypeName, Exception* pInnerException, object* pResult, Exception* pException)
{
try
diff --git a/src/coreclr/System.Private.CoreLib/src/System/GC.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/GC.CoreCLR.cs
index 4222b730e73e6e..2d73e6bdaf01d0 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/GC.CoreCLR.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/GC.CoreCLR.cs
@@ -9,6 +9,7 @@
using System.Collections.Generic;
using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.ExceptionServices;
using System.Runtime.InteropServices;
@@ -308,6 +309,7 @@ public static int GetGeneration(WeakReference wo)
public static int MaxGeneration => GetMaxGeneration();
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "GCInterface_GetNextFinalizableObject")]
+ [RequiresUnsafe]
private static unsafe partial void* GetNextFinalizeableObject(ObjectHandleOnStack target);
private static unsafe uint RunFinalizers()
@@ -759,6 +761,7 @@ static void Free(NoGCRegionCallbackFinalizerWorkItem* pWorkItem)
}
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "GCInterface_EnableNoGCRegionCallback")]
+ [RequiresUnsafe]
private static unsafe partial EnableNoGCRegionCallbackStatus _EnableNoGCRegionCallback(NoGCRegionCallbackFinalizerWorkItem* callback, long totalSize);
internal static long GetGenerationBudget(int generation)
@@ -871,6 +874,7 @@ internal struct GCConfigurationContext
}
[UnmanagedCallersOnly]
+ [RequiresUnsafe]
private static unsafe void ConfigCallback(void* configurationContext, byte* name, byte* publicKey, GCConfigurationType type, long data)
{
// If the public key is null, it means that the corresponding configuration isn't publicly available
@@ -932,6 +936,7 @@ internal enum GCConfigurationType
}
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "GCInterface_EnumerateConfigurationValues")]
+ [RequiresUnsafe]
internal static unsafe partial void _EnumerateConfigurationValues(void* configurationDictionary, delegate* unmanaged callback);
internal enum RefreshMemoryStatus
diff --git a/src/coreclr/System.Private.CoreLib/src/System/IO/Stream.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/IO/Stream.CoreCLR.cs
index 18e9ca018f4218..b485bf5de46401 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/IO/Stream.CoreCLR.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/IO/Stream.CoreCLR.cs
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
+using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@@ -9,6 +10,7 @@ namespace System.IO
public abstract unsafe partial class Stream
{
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "Stream_HasOverriddenSlow")]
+ [RequiresUnsafe]
[return: MarshalAs(UnmanagedType.Bool)]
private static partial bool HasOverriddenSlow(MethodTable* pMT, [MarshalAs(UnmanagedType.Bool)] bool isRead);
diff --git a/src/coreclr/System.Private.CoreLib/src/System/Math.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Math.CoreCLR.cs
index 530355082d26d2..29e85816c4595e 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/Math.CoreCLR.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/Math.CoreCLR.cs
@@ -10,6 +10,7 @@
**
===========================================================*/
+using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
namespace System
@@ -122,9 +123,11 @@ public static unsafe (double Sin, double Cos) SinCos(double x)
public static extern double Tanh(double value);
[MethodImpl(MethodImplOptions.InternalCall)]
+ [RequiresUnsafe]
private static extern unsafe double ModF(double x, double* intptr);
[MethodImpl(MethodImplOptions.InternalCall)]
+ [RequiresUnsafe]
private static extern unsafe void SinCos(double x, double* sin, double* cos);
}
}
diff --git a/src/coreclr/System.Private.CoreLib/src/System/MathF.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/MathF.CoreCLR.cs
index 90403480bf5df0..6b9eb3cb128213 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/MathF.CoreCLR.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/MathF.CoreCLR.cs
@@ -7,6 +7,7 @@
**
===========================================================*/
+using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
namespace System
@@ -119,9 +120,11 @@ public static unsafe (float Sin, float Cos) SinCos(float x)
public static extern float Tanh(float x);
[MethodImpl(MethodImplOptions.InternalCall)]
+ [RequiresUnsafe]
private static extern unsafe float ModF(float x, float* intptr);
[MethodImpl(MethodImplOptions.InternalCall)]
+ [RequiresUnsafe]
private static extern unsafe void SinCos(float x, float* sin, float* cos);
}
}
diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/AssemblyName.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/AssemblyName.CoreCLR.cs
index 48396e6dd42ef9..ab666d209b3abb 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/AssemblyName.CoreCLR.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/AssemblyName.CoreCLR.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
using System.Configuration.Assemblies;
+using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@@ -62,6 +63,7 @@ public void SetVersion(Version? version, ushort defaultValue)
public sealed partial class AssemblyName
{
+ [RequiresUnsafe]
internal unsafe AssemblyName(NativeAssemblyNameParts* pParts)
: this()
{
@@ -144,6 +146,7 @@ private static ProcessorArchitecture CalculateProcArch(PortableExecutableKinds p
return ProcessorArchitecture.None;
}
+ [RequiresUnsafe]
private static unsafe void ParseAsAssemblySpec(char* pAssemblyName, void* pAssemblySpec)
{
AssemblyNameParser.AssemblyNameParts parts = AssemblyNameParser.Parse(MemoryMarshal.CreateReadOnlySpanFromNullTerminated(pAssemblyName));
@@ -168,6 +171,7 @@ private static unsafe void ParseAsAssemblySpec(char* pAssemblyName, void* pAssem
}
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "AssemblyName_InitializeAssemblySpec")]
+ [RequiresUnsafe]
private static unsafe partial void InitializeAssemblySpec(NativeAssemblyNameParts* pAssemblyNameParts, void* pAssemblySpec);
}
}
diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/ConstructorInvoker.CoreCLR.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/ConstructorInvoker.CoreCLR.cs
index f58e24742dc500..a5027d6a8da32a 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/ConstructorInvoker.CoreCLR.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/ConstructorInvoker.CoreCLR.cs
@@ -1,6 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
+using System.Diagnostics.CodeAnalysis;
+
namespace System.Reflection
{
public partial class ConstructorInvoker
@@ -13,6 +15,7 @@ internal unsafe ConstructorInvoker(RuntimeConstructorInfo constructor) : this(co
_invokeFunc_RefArgs = InterpretedInvoke;
}
+ [RequiresUnsafe]
private unsafe object? InterpretedInvoke(object? obj, IntPtr* args)
{
return RuntimeMethodHandle.InvokeMethod(obj, (void**)args, _signature!, isConstructor: obj is null);
diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/DynamicILGenerator.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/DynamicILGenerator.cs
index ae112cbce2bda6..fed49fef5cea4f 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/DynamicILGenerator.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/DynamicILGenerator.cs
@@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.SymbolStore;
using System.Runtime.InteropServices;
@@ -756,6 +757,7 @@ internal override byte[] GetLocalsSignature()
return m_exceptionHeader;
}
+ [RequiresUnsafe]
internal override unsafe void GetEHInfo(int excNumber, void* exc)
{
Debug.Assert(m_exceptions != null);
@@ -904,6 +906,7 @@ public void SetCode(byte[]? code, int maxStackSize)
}
[CLSCompliant(false)]
+ [RequiresUnsafe]
public unsafe void SetCode(byte* code, int codeSize, int maxStackSize)
{
ArgumentOutOfRangeException.ThrowIfNegative(codeSize);
@@ -920,6 +923,7 @@ public void SetExceptions(byte[]? exceptions)
}
[CLSCompliant(false)]
+ [RequiresUnsafe]
public unsafe void SetExceptions(byte* exceptions, int exceptionsSize)
{
ArgumentOutOfRangeException.ThrowIfNegative(exceptionsSize);
@@ -936,6 +940,7 @@ public void SetLocalSignature(byte[]? localSignature)
}
[CLSCompliant(false)]
+ [RequiresUnsafe]
public unsafe void SetLocalSignature(byte* localSignature, int signatureSize)
{
ArgumentOutOfRangeException.ThrowIfNegative(signatureSize);
diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeAssemblyBuilder.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeAssemblyBuilder.cs
index 474e2c68292709..ee44898231d7e9 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeAssemblyBuilder.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeAssemblyBuilder.cs
@@ -113,6 +113,7 @@ internal RuntimeAssemblyBuilder(AssemblyName name,
#region DefineDynamicAssembly
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "AppDomain_CreateDynamicAssembly")]
+ [RequiresUnsafe]
private static unsafe partial void CreateDynamicAssembly(ObjectHandleOnStack assemblyLoadContext,
NativeAssemblyNameParts* pAssemblyName,
AssemblyHashAlgorithm hashAlgId,
diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeTypeBuilder.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeTypeBuilder.cs
index 58fe7960ab3c6d..9405e17878f3d2 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeTypeBuilder.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/RuntimeTypeBuilder.cs
@@ -126,6 +126,7 @@ internal static partial int SetParamInfo(QCallModule module, int tkMethod, int i
internal static partial void SetClassLayout(QCallModule module, int tk, PackingSize iPackingSize, int iTypeSize);
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "TypeBuilder_SetConstantValue")]
+ [RequiresUnsafe]
private static unsafe partial void SetConstantValue(QCallModule module, int tk, int corType, void* pValue);
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "TypeBuilder_SetPInvokeData", StringMarshalling = StringMarshalling.Utf16)]
diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/InstanceCalliHelper.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/InstanceCalliHelper.cs
index f79445292e7cbc..fe8e3a234d0e53 100644
--- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/InstanceCalliHelper.cs
+++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/InstanceCalliHelper.cs
@@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
namespace System.Reflection
@@ -15,151 +16,197 @@ internal static unsafe class InstanceCalliHelper
// Zero parameter methods such as property getters:
[Intrinsic]
+ [RequiresUnsafe]
internal static bool Call(delegate*]