-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Open
Copilot
wants to merge
41
commits into
main
Choose a base branch
from
copilot/add-new-apis-to-safeprocesshandle
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,526
−84
Open
Changes from all commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
4f3f950
Initial plan
Copilot 92de299
Add ProcessStartOptions class with path resolution and tests
Copilot 0c9d3e2
Fix build errors and test failures in ProcessStartOptions
Copilot 794a8a2
Improve code comments based on review feedback
Copilot a1b3426
Fix exception documentation and add caching comment
Copilot 10ff95a
Address PR feedback: use Process.ResolvePath, fix tests, add null checks
Copilot fc0fd30
Refactor: ProcessStartOptions.ResolvePath as main impl, Process calls it
Copilot f687eb8
address my own feedback
adamsitnik 5459ec9
Simplify Windows tests: remove ConditionalFact, fix nested try-finally
Copilot c3517ee
Refactor tests: partial classes, remove Test prefix, use new() syntax…
Copilot bbea91e
Fix test conditions: remove redundant IsWindows check, use GetFullPat…
Copilot d9d381f
Fix test failures: use ResolveTarget helper for symlinks, fix lambda …
Copilot b4d6e64
Fix Unix test failures: use EndsWith instead of exact path comparison
Copilot 98d4201
Address code review: add file check, fix .exe logic, update comments,…
Copilot 5b024d4
Cache Windows directory value for performance
Copilot add4af6
Remove DictionaryWrapper and fix Unix path test for macOS symlinks
Copilot b3939ad
Use Environment.SystemDirectory and fix Unix path test for macOS
Copilot 63e7fc0
Inline GetSystemDirectory, fix Unix path test, use EndsWith for util …
Copilot 9ceaad1
Update src/libraries/System.Diagnostics.Process/src/System.Diagnostic…
adamsitnik 82e2cec
fix the ResolvePath_UsesCurrentDirectory test
adamsitnik 0f37ab7
Merge remote-tracking branch 'origin/main' into copilot/add-processst…
adamsitnik 27ad99b
Initial plan
Copilot 90ba788
Add ProcessExitStatus type, Windows interop files, and ProcessUtils
Copilot 23a457a
Add SafeProcessHandle new APIs, ProcessExitStatus, interop definition…
Copilot 3017731
Add test files for SafeProcessHandle APIs
Copilot fb6e0a4
Merge remote-tracking branch 'origin/main' into copilot/add-new-apis-…
adamsitnik 51bee9d
Address review feedback: consolidate interop files, reuse existing AP…
Copilot 2e5f817
fix the build
adamsitnik e65c2bf
Fix bugs found during code review: remove CloseHandle on pseudo-handl…
Copilot 5a26663
Add ReaderWriterLockSlim to prevent accidental handle inheritance bet…
Copilot 180fc9b
Address jkotas feedback: simplify handle checks, fix OOM safety, fold…
Copilot 5271b03
Merge remote-tracking branch 'origin/main' into copilot/add-new-apis-…
adamsitnik febd0a6
cleanup
adamsitnik 7973122
Address round 4 review feedback: Resume protection, NativeMemory.Allo…
Copilot 8f3c12e
Remove leftover blank line in Process.cs and add test for starting pr…
Copilot adeeb03
Use typed pointers instead of IntPtr for NativeMemory.Alloc results
Copilot a3f204c
Changes before error encountered
Copilot af1336a
Make Resume, KillProcessGroup internal; replace ConditionalFact with …
Copilot b73faef
GenerateConsoleCtrlEvent doesn’t work on Nano Server
adamsitnik 776b250
Make sure we kill entire process group when available
adamsitnik 2adcdfe
Address jkotas feedback: combine signal tests into Theory, remove Get…
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.JobObjects.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } |
64 changes: 64 additions & 0 deletions
64
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.ProcThreadAttributeList.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 nuint 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, | ||
| nuint cbSize, | ||
| void* lpPreviousValue, | ||
| nuint lpReturnSize); | ||
|
|
||
| [LibraryImport(Libraries.Kernel32, SetLastError = true)] | ||
| internal static unsafe partial void DeleteProcThreadAttributeList(LPPROC_THREAD_ATTRIBUTE_LIST lpAttributeList); | ||
| } | ||
| } |
14 changes: 14 additions & 0 deletions
14
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.ResumeThread_IntPtr.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.