1 //=- RemoteTargetExternal.inc - LLVM out-of-process JIT execution for Unix --=//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Implementation of the Unix-specific parts of the RemoteTargetExternal class
11 // which executes JITed code in a separate process from where it was built.
13 //===----------------------------------------------------------------------===//
22 struct ConnectionData_t {
26 ConnectionData_t(int in, int out) : InputPipe(in), OutputPipe(out) {}
33 void RemoteTargetExternal::create() {
38 if (pipe(PipeFD[0]) != 0 || pipe(PipeFD[1]) != 0)
39 perror("Error creating pipe: ");
46 // Close the parent ends of the pipes
50 // Use our pipes as stdin and stdout
51 if (PipeFD[0][0] != STDIN_FILENO) {
52 dup2(PipeFD[0][0], STDIN_FILENO);
55 if (PipeFD[1][1] != STDOUT_FILENO) {
56 dup2(PipeFD[1][1], STDOUT_FILENO);
60 // Execute the child process.
61 char *args[1] = { NULL };
62 int rc = execv(ChildName.c_str(), args);
64 perror("Error executing child process: ");
69 // Close the child ends of the pipes
73 // Store the parent ends of the pipes
74 ConnectionData = (void*)new ConnectionData_t(PipeFD[1][0], PipeFD[0][1]);
76 Receive(LLI_ChildActive);
80 int RemoteTargetExternal::WriteBytes(const void *Data, size_t Size) {
81 return write(((ConnectionData_t*)ConnectionData)->OutputPipe, Data, Size);
84 int RemoteTargetExternal::ReadBytes(void *Data, size_t Size) {
85 return read(((ConnectionData_t*)ConnectionData)->InputPipe, Data, Size);
88 void RemoteTargetExternal::Wait() {
92 RemoteTargetExternal::~RemoteTargetExternal() {
93 delete static_cast<ConnectionData_t *>(ConnectionData);