mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-05-24 18:38:50 +00:00
Remove the GetProcessId() call from Win32/Program.inc, take 2.
GetProcessId() was introduced only in Windows XP, and we want to support earlier versions. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@82548 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
460a786b34
commit
92d32367ef
@ -22,6 +22,13 @@
|
|||||||
//=== and must not be UNIX code
|
//=== and must not be UNIX code
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
struct Win32ProcessInfo {
|
||||||
|
HANDLE hProcess;
|
||||||
|
DWORD dwProcessId;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
using namespace sys;
|
using namespace sys;
|
||||||
|
|
||||||
@ -29,15 +36,16 @@ Program::Program() : Data_(0) {}
|
|||||||
|
|
||||||
Program::~Program() {
|
Program::~Program() {
|
||||||
if (Data_) {
|
if (Data_) {
|
||||||
HANDLE hProcess = reinterpret_cast<HANDLE>(Data_);
|
Win32ProcessInfo* wpi = reinterpret_cast<Win32ProcessInfo*>(Data_);
|
||||||
CloseHandle(hProcess);
|
CloseHandle(wpi->hProcess);
|
||||||
|
delete wpi;
|
||||||
Data_ = 0;
|
Data_ = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned Program::GetPid() const {
|
unsigned Program::GetPid() const {
|
||||||
HANDLE hProcess = reinterpret_cast<HANDLE>(Data_);
|
Win32ProcessInfo* wpi = reinterpret_cast<Win32ProcessInfo*>(Data_);
|
||||||
return GetProcessId(hProcess);
|
return wpi->dwProcessId;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This function just uses the PATH environment variable to find the program.
|
// This function just uses the PATH environment variable to find the program.
|
||||||
@ -138,8 +146,9 @@ Program::Execute(const Path& path,
|
|||||||
unsigned memoryLimit,
|
unsigned memoryLimit,
|
||||||
std::string* ErrMsg) {
|
std::string* ErrMsg) {
|
||||||
if (Data_) {
|
if (Data_) {
|
||||||
HANDLE hProcess = reinterpret_cast<HANDLE>(Data_);
|
Win32ProcessInfo* wpi = reinterpret_cast<Win32ProcessInfo*>(Data_);
|
||||||
CloseHandle(Data_);
|
CloseHandle(wpi->hProcess);
|
||||||
|
delete wpi;
|
||||||
Data_ = 0;
|
Data_ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -269,7 +278,10 @@ Program::Execute(const Path& path,
|
|||||||
path.str() + "'");
|
path.str() + "'");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Data_ = reinterpret_cast<void*>(pi.hProcess);
|
Win32ProcessInfo* wpi = new Win32ProcessInfo;
|
||||||
|
wpi->hProcess = pi.hProcess;
|
||||||
|
wpi->dwProcessId = pi.dwProcessId;
|
||||||
|
Data_ = wpi;
|
||||||
|
|
||||||
// Make sure these get closed no matter what.
|
// Make sure these get closed no matter what.
|
||||||
AutoHandle hThread(pi.hThread);
|
AutoHandle hThread(pi.hThread);
|
||||||
@ -310,7 +322,8 @@ Program::Wait(unsigned secondsToWait,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
HANDLE hProcess = reinterpret_cast<HANDLE>(Data_);
|
Win32ProcessInfo* wpi = reinterpret_cast<Win32ProcessInfo*>(Data_);
|
||||||
|
HANDLE hProcess = wpi->hProcess;
|
||||||
|
|
||||||
// Wait for the process to terminate.
|
// Wait for the process to terminate.
|
||||||
DWORD millisecondsToWait = INFINITE;
|
DWORD millisecondsToWait = INFINITE;
|
||||||
@ -346,7 +359,8 @@ Program::Kill(std::string* ErrMsg) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
HANDLE hProcess = reinterpret_cast<HANDLE>(Data_);
|
Win32ProcessInfo* wpi = reinterpret_cast<Win32ProcessInfo*>(Data_);
|
||||||
|
HANDLE hProcess = wpi->hProcess;
|
||||||
if (TerminateProcess(hProcess, 1) == 0) {
|
if (TerminateProcess(hProcess, 1) == 0) {
|
||||||
MakeErrMsg(ErrMsg, "The process couldn't be killed!");
|
MakeErrMsg(ErrMsg, "The process couldn't be killed!");
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user