diff options
Diffstat (limited to 'tools/lli/RemoteTargetExternal.h')
-rw-r--r-- | tools/lli/RemoteTargetExternal.h | 97 |
1 files changed, 61 insertions, 36 deletions
diff --git a/tools/lli/RemoteTargetExternal.h b/tools/lli/RemoteTargetExternal.h index a4bfad2..f87fc61 100644 --- a/tools/lli/RemoteTargetExternal.h +++ b/tools/lli/RemoteTargetExternal.h @@ -15,21 +15,28 @@ #ifndef LLI_REMOTETARGETEXTERNAL_H #define LLI_REMOTETARGETEXTERNAL_H -#include "llvm/Config/config.h" - +#include "RPCChannel.h" +#include "RemoteTarget.h" +#include "RemoteTargetMessage.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" +#include "llvm/Config/config.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 { + RPCChannel RPC; + + bool WriteBytes(const void *Data, size_t Size) { + return RPC.WriteBytes(Data, Size); + } + + bool ReadBytes(void *Data, size_t Size) { return RPC.ReadBytes(Data, Size); } + public: /// Allocate space in the remote target address space. /// @@ -37,11 +44,10 @@ 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. - virtual bool allocateSpace(size_t Size, - unsigned Alignment, - uint64_t &Address); + bool allocateSpace(size_t Size, unsigned Alignment, + uint64_t &Address) override; /// Load data into the target address space. /// @@ -49,9 +55,9 @@ 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. - virtual bool loadData(uint64_t Address, const void *Data, size_t Size); + bool loadData(uint64_t Address, const void *Data, size_t Size) override; /// Load code into the target address space and prepare it for execution. /// @@ -59,9 +65,9 @@ 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. - virtual bool loadCode(uint64_t Address, const void *Data, size_t Size); + bool loadCode(uint64_t Address, const void *Data, size_t Size) override; /// Execute code in the target process. The called function is required /// to be of signature int "(*)(void)". @@ -70,47 +76,66 @@ 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. - virtual bool executeCode(uint64_t Address, int &RetVal); + bool executeCode(uint64_t Address, int &RetVal) override; - /// 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. - virtual unsigned getPageAlignment() { return 4096; } + unsigned getPageAlignment() override { return 4096; } + + bool create() override { + RPC.ChildName = ChildName; + if (!RPC.createServer()) + return true; - /// Start the remote process. - virtual void create(); + // We must get Ack from the client (blocking read) + if (!Receive(LLI_ChildActive)) { + ErrorMsg += ", (RPCChannel::create) - Stopping process!"; + stop(); + return false; + } + + return true; + } /// Terminate the remote process. - virtual void stop(); + void stop() override; RemoteTargetExternal(std::string &Name) : RemoteTarget(), ChildName(Name) {} - virtual ~RemoteTargetExternal(); + 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, + bool SendAllocateSpace(uint32_t Alignment, uint32_t Size); + bool 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(); + bool SendExecute(uint64_t Addr); + bool SendTerminate(); + + // High-level wrappers for receiving data + bool Receive(LLIMessageType Msg); + bool Receive(LLIMessageType Msg, int32_t &Data); + bool Receive(LLIMessageType Msg, uint64_t &Data); + + // Lower level target-independent read/write to deal with errors + bool ReceiveHeader(LLIMessageType Msg); + bool ReceivePayload(); + bool SendHeader(LLIMessageType Msg); + bool SendPayload(); + + // Functions to append/retrieve data from the payload + SmallVector<const void *, 2> SendData; + SmallVector<void *, 1> ReceiveData; // Future proof + SmallVector<int, 2> Sizes; + void AppendWrite(const void *Data, uint32_t Size); + void AppendRead(void *Data, uint32_t Size); }; } // end namespace llvm |