X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=tools%2Flli%2FRemoteTarget.h;h=ee758a2747a4d92044046090004933ad5c2947f6;hb=37ac8d3622407cf5fd974407c5b8b301a2fdfcfd;hp=d05d3c6f45683f9587784d3b671798ee721a9da4;hpb=dbf545719a22bf03403c1d0137ae0f5726f36de3;p=oota-llvm.git diff --git a/tools/lli/RemoteTarget.h b/tools/lli/RemoteTarget.h index d05d3c6f456..ee758a2747a 100644 --- a/tools/lli/RemoteTarget.h +++ b/tools/lli/RemoteTarget.h @@ -12,11 +12,11 @@ // //===----------------------------------------------------------------------===// -#ifndef REMOTEPROCESS_H -#define REMOTEPROCESS_H +#ifndef LLVM_TOOLS_LLI_REMOTETARGET_H +#define LLVM_TOOLS_LLI_REMOTETARGET_H -#include "llvm/ADT/StringRef.h" #include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringRef.h" #include "llvm/Support/DataTypes.h" #include "llvm/Support/Memory.h" #include @@ -25,10 +25,13 @@ namespace llvm { class RemoteTarget { - std::string ErrorMsg; bool IsRunning; - SmallVector Allocations; + typedef SmallVector AllocMapType; + AllocMapType Allocations; + +protected: + std::string ErrorMsg; public: StringRef getErrorMsg() const { return ErrorMsg; } @@ -39,9 +42,23 @@ public: /// @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 + /// @returns True on success. On failure, ErrorMsg is updated with /// descriptive text of the encountered error. - bool allocateSpace(size_t Size, unsigned Alignment, uint64_t &Address); + virtual bool allocateSpace(size_t Size, + unsigned Alignment, + uint64_t &Address); + + bool isAllocatedMemory(uint64_t Address, uint32_t Size) { + uint64_t AddressEnd = Address + Size; + for (AllocMapType::const_iterator I = Allocations.begin(), + E = Allocations.end(); + I != E; ++I) { + if (Address >= (uint64_t)I->base() && + AddressEnd <= (uint64_t)I->base() + I->size()) + return true; + } + return false; + } /// Load data into the target address space. /// @@ -49,9 +66,11 @@ public: /// @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 + /// @returns True on success. On failure, ErrorMsg is updated with /// descriptive text of the encountered error. - bool loadData(uint64_t Address, const void *Data, size_t Size); + virtual bool loadData(uint64_t Address, + const void *Data, + size_t Size); /// Load code into the target address space and prepare it for execution. /// @@ -59,9 +78,11 @@ public: /// @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 + /// @returns True on success. On failure, ErrorMsg is updated with /// descriptive text of the encountered error. - bool loadCode(uint64_t Address, const void *Data, size_t Size); + 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)". @@ -70,26 +91,26 @@ public: /// process. /// @param[out] RetVal The integer return value of the called function. /// - /// @returns False on success. On failure, ErrorMsg is updated with + /// @returns True on success. On failure, ErrorMsg is updated with /// descriptive text of the encountered error. - bool executeCode(uint64_t Address, int &RetVal); + virtual bool executeCode(uint64_t Address, + int &RetVal); - /// Minimum alignment for memory permissions. Used to seperate code and + /// Minimum alignment for memory permissions. Used to separate 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. - unsigned getPageAlignment() { return 4096; } + virtual unsigned getPageAlignment() { return 4096; } /// Start the remote process. - void create(); + virtual bool create(); /// Terminate the remote process. - void stop(); - - RemoteTarget() : ErrorMsg(""), IsRunning(false) {} - ~RemoteTarget() { if (IsRunning) stop(); } + virtual void stop(); + RemoteTarget() : IsRunning(false), ErrorMsg("") {} + virtual ~RemoteTarget() { if (IsRunning) stop(); } private: // Main processing function for the remote target process. Command messages // are received on file descriptor CmdFD and responses come back on OutFD.