Skip to content

Commit 649ff28

Browse files
iSazonovdaxian-dbw
authored andcommitted
Clean up '#if CORE' in ProcessCodeMethods.cs and 'ClrFacade.GetSafeProcessHandle' (PowerShell#4428)
1 parent 0e4cd63 commit 649ff28

4 files changed

Lines changed: 22 additions & 39 deletions

File tree

src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ protected override void ProcessRecord()
677677
}
678678
else if (Module.IsPresent)
679679
{
680-
//if only modules are to be displayed
680+
//if only modules are to be displayed
681681
try
682682
{
683683
WriteObject(process.Modules, true);
@@ -800,7 +800,7 @@ private static string RetrieveProcessUserName(Process process)
800800
do
801801
{
802802
int error;
803-
if (!Win32Native.OpenProcessToken(ClrFacade.GetSafeProcessHandle(process), TOKEN_QUERY, out processTokenHandler)) { break; }
803+
if (!Win32Native.OpenProcessToken(process.Handle, TOKEN_QUERY, out processTokenHandler)) { break; }
804804

805805
// Set the default length to be 256, so it will be sufficient for most cases
806806
int tokenInfoLength = 256;
@@ -1196,7 +1196,7 @@ public SwitchParameter PassThru
11961196

11971197

11981198
//Addition by v-ramch Mar 18 2008
1199-
//Added force parameter
1199+
//Added force parameter
12001200
/// <summary>
12011201
/// Specifies whether to force a process to kill
12021202
/// even if it has dependent services.
@@ -1235,7 +1235,7 @@ protected override void ProcessRecord()
12351235

12361236
try
12371237
{
1238-
// Many properties including Name are not available if the process has exited.
1238+
// Many properties including Name are not available if the process has exited.
12391239
// If this is the case, we skip the process. If the process is from a remote
12401240
// machine, then we generate a non-terminating error because .NET doesn't support
12411241
// terminate a remote process.
@@ -1370,7 +1370,7 @@ private bool IsProcessOwnedByCurrentUser(Process process)
13701370
IntPtr ph = IntPtr.Zero;
13711371
try
13721372
{
1373-
if (Win32Native.OpenProcessToken(ClrFacade.GetSafeProcessHandle(process), TOKEN_QUERY, out ph))
1373+
if (Win32Native.OpenProcessToken(process.Handle, TOKEN_QUERY, out ph))
13741374
{
13751375
if (_currentUserName == null)
13761376
{
@@ -1423,7 +1423,7 @@ private void StopDependentService(Process process)
14231423
string serviceName = oService.CimInstanceProperties["Name"].Value.ToString();
14241424
using (var service = new System.ServiceProcess.ServiceController(serviceName))
14251425
{
1426-
//try stopping the service, if cant we are not writing exception
1426+
//try stopping the service, if cant we are not writing exception
14271427
try
14281428
{
14291429
service.Stop();
@@ -1782,7 +1782,7 @@ public string RedirectStandardError
17821782

17831783

17841784
/// <summary>
1785-
/// Redirect input
1785+
/// Redirect input
17861786
/// </summary>
17871787
[Parameter(ParameterSetName = "Default")]
17881788
[Alias("RSI")]
@@ -1800,7 +1800,7 @@ public string RedirectStandardInput
18001800

18011801

18021802
/// <summary>
1803-
/// Redirect output
1803+
/// Redirect output
18041804
/// </summary>
18051805
[Parameter(ParameterSetName = "Default")]
18061806
[Alias("RSO")]
@@ -1820,7 +1820,7 @@ public string RedirectStandardOutput
18201820
/// Verb
18211821
/// </summary>
18221822
/// <remarks>
1823-
/// The 'Verb' parameter is not supported in OneCore PowerShell
1823+
/// The 'Verb' parameter is not supported in OneCore PowerShell
18241824
/// because 'UseShellExecute' is not supported in CoreCLR.
18251825
/// </remarks>
18261826
[Parameter(ParameterSetName = "UseShellExecute")]
@@ -2155,7 +2155,7 @@ private void Dispose(bool isDisposing)
21552155
#region Private Methods
21562156

21572157
/// <summary>
2158-
/// When Process exits the wait handle is set.
2158+
/// When Process exits the wait handle is set.
21592159
/// </summary>
21602160
private void myProcess_Exited(object sender, System.EventArgs e)
21612161
{
@@ -2449,7 +2449,7 @@ private Process StartWithCreateProcess(ProcessStartInfo startinfo)
24492449
{
24502450
lpStartupInfo.hStdError = new SafeFileHandle(ProcessNativeMethods.GetStdHandle(-12), false);
24512451
}
2452-
//STARTF_USESTDHANDLES
2452+
//STARTF_USESTDHANDLES
24532453
lpStartupInfo.dwFlags = 0x100;
24542454

24552455
int creationFlags = 0;
@@ -2529,7 +2529,7 @@ private Process StartWithCreateProcess(ProcessStartInfo startinfo)
25292529
}
25302530
else if (error == 0x424)
25312531
{
2532-
// The API 'CreateProcessWithLogonW' depends on the 'Secondary Logon' service, but the component 'Microsoft-Windows-SecondaryLogonService'
2532+
// The API 'CreateProcessWithLogonW' depends on the 'Secondary Logon' service, but the component 'Microsoft-Windows-SecondaryLogonService'
25332533
// is not installed in OneCoreUAP. We will get error code 0x424 when the service is not available.
25342534
message = StringUtil.Format(ProcessResources.ParameterNotSupported, "-Credential", "Start-Process");
25352535
er = new ErrorRecord(new NotSupportedException(message), "NotSupportedException", ErrorCategory.NotInstalled, null);
@@ -2607,7 +2607,7 @@ private Process StartWithShellExecute(ProcessStartInfo startInfo)
26072607
ErrorRecord er = new ErrorRecord(new InvalidOperationException(message), "InvalidOperationException", ErrorCategory.InvalidOperation, null);
26082608
ThrowTerminatingError(er);
26092609
}
2610-
return result;
2610+
return result;
26112611
}
26122612
#endif
26132613
#endregion
@@ -2621,7 +2621,7 @@ private Process StartWithShellExecute(ProcessStartInfo startInfo)
26212621
internal class ProcessCollection
26222622
{
26232623
/// <summary>
2624-
/// JobObjectHandle is a reference to the job object used to track
2624+
/// JobObjectHandle is a reference to the job object used to track
26252625
/// the child processes created by the main process hosted by the Start-Process cmdlet.
26262626
/// </summary>
26272627
private Microsoft.PowerShell.Commands.SafeJobHandle _jobObjectHandle;
@@ -2636,7 +2636,7 @@ internal ProcessCollection()
26362636
}
26372637

26382638
/// <summary>
2639-
/// Start API assigns the process to the JobObject and starts monitoring
2639+
/// Start API assigns the process to the JobObject and starts monitoring
26402640
/// the child processes hosted by the process created by Start-Process cmdlet.
26412641
/// </summary>
26422642
internal bool AssignProcessToJobObject(Process process)
@@ -2688,8 +2688,8 @@ internal void WaitOne(ManualResetEvent waitHandleToUse)
26882688
}
26892689

26902690
/// <summary>
2691-
/// JOBOBJECT_BASIC_PROCESS_ID_LIST Contains the process identifier list for a job object.
2692-
/// If the job is nested, the process identifier list consists of all
2691+
/// JOBOBJECT_BASIC_PROCESS_ID_LIST Contains the process identifier list for a job object.
2692+
/// If the job is nested, the process identifier list consists of all
26932693
/// processes associated with the job and its child jobs.
26942694
/// </summary>
26952695
[StructLayout(LayoutKind.Sequential)]
@@ -2701,14 +2701,14 @@ internal struct JOBOBJECT_BASIC_PROCESS_ID_LIST
27012701
public uint NumberOfAssignedProcess;
27022702

27032703
/// <summary>
2704-
/// The number of process identifiers returned in the ProcessIdList buffer.
2705-
/// If this number is less than NumberOfAssignedProcesses, increase
2704+
/// The number of process identifiers returned in the ProcessIdList buffer.
2705+
/// If this number is less than NumberOfAssignedProcesses, increase
27062706
/// the size of the buffer to accommodate the complete list.
27072707
/// </summary>
27082708
public uint NumberOfProcessIdsInList;
27092709

27102710
/// <summary>
2711-
/// A variable-length array of process identifiers returned by this call.
2711+
/// A variable-length array of process identifiers returned by this call.
27122712
/// Array elements 0 through NumberOfProcessIdsInList minus 1
27132713
/// contain valid process identifiers.
27142714
/// </summary>

src/System.Management.Automation/engine/ProcessCodeMethods.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,8 @@ internal static int GetParentPid(Process process)
5858
Diagnostics.Assert(process != null, "Ensure process is not null before calling");
5959
PROCESS_BASIC_INFORMATION pbi;
6060
int size;
61-
#if CORECLR
62-
var res = NtQueryInformationProcess(process.SafeHandle.DangerousGetHandle(), 0, out pbi, Marshal.SizeOf<PROCESS_BASIC_INFORMATION>(), out size);
63-
#else
6461
var res = NtQueryInformationProcess(process.Handle, 0, out pbi, Marshal.SizeOf<PROCESS_BASIC_INFORMATION>(), out size);
65-
#endif
62+
6663
return res != 0 ? InvalidProcessId : pbi.InheritedFromUniqueProcessId.ToInt32();
6764
}
6865

src/System.Management.Automation/namespaces/Win32Native.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ internal static extern bool LookupAccountSid(string lpSystemName,
140140
[ResourceExposure(ResourceScope.Machine)]
141141
[SuppressMessage("Microsoft.Security", "CA2118:ReviewSuppressUnmanagedCodeSecurityUsage")]
142142
[return: MarshalAs(UnmanagedType.Bool)]
143-
internal static extern bool OpenProcessToken(SafeHandle processHandle, uint desiredAccess, out IntPtr tokenHandle);
143+
internal static extern bool OpenProcessToken(IntPtr processHandle, uint desiredAccess, out IntPtr tokenHandle);
144144

145145
/// <summary>
146146
/// The GetTokenInformation function retrieves a specified type of information about an access token.

src/System.Management.Automation/utils/ClrFacade.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,6 @@ static ClrFacade()
4747
/// </summary>
4848
internal static readonly char FIRST_CHAR_PSASSEMBLY_MARK = (char)0x29f9;
4949

50-
#region Process
51-
52-
/// <summary>
53-
/// Facade for Process.Handle to get SafeHandle
54-
/// </summary>
55-
/// <param name="process"></param>
56-
/// <returns>SafeHandle</returns>
57-
internal static SafeHandle GetSafeProcessHandle(Process process)
58-
{
59-
return process.SafeHandle;
60-
}
61-
62-
#endregion Process
63-
6450
#region Assembly
6551

6652
internal static IEnumerable<Assembly> GetAssemblies(TypeResolutionState typeResolutionState, TypeName typeName)

0 commit comments

Comments
 (0)