-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Implement ProcessStartInfo.KillOnParentExit for Windows #126699
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
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
abb8c0e
Implement ProcessStartInfo.KillOnParentExit for Windows
Copilot 31f6e6b
Address review feedback: defensive UserName check, resume only on hap…
Copilot b910623
address my own feedback:
adamsitnik cc04598
Address review feedback: add SupportedOSPlatform("windows"), check Re…
Copilot afab02e
Add Windows SDK doc link for JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE and r…
Copilot 309480c
increase test coverage:
adamsitnik f0f9714
fix a bug discovered by the tests: when all standard handles are inva…
adamsitnik 7f887bd
Don't create (and upload) a memory dump for this test, as AV is inten…
adamsitnik afbcc1e
Merge remote-tracking branch 'origin/main' into copilot/add-kill-on-p…
adamsitnik ede5e33
Apply suggestions from code review
adamsitnik 9bb0ef4
Apply suggestions from code review
adamsitnik 7b0e652
make the tests less flaky
adamsitnik c432cd5
refactor the code: move all logic related to extended startup info in…
adamsitnik 6bae099
Merge branch 'main' into copilot/add-kill-on-parent-exit-property
adamsitnik bbab88f
Update src/libraries/System.Diagnostics.Process/tests/KillOnParentExi…
jkotas baea489
Move ResumeThread P/Invoke to dedicated file and remove redundant Ski…
Copilot 4fdc31a
Use nuint for numerical fields in job object structs and fix processI…
Copilot 04d67a9
Change ResumeThread return type to uint (matches DWORD) and remove in…
Copilot 20559e0
Use IsInvalidHandle for thread handle assertion (checks both 0 and -1)
Copilot 35b273c
try to avoid creating a memory dump
adamsitnik 8beb026
Apply suggestions from code review
adamsitnik c5b7d59
Replace local ResumeThread P/Invoke in ProcessHandlesTests with share…
Copilot 84ca617
Remove unused System.Runtime.InteropServices using after removing loc…
Copilot 96e2804
Remove defensive HELIX_WORKITEM_UPLOAD_ROOT env var from crash test
Copilot f497166
Address jkotas feedback: remove unused enum, unnecessary early return…
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
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
75 changes: 75 additions & 0 deletions
75
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,75 @@ | ||
| // 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; | ||
| using Microsoft.Win32.SafeHandles; | ||
|
|
||
| internal static partial class Interop | ||
| { | ||
| internal static partial class Kernel32 | ||
| { | ||
| internal sealed class SafeJobHandle : SafeHandleZeroOrMinusOneIsInvalid | ||
| { | ||
| public SafeJobHandle() : base(true) { } | ||
|
|
||
| protected override bool ReleaseHandle() => Interop.Kernel32.CloseHandle(handle); | ||
| } | ||
|
|
||
| [LibraryImport(Libraries.Kernel32, SetLastError = true)] | ||
| internal static partial SafeJobHandle CreateJobObjectW(IntPtr lpJobAttributes, IntPtr lpName); | ||
|
|
||
| internal const uint JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE = 0x00002000; | ||
|
|
||
| internal enum JOBOBJECTINFOCLASS | ||
| { | ||
| 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 nuint MinimumWorkingSetSize; | ||
| internal nuint MaximumWorkingSetSize; | ||
| internal uint ActiveProcessLimit; | ||
| internal nuint 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 nuint ProcessMemoryLimit; | ||
| internal nuint JobMemoryLimit; | ||
| internal nuint PeakProcessMemoryUsed; | ||
| internal nuint PeakJobMemoryUsed; | ||
| } | ||
|
|
||
| [LibraryImport(Libraries.Kernel32, SetLastError = true)] | ||
| [return: MarshalAs(UnmanagedType.Bool)] | ||
| internal static partial bool SetInformationJobObject(SafeJobHandle hJob, JOBOBJECTINFOCLASS JobObjectInfoClass, ref JOBOBJECT_EXTENDED_LIMIT_INFORMATION lpJobObjectInfo, uint cbJobObjectInfoLength); | ||
|
|
||
| [LibraryImport(Libraries.Kernel32, SetLastError = true)] | ||
| [return: MarshalAs(UnmanagedType.Bool)] | ||
| internal static partial bool AssignProcessToJobObject(SafeJobHandle hJob, SafeProcessHandle hProcess); | ||
|
|
||
| internal const int PROC_THREAD_ATTRIBUTE_JOB_LIST = 0x0002000D; | ||
| } | ||
| } |
14 changes: 14 additions & 0 deletions
14
src/libraries/Common/src/Interop/Windows/Kernel32/Interop.ResumeThread.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 uint 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
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.