Skip to content

Commit 8a31e66

Browse files
authored
Annotate System.Diagnostics.Process APIs throwing PNSE on iOS/tvOS (#49354)
* Process.Start * Remove redundant annotations * Remove iOS since it's in the default list of supported platforms * Process.Kill * Make Process.Kill throw PNSE on iOS/tvOS * Annotate windows-related implementation of Kill method
1 parent 2d0fe49 commit 8a31e66

File tree

6 files changed

+49
-3
lines changed

6 files changed

+49
-3
lines changed

eng/versioning.targets

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,16 @@
3636
<CrossPlatformAndHasNoBrowserTarget>true</CrossPlatformAndHasNoBrowserTarget>
3737
</PropertyGroup>
3838

39-
<!-- Enables browser warnings for cross platform or Brwoser targeted builds -->
39+
<!-- Enables browser warnings for cross platform or Browser targeted builds -->
4040
<ItemGroup Condition="('$(TargetsBrowser)' == 'true' or '$(CrossPlatformAndHasNoBrowserTarget)' == 'true') and '$(IsTestProject)' != 'true'">
4141
<SupportedPlatform Include="browser"/>
4242
</ItemGroup>
4343

44+
<!-- Enables warnings for tvOS targeted builds -->
45+
<ItemGroup Condition="'$(TargetstvOS)' == 'true' and '$(IsTestProject)' != 'true'">
46+
<SupportedPlatform Include="tvos"/>
47+
</ItemGroup>
48+
4449
<ItemGroup>
4550
<_unsupportedOSPlatforms Include="$(UnsupportedOSPlatforms)" />
4651
</ItemGroup>

src/libraries/System.Diagnostics.Process/ref/System.Diagnostics.Process.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,29 @@ public static void EnterDebugMode() { }
108108
public static System.Diagnostics.Process[] GetProcesses(string machineName) { throw null; }
109109
public static System.Diagnostics.Process[] GetProcessesByName(string? processName) { throw null; }
110110
public static System.Diagnostics.Process[] GetProcessesByName(string? processName, string machineName) { throw null; }
111+
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")]
112+
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")]
111113
public void Kill() { }
114+
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")]
115+
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")]
112116
public void Kill(bool entireProcessTree) { }
113117
public static void LeaveDebugMode() { }
114118
protected void OnExited() { }
115119
public void Refresh() { }
120+
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")]
121+
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")]
116122
public bool Start() { throw null; }
123+
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")]
124+
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")]
117125
public static System.Diagnostics.Process? Start(System.Diagnostics.ProcessStartInfo startInfo) { throw null; }
126+
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")]
127+
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")]
118128
public static System.Diagnostics.Process Start(string fileName) { throw null; }
129+
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")]
130+
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")]
119131
public static System.Diagnostics.Process Start(string fileName, string arguments) { throw null; }
132+
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")]
133+
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")]
120134
public static System.Diagnostics.Process Start(string fileName, System.Collections.Generic.IEnumerable<string> arguments) { throw null; }
121135
[System.CLSCompliantAttribute(false)]
122136
[System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")]

src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.NonUap.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33

44
using System.Collections.Generic;
55
using System.ComponentModel;
6+
using System.Runtime.Versioning;
67

78
namespace System.Diagnostics
89
{
910
public partial class Process : IDisposable
1011
{
12+
[UnsupportedOSPlatform("ios")]
13+
[UnsupportedOSPlatform("tvos")]
1114
public void Kill(bool entireProcessTree)
1215
{
1316
if (!entireProcessTree)

src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Unix.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,15 @@ public static Process Start(string fileName, string arguments, string userName,
5454
}
5555

5656
/// <summary>Terminates the associated process immediately.</summary>
57+
[UnsupportedOSPlatform("ios")]
58+
[UnsupportedOSPlatform("tvos")]
5759
public void Kill()
5860
{
61+
if (OperatingSystem.IsIOS() || OperatingSystem.IsTvOS())
62+
{
63+
throw new PlatformNotSupportedException();
64+
}
65+
5966
EnsureState(State.HaveId);
6067

6168
// Check if we know the process has exited. This avoids us targetting another
@@ -345,6 +352,11 @@ private SafeProcessHandle GetProcessHandle()
345352
/// <param name="startInfo">The start info with which to start the process.</param>
346353
private bool StartCore(ProcessStartInfo startInfo)
347354
{
355+
if (OperatingSystem.IsIOS() || OperatingSystem.IsTvOS())
356+
{
357+
throw new PlatformNotSupportedException();
358+
}
359+
348360
EnsureInitialized();
349361

350362
string? filename;

src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Windows.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ public static void LeaveDebugMode()
8989
}
9090

9191
/// <summary>Terminates the associated process immediately.</summary>
92+
[UnsupportedOSPlatform("ios")]
93+
[UnsupportedOSPlatform("tvos")]
9294
public void Kill()
9395
{
9496
using (SafeProcessHandle handle = GetProcessHandle(Interop.Advapi32.ProcessOptions.PROCESS_TERMINATE | Interop.Advapi32.ProcessOptions.PROCESS_QUERY_LIMITED_INFORMATION, throwIfExited: false))

src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using Microsoft.Win32.SafeHandles;
5+
using System.Collections.Generic;
56
using System.Collections.ObjectModel;
67
using System.ComponentModel;
78
using System.Globalization;
89
using System.IO;
910
using System.Runtime.Serialization;
11+
using System.Runtime.Versioning;
1012
using System.Text;
1113
using System.Threading;
1214
using System.Threading.Tasks;
13-
using System.Runtime.Versioning;
14-
using System.Collections.Generic;
1515

1616
namespace System.Diagnostics
1717
{
@@ -1197,6 +1197,8 @@ private void SetProcessId(int processId)
11971197
/// component.
11981198
/// </para>
11991199
/// </devdoc>
1200+
[UnsupportedOSPlatform("ios")]
1201+
[UnsupportedOSPlatform("tvos")]
12001202
public bool Start()
12011203
{
12021204
Close();
@@ -1238,6 +1240,8 @@ public bool Start()
12381240
/// component.
12391241
/// </para>
12401242
/// </devdoc>
1243+
[UnsupportedOSPlatform("ios")]
1244+
[UnsupportedOSPlatform("tvos")]
12411245
public static Process Start(string fileName)
12421246
{
12431247
// the underlying Start method can only return null on Windows platforms,
@@ -1254,6 +1258,8 @@ public static Process Start(string fileName)
12541258
/// component.
12551259
/// </para>
12561260
/// </devdoc>
1261+
[UnsupportedOSPlatform("ios")]
1262+
[UnsupportedOSPlatform("tvos")]
12571263
public static Process Start(string fileName, string arguments)
12581264
{
12591265
// the underlying Start method can only return null on Windows platforms,
@@ -1265,6 +1271,8 @@ public static Process Start(string fileName, string arguments)
12651271
/// <summary>
12661272
/// Starts a process resource by specifying the name of an application and a set of command line arguments
12671273
/// </summary>
1274+
[UnsupportedOSPlatform("ios")]
1275+
[UnsupportedOSPlatform("tvos")]
12681276
public static Process Start(string fileName, IEnumerable<string> arguments)
12691277
{
12701278
if (fileName == null)
@@ -1289,6 +1297,8 @@ public static Process Start(string fileName, IEnumerable<string> arguments)
12891297
/// component.
12901298
/// </para>
12911299
/// </devdoc>
1300+
[UnsupportedOSPlatform("ios")]
1301+
[UnsupportedOSPlatform("tvos")]
12921302
public static Process? Start(ProcessStartInfo startInfo)
12931303
{
12941304
Process process = new Process();

0 commit comments

Comments
 (0)