diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS deleted file mode 100644 index 9a575e24093..00000000000 --- a/.github/CODEOWNERS +++ /dev/null @@ -1,117 +0,0 @@ -# Users referenced in this file will automatically be requested as reviewers for PRs that modify the given paths. -# See https://help.github.com/articles/about-code-owners/ - -/src/libraries/Common/src/System/Net/Http/aspnetcore/ @dotnet/http -/src/libraries/Common/tests/Tests/System/Net/aspnetcore/ @dotnet/http - -# CoreCLR Code Owners - -/src/coreclr/inc/corinfo.h @dotnet/jit-contrib -/src/coreclr/inc/corjit.h @dotnet/jit-contrib -/src/coreclr/jit/ @dotnet/jit-contrib -/src/coreclr/interpreter/ @brzvlad @janvorli @kg -/src/coreclr/vm/interpexec* @brzvlad @janvorli @kg -/src/coreclr/nativeaot @MichalStrehovsky -/src/coreclr/tools/Common @dotnet/crossgen-contrib @MichalStrehovsky -/src/coreclr/tools/aot @dotnet/crossgen-contrib -/src/coreclr/tools/aot/ILCompiler.Compiler @MichalStrehovsky -/src/coreclr/tools/aot/ILCompiler.RyuJit @MichalStrehovsky -/src/coreclr/tools/aot/ILCompiler.MetadataTransform @MichalStrehovsky - -# Mono Code Owners - -/src/mono @steveisok @vitek-karas - -/src/mono/llvm @steveisok @vitek-karas - -/src/mono/mono/arch @steveisok @vitek-karas -/src/mono/mono/eglib @steveisok @vitek-karas - -/src/mono/mono/metadata @thaystg @steveisok @vitek-karas -/src/mono/mono/metadata/*-win* @lateralusX @steveisok -/src/mono/mono/metadata/handle* @steveisok @vitek-karas -/src/mono/mono/metadata/monitor* @brzvlad @steveisok @vitek-karas -/src/mono/mono/metadata/sgen* @brzvlad @steveisok @vitek-karas -/src/mono/mono/metadata/thread* @lateralusX @steveisok @vitek-karas -/src/mono/mono/metadata/w32* @lateralusX @steveisok @vitek-karas - -/src/mono/mono/eventpipe @lateralusX @steveisok @vitek-karas - -/src/mono/mono/mini @steveisok @vitek-karas -/src/mono/mono/mini/*cfgdump* @steveisok @vitek-karas -/src/mono/mono/mini/*exceptions* @BrzVlad @steveisok @vitek-karas -/src/mono/mono/mini/*llvm* @steveisok @vitek-karas -/src/mono/mono/mini/*ppc* @steveisok @vitek-karas -/src/mono/mono/mini/*profiler* @BrzVlad @steveisok @vitek-karas -/src/mono/mono/mini/*riscv* @steveisok @vitek-karas -/src/mono/mono/mini/*type-check* @steveisok @vitek-karas -/src/mono/mono/mini/debugger-agent.c @thaystg @steveisok @vitek-karas -/src/mono/mono/mini/interp/* @BrzVlad @kotlarmilos @steveisok @vitek-karas -/src/mono/mono/mini/interp/*jiterp* @kg @steveisok @vitek-karas -/src/mono/mono/mini/*simd* @steveisok @vitek-karas - -/src/mono/mono/profiler @BrzVlad @steveisok @vitek-karas -/src/mono/mono/sgen @BrzVlad @steveisok @vitek-karas - -/src/mono/mono/utils @steveisok @vitek-karas -/src/mono/mono/utils/*-win* @lateralusX @steveisok @vitek-karas -/src/mono/mono/utils/atomic* @steveisok @vitek-karas -/src/mono/mono/utils/mono-hwcap* @steveisok @vitek-karas -/src/mono/mono/utils/mono-mem* @steveisok @vitek-karas -/src/mono/mono/utils/mono-threads* @steveisok @vitek-karas - -/src/mono/dlls @thaystg @steveisok @vitek-karas - -/src/native/public/mono @steveisok @vitek-karas -/src/native/eventpipe @noahfalk @lateralusX @mdh1418 -/src/native/external/libunwind @janvorli @AaronRobinsonMSFT @dotnet/dotnet-diag -/src/native/external/libunwind_extras @janvorli @AaronRobinsonMSFT @dotnet/dotnet-diag - -/src/libraries/sendtohelix-browser.targets @akoeplinger -/src/libraries/sendtohelix-wasm.targets @akoeplinger -/src/libraries/sendtohelix-wasi.targets @akoeplinger -/src/mono/browser @lewing @pavelsavara -/src/mono/wasi @lewing @pavelsavara -/src/mono/wasm @lewing @pavelsavara -/src/mono/browser/debugger @thaystg @ilonatommy -/src/mono/wasm/build @maraf @akoeplinger -/src/mono/wasi/build @maraf @akoeplinger -/src/mono/browser/build @maraf @akoeplinger -/src/mono/sample/wasm @lewing @pavelsavara -/src/mono/sample/wasi @lewing @pavelsavara -/src/libraries/System.Runtime.InteropServices.JavaScript @lewing @pavelsavara - -/src/mono/nuget/*WebAssembly*/ @lewing @akoeplinger -/src/mono/nuget/*MonoTargets*/ @lewing @akoeplinger -/src/mono/nuget/*BrowserDebugHost*/ @lewing @akoeplinger -/src/mono/nuget/*Workload.Mono.Toolchain*/ @lewing @akoeplinger -/src/mono/nuget/*MonoAOTCompiler*/ @lewing @akoeplinger - -/src/mono/wasm/Wasm* @maraf @ilonatommy -/src/mono/wasm/testassets @maraf @ilonatommy -/src/mono/wasi/testassets @maraf @ilonatommy -/src/tasks/WasmAppBuilder/ @maraf @akoeplinger -/src/tasks/WorkloadBuildTasks/ @akoeplinger -/src/tasks/AotCompilerTask/ @akoeplinger -/src/tasks/WasmBuildTasks/ @maraf @akoeplinger - -/eng/pipelines/**/*wasm* @akoeplinger - -# ILLink codeowners -/src/tools/illink/ @marek-safar -/src/tools/illink/src/analyzer/ @radekdoulik -/src/tools/illink/src/ILLink.Tasks/ @sbomer -/src/tools/illink/src/ILLink.RoslynAnalyzer/ @sbomer -/src/tools/illink/src/linker/ @marek-safar @mrvoorhe -/src/tools/illink/test/ @marek-safar @mrvoorhe - -# Obsoletions / Custom Diagnostics - -/docs/project/list-of-diagnostics.md @jeffhandley -/src/libraries/Common/src/System/Obsoletions.cs @jeffhandley - -# Area ownership and repo automation -/docs/area-owners.* @jeffhandley -/docs/issue*.md @jeffhandley -/.github/policies/ @jeffhandley @mkArtakMSFT -/.github/workflows/ @jeffhandley @dotnet/runtime-infrastructure diff --git a/Directory.Build.props b/Directory.Build.props index 99eee260233..b082475fb5e 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -229,7 +229,7 @@ - runtime + runtimelab https://github.com/dotnet/$(GitHubRepositoryName) https://dot.net microsoft,dotnetframework diff --git a/eng/Versions.props b/eng/Versions.props index 28f6b0c3ea4..cabfa3d622d 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -12,7 +12,7 @@ 8.0.$([MSBuild]::Add($([System.Version]::Parse('$(PackageVersionNet9)').Build),11)) 7.0.20 6.0.36 - rc + unsafe 1 false diff --git a/src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj b/src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj index c12d6c854ac..d7ac59703f4 100644 --- a/src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj +++ b/src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj @@ -22,6 +22,7 @@ true true true + true diff --git a/src/libraries/Directory.Build.props b/src/libraries/Directory.Build.props index 33938989e38..1c0841e0fe9 100644 --- a/src/libraries/Directory.Build.props +++ b/src/libraries/Directory.Build.props @@ -50,6 +50,7 @@ annotations true + true diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems index d3b69efe615..a312398fab0 100644 --- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems +++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems @@ -286,6 +286,7 @@ + diff --git a/src/libraries/System.Private.CoreLib/src/System/Buffers/SharedArrayPool.cs b/src/libraries/System.Private.CoreLib/src/System/Buffers/SharedArrayPool.cs index ad4488005da..da600c91337 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Buffers/SharedArrayPool.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Buffers/SharedArrayPool.cs @@ -60,7 +60,10 @@ public override T[] Rent(int minimumLength) SharedArrayPoolThreadLocalArray[]? tlsBuckets = t_tlsBuckets; if (tlsBuckets is not null && (uint)bucketIndex < (uint)tlsBuckets.Length) { - buffer = Unsafe.As(tlsBuckets[bucketIndex].Array); + unsafe + { + buffer = Unsafe.As(tlsBuckets[bucketIndex].Array); + } if (buffer is not null) { tlsBuckets[bucketIndex].Array = null; @@ -79,7 +82,10 @@ public override T[] Rent(int minimumLength) SharedArrayPoolPartitions? b = perCoreBuckets[bucketIndex]; if (b is not null) { - buffer = Unsafe.As(b.TryPop()); + unsafe + { + buffer = Unsafe.As(b.TryPop()); + } if (buffer is not null) { if (log.IsEnabled()) diff --git a/src/libraries/System.Private.CoreLib/src/System/Delegate.cs b/src/libraries/System.Private.CoreLib/src/System/Delegate.cs index 6efa9f48554..6ba2252a52b 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Delegate.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Delegate.cs @@ -128,9 +128,15 @@ public TDelegate Current public bool MoveNext() { int index = _index + 1; - if ((_current = Unsafe.As(_delegate?.TryGetAt(index))) == null) + unsafe { - return false; + unsafe + { + if ((_current = Unsafe.As(_delegate?.TryGetAt(index))) == null) + { + return false; + } + } } _index = index; return true; diff --git a/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/RequiresUnsafeAttribute.cs b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/RequiresUnsafeAttribute.cs new file mode 100644 index 00000000000..1b30230d95c --- /dev/null +++ b/src/libraries/System.Private.CoreLib/src/System/Diagnostics/CodeAnalysis/RequiresUnsafeAttribute.cs @@ -0,0 +1,18 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace System.Diagnostics.CodeAnalysis +{ + /// + /// Indicates that the specified method requires dynamic access to code that is not referenced + /// statically, for example through . + /// + /// + /// This allows tools to understand which methods are unsafe to call when removing unreferenced + /// code from an application. + /// + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor, Inherited = false)] + internal sealed class RequiresUnsafeAttribute : Attribute + { + } +} diff --git a/src/libraries/System.Private.CoreLib/src/System/Memory.cs b/src/libraries/System.Private.CoreLib/src/System/Memory.cs index c8eac110cb5..b37ef4260a6 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Memory.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Memory.cs @@ -284,8 +284,11 @@ public Span Span { // Special-case string since it's the most common for ROM. - refToReturn = ref Unsafe.As(ref ((string)tmpObject).GetRawStringData()); - lengthOfUnderlyingSpan = Unsafe.As(tmpObject).Length; + unsafe + { + refToReturn = ref Unsafe.As(ref ((string)tmpObject).GetRawStringData()); + lengthOfUnderlyingSpan = Unsafe.As(tmpObject).Length; + } } else if (RuntimeHelpers.ObjectHasComponentSize(tmpObject)) { @@ -379,6 +382,11 @@ public Span Span /// /// An instance with nonprimitive (non-blittable) members cannot be pinned. /// + /// + /// To use this method safely, the target must not be torn while the + /// returned is in use. + /// + [RequiresUnsafe] public unsafe MemoryHandle Pin() { // Just like the Span property getter, we have special support for a mutable Memory diff --git a/src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.cs b/src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.cs index 9687896e6fc..8ead6e27e16 100644 --- a/src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.cs +++ b/src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.cs @@ -5905,7 +5905,10 @@ internal SpanSplitEnumerator(ReadOnlySpan source, ReadOnlySpan separators) _source = source; if (typeof(T) == typeof(char) && separators.Length == 0) { - _searchValues = Unsafe.As>(string.SearchValuesStorage.WhiteSpaceChars); + unsafe + { + _searchValues = Unsafe.As>(string.SearchValuesStorage.WhiteSpaceChars); + } _splitMode = SpanSplitEnumeratorMode.SearchValues; } else diff --git a/src/libraries/System.Private.CoreLib/src/System/ReadOnlyMemory.cs b/src/libraries/System.Private.CoreLib/src/System/ReadOnlyMemory.cs index 85e4feace8c..abbba4c3969 100644 --- a/src/libraries/System.Private.CoreLib/src/System/ReadOnlyMemory.cs +++ b/src/libraries/System.Private.CoreLib/src/System/ReadOnlyMemory.cs @@ -206,8 +206,11 @@ public ReadOnlySpan Span { // Special-case string since it's the most common for ROM. - refToReturn = ref Unsafe.As(ref ((string)tmpObject).GetRawStringData()); - lengthOfUnderlyingSpan = Unsafe.As(tmpObject).Length; + unsafe + { + refToReturn = ref Unsafe.As(ref ((string)tmpObject).GetRawStringData()); + lengthOfUnderlyingSpan = Unsafe.As(tmpObject).Length; + } } else if (RuntimeHelpers.ObjectHasComponentSize(tmpObject)) { @@ -223,8 +226,11 @@ public ReadOnlySpan Span // 'tmpObject is T[]' below also handles things like int[] <-> uint[] being convertible Debug.Assert(tmpObject is T[]); - refToReturn = ref MemoryMarshal.GetArrayDataReference(Unsafe.As(tmpObject)); - lengthOfUnderlyingSpan = Unsafe.As(tmpObject).Length; + unsafe + { + refToReturn = ref MemoryMarshal.GetArrayDataReference(Unsafe.As(tmpObject)); + lengthOfUnderlyingSpan = Unsafe.As(tmpObject).Length; + } } else { @@ -235,9 +241,12 @@ public ReadOnlySpan Span // constructor or other public API which would allow such a conversion. Debug.Assert(tmpObject is MemoryManager); - Span memoryManagerSpan = Unsafe.As>(tmpObject).GetSpan(); - refToReturn = ref MemoryMarshal.GetReference(memoryManagerSpan); - lengthOfUnderlyingSpan = memoryManagerSpan.Length; + unsafe + { + Span memoryManagerSpan = Unsafe.As>(tmpObject).GetSpan(); + refToReturn = ref MemoryMarshal.GetReference(memoryManagerSpan); + lengthOfUnderlyingSpan = memoryManagerSpan.Length; + } } // If the Memory or ReadOnlyMemory instance is torn, this property getter has undefined behavior. diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/ConditionalWeakTable.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/ConditionalWeakTable.cs index bdbb94609cd..044f8647baa 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/ConditionalWeakTable.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/ConditionalWeakTable.cs @@ -711,7 +711,10 @@ internal bool Remove(TKey key, [MaybeNullWhen(false)] out TValue value) if (entryIndex != -1) { RemoveIndex(entryIndex); - value = Unsafe.As(valueObject!); + unsafe + { + value = Unsafe.As(valueObject!); + } return true; } diff --git a/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/Unsafe.cs b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/Unsafe.cs index 154cd64a421..09e39599450 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/Unsafe.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/Unsafe.cs @@ -63,6 +63,7 @@ public static int SizeOf() // Mono:As [NonVersionable] [MethodImpl(MethodImplOptions.AggressiveInlining)] + [RequiresUnsafe] [return: NotNullIfNotNull(nameof(o))] public static T? As(object? o) where T : class? { diff --git a/src/libraries/System.Private.CoreLib/src/System/SearchValues/Strings/AsciiStringSearchValuesTeddyBase.cs b/src/libraries/System.Private.CoreLib/src/System/SearchValues/Strings/AsciiStringSearchValuesTeddyBase.cs index b764e3a22d8..2cb026919f9 100644 --- a/src/libraries/System.Private.CoreLib/src/System/SearchValues/Strings/AsciiStringSearchValuesTeddyBase.cs +++ b/src/libraries/System.Private.CoreLib/src/System/SearchValues/Strings/AsciiStringSearchValuesTeddyBase.cs @@ -560,11 +560,14 @@ private bool TryFindMatch(ReadOnlySpan span, ref char searchSpace, Vector1 object? bucket = _buckets[candidateOffset]; Debug.Assert(bucket is not null); - if (TBucketized.Value - ? StartsWith(ref matchRef, lengthRemaining, Unsafe.As(bucket)) - : StartsWith(ref matchRef, lengthRemaining, Unsafe.As(bucket))) + unsafe { - return true; + if (TBucketized.Value + ? StartsWith(ref matchRef, lengthRemaining, Unsafe.As(bucket)) + : StartsWith(ref matchRef, lengthRemaining, Unsafe.As(bucket))) + { + return true; + } } candidateMask = BitOperations.ResetLowestSetBit(candidateMask); @@ -605,11 +608,14 @@ private bool TryFindMatch(ReadOnlySpan span, ref char searchSpace, Vector2 object? bucket = _buckets[candidateOffset]; Debug.Assert(bucket is not null); - if (TBucketized.Value - ? StartsWith(ref matchRef, lengthRemaining, Unsafe.As(bucket)) - : StartsWith(ref matchRef, lengthRemaining, Unsafe.As(bucket))) + unsafe { - return true; + if (TBucketized.Value + ? StartsWith(ref matchRef, lengthRemaining, Unsafe.As(bucket)) + : StartsWith(ref matchRef, lengthRemaining, Unsafe.As(bucket))) + { + return true; + } } candidateMask = BitOperations.ResetLowestSetBit(candidateMask); @@ -650,11 +656,14 @@ private bool TryFindMatch(ReadOnlySpan span, ref char searchSpace, Vector5 object? bucket = _buckets[candidateOffset]; Debug.Assert(bucket is not null); - if (TBucketized.Value - ? StartsWith(ref matchRef, lengthRemaining, Unsafe.As(bucket)) - : StartsWith(ref matchRef, lengthRemaining, Unsafe.As(bucket))) + unsafe { - return true; + if (TBucketized.Value + ? StartsWith(ref matchRef, lengthRemaining, Unsafe.As(bucket)) + : StartsWith(ref matchRef, lengthRemaining, Unsafe.As(bucket))) + { + return true; + } } candidateMask = BitOperations.ResetLowestSetBit(candidateMask); diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs index 1cd3b2e3b54..70e778010cd 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs @@ -6743,7 +6743,10 @@ private static Task WhenAny(IEnumerable tasks) where TTask // since if argument was strongly-typed as an array, it would have bound to the array-based overload. if (tasks.GetType() == typeof(List)) { - return WhenAnyCore((ReadOnlySpan)CollectionsMarshal.AsSpan(Unsafe.As>(tasks))); + unsafe + { + return WhenAnyCore((ReadOnlySpan)CollectionsMarshal.AsSpan(Unsafe.As>(tasks))); + } } if (tasks is TTask[] tasksAsArray) { diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/ValueTask.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/ValueTask.cs index 90f86c68159..5de25750326 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/ValueTask.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Tasks/ValueTask.cs @@ -762,7 +762,10 @@ public bool IsFaulted return t.IsFaulted; } - return Unsafe.As>(obj).GetStatus(_token) == ValueTaskSourceStatus.Faulted; + unsafe + { + return Unsafe.As>(obj).GetStatus(_token) == ValueTaskSourceStatus.Faulted; + } } } @@ -789,7 +792,10 @@ public bool IsCanceled return t.IsCanceled; } - return Unsafe.As>(obj).GetStatus(_token) == ValueTaskSourceStatus.Canceled; + unsafe + { + return Unsafe.As>(obj).GetStatus(_token) == ValueTaskSourceStatus.Canceled; + } } } @@ -814,7 +820,10 @@ public TResult Result return t.ResultOnSuccess; } - return Unsafe.As>(obj).GetResult(_token); + unsafe + { + return Unsafe.As>(obj).GetResult(_token); + } } } diff --git a/src/tools/illink/src/ILLink.RoslynAnalyzer/build/Microsoft.NET.ILLink.Analyzers.props b/src/tools/illink/src/ILLink.RoslynAnalyzer/build/Microsoft.NET.ILLink.Analyzers.props index 18ae6cb8fd5..e8a5e17d0c5 100644 --- a/src/tools/illink/src/ILLink.RoslynAnalyzer/build/Microsoft.NET.ILLink.Analyzers.props +++ b/src/tools/illink/src/ILLink.RoslynAnalyzer/build/Microsoft.NET.ILLink.Analyzers.props @@ -3,6 +3,7 @@ +