LLVM: lib/ExecutionEngine/Orc/ExecutorProcessControl.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

10

17

18#define DEBUG_TYPE "orc"

19

20namespace llvm {

21namespace orc {

22

24

26

28

30 std::shared_ptr SSP, std::unique_ptr D,

32 std::unique_ptrjitlink::JITLinkMemoryManager MemMgr)

35

36 OwnedMemMgr = std::move(MemMgr);

37 if (!OwnedMemMgr)

38 OwnedMemMgr = std::make_uniquejitlink::InProcessMemoryManager(

40

43 this->MemMgr = OwnedMemMgr.get();

49 GlobalManglingPrefix = '_';

50

55}

56

59 std::shared_ptr SSP,

60 std::unique_ptr D,

61 std::unique_ptrjitlink::JITLinkMemoryManager MemMgr) {

62

64 SSP = std::make_shared();

65

66 if (D)

67 D = std::make_unique();

68

72

74

75 return std::make_unique(

76 std::move(SSP), std::move(D), std::move(TT), *PageSize,

78}

79

81SelfExecutorProcessControl::loadDylib(const char *DylibPath) {

82 std::string ErrMsg;

84 if (!Dylib.isValid())

87}

88

89void SelfExecutorProcessControl::lookupSymbolsAsync(

92 std::vectortpctypes::LookupResult R;

93

94 for (auto &Elem : Request) {

96 R.push_back(std::vector());

97 for (auto &KV : Elem.Symbols) {

98 auto &Sym = KV.first;

99 std::string Tmp((*Sym).data() + !!GlobalManglingPrefix,

100 (*Sym).size() - !!GlobalManglingPrefix);

101 void *Addr = Dylib.getAddressOfSymbol(Tmp.c_str());

103

105 MissingSymbols.push_back(Sym);

106 return Complete(

107 make_error(SSP, std::move(MissingSymbols)));

108 }

109

110 R.back().push_back(

112 }

113 }

114

115 Complete(std::move(R));

116}

117

118Expected<int32_t>

121 using MainTy = int (*)(int, char *[]);

123}

124

127 using VoidTy = int (*)();

129}

130

133 using IntTy = int (*)(int);

135}

136

140 using WrapperFnTy =

142 auto *WrapperFn = WrapperFnAddr.toPtr();

143 SendResult(WrapperFn(ArgBuffer.data(), ArgBuffer.size()));

144}

145

147 D->shutdown();

149}

150

153 for (auto &W : Ws)

154 *W.Addr.toPtr<uint8_t *>() = W.Value;

156}

157

160 for (auto &W : Ws)

161 *W.Addr.toPtr<uint16_t *>() = W.Value;

163}

164

167 for (auto &W : Ws)

168 *W.Addr.toPtr<uint32_t *>() = W.Value;

170}

171

174 for (auto &W : Ws)

175 *W.Addr.toPtr<uint64_t *>() = W.Value;

177}

178

181 for (auto &W : Ws)

182 memcpy(W.Addr.toPtr<char *>(), W.Buffer.data(), W.Buffer.size());

184}

185

188 if (IsArch64Bit) {

189 for (auto &W : Ws)

190 *W.Addr.toPtr<uint64_t *>() = W.Value.getValue();

191 } else {

192 for (auto &W : Ws)

193 *W.Addr.toPtr<uint32_t *>() = static_cast<uint32_t>(W.Value.getValue());

194 }

195

197}

198

200SelfExecutorProcessControl::jitDispatchViaWrapperFunctionManager(

201 void *Ctx, const void *FnTag, const char *Data, size_t Size) {

202

204 dbgs() << "jit-dispatch call with tag " << FnTag << " and " << Size

205 << " byte payload.\n";

206 });

207

208 std::promiseshared::WrapperFunctionResult ResultP;

209 auto ResultF = ResultP.get_future();

210 static_cast<SelfExecutorProcessControl *>(Ctx)

213 [ResultP = std::move(ResultP)](

214 shared::WrapperFunctionResult Result) mutable {

215 ResultP.set_value(std::move(Result));

216 },

218

219 return ResultF.get().release();

220}

221

222}

223}

static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")

static cl::opt< int > PageSize("imp-null-check-page-size", cl::desc("The page size of the target in bytes"), cl::init(4096), cl::Hidden)

Provides a library for accessing information about this process and other processes on the operating ...

LLVM_ABI llvm::orc::shared::CWrapperFunctionResult llvm_orc_deregisterEHFrameSectionWrapper(const char *Data, uint64_t Size)

LLVM_ABI llvm::orc::shared::CWrapperFunctionResult llvm_orc_registerEHFrameSectionWrapper(const char *Data, uint64_t Size)

ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...

size_t size() const

size - Get the array size.

Lightweight error class with error context and mandatory checking.

static ErrorSuccess success()

Create a success value.

Tagged union holding either a T or a Error.

Triple - Helper class for working with autoconf configuration names.

bool isOSBinFormatMachO() const

Tests whether the environment is MachO.

unique_function< void(Expected< std::vector< tpctypes::LookupResult > >)> SymbolLookupCompleteFn

void runJITDispatchHandler(SendResultFunction SendResult, ExecutorAddr HandlerFnTagAddr, ArrayRef< char > ArgBuffer)

Run a registered jit-side wrapper function.

Represents an address in the executor process.

static ExecutorAddr fromPtr(T *Ptr, UnwrapFn &&Unwrap=UnwrapFn())

Create an ExecutorAddr from the given pointer.

std::enable_if_t< std::is_pointer< T >::value, T > toPtr(WrapFn &&Wrap=WrapFn()) const

Cast this ExecutorAddr to a pointer of the given type.

A handler or incoming WrapperFunctionResults – either return values from callWrapper* calls,...

ExecutorProcessControl supports interaction with a JIT target process.

std::unique_ptr< TaskDispatcher > D

std::shared_ptr< SymbolStringPool > SSP

StringMap< ExecutorAddr > BootstrapSymbols

jitlink::JITLinkMemoryManager * MemMgr

ExecutionSession & getExecutionSession()

Return the ExecutionSession associated with this instance.

virtual ~ExecutorProcessControl()

void writePointersAsync(ArrayRef< tpctypes::PointerWrite > Ws, WriteResultFn OnWriteComplete) override

void writeUInt32sAsync(ArrayRef< tpctypes::UInt32Write > Ws, WriteResultFn OnWriteComplete) override

void writeUInt8sAsync(ArrayRef< tpctypes::UInt8Write > Ws, WriteResultFn OnWriteComplete) override

void writeUInt16sAsync(ArrayRef< tpctypes::UInt16Write > Ws, WriteResultFn OnWriteComplete) override

void writeBuffersAsync(ArrayRef< tpctypes::BufferWrite > Ws, WriteResultFn OnWriteComplete) override

void writeUInt64sAsync(ArrayRef< tpctypes::UInt64Write > Ws, WriteResultFn OnWriteComplete) override

SelfExecutorProcessControl(std::shared_ptr< SymbolStringPool > SSP, std::unique_ptr< TaskDispatcher > D, Triple TargetTriple, unsigned PageSize, std::unique_ptr< jitlink::JITLinkMemoryManager > MemMgr)

Error disconnect() override

Disconnect from the target process.

Expected< int32_t > runAsVoidFunction(ExecutorAddr VoidFnAddr) override

Run function with a int (*)(void) signature.

Expected< int32_t > runAsMain(ExecutorAddr MainFnAddr, ArrayRef< std::string > Args) override

Run function with a main-like signature.

void callWrapperAsync(ExecutorAddr WrapperFnAddr, IncomingWFRHandler OnComplete, ArrayRef< char > ArgBuffer) override

Run a wrapper function in the executor.

static Expected< std::unique_ptr< SelfExecutorProcessControl > > Create(std::shared_ptr< SymbolStringPool > SSP=nullptr, std::unique_ptr< TaskDispatcher > D=nullptr, std::unique_ptr< jitlink::JITLinkMemoryManager > MemMgr=nullptr)

Create a SelfExecutorProcessControl with the given symbol string pool and memory manager.

Expected< int32_t > runAsIntFunction(ExecutorAddr IntFnAddr, int Arg) override

Run function with a int (*)(int) signature.

This class provides a portable interface to dynamic libraries which also might be known as shared lib...

static DynamicLibrary getPermanentLibrary(const char *filename, std::string *errMsg=nullptr)

This function permanently loads the dynamic library at the given path using the library load operatio...

static Expected< unsigned > getPageSize()

Get the process's page size.

static unsigned getPageSizeEstimate()

Get the process's estimated page size.

const char * DeregisterEHFrameSectionWrapperName

const char * RegisterEHFrameSectionWrapperName

int runAsVoidFunction(int(*Func)(void))

int runAsIntFunction(int(*Func)(int), int Arg)

std::vector< SymbolStringPtr > SymbolNameVector

A vector of symbol names.

int runAsMain(int(*Main)(int, char *[]), ArrayRef< std::string > Args, std::optional< StringRef > ProgramName=std::nullopt)

Run a main function, returning the result.

std::string getProcessTriple()

getProcessTriple() - Return an appropriate target triple for generating code to be loaded into the cu...

This is an optimization pass for GlobalISel generic memory operations.

std::error_code inconvertibleErrorCode()

The value returned by this function can be returned from convertToErrorCode for Error values where no...

raw_ostream & dbgs()

dbgs() - This returns a reference to a raw_ostream for debugging messages.

OutputIt move(R &&Range, OutputIt Out)

Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.

Implement std::hash so that hash_code can be used in STL containers.