Skip to content

Commit 6c8d2b0

Browse files
authored
[release/6.0-maui] Exclude the managed code around libproc on iOS/tvOS (#62235)
* Exclude the managed code around libproc on iOS/tvOS (#61590) Since libproc is a private Apple API, it is not available on iOS/tvOS and should be excluded (see #61265 (comment) and above for more details). This PR excludes $(CommonPath)Interop\OSX\Interop.libproc.cs on the iOS/tvOS as well as makes some methods in Process, ProcessManager, and ProcessThread classes calling that API throw PNSE so that for iOS/tvOS it's possible to re-use the respective *.UnknownUnix.cs parts. * [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) * Skip System.Diagnostics.TextWriterTraceListenerTests.XmlWriterTraceListenerTests on iOS/tvOS (#61807) This marks System.Diagnostics.TextWriterTraceListenerTests.XmlWriterTraceListenerTests withSkipOnPlatform attribute for iOS/tvOS as those tests try to create a process info, which throws PNSE after S.D.Process API's around libproc have been excluded in #61590. * Disable several failing tests on iOSSimulator arm64 #61826 A few tests popped up as failures on the rolling build due to parts of System.Diagnostics.Process throwing PNSE. Disabled the functional tests from running on arm64 as mlaunch can't detect the return code. * Use separate partials for iOS&tvOS instead of UnknowUnix in System.Diagnostics.Process (#61871) * Remove NoWarn removal
1 parent 5e7fb16 commit 6c8d2b0

File tree

19 files changed

+292
-4
lines changed

19 files changed

+292
-4
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: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@
309309
<Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.SchedGetSetAffinity.cs"
310310
Link="Common\Interop\Linux\Interop.SchedGetSetAffinity.cs" />
311311
</ItemGroup>
312-
<ItemGroup Condition=" '$(TargetsOSX)' == 'true' or '$(TargetsiOS)' == 'true' or '$(TargetstvOS)' == 'true'">
312+
<ItemGroup Condition=" '$(TargetsOSX)' == 'true'">
313313
<Compile Include="System\Diagnostics\Process.BSD.cs" />
314314
<Compile Include="System\Diagnostics\Process.OSX.cs" />
315315
<Compile Include="System\Diagnostics\ProcessManager.BSD.cs" />
@@ -329,7 +329,7 @@
329329
<Compile Include="System\Diagnostics\ProcessManager.Win32.cs" />
330330
<Compile Include="System\Diagnostics\ProcessStartInfo.Win32.cs" />
331331
</ItemGroup>
332-
<ItemGroup Condition="'$(TargetsAnyOS)' != 'true'">
332+
<ItemGroup Condition="'$(TargetsAnyOS)' != 'true' and '$(TargetsiOS)' != 'true' and '$(TargetstvOS)' != 'true'">
333333
<Compile Include="System\Diagnostics\Process.NonUap.cs" />
334334
</ItemGroup>
335335
<ItemGroup Condition=" '$(TargetsFreeBSD)' == 'true'">
@@ -345,6 +345,11 @@
345345
<Compile Include="$(CommonPath)Interop\FreeBSD\Interop.Process.GetProcInfo.cs"
346346
Link="Common\Interop\FreeBSD\Interop.Process.GetProcInfo.cs" />
347347
</ItemGroup>
348+
<ItemGroup Condition="'$(TargetsiOS)' == 'true' or '$(TargetstvOS)' == 'true'">
349+
<Compile Include="System\Diagnostics\Process.iOS.cs" />
350+
<Compile Include="System\Diagnostics\ProcessManager.iOS.cs" />
351+
<Compile Include="System\Diagnostics\ProcessThread.iOS.cs" />
352+
</ItemGroup>
348353
<ItemGroup Condition="'$(TargetsUnknownUnix)' == 'true'">
349354
<Compile Include="System\Diagnostics\Process.UnknownUnix.cs" />
350355
<Compile Include="System\Diagnostics\ProcessManager.UnknownUnix.cs" />

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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public partial class Process : IDisposable
99
/// Creates an array of <see cref="Process"/> components that are associated with process resources on a
1010
/// remote computer. These process resources share the specified process name.
1111
/// </summary>
12-
public static Process[] GetProcessesByName(string processName, string machineName)
12+
public static Process[] GetProcessesByName(string? processName, string machineName)
1313
{
1414
throw new PlatformNotSupportedException();
1515
}
@@ -82,5 +82,6 @@ private string GetPathToOpenFile()
8282
throw new PlatformNotSupportedException();
8383
}
8484

85+
private int ParentProcessId => throw new PlatformNotSupportedException();
8586
}
8687
}

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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ public bool HasExited
193193
}
194194

195195
/// <summary>Gets the time the associated process was started.</summary>
196+
[UnsupportedOSPlatform("ios")]
197+
[UnsupportedOSPlatform("tvos")]
196198
public DateTime StartTime
197199
{
198200
get
@@ -1039,6 +1041,8 @@ public static Process GetProcessById(int processId)
10391041
/// local computer. These process resources share the specified process name.
10401042
/// </para>
10411043
/// </devdoc>
1044+
[UnsupportedOSPlatform("ios")]
1045+
[UnsupportedOSPlatform("tvos")]
10421046
public static Process[] GetProcessesByName(string? processName)
10431047
{
10441048
return GetProcessesByName(processName, ".");
@@ -1050,6 +1054,8 @@ public static Process[] GetProcessesByName(string? processName)
10501054
/// component for each process resource on the local computer.
10511055
/// </para>
10521056
/// </devdoc>
1057+
[UnsupportedOSPlatform("ios")]
1058+
[UnsupportedOSPlatform("tvos")]
10531059
public static Process[] GetProcesses()
10541060
{
10551061
return GetProcesses(".");
@@ -1062,6 +1068,8 @@ public static Process[] GetProcesses()
10621068
/// process resource on the specified computer.
10631069
/// </para>
10641070
/// </devdoc>
1071+
[UnsupportedOSPlatform("ios")]
1072+
[UnsupportedOSPlatform("tvos")]
10651073
public static Process[] GetProcesses(string machineName)
10661074
{
10671075
bool isRemoteMachine = ProcessManager.IsRemoteMachine(machineName);
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
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+
/// Creates an array of <see cref="Process"/> components that are associated with process resources on a
21+
/// remote computer. These process resources share the specified process name.
22+
/// </summary>
23+
[UnsupportedOSPlatform("ios")]
24+
[UnsupportedOSPlatform("tvos")]
25+
public static Process[] GetProcessesByName(string? processName, string machineName)
26+
{
27+
throw new PlatformNotSupportedException();
28+
}
29+
30+
/// <summary>Gets the amount of time the process has spent running code inside the operating system core.</summary>
31+
[UnsupportedOSPlatform("ios")]
32+
[UnsupportedOSPlatform("tvos")]
33+
public TimeSpan PrivilegedProcessorTime
34+
{
35+
get { throw new PlatformNotSupportedException(); }
36+
}
37+
38+
/// <summary>Gets the time the associated process was started.</summary>
39+
[UnsupportedOSPlatform("ios")]
40+
[UnsupportedOSPlatform("tvos")]
41+
internal DateTime StartTimeCore
42+
{
43+
get { throw new PlatformNotSupportedException(); }
44+
}
45+
46+
/// <summary>
47+
/// Gets the amount of time the associated process has spent utilizing the CPU.
48+
/// It is the sum of the <see cref='System.Diagnostics.Process.UserProcessorTime'/> and
49+
/// <see cref='System.Diagnostics.Process.PrivilegedProcessorTime'/>.
50+
/// </summary>
51+
[UnsupportedOSPlatform("ios")]
52+
[UnsupportedOSPlatform("tvos")]
53+
public TimeSpan TotalProcessorTime
54+
{
55+
get { throw new PlatformNotSupportedException(); }
56+
}
57+
58+
/// <summary>
59+
/// Gets the amount of time the associated process has spent running code
60+
/// inside the application portion of the process (not the operating system core).
61+
/// </summary>
62+
[UnsupportedOSPlatform("ios")]
63+
[UnsupportedOSPlatform("tvos")]
64+
public TimeSpan UserProcessorTime
65+
{
66+
get { throw new PlatformNotSupportedException(); }
67+
}
68+
69+
/// <summary>
70+
/// Returns all immediate child processes.
71+
/// </summary>
72+
private IReadOnlyList<Process> GetChildProcesses(Process[]? processes = null)
73+
{
74+
throw new PlatformNotSupportedException();
75+
}
76+
77+
/// <summary>Gets parent process ID</summary>
78+
private int GetParentProcessId =>
79+
throw new PlatformNotSupportedException();
80+
81+
/// <summary>
82+
/// Gets or sets which processors the threads in this process can be scheduled to run on.
83+
/// </summary>
84+
private IntPtr ProcessorAffinityCore
85+
{
86+
get { throw new PlatformNotSupportedException(); }
87+
set { throw new PlatformNotSupportedException(); }
88+
}
89+
90+
/// <summary>
91+
/// Make sure we have obtained the min and max working set limits.
92+
/// </summary>
93+
private void GetWorkingSetLimits(out IntPtr minWorkingSet, out IntPtr maxWorkingSet)
94+
{
95+
throw new PlatformNotSupportedException();
96+
}
97+
98+
/// <summary>Sets one or both of the minimum and maximum working set limits.</summary>
99+
/// <param name="newMin">The new minimum working set limit, or null not to change it.</param>
100+
/// <param name="newMax">The new maximum working set limit, or null not to change it.</param>
101+
/// <param name="resultingMin">The resulting minimum working set limit after any changes applied.</param>
102+
/// <param name="resultingMax">The resulting maximum working set limit after any changes applied.</param>
103+
private void SetWorkingSetLimitsCore(IntPtr? newMin, IntPtr? newMax, out IntPtr resultingMin, out IntPtr resultingMax)
104+
{
105+
throw new PlatformNotSupportedException();
106+
}
107+
108+
/// <summary>Gets execution path</summary>
109+
private string GetPathToOpenFile()
110+
{
111+
throw new PlatformNotSupportedException();
112+
}
113+
114+
private int ParentProcessId => throw new PlatformNotSupportedException();
115+
116+
private static bool IsProcessInvalidException(Exception e) =>
117+
// InvalidOperationException signifies conditions such as the process already being dead.
118+
// Win32Exception signifies issues such as insufficient permissions to get details on the process.
119+
// In either case, the predicate couldn't be applied so return the fallback result.
120+
e is InvalidOperationException || e is Win32Exception;
121+
}
122+
}

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);
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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.Runtime.Versioning;
5+
6+
namespace System.Diagnostics
7+
{
8+
internal static partial class ProcessManager
9+
{
10+
/// <summary>Gets the IDs of all processes on the current machine.</summary>
11+
public static int[] GetProcessIds()
12+
{
13+
throw new PlatformNotSupportedException();
14+
}
15+
16+
/// <summary>Gets process infos for each process on the specified machine.</summary>
17+
/// <param name="machineName">The target machine.</param>
18+
/// <returns>An array of process infos, one per found process.</returns>
19+
[UnsupportedOSPlatform("ios")]
20+
[UnsupportedOSPlatform("tvos")]
21+
public static ProcessInfo[] GetProcessInfos(string machineName)
22+
{
23+
throw new PlatformNotSupportedException();
24+
}
25+
26+
/// <summary>Gets an array of module infos for the specified process.</summary>
27+
/// <param name="processId">The ID of the process whose modules should be enumerated.</param>
28+
/// <returns>The array of modules.</returns>
29+
internal static ProcessModuleCollection GetModules(int processId)
30+
{
31+
return new ProcessModuleCollection(0);
32+
}
33+
34+
private static ProcessInfo CreateProcessInfo(int pid)
35+
{
36+
throw new PlatformNotSupportedException();
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)