/// @brief An abstraction for finding and executing programs.
class Program {
/// Opaque handle for target specific data.
/// @brief An abstraction for finding and executing programs.
class Program {
/// Opaque handle for target specific data.
- void *Data;
-
- unsigned Pid_;
// Noncopyable.
Program(const Program& other);
// Noncopyable.
Program(const Program& other);
~Program();
/// Return process ID of this program.
~Program();
/// Return process ID of this program.
- unsigned GetPid() { return Pid_; }
/// This function executes the program using the \p arguments provided. The
/// invoked program will inherit the stdin, stdout, and stderr file
/// This function executes the program using the \p arguments provided. The
/// invoked program will inherit the stdin, stdout, and stderr file
namespace llvm {
using namespace sys;
namespace llvm {
using namespace sys;
-Program::Program() : Pid_(0) {}
+Program::Program() : Data_(0) {}
+unsigned Program::GetPid() {
+ return reinterpret_cast<unsigned>(Data_);
+}
+
// This function just uses the PATH environment variable to find the program.
Path
Program::FindProgramByName(const std::string& progName) {
// This function just uses the PATH environment variable to find the program.
Path
Program::FindProgramByName(const std::string& progName) {
+ Data_ = reinterpret_cast<void*>(child);
#ifdef HAVE_SYS_WAIT_H
struct sigaction Act, Old;
#ifdef HAVE_SYS_WAIT_H
struct sigaction Act, Old;
MakeErrMsg(ErrMsg, "Process not started!");
return -1;
}
MakeErrMsg(ErrMsg, "Process not started!");
return -1;
}
// Parent process: Wait for the child process to terminate.
int status;
// Parent process: Wait for the child process to terminate.
int status;
- int child = this->Pid_;
+ pid_t child = reinterpret_cast<pid_t>(Data_);
while (wait(&status) != child)
if (secondsToWait && errno == EINTR) {
// Kill the child.
while (wait(&status) != child)
if (secondsToWait && errno == EINTR) {
// Kill the child.
bool
Program::Kill(std::string* ErrMsg) {
bool
Program::Kill(std::string* ErrMsg) {
MakeErrMsg(ErrMsg, "Process not started!");
return true;
}
MakeErrMsg(ErrMsg, "Process not started!");
return true;
}
- return (kill(Pid_, SIGKILL) == 0);
+ pid_t pid = reinterpret_cast<pid_t>(Data_);
+ return (kill(pid, SIGKILL) == 0);
}
bool Program::ChangeStdinToBinary(){
}
bool Program::ChangeStdinToBinary(){
namespace llvm {
using namespace sys;
namespace llvm {
using namespace sys;
-Program::Program() : Pid_(0), Data(0) {}
+Program::Program() : Data_(0) {}
- if (Data) {
- HANDLE hProcess = (HANDLE) Data;
+ if (Data_) {
+ HANDLE hProcess = reinterpret_cast<HANDLE>(Data_);
+unsigned Program::GetPid() {
+ HANDLE hProcess = reinterpret_cast<HANDLE>(Data_);
+ return GetProcessId(hProcess);
+}
+
// This function just uses the PATH environment variable to find the program.
Path
Program::FindProgramByName(const std::string& progName) {
// This function just uses the PATH environment variable to find the program.
Path
Program::FindProgramByName(const std::string& progName) {
const Path** redirects,
unsigned memoryLimit,
std::string* ErrMsg) {
const Path** redirects,
unsigned memoryLimit,
std::string* ErrMsg) {
- if (Data) {
- HANDLE hProcess = (HANDLE) Data;
- CloseHandle(Data);
- Data = 0;
+ if (Data_) {
+ HANDLE hProcess = reinterpret_cast<HANDLE>(Data_);
+ CloseHandle(Data_);
+ Data_ = 0;
}
if (!path.canExecute()) {
}
if (!path.canExecute()) {
path.str() + "'");
return false;
}
path.str() + "'");
return false;
}
- Pid_ = pi.dwProcessId;
- Data = pi.hProcess;
+ Data_ = reinterpret_cast<void*>(pi.hProcess);
// Make sure these get closed no matter what.
AutoHandle hThread(pi.hThread);
// Make sure these get closed no matter what.
AutoHandle hThread(pi.hThread);
int
Program::Wait(unsigned secondsToWait,
std::string* ErrMsg) {
int
Program::Wait(unsigned secondsToWait,
std::string* ErrMsg) {
MakeErrMsg(ErrMsg, "Process not started!");
return -1;
}
MakeErrMsg(ErrMsg, "Process not started!");
return -1;
}
- HANDLE hProcess = (HANDLE) Data;
+ HANDLE hProcess = reinterpret_cast<HANDLE>(Data_);
// Wait for the process to terminate.
DWORD millisecondsToWait = INFINITE;
// Wait for the process to terminate.
DWORD millisecondsToWait = INFINITE;
bool
Program::Kill(std::string* ErrMsg) {
bool
Program::Kill(std::string* ErrMsg) {
MakeErrMsg(ErrMsg, "Process not started!");
return true;
}
MakeErrMsg(ErrMsg, "Process not started!");
return true;
}
- HANDLE hProcess = reinterpret_cast<HANDLE>(Data);
+ HANDLE hProcess = reinterpret_cast<HANDLE>(Data_);
return TerminateProcess(hProcess, 1);
}
return TerminateProcess(hProcess, 1);
}