Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Annotate System.Diagnostics.Process APIs throwing PNSE on iOS/tvOS #49354

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")]
Copy link
Contributor

@marek-safar marek-safar Mar 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about other methods like Kill? Does the implementation work?

[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