Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public ArgIterator(RuntimeArgumentHandle arglist)
// This is much like the C va_start macro

[CLSCompliant(false)]
[RequiresUnsafe]
public ArgIterator(RuntimeArgumentHandle arglist, void* ptr)
{
IntPtr cookie = arglist.Value;
Expand Down
Original file line number Diff line number Diff line change
@@ -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.InteropServices;

namespace System
Expand All @@ -14,6 +15,7 @@ public ArgIterator(RuntimeArgumentHandle arglist)
}

[CLSCompliant(false)]
[RequiresUnsafe]
public unsafe ArgIterator(RuntimeArgumentHandle arglist, void* ptr)
{
throw new PlatformNotSupportedException(SR.PlatformNotSupported_ArgIterator);
Expand Down
Original file line number Diff line number Diff line change
@@ -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.Emit
{
public class DynamicILInfo
Expand All @@ -15,16 +17,19 @@ internal DynamicILInfo()
public void SetCode(byte[] code, int maxStackSize) { }

[CLSCompliant(false)]
[RequiresUnsafe]
public unsafe void SetCode(byte* code, int codeSize, int maxStackSize) { }

public void SetExceptions(byte[] exceptions) { }

[CLSCompliant(false)]
[RequiresUnsafe]
public unsafe void SetExceptions(byte* exceptions, int exceptionsSize) { }

public void SetLocalSignature(byte[] localSignature) { }

[CLSCompliant(false)]
[RequiresUnsafe]
public unsafe void SetLocalSignature(byte* localSignature, int signatureSize) { }

public int GetTokenFor(RuntimeMethodHandle method)
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -16,6 +17,7 @@ public static class AssemblyExtensions
// associated, is alive. The caller is responsible for keeping the assembly object alive while accessing the
// metadata blob.
[CLSCompliant(false)] // out byte* blob
[RequiresUnsafe]
public static unsafe bool TryGetRawMetadata(this Assembly assembly, out byte* blob, out int length)
{
ArgumentNullException.ThrowIfNull(assembly);
Expand Down
Original file line number Diff line number Diff line change
@@ -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.Versioning;

Expand Down Expand Up @@ -37,6 +38,7 @@ public static partial class JavaMarshal
/// runtime code when cross-reference marking is required.
/// Additionally, this callback must be implemented in unmanaged code.
/// </remarks>
[RequiresUnsafe]
public static unsafe void Initialize(delegate* unmanaged<MarkCrossReferencesArgs*, void> markCrossReferences)
{
ArgumentNullException.ThrowIfNull(markCrossReferences);
Expand All @@ -61,6 +63,7 @@ public static unsafe void Initialize(delegate* unmanaged<MarkCrossReferencesArgs
/// <returns>A <see cref="GCHandle"/> that represents the allocated reference-tracking handle.</returns>
/// <exception cref="ArgumentNullException"><paramref name="obj"/> is null.</exception>
/// <exception cref="PlatformNotSupportedException">The runtime or platform does not support Java cross-reference marshalling.</exception>
[RequiresUnsafe]
public static unsafe GCHandle CreateReferenceTrackingHandle(object obj, void* context)
{
ArgumentNullException.ThrowIfNull(obj);
Expand All @@ -79,6 +82,7 @@ public static unsafe GCHandle CreateReferenceTrackingHandle(object obj, void* co
/// The returned pointer is the exact value that was originally provided as
/// the context parameter when the handle was created.
/// </remarks>
[RequiresUnsafe]
public static unsafe void* GetContext(GCHandle obj)
{
IntPtr handle = GCHandle.ToIntPtr(obj);
Expand All @@ -99,6 +103,7 @@ public static unsafe GCHandle CreateReferenceTrackingHandle(object obj, void* co
/// <param name="crossReferences">A pointer to the structure containing cross-reference information produced during marking.</param>
/// <param name="unreachableObjectHandles">A span of <see cref="GCHandle"/> values that were determined to be unreachable from the native side.</param>
/// <exception cref="PlatformNotSupportedException">The runtime or platform does not support Java cross-reference marshalling.</exception>
[RequiresUnsafe]
public static unsafe void FinishCrossReferenceProcessing(
MarkCrossReferencesArgs* crossReferences,
ReadOnlySpan<GCHandle> unreachableObjectHandles)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,13 @@ protected void WriteEvent(int eventId, string? arg1, string? arg2) { }
protected void WriteEvent(int eventId, string? arg1, string? arg2, string? arg3) { }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource will serialize the whole object graph. Trimmer will not safely handle this case because properties may be trimmed. This can be suppressed if the object is a primitive type")]
[System.CLSCompliantAttribute(false)]
[System.Diagnostics.CodeAnalysis.RequiresUnsafeAttribute]
protected unsafe void WriteEventCore(int eventId, int eventDataCount, System.Diagnostics.Tracing.EventSource.EventData* data) { }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource will serialize the whole object graph. Trimmer will not safely handle this case because properties may be trimmed. This can be suppressed if the object is a primitive type")]
protected void WriteEventWithRelatedActivityId(int eventId, System.Guid relatedActivityId, params object?[] args) { }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource will serialize the whole object graph. Trimmer will not safely handle this case because properties may be trimmed. This can be suppressed if the object is a primitive type")]
[System.CLSCompliantAttribute(false)]
[System.Diagnostics.CodeAnalysis.RequiresUnsafeAttribute]
protected unsafe void WriteEventWithRelatedActivityIdCore(int eventId, System.Guid* relatedActivityId, int eventDataCount, System.Diagnostics.Tracing.EventSource.EventData* data) { }
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("EventSource will serialize the whole object graph. Trimmer will not safely handle this case because properties may be trimmed. This can be suppressed if the object is a primitive type")]
public void Write<[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembersAttribute(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicProperties)] T>(string? eventName, System.Diagnostics.Tracing.EventSourceOptions options, T data) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,10 +390,13 @@ public static partial class Vector
public static System.Numerics.Vector<T> LessThanOrEqual<T>(System.Numerics.Vector<T> left, System.Numerics.Vector<T> right) { throw null; }
public static System.Numerics.Vector<T> LessThan<T>(System.Numerics.Vector<T> left, System.Numerics.Vector<T> right) { throw null; }
[System.CLSCompliantAttribute(false)]
[System.Diagnostics.CodeAnalysis.RequiresUnsafeAttribute]
public static unsafe System.Numerics.Vector<T> Load<T>(T* source) { throw null; }
[System.CLSCompliantAttribute(false)]
[System.Diagnostics.CodeAnalysis.RequiresUnsafeAttribute]
public static unsafe System.Numerics.Vector<T> LoadAligned<T>(T* source) { throw null; }
[System.CLSCompliantAttribute(false)]
[System.Diagnostics.CodeAnalysis.RequiresUnsafeAttribute]
public static unsafe System.Numerics.Vector<T> LoadAlignedNonTemporal<T>(T* source) { throw null; }
public static System.Numerics.Vector<T> LoadUnsafe<T>(ref readonly T source) { throw null; }
[System.CLSCompliantAttribute(false)]
Expand Down Expand Up @@ -491,28 +494,40 @@ public static partial class Vector
public static (System.Numerics.Vector<float> Sin, System.Numerics.Vector<float> Cos) SinCos(System.Numerics.Vector<float> vector) { throw null; }
public static System.Numerics.Vector<T> SquareRoot<T>(System.Numerics.Vector<T> value) { throw null; }
[System.CLSCompliantAttribute(false)]
[System.Diagnostics.CodeAnalysis.RequiresUnsafeAttribute]
public static unsafe void Store<T>(this System.Numerics.Vector<T> source, T* destination) { throw null; }
[System.CLSCompliantAttribute(false)]
[System.Diagnostics.CodeAnalysis.RequiresUnsafeAttribute]
public static unsafe void Store(this System.Numerics.Vector2 source, float* destination) { throw null; }
[System.CLSCompliantAttribute(false)]
[System.Diagnostics.CodeAnalysis.RequiresUnsafeAttribute]
public static unsafe void Store(this System.Numerics.Vector3 source, float* destination) { throw null; }
[System.CLSCompliantAttribute(false)]
[System.Diagnostics.CodeAnalysis.RequiresUnsafeAttribute]
public static unsafe void Store(this System.Numerics.Vector4 source, float* destination) { throw null; }
[System.CLSCompliantAttribute(false)]
[System.Diagnostics.CodeAnalysis.RequiresUnsafeAttribute]
public static unsafe void StoreAligned<T>(this System.Numerics.Vector<T> source, T* destination) { throw null; }
[System.CLSCompliantAttribute(false)]
[System.Diagnostics.CodeAnalysis.RequiresUnsafeAttribute]
public static unsafe void StoreAligned(this System.Numerics.Vector2 source, float* destination) { throw null; }
[System.CLSCompliantAttribute(false)]
[System.Diagnostics.CodeAnalysis.RequiresUnsafeAttribute]
public static unsafe void StoreAligned(this System.Numerics.Vector3 source, float* destination) { throw null; }
[System.CLSCompliantAttribute(false)]
[System.Diagnostics.CodeAnalysis.RequiresUnsafeAttribute]
public static unsafe void StoreAligned(this System.Numerics.Vector4 source, float* destination) { throw null; }
[System.CLSCompliantAttribute(false)]
[System.Diagnostics.CodeAnalysis.RequiresUnsafeAttribute]
public static unsafe void StoreAlignedNonTemporal<T>(this System.Numerics.Vector<T> source, T* destination) { throw null; }
[System.CLSCompliantAttribute(false)]
[System.Diagnostics.CodeAnalysis.RequiresUnsafeAttribute]
public static unsafe void StoreAlignedNonTemporal(this System.Numerics.Vector2 source, float* destination) { throw null; }
[System.CLSCompliantAttribute(false)]
[System.Diagnostics.CodeAnalysis.RequiresUnsafeAttribute]
public static unsafe void StoreAlignedNonTemporal(this System.Numerics.Vector3 source, float* destination) { throw null; }
[System.CLSCompliantAttribute(false)]
[System.Diagnostics.CodeAnalysis.RequiresUnsafeAttribute]
public static unsafe void StoreAlignedNonTemporal(this System.Numerics.Vector4 source, float* destination) { throw null; }
public static void StoreUnsafe<T>(this System.Numerics.Vector<T> source, ref T destination) { throw null; }
public static void StoreUnsafe(this System.Numerics.Vector2 source, ref float destination) { throw null; }
Expand Down Expand Up @@ -688,10 +703,13 @@ public readonly void CopyTo(System.Span<float> destination) { }
public static bool LessThanOrEqualAll(System.Numerics.Vector2 left, System.Numerics.Vector2 right) { throw null; }
public static bool LessThanOrEqualAny(System.Numerics.Vector2 left, System.Numerics.Vector2 right) { throw null; }
[CLSCompliant(false)]
[System.Diagnostics.CodeAnalysis.RequiresUnsafeAttribute]
public static unsafe System.Numerics.Vector2 Load(float* source) { throw null; }
[CLSCompliant(false)]
[System.Diagnostics.CodeAnalysis.RequiresUnsafeAttribute]
public static unsafe System.Numerics.Vector2 LoadAligned(float* source) { throw null; }
[CLSCompliant(false)]
[System.Diagnostics.CodeAnalysis.RequiresUnsafeAttribute]
public static unsafe System.Numerics.Vector2 LoadAlignedNonTemporal(float* source) { throw null; }
public static System.Numerics.Vector2 LoadUnsafe(ref readonly float source) { throw null; }
[CLSCompliant(false)]
Expand Down Expand Up @@ -856,10 +874,13 @@ public readonly void CopyTo(System.Span<float> destination) { }
public static bool LessThanOrEqualAll(System.Numerics.Vector3 left, System.Numerics.Vector3 right) { throw null; }
public static bool LessThanOrEqualAny(System.Numerics.Vector3 left, System.Numerics.Vector3 right) { throw null; }
[CLSCompliant(false)]
[System.Diagnostics.CodeAnalysis.RequiresUnsafeAttribute]
public static unsafe System.Numerics.Vector3 Load(float* source) { throw null; }
[CLSCompliant(false)]
[System.Diagnostics.CodeAnalysis.RequiresUnsafeAttribute]
public static unsafe System.Numerics.Vector3 LoadAligned(float* source) { throw null; }
[CLSCompliant(false)]
[System.Diagnostics.CodeAnalysis.RequiresUnsafeAttribute]
public static unsafe System.Numerics.Vector3 LoadAlignedNonTemporal(float* source) { throw null; }
public static System.Numerics.Vector3 LoadUnsafe(ref readonly float source) { throw null; }
[CLSCompliant(false)]
Expand Down Expand Up @@ -1028,10 +1049,13 @@ public readonly void CopyTo(System.Span<float> destination) { }
public static System.Numerics.Vector4 Log(System.Numerics.Vector4 vector) { throw null; }
public static System.Numerics.Vector4 Log2(System.Numerics.Vector4 vector) { throw null; }
[CLSCompliant(false)]
[System.Diagnostics.CodeAnalysis.RequiresUnsafeAttribute]
public static unsafe System.Numerics.Vector4 Load(float* source) { throw null; }
[CLSCompliant(false)]
[System.Diagnostics.CodeAnalysis.RequiresUnsafeAttribute]
public static unsafe System.Numerics.Vector4 LoadAligned(float* source) { throw null; }
[CLSCompliant(false)]
[System.Diagnostics.CodeAnalysis.RequiresUnsafeAttribute]
public static unsafe System.Numerics.Vector4 LoadAlignedNonTemporal(float* source) { throw null; }
public static System.Numerics.Vector4 LoadUnsafe(ref readonly float source) { throw null; }
[CLSCompliant(false)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,7 @@
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\IteratorStateMachineAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\ITuple.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\LoadHint.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\MemorySafetyRulesAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\MethodCodeType.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\MethodImplAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\MethodImplOptions.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,22 @@
namespace System.Diagnostics.CodeAnalysis
{
/// <summary>
/// Indicates that the specified method requires unsafe code that may not be available
/// in all execution environments.
/// Indicates that the specified member requires the caller to be in an unsafe context.
/// </summary>
/// <remarks>
/// This allows tools to understand which methods are unsafe to call when targeting
/// environments that do not support unsafe code.
/// </remarks>
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Property, Inherited = false)]
[Conditional("DEBUG")]
internal sealed class RequiresUnsafeAttribute : Attribute
[AttributeUsage(
AttributeTargets.Constructor | AttributeTargets.Event | AttributeTargets.Method | AttributeTargets.Property,
Comment thread
jjonescz marked this conversation as resolved.
Resolved
Inherited = false,
Comment thread
jjonescz marked this conversation as resolved.
Resolved
AllowMultiple = false)]
#if SYSTEM_PRIVATE_CORELIB
public
#else
internal
#endif
sealed class RequiresUnsafeAttribute : Attribute
{
/// <summary>
/// Initializes a new instance of the <see cref="RequiresUnsafeAttribute"/> class.
/// </summary>
public RequiresUnsafeAttribute() { }
Comment thread
jjonescz marked this conversation as resolved.
Resolved
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.ComponentModel;

namespace System.Runtime.CompilerServices
{
/// <summary>Indicates the version of the memory safety rules used when the module was compiled.</summary>
[EditorBrowsable(EditorBrowsableState.Never)]
[AttributeUsage(AttributeTargets.Module, Inherited = false, AllowMultiple = false)]
public sealed class MemorySafetyRulesAttribute : Attribute
{
/// <summary>Initializes a new instance of the <see cref="MemorySafetyRulesAttribute"/> class.</summary>
/// <param name="version">The version of the memory safety rules used when the module was compiled.</param>
public MemorySafetyRulesAttribute(int version) => Version = version;

/// <summary>Gets the version of the memory safety rules used when the module was compiled.</summary>
public int Version { get; }
Comment thread
jjonescz marked this conversation as resolved.
Resolved
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public struct ComInterfaceEntry
public IntPtr Vtable;
}

[RequiresUnsafe]
protected abstract unsafe ComInterfaceEntry* ComputeVtables(object obj, CreateComInterfaceFlags flags, out int count);

protected abstract object? CreateObject(IntPtr externalComObject, CreateObjectFlags flags);
Expand All @@ -47,6 +48,8 @@ public static unsafe bool TryGetObject(IntPtr unknown, [NotNullWhen(true)] out o
public struct ComInterfaceDispatch
{
public IntPtr Vtable;

[RequiresUnsafe]
public static unsafe T GetInstance<T>(ComInterfaceDispatch* dispatchPtr) where T : class
{
throw new PlatformNotSupportedException();
Expand Down
Loading
Loading