1 //===---- OrcRemoteTargetClient.h - Orc Remote-target Client ----*- C++ -*-===//
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 // This file defines the OrcRemoteTargetClient class and helpers. This class
11 // can be used to communicate over an RPCChannel with an OrcRemoteTargetServer
12 // instance to support remote-JITing.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_EXECUTIONENGINE_ORC_ORCREMOTETARGETCLIENT_H
17 #define LLVM_EXECUTIONENGINE_ORC_ORCREMOTETARGETCLIENT_H
19 #include "IndirectionUtils.h"
20 #include "OrcRemoteTargetRPCAPI.h"
21 #include <system_error>
23 #define DEBUG_TYPE "orc-remote"
29 /// This class provides utilities (including memory manager, indirect stubs
30 /// manager, and compile callback manager types) that support remote JITing
33 /// Each of the utility classes talks to a JIT server (an instance of the
34 /// OrcRemoteTargetServer class) via an RPC system (see RPCUtils.h) to carry out
36 template <typename ChannelT>
37 class OrcRemoteTargetClient : public OrcRemoteTargetRPCAPI {
39 /// Remote memory manager.
40 class RCMemoryManager : public RuntimeDyld::MemoryManager {
42 RCMemoryManager(OrcRemoteTargetClient &Client, ResourceIdMgr::ResourceId Id)
43 : Client(Client), Id(Id) {
44 DEBUG(dbgs() << "Created remote allocator " << Id << "\n");
48 Client.destroyRemoteAllocator(Id);
49 DEBUG(dbgs() << "Destroyed remote allocator " << Id << "\n");
52 uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment,
54 StringRef SectionName) override {
55 Unmapped.back().CodeAllocs.emplace_back(Size, Alignment);
56 uint8_t *Alloc = reinterpret_cast<uint8_t *>(
57 Unmapped.back().CodeAllocs.back().getLocalAddress());
58 DEBUG(dbgs() << "Allocator " << Id << " allocated code for "
59 << SectionName << ": " << Alloc << " (" << Size
60 << " bytes, alignment " << Alignment << ")\n");
64 uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment,
65 unsigned SectionID, StringRef SectionName,
66 bool IsReadOnly) override {
68 Unmapped.back().RODataAllocs.emplace_back(Size, Alignment);
69 uint8_t *Alloc = reinterpret_cast<uint8_t *>(
70 Unmapped.back().RODataAllocs.back().getLocalAddress());
71 DEBUG(dbgs() << "Allocator " << Id << " allocated ro-data for "
72 << SectionName << ": " << Alloc << " (" << Size
73 << " bytes, alignment " << Alignment << ")\n");
77 Unmapped.back().RWDataAllocs.emplace_back(Size, Alignment);
78 uint8_t *Alloc = reinterpret_cast<uint8_t *>(
79 Unmapped.back().RWDataAllocs.back().getLocalAddress());
80 DEBUG(dbgs() << "Allocator " << Id << " allocated rw-data for "
81 << SectionName << ": " << Alloc << " (" << Size
82 << " bytes, alignment " << Alignment << "\n");
86 void reserveAllocationSpace(uintptr_t CodeSize, uint32_t CodeAlign,
87 uintptr_t RODataSize, uint32_t RODataAlign,
89 uint32_t RWDataAlign) override {
90 Unmapped.push_back(ObjectAllocs());
92 DEBUG(dbgs() << "Allocator " << Id << " reserved:\n");
95 if (std::error_code EC = Client.reserveMem(
96 Unmapped.back().RemoteCodeAddr, Id, CodeSize, CodeAlign)) {
98 // FIXME; Add error to poll.
99 llvm_unreachable("Failed reserving remote memory.");
101 DEBUG(dbgs() << " code: "
102 << format("0x%016x", Unmapped.back().RemoteCodeAddr)
103 << " (" << CodeSize << " bytes, alignment " << CodeAlign
107 if (RODataSize != 0) {
108 if (auto EC = Client.reserveMem(Unmapped.back().RemoteRODataAddr, Id,
109 RODataSize, RODataAlign)) {
110 // FIXME; Add error to poll.
111 llvm_unreachable("Failed reserving remote memory.");
113 DEBUG(dbgs() << " ro-data: "
114 << format("0x%016x", Unmapped.back().RemoteRODataAddr)
115 << " (" << RODataSize << " bytes, alignment "
116 << RODataAlign << ")\n");
119 if (RWDataSize != 0) {
120 if (auto EC = Client.reserveMem(Unmapped.back().RemoteRWDataAddr, Id,
121 RWDataSize, RWDataAlign)) {
122 // FIXME; Add error to poll.
123 llvm_unreachable("Failed reserving remote memory.");
125 DEBUG(dbgs() << " rw-data: "
126 << format("0x%016x", Unmapped.back().RemoteRWDataAddr)
127 << " (" << RWDataSize << " bytes, alignment "
128 << RWDataAlign << ")\n");
132 bool needsToReserveAllocationSpace() override { return true; }
134 void registerEHFrames(uint8_t *Addr, uint64_t LoadAddr,
135 size_t Size) override {}
137 void deregisterEHFrames(uint8_t *addr, uint64_t LoadAddr,
138 size_t Size) override {}
140 void notifyObjectLoaded(RuntimeDyld &Dyld,
141 const object::ObjectFile &Obj) override {
142 DEBUG(dbgs() << "Allocator " << Id << " applied mappings:\n");
143 for (auto &ObjAllocs : Unmapped) {
145 TargetAddress NextCodeAddr = ObjAllocs.RemoteCodeAddr;
146 for (auto &Alloc : ObjAllocs.CodeAllocs) {
147 NextCodeAddr = RoundUpToAlignment(NextCodeAddr, Alloc.getAlign());
148 Dyld.mapSectionAddress(Alloc.getLocalAddress(), NextCodeAddr);
149 DEBUG(dbgs() << " code: "
150 << static_cast<void *>(Alloc.getLocalAddress())
151 << " -> " << format("0x%016x", NextCodeAddr) << "\n");
152 Alloc.setRemoteAddress(NextCodeAddr);
153 NextCodeAddr += Alloc.getSize();
157 TargetAddress NextRODataAddr = ObjAllocs.RemoteRODataAddr;
158 for (auto &Alloc : ObjAllocs.RODataAllocs) {
160 RoundUpToAlignment(NextRODataAddr, Alloc.getAlign());
161 Dyld.mapSectionAddress(Alloc.getLocalAddress(), NextRODataAddr);
162 DEBUG(dbgs() << " ro-data: "
163 << static_cast<void *>(Alloc.getLocalAddress())
164 << " -> " << format("0x%016x", NextRODataAddr)
166 Alloc.setRemoteAddress(NextRODataAddr);
167 NextRODataAddr += Alloc.getSize();
171 TargetAddress NextRWDataAddr = ObjAllocs.RemoteRWDataAddr;
172 for (auto &Alloc : ObjAllocs.RWDataAllocs) {
174 RoundUpToAlignment(NextRWDataAddr, Alloc.getAlign());
175 Dyld.mapSectionAddress(Alloc.getLocalAddress(), NextRWDataAddr);
176 DEBUG(dbgs() << " rw-data: "
177 << static_cast<void *>(Alloc.getLocalAddress())
178 << " -> " << format("0x%016x", NextRWDataAddr)
180 Alloc.setRemoteAddress(NextRWDataAddr);
181 NextRWDataAddr += Alloc.getSize();
184 Unfinalized.push_back(std::move(ObjAllocs));
189 bool finalizeMemory(std::string *ErrMsg = nullptr) override {
190 DEBUG(dbgs() << "Allocator " << Id << " finalizing:\n");
192 for (auto &ObjAllocs : Unfinalized) {
194 for (auto &Alloc : ObjAllocs.CodeAllocs) {
195 DEBUG(dbgs() << " copying code: "
196 << static_cast<void *>(Alloc.getLocalAddress()) << " -> "
197 << format("0x%016x", Alloc.getRemoteAddress()) << " ("
198 << Alloc.getSize() << " bytes)\n");
199 Client.writeMem(Alloc.getRemoteAddress(), Alloc.getLocalAddress(),
203 if (ObjAllocs.RemoteCodeAddr) {
204 DEBUG(dbgs() << " setting R-X permissions on code block: "
205 << format("0x%016x", ObjAllocs.RemoteCodeAddr) << "\n");
206 Client.setProtections(Id, ObjAllocs.RemoteCodeAddr,
207 sys::Memory::MF_READ | sys::Memory::MF_EXEC);
210 for (auto &Alloc : ObjAllocs.RODataAllocs) {
211 DEBUG(dbgs() << " copying ro-data: "
212 << static_cast<void *>(Alloc.getLocalAddress()) << " -> "
213 << format("0x%016x", Alloc.getRemoteAddress()) << " ("
214 << Alloc.getSize() << " bytes)\n");
215 Client.writeMem(Alloc.getRemoteAddress(), Alloc.getLocalAddress(),
219 if (ObjAllocs.RemoteRODataAddr) {
220 DEBUG(dbgs() << " setting R-- permissions on ro-data block: "
221 << format("0x%016x", ObjAllocs.RemoteRODataAddr)
223 Client.setProtections(Id, ObjAllocs.RemoteRODataAddr,
224 sys::Memory::MF_READ);
227 for (auto &Alloc : ObjAllocs.RWDataAllocs) {
228 DEBUG(dbgs() << " copying rw-data: "
229 << static_cast<void *>(Alloc.getLocalAddress()) << " -> "
230 << format("0x%016x", Alloc.getRemoteAddress()) << " ("
231 << Alloc.getSize() << " bytes)\n");
232 Client.writeMem(Alloc.getRemoteAddress(), Alloc.getLocalAddress(),
236 if (ObjAllocs.RemoteRWDataAddr) {
237 DEBUG(dbgs() << " setting RW- permissions on rw-data block: "
238 << format("0x%016x", ObjAllocs.RemoteRWDataAddr)
240 Client.setProtections(Id, ObjAllocs.RemoteRWDataAddr,
241 sys::Memory::MF_READ | sys::Memory::MF_WRITE);
252 Alloc(uint64_t Size, unsigned Align)
253 : Size(Size), Align(Align), Contents(new char[Size + Align - 1]),
257 : Size(std::move(Other.Size)), Align(std::move(Other.Align)),
258 Contents(std::move(Other.Contents)),
259 RemoteAddr(std::move(Other.RemoteAddr)) {}
261 Alloc &operator=(Alloc &&Other) {
262 Size = std::move(Other.Size);
263 Align = std::move(Other.Align);
264 Contents = std::move(Other.Contents);
265 RemoteAddr = std::move(Other.RemoteAddr);
269 uint64_t getSize() const { return Size; }
271 unsigned getAlign() const { return Align; }
273 char *getLocalAddress() const {
274 uintptr_t LocalAddr = reinterpret_cast<uintptr_t>(Contents.get());
275 LocalAddr = RoundUpToAlignment(LocalAddr, Align);
276 return reinterpret_cast<char *>(LocalAddr);
279 void setRemoteAddress(TargetAddress RemoteAddr) {
280 this->RemoteAddr = RemoteAddr;
283 TargetAddress getRemoteAddress() const { return RemoteAddr; }
288 std::unique_ptr<char[]> Contents;
289 TargetAddress RemoteAddr;
292 struct ObjectAllocs {
294 : RemoteCodeAddr(0), RemoteRODataAddr(0), RemoteRWDataAddr(0) {}
295 TargetAddress RemoteCodeAddr;
296 TargetAddress RemoteRODataAddr;
297 TargetAddress RemoteRWDataAddr;
298 std::vector<Alloc> CodeAllocs, RODataAllocs, RWDataAllocs;
301 OrcRemoteTargetClient &Client;
302 ResourceIdMgr::ResourceId Id;
303 std::vector<ObjectAllocs> Unmapped;
304 std::vector<ObjectAllocs> Unfinalized;
307 /// Remote indirect stubs manager.
308 class RCIndirectStubsManager : public IndirectStubsManager {
310 RCIndirectStubsManager(OrcRemoteTargetClient &Remote,
311 ResourceIdMgr::ResourceId Id)
312 : Remote(Remote), Id(Id) {}
314 ~RCIndirectStubsManager() { Remote.destroyIndirectStubsManager(Id); }
316 std::error_code createStub(StringRef StubName, TargetAddress StubAddr,
317 JITSymbolFlags StubFlags) override {
318 if (auto EC = reserveStubs(1))
321 return createStubInternal(StubName, StubAddr, StubFlags);
324 std::error_code createStubs(const StubInitsMap &StubInits) override {
325 if (auto EC = reserveStubs(StubInits.size()))
328 for (auto &Entry : StubInits)
329 if (auto EC = createStubInternal(Entry.first(), Entry.second.first,
330 Entry.second.second))
333 return std::error_code();
336 JITSymbol findStub(StringRef Name, bool ExportedStubsOnly) override {
337 auto I = StubIndexes.find(Name);
338 if (I == StubIndexes.end())
340 auto Key = I->second.first;
341 auto Flags = I->second.second;
342 auto StubSymbol = JITSymbol(getStubAddr(Key), Flags);
343 if (ExportedStubsOnly && !StubSymbol.isExported())
348 JITSymbol findPointer(StringRef Name) override {
349 auto I = StubIndexes.find(Name);
350 if (I == StubIndexes.end())
352 auto Key = I->second.first;
353 auto Flags = I->second.second;
354 return JITSymbol(getPtrAddr(Key), Flags);
357 std::error_code updatePointer(StringRef Name,
358 TargetAddress NewAddr) override {
359 auto I = StubIndexes.find(Name);
360 assert(I != StubIndexes.end() && "No stub pointer for symbol");
361 auto Key = I->second.first;
362 return Remote.writePointer(getPtrAddr(Key), NewAddr);
366 struct RemoteIndirectStubsInfo {
367 RemoteIndirectStubsInfo(TargetAddress StubBase, TargetAddress PtrBase,
369 : StubBase(StubBase), PtrBase(PtrBase), NumStubs(NumStubs) {}
370 TargetAddress StubBase;
371 TargetAddress PtrBase;
375 OrcRemoteTargetClient &Remote;
376 ResourceIdMgr::ResourceId Id;
377 std::vector<RemoteIndirectStubsInfo> RemoteIndirectStubsInfos;
378 typedef std::pair<uint16_t, uint16_t> StubKey;
379 std::vector<StubKey> FreeStubs;
380 StringMap<std::pair<StubKey, JITSymbolFlags>> StubIndexes;
382 std::error_code reserveStubs(unsigned NumStubs) {
383 if (NumStubs <= FreeStubs.size())
384 return std::error_code();
386 unsigned NewStubsRequired = NumStubs - FreeStubs.size();
387 TargetAddress StubBase;
388 TargetAddress PtrBase;
389 unsigned NumStubsEmitted;
391 Remote.emitIndirectStubs(StubBase, PtrBase, NumStubsEmitted, Id,
394 unsigned NewBlockId = RemoteIndirectStubsInfos.size();
395 RemoteIndirectStubsInfos.push_back(
396 RemoteIndirectStubsInfo(StubBase, PtrBase, NumStubsEmitted));
398 for (unsigned I = 0; I < NumStubsEmitted; ++I)
399 FreeStubs.push_back(std::make_pair(NewBlockId, I));
401 return std::error_code();
404 std::error_code createStubInternal(StringRef StubName,
405 TargetAddress InitAddr,
406 JITSymbolFlags StubFlags) {
407 auto Key = FreeStubs.back();
408 FreeStubs.pop_back();
409 StubIndexes[StubName] = std::make_pair(Key, StubFlags);
410 return Remote.writePointer(getPtrAddr(Key), InitAddr);
413 TargetAddress getStubAddr(StubKey K) {
414 assert(RemoteIndirectStubsInfos[K.first].StubBase != 0 &&
415 "Missing stub address");
416 return RemoteIndirectStubsInfos[K.first].StubBase +
417 K.second * Remote.getIndirectStubSize();
420 TargetAddress getPtrAddr(StubKey K) {
421 assert(RemoteIndirectStubsInfos[K.first].PtrBase != 0 &&
422 "Missing pointer address");
423 return RemoteIndirectStubsInfos[K.first].PtrBase +
424 K.second * Remote.getPointerSize();
428 /// Remote compile callback manager.
429 class RCCompileCallbackManager : public JITCompileCallbackManager {
431 RCCompileCallbackManager(TargetAddress ErrorHandlerAddress,
432 OrcRemoteTargetClient &Remote)
433 : JITCompileCallbackManager(ErrorHandlerAddress), Remote(Remote) {
434 assert(!Remote.CompileCallback && "Compile callback already set");
435 Remote.CompileCallback = [this](TargetAddress TrampolineAddr) {
436 return executeCompileCallback(TrampolineAddr);
438 Remote.emitResolverBlock();
443 TargetAddress BlockAddr = 0;
444 uint32_t NumTrampolines = 0;
445 auto EC = Remote.emitTrampolineBlock(BlockAddr, NumTrampolines);
446 assert(!EC && "Failed to create trampolines");
448 uint32_t TrampolineSize = Remote.getTrampolineSize();
449 for (unsigned I = 0; I < NumTrampolines; ++I)
450 this->AvailableTrampolines.push_back(BlockAddr + (I * TrampolineSize));
453 OrcRemoteTargetClient &Remote;
456 /// Create an OrcRemoteTargetClient.
457 /// Channel is the ChannelT instance to communicate on. It is assumed that
458 /// the channel is ready to be read from and written to.
459 static ErrorOr<OrcRemoteTargetClient> Create(ChannelT &Channel) {
461 OrcRemoteTargetClient H(Channel, EC);
467 /// Call the int(void) function at the given address in the target and return
469 std::error_code callIntVoid(int &Result, TargetAddress Addr) {
470 DEBUG(dbgs() << "Calling int(*)(void) " << format("0x%016x", Addr) << "\n");
472 if (auto EC = call<CallIntVoid>(Channel, Addr))
476 if (auto EC = listenForCompileRequests(NextProcId))
479 if (NextProcId != CallIntVoidResponseId)
480 return orcError(OrcErrorCode::UnexpectedRPCCall);
482 return handle<CallIntVoidResponse>(Channel, [&](int R) {
484 DEBUG(dbgs() << "Result: " << R << "\n");
485 return std::error_code();
489 /// Call the int(int, char*[]) function at the given address in the target and
490 /// return its result.
491 std::error_code callMain(int &Result, TargetAddress Addr,
492 const std::vector<std::string> &Args) {
493 DEBUG(dbgs() << "Calling int(*)(int, char*[]) " << format("0x%016x", Addr)
496 if (auto EC = call<CallMain>(Channel, Addr, Args))
500 if (auto EC = listenForCompileRequests(NextProcId))
503 if (NextProcId != CallMainResponseId)
504 return orcError(OrcErrorCode::UnexpectedRPCCall);
506 return handle<CallMainResponse>(Channel, [&](int R) {
508 DEBUG(dbgs() << "Result: " << R << "\n");
509 return std::error_code();
513 /// Call the void() function at the given address in the target and wait for
515 std::error_code callVoidVoid(TargetAddress Addr) {
516 DEBUG(dbgs() << "Calling void(*)(void) " << format("0x%016x", Addr)
519 if (auto EC = call<CallVoidVoid>(Channel, Addr))
523 if (auto EC = listenForCompileRequests(NextProcId))
526 if (NextProcId != CallVoidVoidResponseId)
527 return orcError(OrcErrorCode::UnexpectedRPCCall);
529 return handle<CallVoidVoidResponse>(Channel, doNothing);
532 /// Create an RCMemoryManager which will allocate its memory on the remote
535 createRemoteMemoryManager(std::unique_ptr<RCMemoryManager> &MM) {
536 assert(!MM && "MemoryManager should be null before creation.");
538 auto Id = AllocatorIds.getNext();
539 if (auto EC = call<CreateRemoteAllocator>(Channel, Id))
541 MM = llvm::make_unique<RCMemoryManager>(*this, Id);
542 return std::error_code();
545 /// Create an RCIndirectStubsManager that will allocate stubs on the remote
548 createIndirectStubsManager(std::unique_ptr<RCIndirectStubsManager> &I) {
549 assert(!I && "Indirect stubs manager should be null before creation.");
550 auto Id = IndirectStubOwnerIds.getNext();
551 if (auto EC = call<CreateIndirectStubsOwner>(Channel, Id))
553 I = llvm::make_unique<RCIndirectStubsManager>(*this, Id);
554 return std::error_code();
557 /// Search for symbols in the remote process. Note: This should be used by
558 /// symbol resolvers *after* they've searched the local symbol table in the
560 std::error_code getSymbolAddress(TargetAddress &Addr, StringRef Name) {
561 // Check for an 'out-of-band' error, e.g. from an MM destructor.
563 return ExistingError;
565 // Request remote symbol address.
566 if (auto EC = call<GetSymbolAddress>(Channel, Name))
569 return expect<GetSymbolAddressResponse>(Channel, [&](TargetAddress &A) {
571 DEBUG(dbgs() << "Remote address lookup " << Name << " = "
572 << format("0x%016x", Addr) << "\n");
573 return std::error_code();
577 /// Get the triple for the remote target.
578 const std::string &getTargetTriple() const { return RemoteTargetTriple; }
580 std::error_code terminateSession() { return call<TerminateSession>(Channel); }
583 OrcRemoteTargetClient(ChannelT &Channel, std::error_code &EC)
584 : Channel(Channel), RemotePointerSize(0), RemotePageSize(0),
585 RemoteTrampolineSize(0), RemoteIndirectStubSize(0) {
586 if ((EC = call<GetRemoteInfo>(Channel)))
589 EC = expect<GetRemoteInfoResponse>(
590 Channel, readArgs(RemoteTargetTriple, RemotePointerSize, RemotePageSize,
591 RemoteTrampolineSize, RemoteIndirectStubSize));
594 void destroyRemoteAllocator(ResourceIdMgr::ResourceId Id) {
595 if (auto EC = call<DestroyRemoteAllocator>(Channel, Id)) {
596 // FIXME: This will be triggered by a removeModuleSet call: Propagate
597 // error return up through that.
598 llvm_unreachable("Failed to destroy remote allocator.");
599 AllocatorIds.release(Id);
603 std::error_code destroyIndirectStubsManager(ResourceIdMgr::ResourceId Id) {
604 IndirectStubOwnerIds.release(Id);
605 return call<DestroyIndirectStubsOwner>(Channel, Id);
608 std::error_code emitIndirectStubs(TargetAddress &StubBase,
609 TargetAddress &PtrBase,
610 uint32_t &NumStubsEmitted,
611 ResourceIdMgr::ResourceId Id,
612 uint32_t NumStubsRequired) {
613 if (auto EC = call<EmitIndirectStubs>(Channel, Id, NumStubsRequired))
616 return expect<EmitIndirectStubsResponse>(
617 Channel, readArgs(StubBase, PtrBase, NumStubsEmitted));
620 std::error_code emitResolverBlock() {
621 // Check for an 'out-of-band' error, e.g. from an MM destructor.
623 return ExistingError;
625 return call<EmitResolverBlock>(Channel);
628 std::error_code emitTrampolineBlock(TargetAddress &BlockAddr,
629 uint32_t &NumTrampolines) {
630 // Check for an 'out-of-band' error, e.g. from an MM destructor.
632 return ExistingError;
634 if (auto EC = call<EmitTrampolineBlock>(Channel))
637 return expect<EmitTrampolineBlockResponse>(
638 Channel, [&](TargetAddress BAddr, uint32_t NTrampolines) {
640 NumTrampolines = NTrampolines;
641 return std::error_code();
645 uint32_t getIndirectStubSize() const { return RemoteIndirectStubSize; }
646 uint32_t getPageSize() const { return RemotePageSize; }
647 uint32_t getPointerSize() const { return RemotePointerSize; }
649 uint32_t getTrampolineSize() const { return RemoteTrampolineSize; }
651 std::error_code listenForCompileRequests(uint32_t &NextId) {
652 // Check for an 'out-of-band' error, e.g. from an MM destructor.
654 return ExistingError;
656 if (auto EC = getNextProcId(Channel, NextId))
659 while (NextId == RequestCompileId) {
660 TargetAddress TrampolineAddr = 0;
661 if (auto EC = handle<RequestCompile>(Channel, readArgs(TrampolineAddr)))
664 TargetAddress ImplAddr = CompileCallback(TrampolineAddr);
665 if (auto EC = call<RequestCompileResponse>(Channel, ImplAddr))
668 if (auto EC = getNextProcId(Channel, NextId))
672 return std::error_code();
675 std::error_code readMem(char *Dst, TargetAddress Src, uint64_t Size) {
676 // Check for an 'out-of-band' error, e.g. from an MM destructor.
678 return ExistingError;
680 if (auto EC = call<ReadMem>(Channel, Src, Size))
683 if (auto EC = expect<ReadMemResponse>(
684 Channel, [&]() { return Channel.readBytes(Dst, Size); }))
687 return std::error_code();
690 std::error_code reserveMem(TargetAddress &RemoteAddr,
691 ResourceIdMgr::ResourceId Id, uint64_t Size,
694 // Check for an 'out-of-band' error, e.g. from an MM destructor.
696 return ExistingError;
698 if (auto EC = call<ReserveMem>(Channel, Id, Size, Align))
701 if (auto EC = expect<ReserveMemResponse>(Channel, [&](TargetAddress Addr) {
703 return std::error_code();
707 return std::error_code();
710 std::error_code setProtections(ResourceIdMgr::ResourceId Id,
711 TargetAddress RemoteSegAddr,
712 unsigned ProtFlags) {
713 return call<SetProtections>(Channel, Id, RemoteSegAddr, ProtFlags);
716 std::error_code writeMem(TargetAddress Addr, const char *Src, uint64_t Size) {
717 // Check for an 'out-of-band' error, e.g. from an MM destructor.
719 return ExistingError;
721 // Make the send call.
722 if (auto EC = call<WriteMem>(Channel, Addr, Size))
725 // Follow this up with the section contents.
726 if (auto EC = Channel.appendBytes(Src, Size))
729 return Channel.send();
732 std::error_code writePointer(TargetAddress Addr, TargetAddress PtrVal) {
733 // Check for an 'out-of-band' error, e.g. from an MM destructor.
735 return ExistingError;
737 return call<WritePtr>(Channel, Addr, PtrVal);
740 static std::error_code doNothing() { return std::error_code(); }
743 std::error_code ExistingError;
744 std::string RemoteTargetTriple;
745 uint32_t RemotePointerSize;
746 uint32_t RemotePageSize;
747 uint32_t RemoteTrampolineSize;
748 uint32_t RemoteIndirectStubSize;
749 ResourceIdMgr AllocatorIds, IndirectStubOwnerIds;
750 std::function<TargetAddress(TargetAddress)> CompileCallback;
753 } // end namespace remote
754 } // end namespace orc
755 } // end namespace llvm