runtime: Mark APIs as unsupported on Browser WASM
We can use UnsupportedOSPlatformAttribute("browser") attribute to mark unsupported APIs on Browser WASM so that the analyzer can provide warnings when developers accidentally call platform-specific APIs.
Spec: https://github.com/dotnet/designs/pull/144
We use the scanner (https://github.com/dotnet/platform-compat) to gather the list of all the APIs throwing PNSE on Browser WASM at the moment. Below is the file containing ~4500 PNSE methods. pnse-17082020.txt
There can be some special cases:
- APIs can be Windows-specific
- APIs might throw PNSE for all platforms
- APIs might not be considered to be marked (e.g. APIs are not meant to be directly called by user code)
- other cases?
Namespaces (L# in file above)
- Microsoft.VisualBasic L2-L45 (marked as Windows-specific)
- System.Security.AccessControl L46-65 (marked as Windows-specific)
- Microsoft.Win32.Registry L66-106 (marked as Windows-specific)
- System.Collections L107-L110 (
https://github.com/dotnet/runtime/pull/41085) serialization-related infrastructure - System.Collections.Specialize L111-L114 (
https://github.com/dotnet/runtime/pull/41085) serialization-related infrastructure - System.ComponentModel L115-L120 (https://github.com/dotnet/runtime/pull/41094) backport https://github.com/dotnet/runtime/pull/41967
- System.Console L121-L172 (https://github.com/dotnet/runtime/pull/41184) backport https://github.com/dotnet/runtime/pull/41967
- System.Data.Common L173-L178 (
https://github.com/dotnet/runtime/pull/41263) false-positive, obsolete, serialization related - System.Data.Odbc (https://github.com/dotnet/runtime/pull/40612) No backport necessary
- System.Diagnostics.FileVersionInfo L179-L207 (https://github.com/dotnet/runtime/pull/41271) backport https://github.com/dotnet/runtime/pull/41967
- System.Diagnostics.Process L208-L388 (https://github.com/dotnet/runtime/pull/41694) backport https://github.com/dotnet/runtime/pull/41967
- System.Diagnostics.TextWriterTraceListener L389-L393 (
https://github.com/dotnet/runtime/pull/41327) False Positive - System.DirectoryServices.Protocols (https://github.com/dotnet/runtime/pull/40612) No backport necessary
- System.Drawing.Common (https://github.com/dotnet/runtime/pull/40612) No backport necessary
- System.IO.Compression L394-429 (https://github.com/dotnet/runtime/pull/41683) backport https://github.com/dotnet/runtime/pull/41967
- System.IO.FileSystem.AccessControl L430-L489 (marked as Windows-specific)
- System.IO.FileSystem L490-L495 (marked as Windows-specific)
- System.IO.FileSystem.DriveInfo L496-L497 (
https://github.com/dotnet/runtime/pull/41328) - System.IO.FileSystem.Watcher L498-L547 (https://github.com/dotnet/runtime/pull/41682) backport https://github.com/dotnet/runtime/pull/41967
- System.IO.IsolatedStorage L548-L647 (https://github.com/dotnet/runtime/pull/41700) backport https://github.com/dotnet/runtime/pull/41967
- System.IO.MemoryMappedFiles L648-L662 (
https://github.com/dotnet/runtime/pull/41971) false-positive - System.IO.Pipes L663-L778 (https://github.com/dotnet/runtime/pull/41976) backport https://github.com/dotnet/runtime/pull/42267
- System.IO.Ports (https://github.com/dotnet/runtime/pull/40612) No backport necessary
- System.Linq.Expressions L779 (marked as obsolete)
- System.Linq.Queryable L780-L782 (
https://github.com/dotnet/runtime/pull/41330) False Positive - System.Net.Connections L783 (the namespace is being removed; see PRs 41648 and 42099)
- System.Net.Http L784-L872 (https://github.com/dotnet/runtime/pull/42074) backport https://github.com/dotnet/runtime/pull/42267
- System.Net.HttpListener L873-L883 (https://github.com/dotnet/runtime/pull/42063) backport https://github.com/dotnet/runtime/pull/42267
- System.Net.Mail L884-L1083 (https://github.com/dotnet/runtime/pull/40924) backport https://github.com/dotnet/runtime/pull/41967
- System.Net.NameResolution L1084-L1109 (https://github.com/dotnet/runtime/pull/41985) backport https://github.com/dotnet/runtime/pull/41967
- System.Net.NetworkInformation L1110-L1208 (https://github.com/dotnet/runtime/pull/40924) backport https://github.com/dotnet/runtime/pull/41967
- System.Net.Ping L1209-L1250 (https://github.com/dotnet/runtime/pull/40924) backport https://github.com/dotnet/runtime/pull/41967
- System.Net.Primitives L1251-L1255 (
https://github.com/dotnet/runtime/pull/41987) false-positive - System.Net.Requests L1256-L1600 (https://github.com/dotnet/runtime/pull/40924) backport https://github.com/dotnet/runtime/pull/41967
- System.Net.Security L1601-L1828 (https://github.com/dotnet/runtime/pull/40924) backport https://github.com/dotnet/runtime/pull/41967
- System.Net.Sockets L1829-L2240 (https://github.com/dotnet/runtime/pull/40924) backport https://github.com/dotnet/runtime/pull/41967
- System.Net.Webclient L2241-L2374 (https://github.com/dotnet/runtime/pull/40924) backport https://github.com/dotnet/runtime/pull/41967
- System.Net.WebHeaderCollection L2375-L2377 Serialization Infrastructure
- System.Net.WebProxy L2378-L2383 obsolete/all platforms/serialization-related infrastructure
- System.Net.WebSockets.Client L2384-L2400 (https://github.com/dotnet/runtime/pull/41963) backport https://github.com/dotnet/runtime/pull/41967
- System.Net.WebSockets L2401 PNSE everywhere
- System.Runtime L2402-L2424, L2445-L2467 (
https://github.com/dotnet/runtime/pull/42030) False-positives/PNSE all mono/windows only - System.Utf8String.Experimental L2425-L2444, L2507-L2523 likely false positive
- System.Threading.Thread L2468-L2474, L2497 (
https://github.com/dotnet/runtime/pull/41892) - System.Threading.ThreadPool L2475-L2484, L2490 (https://github.com/dotnet/runtime/pull/41891) backport https://github.com/dotnet/runtime/pull/41967
- System.Threading L2485-L2489, L2496, L2498-L2499 (
https://github.com/dotnet/runtime/pull/41888) - System.Threading.Overlapped L2491-L2495 (
https://github.com/dotnet/runtime/pull/41884) windows-specific - System.Private.CoreLib L2500-L2506, L2524-L2600 False-positives/Serialization-related/PNSE all platforms
- System.Runtime.Serialization.Xml L2601-L2617 (all platforms)
- System.Private.Xml L2618 false-positive
- System.Private.Xml.Linq L2619 serialization-related infrastructure
- System.Reflection.DispatchProxy L2620 false-positive (DispatchProxyTests.cs tests pass)
- System.Resources.Writer L2621-L2623 false-positives (ResourceWriterUnitTest.cs passes)
- System.Runtime.InteropServices L2624-L2625 (windows-specific), 2626-2628 (all platforms)
- System.Runtime.Serialization.Formatters L2629-L2630 obsolete
- System.Security.AccessControl L2631-L2909 windows-specific
- System.Security.Claims L2910-2915 (all platforms)
- System.Secuirty.Cryptography L2916-L3464 (https://github.com/dotnet/runtime/pull/42010) backport https://github.com/dotnet/runtime/pull/42267
- System.Security.Cryptography.Cng L3465-L3716 windows-specific
- System.Security.Cryptography.Csp L3717-L3895 (https://github.com/dotnet/runtime/pull/40612) No backport necessary
- System.Security.Cryptography.Encoding L3896-L3974 (https://github.com/dotnet/runtime/pull/40612) No backport necessary
- System.Security.Cryptography.OpenSsl L3975-L4034(https://github.com/dotnet/runtime/pull/40612) No backport necessary
- System.Security.Cryptography.Pkcs (https://github.com/dotnet/runtime/pull/40612) No backport necessary
- System.Security.Cryptography.Primitives L4035-L4045(https://github.com/dotnet/runtime/pull/40612) No backport necessary
- System.Security.Cryptography.X509Certificates L4046-4375(https://github.com/dotnet/runtime/pull/40612) No backport necessary
- System.Security.Cryptography.Xml (https://github.com/dotnet/runtime/pull/40612) No backport necessary
- System.Security.Principal.Windows L4376-L4471 windows-specific
- System.Text.Encodings.Web L4472 Looks like a false-positive
- System.Text.Json L4473-L4494 Looks like false-positives
- System.Text.RegularExpressions L4495-L4499 Looks like false-positives
- System.Transactions.Local L4500-4509 (
https://github.com/dotnet/runtime/pull/42027) PNSE all platforms
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 15 (11 by maintainers)
All the namespaces mentioned in this issue are covered so I’m closing it as completed
I see, in that case, the closest approximation would be to read System.Reflection.AssemblyFileVersionAttribute from the assembly.
It looks like the exception scanner doesn’t gather PNSEs thrown from runtime, e.g. something that uses
mono_error_set_platform_not_supportedmethod. At least, I don’t see appropriate APIs in the result file attached to the PR’s description. In case of Browser, an example of such API could be Thread.Start() which invokesStartInternal -> ves_icall_System_Threading_Thread_StartInternal -> mono_error_set_platform_not_supported.This is what we have been doing so far.
I’ve been encountering similar stuff with https://github.com/dotnet/runtime/pull/41209, where we’re trying to get the runtime repo ready to receive the analyzer. We don’t yet have a solid strategy for this scenario.