1 //===- RemoteTarget.h - LLVM Remote process JIT execution ----------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Definition of the RemoteTarget class which executes JITed code in a
11 // separate address range from where it was built.
13 //===----------------------------------------------------------------------===//
15 #ifndef REMOTEPROCESS_H
16 #define REMOTEPROCESS_H
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/ADT/StringRef.h"
20 #include "llvm/Support/DataTypes.h"
21 #include "llvm/Support/Memory.h"
31 SmallVector<sys::MemoryBlock, 16> Allocations;
34 StringRef getErrorMsg() const { return ErrorMsg; }
36 /// Allocate space in the remote target address space.
38 /// @param Size Amount of space, in bytes, to allocate.
39 /// @param Alignment Required minimum alignment for allocated space.
40 /// @param[out] Address Remote address of the allocated memory.
42 /// @returns False on success. On failure, ErrorMsg is updated with
43 /// descriptive text of the encountered error.
44 bool allocateSpace(size_t Size, unsigned Alignment, uint64_t &Address);
46 /// Load data into the target address space.
48 /// @param Address Destination address in the target process.
49 /// @param Data Source address in the host process.
50 /// @param Size Number of bytes to copy.
52 /// @returns False on success. On failure, ErrorMsg is updated with
53 /// descriptive text of the encountered error.
54 bool loadData(uint64_t Address, const void *Data, size_t Size);
56 /// Load code into the target address space and prepare it for execution.
58 /// @param Address Destination address in the target process.
59 /// @param Data Source address in the host process.
60 /// @param Size Number of bytes to copy.
62 /// @returns False on success. On failure, ErrorMsg is updated with
63 /// descriptive text of the encountered error.
64 bool loadCode(uint64_t Address, const void *Data, size_t Size);
66 /// Execute code in the target process. The called function is required
67 /// to be of signature int "(*)(void)".
69 /// @param Address Address of the loaded function in the target
71 /// @param[out] RetVal The integer return value of the called function.
73 /// @returns False on success. On failure, ErrorMsg is updated with
74 /// descriptive text of the encountered error.
75 bool executeCode(uint64_t Address, int &RetVal);
77 /// Minimum alignment for memory permissions. Used to seperate code and
78 /// data regions to make sure data doesn't get marked as code or vice
81 /// @returns Page alignment return value. Default of 4k.
82 unsigned getPageAlignment() { return 4096; }
84 /// Start the remote process.
87 /// Terminate the remote process.
90 RemoteTarget() : ErrorMsg(""), IsRunning(false) {}
91 ~RemoteTarget() { if (IsRunning) stop(); }
94 // Main processing function for the remote target process. Command messages
95 // are received on file descriptor CmdFD and responses come back on OutFD.
96 static void doRemoteTargeting(int CmdFD, int OutFD);
99 } // end namespace llvm