blob: a4bfad2f12f28edcbe36bc1e50f2511f791487a8 [file] [log] [blame]
Andrew Kaylorc2ebf3f2013-10-02 17:12:36 +00001//===----- RemoteTargetExternal.h - LLVM out-of-process JIT execution -----===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// Definition of the RemoteTargetExternal class which executes JITed code in a
11// separate process from where it was built.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLI_REMOTETARGETEXTERNAL_H
16#define LLI_REMOTETARGETEXTERNAL_H
17
18#include "llvm/Config/config.h"
19
20#include "llvm/ADT/SmallVector.h"
21#include "llvm/ADT/StringRef.h"
22#include "llvm/Support/DataTypes.h"
23#include "llvm/Support/Memory.h"
24#include <stdlib.h>
25#include <string>
26
27#include "RemoteTarget.h"
28#include "RemoteTargetMessage.h"
29
30namespace llvm {
31
32class RemoteTargetExternal : public RemoteTarget {
33public:
34 /// Allocate space in the remote target address space.
35 ///
36 /// @param Size Amount of space, in bytes, to allocate.
37 /// @param Alignment Required minimum alignment for allocated space.
38 /// @param[out] Address Remote address of the allocated memory.
39 ///
40 /// @returns False on success. On failure, ErrorMsg is updated with
41 /// descriptive text of the encountered error.
42 virtual bool allocateSpace(size_t Size,
43 unsigned Alignment,
44 uint64_t &Address);
45
46 /// Load data into the target address space.
47 ///
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.
51 ///
52 /// @returns False on success. On failure, ErrorMsg is updated with
53 /// descriptive text of the encountered error.
54 virtual bool loadData(uint64_t Address, const void *Data, size_t Size);
55
56 /// Load code into the target address space and prepare it for execution.
57 ///
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.
61 ///
62 /// @returns False on success. On failure, ErrorMsg is updated with
63 /// descriptive text of the encountered error.
64 virtual bool loadCode(uint64_t Address, const void *Data, size_t Size);
65
66 /// Execute code in the target process. The called function is required
67 /// to be of signature int "(*)(void)".
68 ///
69 /// @param Address Address of the loaded function in the target
70 /// process.
71 /// @param[out] RetVal The integer return value of the called function.
72 ///
73 /// @returns False on success. On failure, ErrorMsg is updated with
74 /// descriptive text of the encountered error.
75 virtual bool executeCode(uint64_t Address, int &RetVal);
76
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
79 /// versa.
80 ///
81 /// @returns Page alignment return value. Default of 4k.
82 virtual unsigned getPageAlignment() { return 4096; }
83
84 /// Start the remote process.
85 virtual void create();
86
87 /// Terminate the remote process.
88 virtual void stop();
89
90 RemoteTargetExternal(std::string &Name) : RemoteTarget(), ChildName(Name) {}
Benjamin Kramerc83946f2013-10-05 11:53:20 +000091 virtual ~RemoteTargetExternal();
Andrew Kaylorc2ebf3f2013-10-02 17:12:36 +000092
93private:
94 std::string ChildName;
95
96 // This will get filled in as a point to an OS-specific structure.
97 void *ConnectionData;
98
99 void SendAllocateSpace(uint32_t Alignment, uint32_t Size);
100 void SendLoadSection(uint64_t Addr,
101 const void *Data,
102 uint32_t Size,
103 bool IsCode);
104 void SendExecute(uint64_t Addr);
105 void SendTerminate();
106
107 void Receive(LLIMessageType Msg);
108 void Receive(LLIMessageType Msg, int &Data);
109 void Receive(LLIMessageType Msg, uint64_t &Data);
110
111 int WriteBytes(const void *Data, size_t Size);
112 int ReadBytes(void *Data, size_t Size);
113 void Wait();
114};
115
116} // end namespace llvm
117
118#endif // LLI_REMOTETARGETEXTERNAL_H