-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(windows): suspend entire process tree
Suspend / resume child processes recursively on Windows, the same as we do on Linux. Improves reliability and performance gains for processes that spawn many child processes.
- Loading branch information
Showing
2 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
lib/native_platform/src/process/repository/src/win32/win32.dart
This file contains 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,53 @@ | ||
// ignore_for_file: non_constant_identifier_names, constant_identifier_names | ||
|
||
import 'dart:convert'; | ||
import 'dart:ffi'; | ||
|
||
final _kernel32 = DynamicLibrary.open('kernel32.dll'); | ||
|
||
final CreateToolhelp32Snapshot = | ||
_kernel32.lookupFunction<IntPtr Function(Uint32, Uint32), int Function(int, int)>( | ||
'CreateToolhelp32Snapshot'); | ||
|
||
final Process32First = _kernel32.lookupFunction< | ||
Int32 Function(IntPtr hSnapshot, Pointer<PROCESSENTRY32> lppe), | ||
int Function(int hSnapshot, Pointer<PROCESSENTRY32> lppe)>('Process32First'); | ||
|
||
final Process32Next = _kernel32.lookupFunction< | ||
Int32 Function(IntPtr hSnapshot, Pointer<PROCESSENTRY32> lppe), | ||
int Function(int hSnapshot, Pointer<PROCESSENTRY32> lppe)>('Process32Next'); | ||
|
||
final class PROCESSENTRY32 extends Struct { | ||
@Int32() | ||
external int dwSize; | ||
@Int32() | ||
external int cntUsage; | ||
@Int32() | ||
external int th32ProcessID; | ||
external Pointer<Uint32> th32DefaultHeapID; | ||
@Int32() | ||
external int th32ModuleID; | ||
@Int32() | ||
external int cntThreads; | ||
@Int32() | ||
external int th32ParentProcessID; | ||
@Int32() | ||
external int pcPriClassBase; | ||
@Int32() | ||
external int dwFlags; | ||
@Array(260) | ||
external Array<Uint8> _szExeFile; | ||
String get szExeFile => _unwrap(_szExeFile); | ||
} | ||
|
||
String _unwrap(Array<Uint8> bytes) { | ||
String buf = ""; | ||
int i = 0; | ||
while (bytes[i] != 0) { | ||
buf += utf8.decode([bytes[i]]); | ||
i += 1; | ||
} | ||
return buf; | ||
} | ||
|
||
const TH32CS_SNAPPROCESS = 0x00000002; |
This file contains 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