From a5faa95e499d3d790739be71e5879a34c220e397 Mon Sep 17 00:00:00 2001 From: Maxim Lipnin Date: Tue, 22 Sep 2020 18:27:27 +0300 Subject: [PATCH] Mark some APIs throwing PNSE from runtime as unsupported on Browser (#42310) * Mark some APIs throwing PNSE from runtime as unsupported on Browser * Annotate APIs in coreclr part --- .../src/System.Private.CoreLib/src/System/Threading/Monitor.cs | 10 ++++++++-- .../src/System/Threading/Thread.CoreCLR.cs | 3 +++ .../System.Threading.Thread/ref/System.Threading.Thread.cs | 2 ++ src/libraries/System.Threading/ref/System.Threading.cs | 5 +++++ .../System.Private.CoreLib/src/System/Threading/Monitor.cs | 6 ++++++ .../System.Private.CoreLib/src/System/Threading/Thread.Mono.cs | 3 +++ 6 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Threading/Monitor.cs b/src/coreclr/src/System.Private.CoreLib/src/System/Threading/Monitor.cs index 80226ac..0665ac8 100644 --- a/src/coreclr/src/System.Private.CoreLib/src/System/Threading/Monitor.cs +++ b/src/coreclr/src/System.Private.CoreLib/src/System/Threading/Monitor.cs @@ -12,10 +12,11 @@ ** =============================================================================*/ -using System.Runtime.CompilerServices; using System.Diagnostics; -using System.Runtime.InteropServices; using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Runtime.Versioning; namespace System.Threading { @@ -170,6 +171,7 @@ namespace System.Threading [MethodImpl(MethodImplOptions.InternalCall)] private static extern bool ObjWait(bool exitContext, int millisecondsTimeout, object obj); + [UnsupportedOSPlatform("browser")] public static bool Wait(object obj, int millisecondsTimeout, bool exitContext) { if (obj == null) @@ -177,21 +179,25 @@ namespace System.Threading return ObjWait(exitContext, millisecondsTimeout, obj); } + [UnsupportedOSPlatform("browser")] public static bool Wait(object obj, TimeSpan timeout, bool exitContext) { return Wait(obj, MillisecondsTimeoutFromTimeSpan(timeout), exitContext); } + [UnsupportedOSPlatform("browser")] public static bool Wait(object obj, int millisecondsTimeout) { return Wait(obj, millisecondsTimeout, false); } + [UnsupportedOSPlatform("browser")] public static bool Wait(object obj, TimeSpan timeout) { return Wait(obj, MillisecondsTimeoutFromTimeSpan(timeout), false); } + [UnsupportedOSPlatform("browser")] public static bool Wait(object obj) { return Wait(obj, Timeout.Infinite, false); diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Threading/Thread.CoreCLR.cs b/src/coreclr/src/System.Private.CoreLib/src/System/Threading/Thread.CoreCLR.cs index 9edaf81..882ce21 100644 --- a/src/coreclr/src/System.Private.CoreLib/src/System/Threading/Thread.CoreCLR.cs +++ b/src/coreclr/src/System.Private.CoreLib/src/System/Threading/Thread.CoreCLR.cs @@ -6,6 +6,7 @@ using System.Globalization; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Serialization; +using System.Runtime.Versioning; namespace System.Threading { @@ -182,6 +183,7 @@ namespace System.Threading /// method on the IThreadable interface passed in the constructor. Once the /// thread is dead, it cannot be restarted with another call to Start. /// + [UnsupportedOSPlatform("browser")] public void Start(object? parameter) { // In the case of a null delegate (second call to start on same thread) @@ -196,6 +198,7 @@ namespace System.Threading Start(); } + [UnsupportedOSPlatform("browser")] public void Start() { #if FEATURE_COMINTEROP_APARTMENT_SUPPORT diff --git a/src/libraries/System.Threading.Thread/ref/System.Threading.Thread.cs b/src/libraries/System.Threading.Thread/ref/System.Threading.Thread.cs index bd511d1..479f7f5 100644 --- a/src/libraries/System.Threading.Thread/ref/System.Threading.Thread.cs +++ b/src/libraries/System.Threading.Thread/ref/System.Threading.Thread.cs @@ -89,7 +89,9 @@ namespace System.Threading public static void Sleep(int millisecondsTimeout) { } public static void Sleep(System.TimeSpan timeout) { } public static void SpinWait(int iterations) { } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public void Start() { } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public void Start(object? parameter) { } [System.ObsoleteAttribute("Thread.Suspend has been deprecated. Please use other classes in System.Threading, such as Monitor, Mutex, Event, and Semaphore, to synchronize Threads or protect resources. https://go.microsoft.com/fwlink/?linkid=14202", false)] public void Suspend() { } diff --git a/src/libraries/System.Threading/ref/System.Threading.cs b/src/libraries/System.Threading/ref/System.Threading.cs index d2f60ac..db8ef2c 100644 --- a/src/libraries/System.Threading/ref/System.Threading.cs +++ b/src/libraries/System.Threading/ref/System.Threading.cs @@ -280,10 +280,15 @@ namespace System.Threading public static void TryEnter(object obj, int millisecondsTimeout, ref bool lockTaken) { } public static bool TryEnter(object obj, System.TimeSpan timeout) { throw null; } public static void TryEnter(object obj, System.TimeSpan timeout, ref bool lockTaken) { } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public static bool Wait(object obj) { throw null; } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public static bool Wait(object obj, int millisecondsTimeout) { throw null; } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public static bool Wait(object obj, int millisecondsTimeout, bool exitContext) { throw null; } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public static bool Wait(object obj, System.TimeSpan timeout) { throw null; } + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("browser")] public static bool Wait(object obj, System.TimeSpan timeout, bool exitContext) { throw null; } } public sealed partial class Mutex : System.Threading.WaitHandle diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Threading/Monitor.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Threading/Monitor.cs index 6f6003d..62fa739 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Threading/Monitor.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Threading/Monitor.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Runtime.CompilerServices; +using System.Runtime.Versioning; namespace System.Threading { @@ -80,6 +81,7 @@ namespace System.Threading return IsEnteredNative(obj); } + [UnsupportedOSPlatform("browser")] public static bool Wait(object obj, int millisecondsTimeout, bool exitContext) { if (obj == null) @@ -87,12 +89,16 @@ namespace System.Threading return ObjWait(exitContext, millisecondsTimeout, obj); } + [UnsupportedOSPlatform("browser")] public static bool Wait(object obj, TimeSpan timeout, bool exitContext) => Wait(obj, MillisecondsTimeoutFromTimeSpan(timeout), exitContext); + [UnsupportedOSPlatform("browser")] public static bool Wait(object obj, int millisecondsTimeout) => Wait(obj, millisecondsTimeout, false); + [UnsupportedOSPlatform("browser")] public static bool Wait(object obj, TimeSpan timeout) => Wait(obj, MillisecondsTimeoutFromTimeSpan(timeout), false); + [UnsupportedOSPlatform("browser")] public static bool Wait(object obj) => Wait(obj, Timeout.Infinite, false); public static void Pulse(object obj) diff --git a/src/mono/netcore/System.Private.CoreLib/src/System/Threading/Thread.Mono.cs b/src/mono/netcore/System.Private.CoreLib/src/System/Threading/Thread.Mono.cs index bf6f7a3..47b26c9 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/System/Threading/Thread.Mono.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/System/Threading/Thread.Mono.cs @@ -5,6 +5,7 @@ using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +using System.Runtime.Versioning; namespace System.Threading { @@ -251,11 +252,13 @@ namespace System.Threading internal static void UninterruptibleSleep0() => SleepInternal(0, false); + [UnsupportedOSPlatform("browser")] public void Start() { StartInternal(this); } + [UnsupportedOSPlatform("browser")] public void Start(object parameter) { if (m_start is ThreadStart) -- 2.7.4