From 522600a229b950314b5f4af84eba4f3e8a0ffea1 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Sun, 2 Dec 2012 13:10:19 +0000 Subject: Vendor import of llvm release_32 branch r168974 (effectively, 3.2 RC2): http://llvm.org/svn/llvm-project/llvm/branches/release_32@168974 --- tools/lli/RemoteTarget.cpp | 61 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 tools/lli/RemoteTarget.cpp (limited to 'tools/lli/RemoteTarget.cpp') diff --git a/tools/lli/RemoteTarget.cpp b/tools/lli/RemoteTarget.cpp new file mode 100644 index 0000000000000..212bdfda1cdbe --- /dev/null +++ b/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/DataTypes.h" +#include "llvm/Support/Memory.h" +#include +#include +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(Mem.base()); + return false; +} + +bool RemoteTarget::loadData(uint64_t Address, const void *Data, size_t Size) { + memcpy ((void*)Address, Data, Size); + return false; +} + +bool RemoteTarget::loadCode(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::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]); +} -- cgit v1.2.3