Skip to content

Commit 62c29ff

Browse files
authored
[iOS] Follow up changes for 61590 (#61670)
This is a follow up PR for #61590. It includes: - additional UnsupportedOSPlatform annotations for some System.Diagnostics.Process APIs throwing PNSE on iOS/tvOS (they started doing so after excluding some managed logic around librpoc ) - fixing a bit ugly workaround for CS0649 (see https://github.com/dotnet/runtime/pull/61590/files#r749525127) - used a local pragma in the ThreadInfo class. - skipping the respective S.D.P. tests ( it will address [iOS/tvOS] System.Diagnostics.Tests.ProcessTests.TestGetProcesses fails on devices #60588 as well)
1 parent 2b23bfa commit 62c29ff

15 files changed

+115
-6
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,11 @@ public Process() { }
8484
public System.DateTime StartTime { get { throw null; } }
8585
public System.ComponentModel.ISynchronizeInvoke? SynchronizingObject { get { throw null; } set { } }
8686
public System.Diagnostics.ProcessThreadCollection Threads { get { throw null; } }
87+
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")]
88+
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")]
8789
public System.TimeSpan TotalProcessorTime { get { throw null; } }
90+
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")]
91+
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")]
8892
public System.TimeSpan UserProcessorTime { get { throw null; } }
8993
[System.ObsoleteAttribute("Process.VirtualMemorySize has been deprecated because the type of the property can't represent all valid results. Use System.Diagnostics.Process.VirtualMemorySize64 instead.")]
9094
public int VirtualMemorySize { get { throw null; } }
@@ -106,9 +110,17 @@ public static void EnterDebugMode() { }
106110
public static System.Diagnostics.Process GetCurrentProcess() { throw null; }
107111
public static System.Diagnostics.Process GetProcessById(int processId) { throw null; }
108112
public static System.Diagnostics.Process GetProcessById(int processId, string machineName) { throw null; }
113+
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")]
114+
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")]
109115
public static System.Diagnostics.Process[] GetProcesses() { throw null; }
116+
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")]
117+
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")]
110118
public static System.Diagnostics.Process[] GetProcesses(string machineName) { throw null; }
119+
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")]
120+
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")]
111121
public static System.Diagnostics.Process[] GetProcessesByName(string? processName) { throw null; }
122+
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")]
123+
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")]
112124
public static System.Diagnostics.Process[] GetProcessesByName(string? processName, string machineName) { throw null; }
113125
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")]
114126
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")]
@@ -233,6 +245,8 @@ internal ProcessThread() { }
233245
public int IdealProcessor { set { } }
234246
public bool PriorityBoostEnabled { get { throw null; } set { } }
235247
public System.Diagnostics.ThreadPriorityLevel PriorityLevel { [System.Runtime.Versioning.SupportedOSPlatform("windows")] [System.Runtime.Versioning.SupportedOSPlatform("linux")] [System.Runtime.Versioning.SupportedOSPlatform("freebsd")] get { throw null; } [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] set { } }
248+
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")]
249+
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")]
236250
public System.TimeSpan PrivilegedProcessorTime { get { throw null; } }
237251
[System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")]
238252
public System.IntPtr ProcessorAffinity { set { } }
@@ -241,7 +255,11 @@ public System.IntPtr ProcessorAffinity { set { } }
241255
[System.Runtime.Versioning.SupportedOSPlatform("linux")]
242256
public System.DateTime StartTime { get { throw null; } }
243257
public System.Diagnostics.ThreadState ThreadState { get { throw null; } }
258+
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")]
259+
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")]
244260
public System.TimeSpan TotalProcessorTime { get { throw null; } }
261+
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")]
262+
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")]
245263
public System.TimeSpan UserProcessorTime { get { throw null; } }
246264
public System.Diagnostics.ThreadWaitReason WaitReason { get { throw null; } }
247265
public void ResetIdealProcessor() { }

src/libraries/System.Diagnostics.Process/src/System.Diagnostics.Process.csproj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-FreeBSD;$(NetCoreAppCurrent)-Linux;$(NetCoreAppCurrent);$(NetCoreAppCurrent)-OSX;$(NetCoreAppCurrent)-iOS;$(NetCoreAppCurrent)-tvOS</TargetFrameworks>
66
<Nullable>enable</Nullable>
77
<!-- Suppress unused field warnings when using PlatformNotSupportedException stubs -->
8-
<NoWarn Condition=" '$(TargetsFreeBSD)' == 'true' or '$(TargetsUnknownUnix)' == 'true' or '$(TargetsiOS)' == 'true' or '$(TargetstvOS)' == 'true' ">$(NoWarn);0649</NoWarn>
98
</PropertyGroup>
109
<PropertyGroup>
1110
<GeneratePlatformNotSupportedAssemblyMessage Condition="'$(TargetsAnyOS)' == 'true'">SR.Process_PlatformNotSupported</GeneratePlatformNotSupportedAssemblyMessage>
@@ -325,7 +324,7 @@
325324
<Compile Include="System\Diagnostics\ProcessManager.Win32.cs" />
326325
<Compile Include="System\Diagnostics\ProcessStartInfo.Win32.cs" />
327326
</ItemGroup>
328-
<ItemGroup Condition="'$(TargetsAnyOS)' != 'true'">
327+
<ItemGroup Condition="'$(TargetsAnyOS)' != 'true' and '$(TargetsiOS)' != 'true' and '$(TargetstvOS)' != 'true'">
329328
<Compile Include="System\Diagnostics\Process.NonUap.cs" />
330329
</ItemGroup>
331330
<ItemGroup Condition=" '$(TargetsFreeBSD)' == 'true'">
@@ -346,6 +345,9 @@
346345
<Compile Include="System\Diagnostics\ProcessManager.UnknownUnix.cs" />
347346
<Compile Include="System\Diagnostics\ProcessThread.UnknownUnix.cs" />
348347
</ItemGroup>
348+
<ItemGroup Condition="'$(TargetsiOS)' == 'true' or '$(TargetstvOS)' == 'true'">
349+
<Compile Include="System\Diagnostics\Process.iOS.cs" />
350+
</ItemGroup>
349351
<ItemGroup>
350352
<ProjectReference Include="$(LibrariesProjectRoot)Microsoft.Win32.Registry\src\Microsoft.Win32.Registry.csproj" />
351353
<Reference Include="Microsoft.Win32.Primitives" />

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

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

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

78
namespace System.Diagnostics
89
{
@@ -12,6 +13,8 @@ public partial class Process
1213
/// Creates an array of <see cref="Process"/> components that are associated with process resources on a
1314
/// remote computer. These process resources share the specified process name.
1415
/// </summary>
16+
[UnsupportedOSPlatform("ios")]
17+
[UnsupportedOSPlatform("tvos")]
1518
public static Process[] GetProcessesByName(string? processName, string machineName)
1619
{
1720
if (processName == null)

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.ComponentModel;
88
using System.Globalization;
99
using System.IO;
10+
using System.Runtime.Versioning;
1011
using System.Text;
1112

1213
namespace System.Diagnostics
@@ -17,6 +18,8 @@ public partial class Process : IDisposable
1718
/// Creates an array of <see cref="Process"/> components that are associated with process resources on a
1819
/// remote computer. These process resources share the specified process name.
1920
/// </summary>
21+
[UnsupportedOSPlatform("ios")]
22+
[UnsupportedOSPlatform("tvos")]
2023
public static Process[] GetProcessesByName(string? processName, string machineName)
2124
{
2225
ProcessManager.ThrowIfRemoteMachine(machineName);

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System.Runtime.Versioning;
5+
46
namespace System.Diagnostics
57
{
68
public partial class Process : IDisposable
@@ -9,12 +11,16 @@ public partial class Process : IDisposable
911
/// Creates an array of <see cref="Process"/> components that are associated with process resources on a
1012
/// remote computer. These process resources share the specified process name.
1113
/// </summary>
14+
[UnsupportedOSPlatform("ios")]
15+
[UnsupportedOSPlatform("tvos")]
1216
public static Process[] GetProcessesByName(string? processName, string machineName)
1317
{
1418
throw new PlatformNotSupportedException();
1519
}
1620

1721
/// <summary>Gets the amount of time the process has spent running code inside the operating system core.</summary>
22+
[UnsupportedOSPlatform("ios")]
23+
[UnsupportedOSPlatform("tvos")]
1824
public TimeSpan PrivilegedProcessorTime
1925
{
2026
get { throw new PlatformNotSupportedException(); }
@@ -31,6 +37,8 @@ internal DateTime StartTimeCore
3137
/// It is the sum of the <see cref='System.Diagnostics.Process.UserProcessorTime'/> and
3238
/// <see cref='System.Diagnostics.Process.PrivilegedProcessorTime'/>.
3339
/// </summary>
40+
[UnsupportedOSPlatform("ios")]
41+
[UnsupportedOSPlatform("tvos")]
3442
public TimeSpan TotalProcessorTime
3543
{
3644
get { throw new PlatformNotSupportedException(); }
@@ -40,6 +48,8 @@ public TimeSpan TotalProcessorTime
4048
/// Gets the amount of time the associated process has spent running code
4149
/// inside the application portion of the process (not the operating system core).
4250
/// </summary>
51+
[UnsupportedOSPlatform("ios")]
52+
[UnsupportedOSPlatform("tvos")]
4353
public TimeSpan UserProcessorTime
4454
{
4555
get { throw new PlatformNotSupportedException(); }

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
@@ -21,6 +21,8 @@ public partial class Process : IDisposable
2121
/// Creates an array of <see cref="Process"/> components that are associated with process resources on a
2222
/// remote computer. These process resources share the specified process name.
2323
/// </summary>
24+
[UnsupportedOSPlatform("ios")]
25+
[UnsupportedOSPlatform("tvos")]
2426
public static Process[] GetProcessesByName(string? processName, string machineName)
2527
{
2628
if (processName == null)

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,8 @@ public static Process GetProcessById(int processId)
10391039
/// local computer. These process resources share the specified process name.
10401040
/// </para>
10411041
/// </devdoc>
1042+
[UnsupportedOSPlatform("ios")]
1043+
[UnsupportedOSPlatform("tvos")]
10421044
public static Process[] GetProcessesByName(string? processName)
10431045
{
10441046
return GetProcessesByName(processName, ".");
@@ -1050,6 +1052,8 @@ public static Process[] GetProcessesByName(string? processName)
10501052
/// component for each process resource on the local computer.
10511053
/// </para>
10521054
/// </devdoc>
1055+
[UnsupportedOSPlatform("ios")]
1056+
[UnsupportedOSPlatform("tvos")]
10531057
public static Process[] GetProcesses()
10541058
{
10551059
return GetProcesses(".");
@@ -1062,6 +1066,8 @@ public static Process[] GetProcesses()
10621066
/// process resource on the specified computer.
10631067
/// </para>
10641068
/// </devdoc>
1069+
[UnsupportedOSPlatform("ios")]
1070+
[UnsupportedOSPlatform("tvos")]
10651071
public static Process[] GetProcesses(string machineName)
10661072
{
10671073
bool isRemoteMachine = ProcessManager.IsRemoteMachine(machineName);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System.Collections.Generic;
5+
using System.ComponentModel;
6+
using System.Runtime.Versioning;
7+
8+
namespace System.Diagnostics
9+
{
10+
public partial class Process : IDisposable
11+
{
12+
[UnsupportedOSPlatform("ios")]
13+
[UnsupportedOSPlatform("tvos")]
14+
public void Kill(bool entireProcessTree)
15+
{
16+
throw new PlatformNotSupportedException();
17+
}
18+
19+
/// <summary>
20+
/// Returns all immediate child processes.
21+
/// </summary>
22+
private IReadOnlyList<Process> GetChildProcesses(Process[]? processes = null)
23+
{
24+
throw new PlatformNotSupportedException();
25+
}
26+
27+
private static bool IsProcessInvalidException(Exception e) =>
28+
// InvalidOperationException signifies conditions such as the process already being dead.
29+
// Win32Exception signifies issues such as insufficient permissions to get details on the process.
30+
// In either case, the predicate couldn't be applied so return the fallback result.
31+
e is InvalidOperationException || e is Win32Exception;
32+
}
33+
}

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

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

44
using Microsoft.Win32.SafeHandles;
55
using System.Collections.Generic;
6+
using System.Runtime.Versioning;
67
using System.Text;
78

89
namespace System.Diagnostics
@@ -44,6 +45,8 @@ public static bool IsProcessRunning(int processId)
4445
/// <summary>Gets the IDs of all processes on the specified machine.</summary>
4546
/// <param name="machineName">The machine to examine.</param>
4647
/// <returns>An array of process IDs from the specified machine.</returns>
48+
[UnsupportedOSPlatform("ios")]
49+
[UnsupportedOSPlatform("tvos")]
4750
public static int[] GetProcessIds(string machineName)
4851
{
4952
ThrowIfRemoteMachine(machineName);

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System.Runtime.Versioning;
5+
46
namespace System.Diagnostics
57
{
68
internal static partial class ProcessManager
@@ -14,6 +16,8 @@ public static int[] GetProcessIds()
1416
/// <summary>Gets process infos for each process on the specified machine.</summary>
1517
/// <param name="machineName">The target machine.</param>
1618
/// <returns>An array of process infos, one per found process.</returns>
19+
[UnsupportedOSPlatform("ios")]
20+
[UnsupportedOSPlatform("tvos")]
1721
public static ProcessInfo[] GetProcessInfos(string machineName)
1822
{
1923
throw new PlatformNotSupportedException();

0 commit comments

Comments
 (0)