Skip to content

Commit

Permalink
Annotate System.Diagnostics.Process APIs throwing PNSE on iOS/tvOS (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
MaximLipnin authored Mar 17, 2021
1 parent 2d0fe49 commit 8a31e66
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 3 deletions.
7 changes: 6 additions & 1 deletion eng/versioning.targets
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,16 @@
<CrossPlatformAndHasNoBrowserTarget>true</CrossPlatformAndHasNoBrowserTarget>
</PropertyGroup>

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

<!-- Enables warnings for tvOS targeted builds -->
<ItemGroup Condition="'$(TargetstvOS)' == 'true' and '$(IsTestProject)' != 'true'">
<SupportedPlatform Include="tvos"/>
</ItemGroup>

<ItemGroup>
<_unsupportedOSPlatforms Include="$(UnsupportedOSPlatforms)" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,29 @@ public static void EnterDebugMode() { }
public static System.Diagnostics.Process[] GetProcesses(string machineName) { throw null; }
public static System.Diagnostics.Process[] GetProcessesByName(string? processName) { throw null; }
public static System.Diagnostics.Process[] GetProcessesByName(string? processName, string machineName) { throw null; }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")]
public void Kill() { }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")]
public void Kill(bool entireProcessTree) { }
public static void LeaveDebugMode() { }
protected void OnExited() { }
public void Refresh() { }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")]
public bool Start() { throw null; }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")]
public static System.Diagnostics.Process? Start(System.Diagnostics.ProcessStartInfo startInfo) { throw null; }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")]
public static System.Diagnostics.Process Start(string fileName) { throw null; }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")]
public static System.Diagnostics.Process Start(string fileName, string arguments) { throw null; }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")]
public static System.Diagnostics.Process Start(string fileName, System.Collections.Generic.IEnumerable<string> arguments) { throw null; }
[System.CLSCompliantAttribute(false)]
[System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@

using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.Versioning;

namespace System.Diagnostics
{
public partial class Process : IDisposable
{
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
public void Kill(bool entireProcessTree)
{
if (!entireProcessTree)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,15 @@ public static Process Start(string fileName, string arguments, string userName,
}

/// <summary>Terminates the associated process immediately.</summary>
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
public void Kill()
{
if (OperatingSystem.IsIOS() || OperatingSystem.IsTvOS())
{
throw new PlatformNotSupportedException();
}

EnsureState(State.HaveId);

// Check if we know the process has exited. This avoids us targetting another
Expand Down Expand Up @@ -345,6 +352,11 @@ private SafeProcessHandle GetProcessHandle()
/// <param name="startInfo">The start info with which to start the process.</param>
private bool StartCore(ProcessStartInfo startInfo)
{
if (OperatingSystem.IsIOS() || OperatingSystem.IsTvOS())
{
throw new PlatformNotSupportedException();
}

EnsureInitialized();

string? filename;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ public static void LeaveDebugMode()
}

/// <summary>Terminates the associated process immediately.</summary>
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
public void Kill()
{
using (SafeProcessHandle handle = GetProcessHandle(Interop.Advapi32.ProcessOptions.PROCESS_TERMINATE | Interop.Advapi32.ProcessOptions.PROCESS_QUERY_LIMITED_INFORMATION, throwIfExited: false))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.Win32.SafeHandles;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Globalization;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Versioning;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Runtime.Versioning;
using System.Collections.Generic;

namespace System.Diagnostics
{
Expand Down Expand Up @@ -1197,6 +1197,8 @@ private void SetProcessId(int processId)
/// component.
/// </para>
/// </devdoc>
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
public bool Start()
{
Close();
Expand Down Expand Up @@ -1238,6 +1240,8 @@ public bool Start()
/// component.
/// </para>
/// </devdoc>
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
public static Process Start(string fileName)
{
// the underlying Start method can only return null on Windows platforms,
Expand All @@ -1254,6 +1258,8 @@ public static Process Start(string fileName)
/// component.
/// </para>
/// </devdoc>
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
public static Process Start(string fileName, string arguments)
{
// the underlying Start method can only return null on Windows platforms,
Expand All @@ -1265,6 +1271,8 @@ public static Process Start(string fileName, string arguments)
/// <summary>
/// Starts a process resource by specifying the name of an application and a set of command line arguments
/// </summary>
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
public static Process Start(string fileName, IEnumerable<string> arguments)
{
if (fileName == null)
Expand All @@ -1289,6 +1297,8 @@ public static Process Start(string fileName, IEnumerable<string> arguments)
/// component.
/// </para>
/// </devdoc>
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
public static Process? Start(ProcessStartInfo startInfo)
{
Process process = new Process();
Expand Down

0 comments on commit 8a31e66

Please sign in to comment.