summaryrefslogtreecommitdiffstats
path: root/llvm/tools/lli/RemoteTarget.cpp
diff options
context:
space:
mode:
authorJim Grosbach <grosbach@apple.com>2012-09-05 16:50:34 +0000
committerJim Grosbach <grosbach@apple.com>2012-09-05 16:50:34 +0000
commit0f435d0851a70bcec792bd43f52973c56b735172 (patch)
tree7b05fb83e6e900b5da54bd45508c80f97e1302f4 /llvm/tools/lli/RemoteTarget.cpp
parent6c2649ca4ee2263a0345b9225de63b68ba082d1a (diff)
downloadbcm5719-llvm-0f435d0851a70bcec792bd43f52973c56b735172.tar.gz
bcm5719-llvm-0f435d0851a70bcec792bd43f52973c56b735172.zip
MCJIT: Add faux remote target execution to lli for the MCJIT.
Simulate a remote target address space by allocating a seperate chunk of memory for the target and re-mapping section addresses to that prior to execution. Later we'll want to have a truly remote process, but for now this gets us closer to being able to test the remote target functionality outside LLDB. rdar://12157052 llvm-svn: 163216
Diffstat (limited to 'llvm/tools/lli/RemoteTarget.cpp')
-rw-r--r--llvm/tools/lli/RemoteTarget.cpp61
1 files changed, 61 insertions, 0 deletions
diff --git a/llvm/tools/lli/RemoteTarget.cpp b/llvm/tools/lli/RemoteTarget.cpp
new file mode 100644
index 00000000000..2ab098b2ef0
--- /dev/null
+++ b/llvm/tools/lli/RemoteTarget.cpp
@@ -0,0 +1,61 @@
+//===- RemoteTarget.cpp - LLVM Remote process JIT execution --------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// Implementation of the RemoteTarget class which executes JITed code in a
+// separate address range from where it was built.
+//
+//===----------------------------------------------------------------------===//
+
+#include "RemoteTarget.h"
+#include <llvm/ADT/StringRef.h>
+#include <llvm/Support/Memory.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string>
+using namespace llvm;
+
+bool RemoteTarget::allocateSpace(size_t Size, unsigned Alignment,
+ uint64_t &Address) {
+ sys::MemoryBlock *Prev = Allocations.size() ? &Allocations.back() : NULL;
+ sys::MemoryBlock Mem = sys::Memory::AllocateRWX(Size, Prev, &ErrorMsg);
+ if (Mem.base() == NULL)
+ return true;
+ if ((uintptr_t)Mem.base() % Alignment) {
+ ErrorMsg = "unable to allocate sufficiently aligned memory";
+ return true;
+ }
+ Address = reinterpret_cast<uint64_t>(Mem.base());
+ return false;
+}
+
+bool RemoteTarget::loadData(uint64_t Address, const void *Data, size_t Size) {
+ memcpy ((void*)Address, Data, Size);
+ sys::MemoryBlock Mem((void*)Address, Size);
+ sys::Memory::setExecutable(Mem, &ErrorMsg);
+ return false;
+}
+
+bool RemoteTarget::loadCode(uint64_t Address, const void *Data, size_t Size) {
+ memcpy ((void*)Address, Data, Size);
+ return false;
+}
+
+bool RemoteTarget::executeCode(uint64_t Address, int &RetVal) {
+ int (*fn)(void) = (int(*)(void))Address;
+ RetVal = fn();
+ return false;
+}
+
+void RemoteTarget::create() {
+}
+
+void RemoteTarget::stop() {
+ for (unsigned i = 0, e = Allocations.size(); i != e; ++i)
+ sys::Memory::ReleaseRWX(Allocations[i]);
+}
OpenPOWER on IntegriCloud