From f40ec3d00b14982e2b78e285f5be6af1def3ef0c Mon Sep 17 00:00:00 2001 From: Maxim Lipnin Date: Tue, 9 Mar 2021 15:59:31 +0300 Subject: [PATCH 1/6] Process.Start --- eng/versioning.targets | 11 ++++++++++- .../ref/System.Diagnostics.Process.cs | 14 ++++++++++++++ .../src/System/Diagnostics/Process.Unix.cs | 9 +++++++++ .../src/System/Diagnostics/Process.cs | 14 ++++++++++++-- 4 files changed, 45 insertions(+), 3 deletions(-) diff --git a/eng/versioning.targets b/eng/versioning.targets index 9e6d9de071847..1a9b3b2cd5fd3 100644 --- a/eng/versioning.targets +++ b/eng/versioning.targets @@ -36,11 +36,20 @@ true - + + + + + + + + + + <_unsupportedOSPlatforms Include="$(UnsupportedOSPlatforms)" /> diff --git a/src/libraries/System.Diagnostics.Process/ref/System.Diagnostics.Process.cs b/src/libraries/System.Diagnostics.Process/ref/System.Diagnostics.Process.cs index 599378b6ea04d..6316f04b1610e 100644 --- a/src/libraries/System.Diagnostics.Process/ref/System.Diagnostics.Process.cs +++ b/src/libraries/System.Diagnostics.Process/ref/System.Diagnostics.Process.cs @@ -113,16 +113,30 @@ 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 arguments) { throw null; } [System.CLSCompliantAttribute(false)] [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")] + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")] public static System.Diagnostics.Process? Start(string fileName, string userName, System.Security.SecureString password, string domain) { throw null; } [System.CLSCompliantAttribute(false)] [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")] + [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")] public static System.Diagnostics.Process? Start(string fileName, string arguments, string userName, System.Security.SecureString password, string domain) { throw null; } public override string ToString() { throw null; } public void WaitForExit() { } diff --git a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Unix.cs b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Unix.cs index 704fab865eb0f..3043a3002e5bf 100644 --- a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Unix.cs +++ b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Unix.cs @@ -41,6 +41,8 @@ public static void LeaveDebugMode() [CLSCompliant(false)] [SupportedOSPlatform("windows")] + [UnsupportedOSPlatform("ios")] + [UnsupportedOSPlatform("tvos")] public static Process Start(string fileName, string userName, SecureString password, string domain) { throw new PlatformNotSupportedException(SR.ProcessStartWithPasswordAndDomainNotSupported); @@ -48,6 +50,8 @@ public static Process Start(string fileName, string userName, SecureString passw [CLSCompliant(false)] [SupportedOSPlatform("windows")] + [UnsupportedOSPlatform("ios")] + [UnsupportedOSPlatform("tvos")] public static Process Start(string fileName, string arguments, string userName, SecureString password, string domain) { throw new PlatformNotSupportedException(SR.ProcessStartWithPasswordAndDomainNotSupported); @@ -345,6 +349,11 @@ private SafeProcessHandle GetProcessHandle() /// The start info with which to start the process. private bool StartCore(ProcessStartInfo startInfo) { + if (OperatingSystem.IsIOS() || OperatingSystem.IsTvOS()) + { + throw new PlatformNotSupportedException(); + } + EnsureInitialized(); string? filename; diff --git a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.cs b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.cs index 6c9181f8655d6..1aec8ec89756f 100644 --- a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.cs +++ b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.cs @@ -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 { @@ -1197,6 +1197,8 @@ private void SetProcessId(int processId) /// component. /// /// + [UnsupportedOSPlatform("ios")] + [UnsupportedOSPlatform("tvos")] public bool Start() { Close(); @@ -1238,6 +1240,8 @@ public bool Start() /// component. /// /// + [UnsupportedOSPlatform("ios")] + [UnsupportedOSPlatform("tvos")] public static Process Start(string fileName) { // the underlying Start method can only return null on Windows platforms, @@ -1254,6 +1258,8 @@ public static Process Start(string fileName) /// component. /// /// + [UnsupportedOSPlatform("ios")] + [UnsupportedOSPlatform("tvos")] public static Process Start(string fileName, string arguments) { // the underlying Start method can only return null on Windows platforms, @@ -1265,6 +1271,8 @@ public static Process Start(string fileName, string arguments) /// /// Starts a process resource by specifying the name of an application and a set of command line arguments /// + [UnsupportedOSPlatform("ios")] + [UnsupportedOSPlatform("tvos")] public static Process Start(string fileName, IEnumerable arguments) { if (fileName == null) @@ -1289,6 +1297,8 @@ public static Process Start(string fileName, IEnumerable arguments) /// component. /// /// + [UnsupportedOSPlatform("ios")] + [UnsupportedOSPlatform("tvos")] public static Process? Start(ProcessStartInfo startInfo) { Process process = new Process(); From 2e3888609459c72aa433978485cc0b8af9af6df5 Mon Sep 17 00:00:00 2001 From: Maxim Lipnin Date: Tue, 9 Mar 2021 17:01:57 +0300 Subject: [PATCH 2/6] Remove redundant annotations --- .../ref/System.Diagnostics.Process.cs | 4 ---- .../src/System/Diagnostics/Process.Unix.cs | 4 ---- 2 files changed, 8 deletions(-) diff --git a/src/libraries/System.Diagnostics.Process/ref/System.Diagnostics.Process.cs b/src/libraries/System.Diagnostics.Process/ref/System.Diagnostics.Process.cs index 6316f04b1610e..22d2d2ee54695 100644 --- a/src/libraries/System.Diagnostics.Process/ref/System.Diagnostics.Process.cs +++ b/src/libraries/System.Diagnostics.Process/ref/System.Diagnostics.Process.cs @@ -130,13 +130,9 @@ public void Refresh() { } public static System.Diagnostics.Process Start(string fileName, System.Collections.Generic.IEnumerable arguments) { throw null; } [System.CLSCompliantAttribute(false)] [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] - [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")] - [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")] public static System.Diagnostics.Process? Start(string fileName, string userName, System.Security.SecureString password, string domain) { throw null; } [System.CLSCompliantAttribute(false)] [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] - [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")] - [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")] public static System.Diagnostics.Process? Start(string fileName, string arguments, string userName, System.Security.SecureString password, string domain) { throw null; } public override string ToString() { throw null; } public void WaitForExit() { } diff --git a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Unix.cs b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Unix.cs index 3043a3002e5bf..e8e8e7e65b1f8 100644 --- a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Unix.cs +++ b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Unix.cs @@ -41,8 +41,6 @@ public static void LeaveDebugMode() [CLSCompliant(false)] [SupportedOSPlatform("windows")] - [UnsupportedOSPlatform("ios")] - [UnsupportedOSPlatform("tvos")] public static Process Start(string fileName, string userName, SecureString password, string domain) { throw new PlatformNotSupportedException(SR.ProcessStartWithPasswordAndDomainNotSupported); @@ -50,8 +48,6 @@ public static Process Start(string fileName, string userName, SecureString passw [CLSCompliant(false)] [SupportedOSPlatform("windows")] - [UnsupportedOSPlatform("ios")] - [UnsupportedOSPlatform("tvos")] public static Process Start(string fileName, string arguments, string userName, SecureString password, string domain) { throw new PlatformNotSupportedException(SR.ProcessStartWithPasswordAndDomainNotSupported); From c3e7b22aad89a20ad417755cfa8d9c19e8210c3b Mon Sep 17 00:00:00 2001 From: Maxim Lipnin Date: Wed, 10 Mar 2021 11:04:12 +0300 Subject: [PATCH 3/6] Remove iOS since it's in the default list of supported platforms --- eng/versioning.targets | 4 ---- 1 file changed, 4 deletions(-) diff --git a/eng/versioning.targets b/eng/versioning.targets index 1a9b3b2cd5fd3..12cad8bf7f1a6 100644 --- a/eng/versioning.targets +++ b/eng/versioning.targets @@ -41,10 +41,6 @@ - - - - From a443cb24ebee3d1c0f15d87e91b160dae0b58d6b Mon Sep 17 00:00:00 2001 From: Maxim Lipnin Date: Wed, 10 Mar 2021 14:37:03 +0300 Subject: [PATCH 4/6] Process.Kill --- .../ref/System.Diagnostics.Process.cs | 4 ++++ .../src/System/Diagnostics/Process.NonUap.cs | 3 +++ .../src/System/Diagnostics/Process.Unix.cs | 2 ++ 3 files changed, 9 insertions(+) diff --git a/src/libraries/System.Diagnostics.Process/ref/System.Diagnostics.Process.cs b/src/libraries/System.Diagnostics.Process/ref/System.Diagnostics.Process.cs index 22d2d2ee54695..4b536fd86d54e 100644 --- a/src/libraries/System.Diagnostics.Process/ref/System.Diagnostics.Process.cs +++ b/src/libraries/System.Diagnostics.Process/ref/System.Diagnostics.Process.cs @@ -108,7 +108,11 @@ 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() { } diff --git a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.NonUap.cs b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.NonUap.cs index be09b7bb146ef..d2c05302f719f 100644 --- a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.NonUap.cs +++ b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.NonUap.cs @@ -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) diff --git a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Unix.cs b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Unix.cs index e8e8e7e65b1f8..6308b5e7204b3 100644 --- a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Unix.cs +++ b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Unix.cs @@ -54,6 +54,8 @@ public static Process Start(string fileName, string arguments, string userName, } /// Terminates the associated process immediately. + [UnsupportedOSPlatform("ios")] + [UnsupportedOSPlatform("tvos")] public void Kill() { EnsureState(State.HaveId); From 0c40365d56ac4ab560eabd8d6930603476005908 Mon Sep 17 00:00:00 2001 From: Maxim Lipnin Date: Wed, 10 Mar 2021 15:14:30 +0300 Subject: [PATCH 5/6] Make Process.Kill throw PNSE on iOS/tvOS --- .../src/System/Diagnostics/Process.Unix.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Unix.cs b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Unix.cs index 6308b5e7204b3..05eee69f480a6 100644 --- a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Unix.cs +++ b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Unix.cs @@ -58,6 +58,11 @@ public static Process Start(string fileName, string arguments, string userName, [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 From b17ba764018e336992d84bb7a09eb85bdb37c66d Mon Sep 17 00:00:00 2001 From: Maxim Lipnin Date: Wed, 10 Mar 2021 16:33:07 +0300 Subject: [PATCH 6/6] Annotate windows-related implementation of Kill method --- .../src/System/Diagnostics/Process.Windows.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Windows.cs b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Windows.cs index 0dfc4ae2357cb..475f31853f4d9 100644 --- a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Windows.cs +++ b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Windows.cs @@ -89,6 +89,8 @@ public static void LeaveDebugMode() } /// Terminates the associated process immediately. + [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))