Skip to content
Closed
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
4 changes: 4 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,10 @@
<WarningsNotAsErrors Condition="'$(OfficialBuild)' != 'true' OR '$(NuGetAuditWarnNotError)' == 'true'">$(WarningsNotAsErrors);NU1901;NU1902;NU1903;NU1904</WarningsNotAsErrors>
<!-- Warnings to always disable -->
<NoWarn>$(NoWarn);CS8500;CS8969</NoWarn>

<!-- Temporarily suppress ILLink RequiresUnsafe call-site diagnostics for the entire repo. -->
<NoWarn>$(NoWarn);IL5000</NoWarn>

<!-- Suppress "CS1591 - Missing XML comment for publicly visible type or member" compiler errors for private assemblies. -->
<NoWarn Condition="'$(IsPrivateAssembly)' == 'true'">$(NoWarn);CS1591</NoWarn>
<!-- Always pass portable to override arcade sdk which uses embedded for local builds -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -711,20 +711,23 @@ internal sealed class LicenseInteropProxy
private Type? _targetRcwType;

[UnsafeAccessor(UnsafeAccessorKind.Method)]
[RequiresUnsafe]
private static extern void SetSavedLicenseKey(
[UnsafeAccessorType(LicenseContextTypeName)] object licContext,
Type type,
string key);

[UnconditionalSuppressMessage("Trimming", "IL2111", Justification = "Manually validated that the annotations are kept in sync.")]
[UnsafeAccessor(UnsafeAccessorKind.StaticMethod)]
[RequiresUnsafe]
private static extern object? CreateWithContext(
[UnsafeAccessorType(LicenseManagerTypeName)] object? licManager,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type type,
[UnsafeAccessorType(LicenseContextTypeName)] object licContext
);

[UnsafeAccessor(UnsafeAccessorKind.StaticMethod)]
[RequiresUnsafe]
private static extern bool ValidateAndRetrieveLicenseDetails(
[UnsafeAccessorType(LicenseInteropHelperTypeName)] object? licInteropHelper,
[UnsafeAccessorType(LicenseContextTypeName)] object? licContext,
Expand All @@ -733,6 +736,7 @@ private static extern bool ValidateAndRetrieveLicenseDetails(
out string? licenseKey);

[UnsafeAccessor(UnsafeAccessorKind.StaticMethod)]
[RequiresUnsafe]
[return: UnsafeAccessorType(LicenseContextTypeName)]
private static extern object? GetCurrentContextInfo(
[UnsafeAccessorType(LicenseInteropHelperTypeName)] object? licInteropHelper,
Expand All @@ -741,23 +745,27 @@ private static extern bool ValidateAndRetrieveLicenseDetails(
out string? key);

[UnsafeAccessor(UnsafeAccessorKind.StaticMethod)]
[RequiresUnsafe]
[return: UnsafeAccessorType(CLRLicenseContextTypeName)]
private static extern object CreateDesignContext(
[UnsafeAccessorType(CLRLicenseContextTypeName)] object? context,
Type type);

[UnsafeAccessor(UnsafeAccessorKind.StaticMethod)]
[RequiresUnsafe]
[return: UnsafeAccessorType(CLRLicenseContextTypeName)]
private static extern object CreateRuntimeContext(
[UnsafeAccessorType(CLRLicenseContextTypeName)] object? context,
Type type,
string? key);

[UnsafeAccessor(UnsafeAccessorKind.Constructor)]
[RequiresUnsafe]
[return:UnsafeAccessorType(LicInfoHelperLicenseContextTypeName)]
private static extern object CreateLicInfoHelperLicenseContext();

[UnsafeAccessor(UnsafeAccessorKind.Method)]
[RequiresUnsafe]
private static extern bool Contains(
[UnsafeAccessorType(LicInfoHelperLicenseContextTypeName)] object? licInfoHelperContext,
string assemblyName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Diagnostics.CodeAnalysis;
using System.Reflection.Metadata;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
Expand All @@ -14,6 +15,7 @@ namespace Internal
internal static partial class VersionResilientHashCode
{
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "VersionResilientHashCode_TypeHashCode")]
[RequiresUnsafe]
private static partial int TypeHashCode(QCallTypeHandle typeHandle);

public static int TypeHashCode(RuntimeType type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ internal static void SetFirstChanceExceptionHandler()

[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "AppContext_SetFirstChanceExceptionHandler")]
[SuppressGCTransition]
[RequiresUnsafe]
private static partial void SetFirstChanceExceptionHandlerInternal();
}
}
5 changes: 5 additions & 0 deletions src/coreclr/System.Private.CoreLib/src/System/ArgIterator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public ArgIterator(RuntimeArgumentHandle arglist)
}

[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "ArgIterator_Init")]
[RequiresUnsafe]
private static partial void Init(ArgIterator* thisPtr, IntPtr cookie);

// create an arg iterator that points just past 'firstArg'.
Expand All @@ -57,6 +58,7 @@ public ArgIterator(RuntimeArgumentHandle arglist, void* ptr)
}

[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "ArgIterator_Init2")]
[RequiresUnsafe]
private static partial void Init(ArgIterator* thisPtr, IntPtr cookie, void* ptr);

// Fetch an argument as a typed referece, advance the iterator.
Expand All @@ -83,6 +85,7 @@ public TypedReference GetNextArg()
}

[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "ArgIterator_GetNextArg")]
[RequiresUnsafe]
private static partial void GetNextArg(ArgIterator* thisPtr, TypedReference* pResult);

// Alternate version of GetNextArg() intended primarily for IJW code
Expand Down Expand Up @@ -118,6 +121,7 @@ public TypedReference GetNextArg(RuntimeTypeHandle rth)
}

[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "ArgIterator_GetNextArg2")]
[RequiresUnsafe]
private static partial void GetNextArg(ArgIterator* thisPtr, QCallTypeHandle rth, TypedReference* pResult);

// This method should invalidate the iterator (va_end). It is not supported yet.
Expand All @@ -143,6 +147,7 @@ public RuntimeTypeHandle GetNextArgType()
}

[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "ArgIterator_GetNextArgType")]
[RequiresUnsafe]
private static partial IntPtr GetNextArgType(ArgIterator* thisPtr);

public override int GetHashCode()
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 @@ -10,6 +11,7 @@ namespace System
internal sealed partial class ComAwareWeakReference
{
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "ComWeakRefToObject")]
[RequiresUnsafe]
private static partial void ComWeakRefToObject(IntPtr pComWeakRef, ObjectHandleOnStack retRcw);

internal static object? ComWeakRefToObject(IntPtr pComWeakRef, object? context)
Expand Down Expand Up @@ -39,6 +41,7 @@ internal static bool PossiblyComObject(object target)
}

[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "ObjectToComWeakRef")]
[RequiresUnsafe]
private static partial IntPtr ObjectToComWeakRef(ObjectHandleOnStack retRcw);

internal static nint ObjectToComWeakRef(object target, out object? context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ private void DelegateConstruct(object target, IntPtr method)
}

[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "Delegate_Construct")]
[RequiresUnsafe]
private static partial void Construct(ObjectHandleOnStack _this, ObjectHandleOnStack target, IntPtr method);

[MethodImpl(MethodImplOptions.InternalCall)]
Expand Down Expand Up @@ -525,6 +526,7 @@ internal IRuntimeMethodInfo FindMethodHandle()
}

[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "Delegate_FindMethodHandle")]
[RequiresUnsafe]
private static partial void FindMethodHandle(ObjectHandleOnStack d, ObjectHandleOnStack retMethodInfo);

private static bool InternalEqualMethodHandles(Delegate left, Delegate right)
Expand All @@ -542,6 +544,7 @@ internal static IntPtr AdjustTarget(object target, IntPtr methodPtr)
}

[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "Delegate_AdjustTarget")]
[RequiresUnsafe]
private static partial IntPtr AdjustTarget(ObjectHandleOnStack target, IntPtr methodPtr);

internal void InitializeVirtualCallStub(IntPtr methodPtr)
Expand All @@ -551,6 +554,7 @@ internal void InitializeVirtualCallStub(IntPtr methodPtr)
}

[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "Delegate_InitializeVirtualCallStub")]
[RequiresUnsafe]
private static partial void InitializeVirtualCallStub(ObjectHandleOnStack d, IntPtr methodPtr);

internal virtual object? GetTarget()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// The Debugger class is a part of the System.Diagnostics package
// and is used for communicating with a debugger.

using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

Expand All @@ -12,6 +13,7 @@ namespace System.Diagnostics
public static partial class Debugger
{
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "DebugDebugger_Break")]
[RequiresUnsafe]
private static partial void BreakInternal();

// Break causes a breakpoint to be signalled to an attached debugger. If no debugger
Expand Down Expand Up @@ -63,6 +65,7 @@ static void NotifyOfCrossThreadDependencySlow()

[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "DebugDebugger_IsManagedDebuggerAttached")]
[SuppressGCTransition]
[RequiresUnsafe]
private static partial int IsManagedDebuggerAttached();

// Posts a message for the attached debugger. If there is no
Expand All @@ -78,12 +81,14 @@ static void NotifyOfCrossThreadDependencySlow()

[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "DebugDebugger_IsLoggingHelper")]
[SuppressGCTransition]
[RequiresUnsafe]
private static partial int IsLoggingInternal();

// Posts a custom notification for the attached debugger. If there is no
// debugger attached, has no effect. The debugger may or may not
// report the notification depending on its settings.
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "DebugDebugger_CustomNotification")]
[RequiresUnsafe]
private static partial void CustomNotification(ObjectHandleOnStack data);

// implementation of CORINFO_HELP_USER_BREAKPOINT
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.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -57,6 +58,7 @@ private void BuildStackFrame(int skipFrames, bool needFileInfo)
#pragma warning restore IDE0060

[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "StackFrame_GetMethodDescFromNativeIP")]
[RequiresUnsafe]
private static partial RuntimeMethodHandleInternal GetMethodDescFromNativeIP(IntPtr ip);

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ internal sealed class StackFrameHelper
#pragma warning restore 414

[UnsafeAccessor(UnsafeAccessorKind.Constructor)]
[RequiresUnsafe]
[return: UnsafeAccessorType("System.Diagnostics.StackTraceSymbols, System.Diagnostics.StackTrace, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
private static extern object CreateStackTraceSymbols();

[UnsafeAccessor(UnsafeAccessorKind.Method)]
[RequiresUnsafe]
private static extern void GetSourceLineInfo(
[UnsafeAccessorType("System.Diagnostics.StackTraceSymbols, System.Diagnostics.StackTrace, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")] object target,
Assembly? assembly, string assemblyPath, IntPtr loadedPeAddress,
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/System.Private.CoreLib/src/System/Enum.CoreCLR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.Numerics;
using System.Reflection;
using System.Runtime.CompilerServices;
Expand All @@ -12,6 +13,7 @@ namespace System
public abstract partial class Enum
{
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "Enum_GetValuesAndNames")]
[RequiresUnsafe]
private static partial void GetEnumValuesAndNames(QCallTypeHandle enumType, ObjectHandleOnStack values, ObjectHandleOnStack names, Interop.BOOL getNames);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public static extern int CurrentManagedThreadId
// Terminates this process with the given exit code.
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "Environment_Exit")]
[DoesNotReturn]
[RequiresUnsafe]
private static partial void _Exit(int exitCode);

[DoesNotReturn]
Expand Down Expand Up @@ -105,6 +106,7 @@ private static unsafe string[] InitializeCommandLineArgs(char* exePath, int argc
}

[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "Environment_GetProcessorCount")]
[RequiresUnsafe]
internal static partial int GetProcessorCount();

[UnmanagedCallersOnly]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ private IDictionary CreateDataContainer()
private static extern bool IsImmutableAgileException(Exception e);

[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "ExceptionNative_GetMethodFromStackTrace")]
[RequiresUnsafe]
private static partial void GetMethodFromStackTrace(ObjectHandleOnStack stackTrace, ObjectHandleOnStack method);

private MethodBase? GetExceptionMethodFromStackTrace()
Expand Down Expand Up @@ -215,6 +216,7 @@ internal static string GetMessageFromNativeResources(ExceptionMessageKind kind)
}

[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "ExceptionNative_GetMessageFromNativeResources")]
[RequiresUnsafe]
private static partial void GetMessageFromNativeResources(ExceptionMessageKind kind, StringHandleOnStack retMesg);

internal readonly struct DispatchState
Expand All @@ -238,6 +240,7 @@ public DispatchState(
}

[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "ExceptionNative_GetFrozenStackTrace")]
[RequiresUnsafe]
private static partial void GetFrozenStackTrace(ObjectHandleOnStack exception, ObjectHandleOnStack stackTrace);

internal DispatchState CaptureDispatchState()
Expand Down
Loading
Loading