Skip to content

Commit

Permalink
[iOS] Follow up changes for 61590 (#61670)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
MaximLipnin authored Nov 18, 2021
1 parent 2b23bfa commit 62c29ff
Show file tree
Hide file tree
Showing 15 changed files with 115 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ public Process() { }
public System.DateTime StartTime { get { throw null; } }
public System.ComponentModel.ISynchronizeInvoke? SynchronizingObject { get { throw null; } set { } }
public System.Diagnostics.ProcessThreadCollection Threads { get { throw null; } }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")]
public System.TimeSpan TotalProcessorTime { get { throw null; } }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")]
public System.TimeSpan UserProcessorTime { get { throw null; } }
[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.")]
public int VirtualMemorySize { get { throw null; } }
Expand All @@ -106,9 +110,17 @@ public static void EnterDebugMode() { }
public static System.Diagnostics.Process GetCurrentProcess() { throw null; }
public static System.Diagnostics.Process GetProcessById(int processId) { throw null; }
public static System.Diagnostics.Process GetProcessById(int processId, string machineName) { throw null; }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")]
public static System.Diagnostics.Process[] GetProcesses() { throw null; }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")]
public static System.Diagnostics.Process[] GetProcesses(string machineName) { throw null; }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")]
public static System.Diagnostics.Process[] GetProcessesByName(string? processName) { throw null; }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")]
public static System.Diagnostics.Process[] GetProcessesByName(string? processName, string machineName) { throw null; }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")]
Expand Down Expand Up @@ -233,6 +245,8 @@ internal ProcessThread() { }
public int IdealProcessor { set { } }
public bool PriorityBoostEnabled { get { throw null; } set { } }
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 { } }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")]
public System.TimeSpan PrivilegedProcessorTime { get { throw null; } }
[System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")]
public System.IntPtr ProcessorAffinity { set { } }
Expand All @@ -241,7 +255,11 @@ public System.IntPtr ProcessorAffinity { set { } }
[System.Runtime.Versioning.SupportedOSPlatform("linux")]
public System.DateTime StartTime { get { throw null; } }
public System.Diagnostics.ThreadState ThreadState { get { throw null; } }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")]
public System.TimeSpan TotalProcessorTime { get { throw null; } }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")]
public System.TimeSpan UserProcessorTime { get { throw null; } }
public System.Diagnostics.ThreadWaitReason WaitReason { get { throw null; } }
public void ResetIdealProcessor() { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-FreeBSD;$(NetCoreAppCurrent)-Linux;$(NetCoreAppCurrent);$(NetCoreAppCurrent)-OSX;$(NetCoreAppCurrent)-iOS;$(NetCoreAppCurrent)-tvOS</TargetFrameworks>
<Nullable>enable</Nullable>
<!-- Suppress unused field warnings when using PlatformNotSupportedException stubs -->
<NoWarn Condition=" '$(TargetsFreeBSD)' == 'true' or '$(TargetsUnknownUnix)' == 'true' or '$(TargetsiOS)' == 'true' or '$(TargetstvOS)' == 'true' ">$(NoWarn);0649</NoWarn>
</PropertyGroup>
<PropertyGroup>
<GeneratePlatformNotSupportedAssemblyMessage Condition="'$(TargetsAnyOS)' == 'true'">SR.Process_PlatformNotSupported</GeneratePlatformNotSupportedAssemblyMessage>
Expand Down Expand Up @@ -325,7 +324,7 @@
<Compile Include="System\Diagnostics\ProcessManager.Win32.cs" />
<Compile Include="System\Diagnostics\ProcessStartInfo.Win32.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetsAnyOS)' != 'true'">
<ItemGroup Condition="'$(TargetsAnyOS)' != 'true' and '$(TargetsiOS)' != 'true' and '$(TargetstvOS)' != 'true'">
<Compile Include="System\Diagnostics\Process.NonUap.cs" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetsFreeBSD)' == 'true'">
Expand All @@ -346,6 +345,9 @@
<Compile Include="System\Diagnostics\ProcessManager.UnknownUnix.cs" />
<Compile Include="System\Diagnostics\ProcessThread.UnknownUnix.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetsiOS)' == 'true' or '$(TargetstvOS)' == 'true'">
<Compile Include="System\Diagnostics\Process.iOS.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(LibrariesProjectRoot)Microsoft.Win32.Registry\src\Microsoft.Win32.Registry.csproj" />
<Reference Include="Microsoft.Win32.Primitives" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

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

namespace System.Diagnostics
{
Expand All @@ -12,6 +13,8 @@ public partial class Process
/// Creates an array of <see cref="Process"/> components that are associated with process resources on a
/// remote computer. These process resources share the specified process name.
/// </summary>
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
public static Process[] GetProcessesByName(string? processName, string machineName)
{
if (processName == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.ComponentModel;
using System.Globalization;
using System.IO;
using System.Runtime.Versioning;
using System.Text;

namespace System.Diagnostics
Expand All @@ -17,6 +18,8 @@ public partial class Process : IDisposable
/// Creates an array of <see cref="Process"/> components that are associated with process resources on a
/// remote computer. These process resources share the specified process name.
/// </summary>
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
public static Process[] GetProcessesByName(string? processName, string machineName)
{
ProcessManager.ThrowIfRemoteMachine(machineName);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Runtime.Versioning;

namespace System.Diagnostics
{
public partial class Process : IDisposable
Expand All @@ -9,12 +11,16 @@ public partial class Process : IDisposable
/// Creates an array of <see cref="Process"/> components that are associated with process resources on a
/// remote computer. These process resources share the specified process name.
/// </summary>
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
public static Process[] GetProcessesByName(string? processName, string machineName)
{
throw new PlatformNotSupportedException();
}

/// <summary>Gets the amount of time the process has spent running code inside the operating system core.</summary>
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
public TimeSpan PrivilegedProcessorTime
{
get { throw new PlatformNotSupportedException(); }
Expand All @@ -31,6 +37,8 @@ internal DateTime StartTimeCore
/// It is the sum of the <see cref='System.Diagnostics.Process.UserProcessorTime'/> and
/// <see cref='System.Diagnostics.Process.PrivilegedProcessorTime'/>.
/// </summary>
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
public TimeSpan TotalProcessorTime
{
get { throw new PlatformNotSupportedException(); }
Expand All @@ -40,6 +48,8 @@ public TimeSpan TotalProcessorTime
/// Gets the amount of time the associated process has spent running code
/// inside the application portion of the process (not the operating system core).
/// </summary>
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
public TimeSpan UserProcessorTime
{
get { throw new PlatformNotSupportedException(); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public partial class Process : IDisposable
/// Creates an array of <see cref="Process"/> components that are associated with process resources on a
/// remote computer. These process resources share the specified process name.
/// </summary>
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
public static Process[] GetProcessesByName(string? processName, string machineName)
{
if (processName == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,8 @@ public static Process GetProcessById(int processId)
/// local computer. These process resources share the specified process name.
/// </para>
/// </devdoc>
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
public static Process[] GetProcessesByName(string? processName)
{
return GetProcessesByName(processName, ".");
Expand All @@ -1050,6 +1052,8 @@ public static Process[] GetProcessesByName(string? processName)
/// component for each process resource on the local computer.
/// </para>
/// </devdoc>
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
public static Process[] GetProcesses()
{
return GetProcesses(".");
Expand All @@ -1062,6 +1066,8 @@ public static Process[] GetProcesses()
/// process resource on the specified computer.
/// </para>
/// </devdoc>
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
public static Process[] GetProcesses(string machineName)
{
bool isRemoteMachine = ProcessManager.IsRemoteMachine(machineName);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

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)
{
throw new PlatformNotSupportedException();
}

/// <summary>
/// Returns all immediate child processes.
/// </summary>
private IReadOnlyList<Process> GetChildProcesses(Process[]? processes = null)
{
throw new PlatformNotSupportedException();
}

private static bool IsProcessInvalidException(Exception e) =>
// InvalidOperationException signifies conditions such as the process already being dead.
// Win32Exception signifies issues such as insufficient permissions to get details on the process.
// In either case, the predicate couldn't be applied so return the fallback result.
e is InvalidOperationException || e is Win32Exception;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using Microsoft.Win32.SafeHandles;
using System.Collections.Generic;
using System.Runtime.Versioning;
using System.Text;

namespace System.Diagnostics
Expand Down Expand Up @@ -44,6 +45,8 @@ public static bool IsProcessRunning(int processId)
/// <summary>Gets the IDs of all processes on the specified machine.</summary>
/// <param name="machineName">The machine to examine.</param>
/// <returns>An array of process IDs from the specified machine.</returns>
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
public static int[] GetProcessIds(string machineName)
{
ThrowIfRemoteMachine(machineName);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Runtime.Versioning;

namespace System.Diagnostics
{
internal static partial class ProcessManager
Expand All @@ -14,6 +16,8 @@ public static int[] GetProcessIds()
/// <summary>Gets process infos for each process on the specified machine.</summary>
/// <param name="machineName">The target machine.</param>
/// <returns>An array of process infos, one per found process.</returns>
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
public static ProcessInfo[] GetProcessInfos(string machineName)
{
throw new PlatformNotSupportedException();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Runtime.Versioning;

namespace System.Diagnostics
{
public partial class ProcessThread
Expand All @@ -20,6 +22,8 @@ private ThreadPriorityLevel PriorityLevelCore
/// Returns the amount of time the thread has spent running code inside the operating
/// system core.
/// </summary>
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
public TimeSpan PrivilegedProcessorTime
{
get { throw new PlatformNotSupportedException(); } // Not available on POSIX
Expand All @@ -32,6 +36,8 @@ public TimeSpan PrivilegedProcessorTime
/// It is the sum of the System.Diagnostics.ProcessThread.UserProcessorTime and
/// System.Diagnostics.ProcessThread.PrivilegedProcessorTime.
/// </summary>
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
public TimeSpan TotalProcessorTime
{
get { throw new PlatformNotSupportedException(); } // Not available on POSIX
Expand All @@ -41,6 +47,8 @@ public TimeSpan TotalProcessorTime
/// Returns the amount of time the associated thread has spent running code
/// inside the application (not the operating system core).
/// </summary>
[UnsupportedOSPlatform("ios")]
[UnsupportedOSPlatform("tvos")]
public TimeSpan UserProcessorTime
{
get { throw new PlatformNotSupportedException(); } // Not available on POSIX
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ namespace System.Diagnostics
/// <internalonly/>
internal sealed class ThreadInfo
{
#pragma warning disable CS0649 // The fields are unused on iOS/tvOS as the respective managed logic (mostly around libproc) is excluded.
internal ulong _threadId;
internal int _processId;
internal int _basePriority;
internal int _currentPriority;
internal IntPtr _startAddress;
internal ThreadState _threadState;
internal ThreadWaitReason _threadWaitReason;
#pragma warning restore CS0649
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace System.Diagnostics.Tests
public partial class ProcessModuleTests : ProcessTestBase
{
[Fact]
[SkipOnPlatform(TestPlatforms.iOS | TestPlatforms.tvOS, "libproc is not supported on iOS/tvOS")]
public void TestModuleProperties()
{
ProcessModuleCollection modules = Process.GetCurrentProcess().Modules;
Expand All @@ -29,6 +30,7 @@ public void TestModuleProperties()
}

[Fact]
[SkipOnPlatform(TestPlatforms.iOS | TestPlatforms.tvOS, "libproc is not supported on iOS/tvOS")]
public void Modules_Get_ContainsHostFileName()
{
ProcessModuleCollection modules = Process.GetCurrentProcess().Modules;
Expand Down
Loading

0 comments on commit 62c29ff

Please sign in to comment.