-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Add new process management APIs to SafeProcessHandle #124375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
4f3f950
92de299
0c9d3e2
794a8a2
a1b3426
10ff95a
fc0fd30
f687eb8
5459ec9
c3517ee
bbea91e
d9d381f
b4d6e64
98d4201
5b024d4
add4af6
b3939ad
63e7fc0
9ceaad1
82e2cec
0f37ab7
27ad99b
90ba788
23a457a
3017731
fb6e0a4
51bee9d
2e5f817
e65c2bf
5a26663
180fc9b
5271b03
febd0a6
7973122
8f3c12e
adeeb03
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using System.Runtime.InteropServices; | ||
|
|
||
| internal static partial class Interop | ||
| { | ||
| internal static partial class Kernel32 | ||
| { | ||
| [LibraryImport(Libraries.Kernel32, SetLastError = true)] | ||
| internal static partial IntPtr CreateJobObjectW(IntPtr lpJobAttributes, IntPtr lpName); | ||
|
|
||
| internal const uint JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE = 0x00002000; | ||
|
|
||
| internal enum JOBOBJECTINFOCLASS | ||
| { | ||
| JobObjectBasicLimitInformation = 2, | ||
| JobObjectExtendedLimitInformation = 9 | ||
| } | ||
|
|
||
| [StructLayout(LayoutKind.Sequential)] | ||
| internal struct IO_COUNTERS | ||
| { | ||
| internal ulong ReadOperationCount; | ||
| internal ulong WriteOperationCount; | ||
| internal ulong OtherOperationCount; | ||
| internal ulong ReadTransferCount; | ||
| internal ulong WriteTransferCount; | ||
| internal ulong OtherTransferCount; | ||
| } | ||
|
|
||
| [StructLayout(LayoutKind.Sequential)] | ||
| internal struct JOBOBJECT_BASIC_LIMIT_INFORMATION | ||
| { | ||
| internal long PerProcessUserTimeLimit; | ||
| internal long PerJobUserTimeLimit; | ||
| internal uint LimitFlags; | ||
| internal UIntPtr MinimumWorkingSetSize; | ||
| internal UIntPtr MaximumWorkingSetSize; | ||
| internal uint ActiveProcessLimit; | ||
| internal UIntPtr Affinity; | ||
| internal uint PriorityClass; | ||
| internal uint SchedulingClass; | ||
| } | ||
|
|
||
| [StructLayout(LayoutKind.Sequential)] | ||
| internal struct JOBOBJECT_EXTENDED_LIMIT_INFORMATION | ||
| { | ||
| internal JOBOBJECT_BASIC_LIMIT_INFORMATION BasicLimitInformation; | ||
| internal IO_COUNTERS IoInfo; | ||
| internal UIntPtr ProcessMemoryLimit; | ||
| internal UIntPtr JobMemoryLimit; | ||
| internal UIntPtr PeakProcessMemoryUsed; | ||
| internal UIntPtr PeakJobMemoryUsed; | ||
| } | ||
|
|
||
| [LibraryImport(Libraries.Kernel32, SetLastError = true)] | ||
| [return: MarshalAs(UnmanagedType.Bool)] | ||
| internal static partial bool SetInformationJobObject(IntPtr hJob, JOBOBJECTINFOCLASS JobObjectInfoClass, ref JOBOBJECT_EXTENDED_LIMIT_INFORMATION lpJobObjectInfo, uint cbJobObjectInfoLength); | ||
|
|
||
| [LibraryImport(Libraries.Kernel32, SetLastError = true)] | ||
| [return: MarshalAs(UnmanagedType.Bool)] | ||
| internal static partial bool TerminateJobObject(IntPtr hJob, uint uExitCode); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using System.Runtime.InteropServices; | ||
|
|
||
| internal static partial class Interop | ||
| { | ||
| internal static partial class Kernel32 | ||
| { | ||
| internal const int PROC_THREAD_ATTRIBUTE_HANDLE_LIST = 0x00020002; | ||
| internal const int PROC_THREAD_ATTRIBUTE_JOB_LIST = 0x0002000D; | ||
| internal const int EXTENDED_STARTUPINFO_PRESENT = 0x00080000; | ||
|
|
||
| [StructLayout(LayoutKind.Sequential)] | ||
| internal struct STARTUPINFOEX | ||
| { | ||
| internal STARTUPINFO StartupInfo; | ||
| internal LPPROC_THREAD_ATTRIBUTE_LIST lpAttributeList; | ||
| } | ||
|
|
||
| internal struct LPPROC_THREAD_ATTRIBUTE_LIST | ||
| { | ||
| internal IntPtr AttributeList; | ||
| } | ||
|
|
||
| [LibraryImport(Libraries.Kernel32, EntryPoint = "CreateProcessW", SetLastError = true, StringMarshalling = StringMarshalling.Utf16)] | ||
| [return: MarshalAs(UnmanagedType.Bool)] | ||
| internal static unsafe partial bool CreateProcess( | ||
| char* lpApplicationName, | ||
| char* lpCommandLine, | ||
| ref SECURITY_ATTRIBUTES procSecAttrs, | ||
| ref SECURITY_ATTRIBUTES threadSecAttrs, | ||
| [MarshalAs(UnmanagedType.Bool)] bool bInheritHandles, | ||
| int dwCreationFlags, | ||
| char* lpEnvironment, | ||
| string? lpCurrentDirectory, | ||
| ref STARTUPINFOEX lpStartupInfo, | ||
| ref PROCESS_INFORMATION lpProcessInformation | ||
| ); | ||
|
|
||
| [LibraryImport(Libraries.Kernel32, SetLastError = true)] | ||
| [return: MarshalAs(UnmanagedType.Bool)] | ||
| internal static unsafe partial bool InitializeProcThreadAttributeList( | ||
| LPPROC_THREAD_ATTRIBUTE_LIST lpAttributeList, | ||
| int dwAttributeCount, | ||
| int dwFlags, | ||
| ref IntPtr lpSize); | ||
|
|
||
| [LibraryImport(Libraries.Kernel32, SetLastError = true)] | ||
| [return: MarshalAs(UnmanagedType.Bool)] | ||
| internal static unsafe partial bool UpdateProcThreadAttribute( | ||
| LPPROC_THREAD_ATTRIBUTE_LIST lpAttributeList, | ||
| int dwFlags, | ||
| IntPtr attribute, | ||
| void* lpValue, | ||
| IntPtr cbSize, | ||
| void* lpPreviousValue, | ||
| IntPtr lpReturnSize); | ||
|
|
||
| [LibraryImport(Libraries.Kernel32, SetLastError = true)] | ||
| internal static unsafe partial void DeleteProcThreadAttributeList(LPPROC_THREAD_ATTRIBUTE_LIST lpAttributeList); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using System.Runtime.InteropServices; | ||
|
|
||
| internal static partial class Interop | ||
| { | ||
| internal static partial class Kernel32 | ||
| { | ||
| [LibraryImport(Libraries.Kernel32, SetLastError = true)] | ||
| internal static partial int ResumeThread(IntPtr hThread); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,17 +1,14 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Licensed to the .NET Foundation under one or more agreements. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // The .NET Foundation licenses this file to you under the MIT license. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /*============================================================ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ** Class: SafeProcessHandle | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ** A wrapper for a process handle | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ===========================================================*/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| using System; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| using System.ComponentModel; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| using System.Diagnostics; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| using System.Diagnostics.CodeAnalysis; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| using System.IO; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| using System.Runtime.InteropServices; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| using System.Threading; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| using System.Threading.Tasks; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| namespace Microsoft.Win32.SafeHandles | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -35,16 +32,34 @@ internal SafeProcessHandle(int processId, SafeWaitHandle handle) : | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| handle.DangerousAddRef(ref _releaseRef); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| internal int ProcessId { get; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| protected override bool ReleaseHandle() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (_releaseRef) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Debug.Assert(_handle != null); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Debug.Assert(_handle is not null); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _handle.DangerousRelease(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return true; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private static SafeProcessHandle OpenCore(int processId) => throw new NotImplementedException(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private static SafeProcessHandle StartCore(ProcessStartOptions options, SafeFileHandle inputHandle, SafeFileHandle outputHandle, SafeFileHandle errorHandle, bool createSuspended) => throw new NotImplementedException(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private ProcessExitStatus WaitForExitCore() => throw new NotImplementedException(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private bool TryWaitForExitCore(int milliseconds, [NotNullWhen(true)] out ProcessExitStatus? exitStatus) => throw new NotImplementedException(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private ProcessExitStatus WaitForExitOrKillOnTimeoutCore(int milliseconds) => throw new NotImplementedException(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private Task<ProcessExitStatus> WaitForExitAsyncCore(CancellationToken cancellationToken) => throw new NotImplementedException(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private Task<ProcessExitStatus> WaitForExitOrKillOnCancellationAsyncCore(CancellationToken cancellationToken) => throw new NotImplementedException(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| internal bool KillCore(bool throwOnError, bool entireProcessGroup = false) => throw new NotImplementedException(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private void ResumeCore() => throw new NotImplementedException(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private void SendSignalCore(PosixSignal signal, bool entireProcessGroup) => throw new NotImplementedException(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+45
to
+63
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private static SafeProcessHandle OpenCore(int processId) => throw new NotImplementedException(); | |
| private static SafeProcessHandle StartCore(ProcessStartOptions options, SafeFileHandle inputHandle, SafeFileHandle outputHandle, SafeFileHandle errorHandle, bool createSuspended) => throw new NotImplementedException(); | |
| private ProcessExitStatus WaitForExitCore() => throw new NotImplementedException(); | |
| private bool TryWaitForExitCore(int milliseconds, [NotNullWhen(true)] out ProcessExitStatus? exitStatus) => throw new NotImplementedException(); | |
| private ProcessExitStatus WaitForExitOrKillOnTimeoutCore(int milliseconds) => throw new NotImplementedException(); | |
| private Task<ProcessExitStatus> WaitForExitAsyncCore(CancellationToken cancellationToken) => throw new NotImplementedException(); | |
| private Task<ProcessExitStatus> WaitForExitOrKillOnCancellationAsyncCore(CancellationToken cancellationToken) => throw new NotImplementedException(); | |
| internal bool KillCore(bool throwOnError, bool entireProcessGroup = false) => throw new NotImplementedException(); | |
| private void ResumeCore() => throw new NotImplementedException(); | |
| private void SendSignalCore(PosixSignal signal, bool entireProcessGroup) => throw new NotImplementedException(); | |
| private static SafeProcessHandle OpenCore(int processId) => throw new PlatformNotSupportedException(); | |
| private static SafeProcessHandle StartCore(ProcessStartOptions options, SafeFileHandle inputHandle, SafeFileHandle outputHandle, SafeFileHandle errorHandle, bool createSuspended) => throw new PlatformNotSupportedException(); | |
| private ProcessExitStatus WaitForExitCore() => throw new PlatformNotSupportedException(); | |
| private bool TryWaitForExitCore(int milliseconds, [NotNullWhen(true)] out ProcessExitStatus? exitStatus) => throw new PlatformNotSupportedException(); | |
| private ProcessExitStatus WaitForExitOrKillOnTimeoutCore(int milliseconds) => throw new PlatformNotSupportedException(); | |
| private Task<ProcessExitStatus> WaitForExitAsyncCore(CancellationToken cancellationToken) => throw new PlatformNotSupportedException(); | |
| private Task<ProcessExitStatus> WaitForExitOrKillOnCancellationAsyncCore(CancellationToken cancellationToken) => throw new PlatformNotSupportedException(); | |
| internal bool KillCore(bool throwOnError, bool entireProcessGroup = false) => throw new PlatformNotSupportedException(); | |
| private void ResumeCore() => throw new PlatformNotSupportedException(); | |
| private void SendSignalCore(PosixSignal signal, bool entireProcessGroup) => throw new PlatformNotSupportedException(); |
Uh oh!
There was an error while loading. Please reload this page.