summaryrefslogtreecommitdiff
path: root/tools/lli/RemoteTargetExternal.h
diff options
context:
space:
mode:
authorAndrew Kaylor <andrew.kaylor@intel.com>2013-10-02 17:12:36 +0000
committerAndrew Kaylor <andrew.kaylor@intel.com>2013-10-02 17:12:36 +0000
commit0ab5c6c16b1b09d76c3ba2d70443b10bcc26169c (patch)
treeaf098f261c3db5f9da3efd5aa5ab1ca9e05046e0 /tools/lli/RemoteTargetExternal.h
parentaf7ae9d6890ce5fae27e38ccebb5da09288c49e0 (diff)
downloadllvm-0ab5c6c16b1b09d76c3ba2d70443b10bcc26169c.tar.gz
llvm-0ab5c6c16b1b09d76c3ba2d70443b10bcc26169c.tar.bz2
llvm-0ab5c6c16b1b09d76c3ba2d70443b10bcc26169c.tar.xz
Adding out-of-process execution support to lli.
At this time only Unix-based systems are supported. Windows has stubs and should re-route to the simulated mode. Thanks to Sriram Murali for contributions to this patch. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@191843 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/lli/RemoteTargetExternal.h')
-rw-r--r--tools/lli/RemoteTargetExternal.h118
1 files changed, 118 insertions, 0 deletions
diff --git a/tools/lli/RemoteTargetExternal.h b/tools/lli/RemoteTargetExternal.h
new file mode 100644
index 0000000000..9a3644ac55
--- /dev/null
+++ b/tools/lli/RemoteTargetExternal.h
@@ -0,0 +1,118 @@
+//===----- RemoteTargetExternal.h - LLVM out-of-process JIT execution -----===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// Definition of the RemoteTargetExternal class which executes JITed code in a
+// separate process from where it was built.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLI_REMOTETARGETEXTERNAL_H
+#define LLI_REMOTETARGETEXTERNAL_H
+
+#include "llvm/Config/config.h"
+
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/DataTypes.h"
+#include "llvm/Support/Memory.h"
+#include <stdlib.h>
+#include <string>
+
+#include "RemoteTarget.h"
+#include "RemoteTargetMessage.h"
+
+namespace llvm {
+
+class RemoteTargetExternal : public RemoteTarget {
+public:
+ /// Allocate space in the remote target address space.
+ ///
+ /// @param Size Amount of space, in bytes, to allocate.
+ /// @param Alignment Required minimum alignment for allocated space.
+ /// @param[out] Address Remote address of the allocated memory.
+ ///
+ /// @returns False on success. On failure, ErrorMsg is updated with
+ /// descriptive text of the encountered error.
+ virtual bool allocateSpace(size_t Size,
+ unsigned Alignment,
+ uint64_t &Address);
+
+ /// Load data into the target address space.
+ ///
+ /// @param Address Destination address in the target process.
+ /// @param Data Source address in the host process.
+ /// @param Size Number of bytes to copy.
+ ///
+ /// @returns False on success. On failure, ErrorMsg is updated with
+ /// descriptive text of the encountered error.
+ virtual bool loadData(uint64_t Address, const void *Data, size_t Size);
+
+ /// Load code into the target address space and prepare it for execution.
+ ///
+ /// @param Address Destination address in the target process.
+ /// @param Data Source address in the host process.
+ /// @param Size Number of bytes to copy.
+ ///
+ /// @returns False on success. On failure, ErrorMsg is updated with
+ /// descriptive text of the encountered error.
+ virtual bool loadCode(uint64_t Address, const void *Data, size_t Size);
+
+ /// Execute code in the target process. The called function is required
+ /// to be of signature int "(*)(void)".
+ ///
+ /// @param Address Address of the loaded function in the target
+ /// process.
+ /// @param[out] RetVal The integer return value of the called function.
+ ///
+ /// @returns False on success. On failure, ErrorMsg is updated with
+ /// descriptive text of the encountered error.
+ virtual bool executeCode(uint64_t Address, int &RetVal);
+
+ /// Minimum alignment for memory permissions. Used to seperate code and
+ /// data regions to make sure data doesn't get marked as code or vice
+ /// versa.
+ ///
+ /// @returns Page alignment return value. Default of 4k.
+ virtual unsigned getPageAlignment() { return 4096; }
+
+ /// Start the remote process.
+ virtual void create();
+
+ /// Terminate the remote process.
+ virtual void stop();
+
+ RemoteTargetExternal(std::string &Name) : RemoteTarget(), ChildName(Name) {}
+ virtual ~RemoteTargetExternal() {}
+
+private:
+ std::string ChildName;
+
+ // This will get filled in as a point to an OS-specific structure.
+ void *ConnectionData;
+
+ void SendAllocateSpace(uint32_t Alignment, uint32_t Size);
+ void SendLoadSection(uint64_t Addr,
+ const void *Data,
+ uint32_t Size,
+ bool IsCode);
+ void SendExecute(uint64_t Addr);
+ void SendTerminate();
+
+ void Receive(LLIMessageType Msg);
+ void Receive(LLIMessageType Msg, int &Data);
+ void Receive(LLIMessageType Msg, uint64_t &Data);
+
+ int WriteBytes(const void *Data, size_t Size);
+ int ReadBytes(void *Data, size_t Size);
+ void Wait();
+};
+
+} // end namespace llvm
+
+#endif // LLI_REMOTETARGETEXTERNAL_H