| 2007 | // } |
| 2008 | |
| 2009 | BFP_EXPORT void BFP_CALLTYPE BfpSpawn_Kill(BfpSpawn* spawn, int exitCode, BfpKillFlags killFlags, BfpSpawnResult* outResult) |
| 2010 | { |
| 2011 | //::EnumWindows((WNDENUMPROC)TerminateAppEnum, (LPARAM)spawn->mProcessId); |
| 2012 | |
| 2013 | if ((killFlags & BfpKillFlag_KillChildren) != 0) |
| 2014 | { |
| 2015 | ImportNTDll(); |
| 2016 | |
| 2017 | HashSet<int> killSet; |
| 2018 | killSet.Add(spawn->mProcessId); |
| 2019 | HashSet<int> killedSet; |
| 2020 | killedSet.Add(spawn->mProcessId); |
| 2021 | |
| 2022 | // New child processes can launch between the NtQuerySystemInformation call and the actual process termination, |
| 2023 | // so we need to run multiple loops until we stop finding child processes |
| 2024 | while (true) |
| 2025 | { |
| 2026 | uint allocSize = 8192; |
| 2027 | uint8* data; |
| 2028 | while (true) |
| 2029 | { |
| 2030 | data = new uint8[allocSize]; |
| 2031 | |
| 2032 | ULONG wantSize = 0; |
| 2033 | NTSTATUS status = gNtQuerySystemInformation(SystemProcessInformation, data, allocSize, &wantSize); |
| 2034 | |
| 2035 | if (status != STATUS_INFO_LENGTH_MISMATCH) |
| 2036 | { |
| 2037 | bool foundNew; |
| 2038 | do |
| 2039 | { |
| 2040 | foundNew = false; |
| 2041 | auto processInfo = (SYSTEM_PROCESS_INFORMATION*)data; |
| 2042 | |
| 2043 | auto curProcessInfo = processInfo; |
| 2044 | while (true) |
| 2045 | { |
| 2046 | if (curProcessInfo == NULL) |
| 2047 | break; |
| 2048 | |
| 2049 | if (killSet.Contains((int)(intptr)curProcessInfo->InheritedFromProcessId)) |
| 2050 | { |
| 2051 | if (killSet.Add((int)(intptr)curProcessInfo->ProcessId)) |
| 2052 | foundNew = true; |
| 2053 | } |
| 2054 | |
| 2055 | if (curProcessInfo->NextEntryOffset == 0) |
| 2056 | break; |
| 2057 | curProcessInfo = (SYSTEM_PROCESS_INFORMATION*)((intptr)curProcessInfo + curProcessInfo->NextEntryOffset); |
| 2058 | } |
| 2059 | } while (foundNew); |
| 2060 | |
| 2061 | delete data; |
| 2062 | break; |
| 2063 | } |
| 2064 | |
| 2065 | allocSize = wantSize + 4096; |
| 2066 | delete data; |
no test coverage detected