[*] NT Processes: GetProcessId() now returns a pointer to a _PROCESS_INFORMATION struct

This commit is contained in:
Reece Wilson 2023-09-15 16:25:40 +01:00
parent 67b047eead
commit 3ba93439c8
2 changed files with 14 additions and 15 deletions

View File

@ -86,8 +86,9 @@ namespace Aurora::Processes
} }
AuWin32CloseHandle(this->poke_); AuWin32CloseHandle(this->poke_);
AuWin32CloseHandle(this->process_); this->process_ = INVALID_HANDLE_VALUE;
AuWin32CloseHandle(this->hthread_); AuWin32CloseHandle(this->processInfo_.hProcess);
AuWin32CloseHandle(this->processInfo_.hThread);
ShutdownPipes(); ShutdownPipes();
} }
@ -99,13 +100,13 @@ namespace Aurora::Processes
return {}; return {};
} }
return ::GetProcessId(this->process_); return (AuUInt)&this->processInfo_;
} }
bool ProcessImpl::TermWinEnumProcesses() bool ProcessImpl::TermWinEnumProcesses()
{ {
#if defined(AURORA_PLATFORM_WIN32) #if defined(AURORA_PLATFORM_WIN32)
return SendExitSignal(this->process_); return SendExitSignal(this->processInfo_.hProcess);
#else #else
return false; return false;
#endif #endif
@ -502,7 +503,6 @@ namespace Aurora::Processes
return false; return false;
} }
PROCESS_INFORMATION processInfo = { 0 };
{ {
STARTUPINFOW startupInfo = { 0 }; STARTUPINFOW startupInfo = { 0 };
startupInfo.cb = sizeof(startupInfo); startupInfo.cb = sizeof(startupInfo);
@ -592,7 +592,7 @@ namespace Aurora::Processes
NULL, NULL, true, NULL, NULL, true,
uCreateFlags, uCreateFlags,
envVarBlock.size() ? envVarBlock.data() : nullptr, envVarBlock.size() ? envVarBlock.data() : nullptr,
wcwd.size() ? wcwd.data() : nullptr, &startupInfo, &processInfo); wcwd.size() ? wcwd.data() : nullptr, &startupInfo, &this->processInfo_);
if (!result) if (!result)
{ {
@ -601,8 +601,7 @@ namespace Aurora::Processes
return false; return false;
} }
this->process_ = processInfo.hProcess; this->process_ = this->processInfo_.hProcess;
this->hthread_ = processInfo.hThread;
RelOtherHandles(); RelOtherHandles();
@ -618,7 +617,7 @@ namespace Aurora::Processes
(bool(primary))) (bool(primary)))
{ {
::SetProcessAffinityMask(this->process_, primary.lower); ::SetProcessAffinityMask(this->process_, primary.lower);
::SetThreadAffinityMask(this->hthread_, primary.lower); ::SetThreadAffinityMask(this->processInfo_.hThread, primary.lower);
} }
else else
{ {
@ -629,7 +628,7 @@ namespace Aurora::Processes
if (!this->startup_.bInDebugMode) if (!this->startup_.bInDebugMode)
{ {
::ResumeThread(this->hthread_); ::ResumeThread(this->processInfo_.hThread);
} }
} }
@ -643,7 +642,7 @@ namespace Aurora::Processes
if (this->type_ == ESpawnType::eSpawnChildProcessWorker) if (this->type_ == ESpawnType::eSpawnChildProcessWorker)
{ {
#if defined(AURORA_PLATFORM_WIN32) #if defined(AURORA_PLATFORM_WIN32)
AssignJobWorker(processInfo.hProcess); AssignJobWorker(this->processInfo_.hProcess);
#endif #endif
} }
} }
@ -653,13 +652,14 @@ namespace Aurora::Processes
{ {
HANDLE b[] = HANDLE b[] =
{ {
this->poke_, processInfo.hProcess this->poke_ /*break on AuProcess/ProcessImpl free*/,
this->processInfo_.hProcess /*break on prorcess free*/
}; };
WaitForMultipleObjects(2, b, FALSE, INFINITE); WaitForMultipleObjects(2, b, FALSE, INFINITE);
DWORD exitCode; DWORD exitCode;
auto result = GetExitCodeProcess(processInfo.hProcess, &exitCode); auto result = GetExitCodeProcess(this->processInfo_.hProcess, &exitCode);
if (result) if (result)
{ {
this->exitCode_ = exitCode; this->exitCode_ = exitCode;
@ -687,7 +687,6 @@ namespace Aurora::Processes
return true; return true;
} }
void ProcessImpl::RelOtherHandles() void ProcessImpl::RelOtherHandles()
{ {
if (!this->bDontRelOut_) if (!this->bDontRelOut_)

View File

@ -43,8 +43,8 @@ namespace Aurora::Processes
void RelOtherHandles(); void RelOtherHandles();
private: private:
PROCESS_INFORMATION processInfo_ {};
HANDLE process_ {INVALID_HANDLE_VALUE}; HANDLE process_ {INVALID_HANDLE_VALUE};
HANDLE hthread_ {INVALID_HANDLE_VALUE};
HANDLE pipeStdOutRead_ {INVALID_HANDLE_VALUE}; HANDLE pipeStdOutRead_ {INVALID_HANDLE_VALUE};
HANDLE pipeStdOutWrite_ {INVALID_HANDLE_VALUE}; HANDLE pipeStdOutWrite_ {INVALID_HANDLE_VALUE};