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"
22 #define DEBUG_TYPE "orc-remote"
28 /// This class provides utilities (including memory manager, indirect stubs
29 /// manager, and compile callback manager types) that support remote JITing
32 /// Each of the utility classes talks to a JIT server (an instance of the
33 /// OrcRemoteTargetServer class) via an RPC system (see RPCUtils.h) to carry out
35 template <typename ChannelT>
36 class OrcRemoteTargetClient : public OrcRemoteTargetRPCAPI {
38 /// Remote memory manager.
39 class RCMemoryManager : public RuntimeDyld::MemoryManager {
41 RCMemoryManager(OrcRemoteTargetClient &Client, ResourceIdMgr::ResourceId Id)
42 : Client(Client), Id(Id) {
43 DEBUG(dbgs() << "Created remote allocator " << Id << "\n");
47 Client.destroyRemoteAllocator(Id);
48 DEBUG(dbgs() << "Destroyed remote allocator " << Id << "\n");
51 uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment,
53 StringRef SectionName) override {
54 Unmapped.back().CodeAllocs.emplace_back(Size, Alignment);
55 uint8_t *Alloc = reinterpret_cast<uint8_t *>(
56 Unmapped.back().CodeAllocs.back().getLocalAddress());
57 DEBUG(dbgs() << "Allocator " << Id << " allocated code for "
58 << SectionName << ": " << Alloc << " (" << Size
59 << " bytes, alignment " << Alignment << ")\n");
63 uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment,
64 unsigned SectionID, StringRef SectionName,
65 bool IsReadOnly) override {
67 Unmapped.back().RODataAllocs.emplace_back(Size, Alignment);
68 uint8_t *Alloc = reinterpret_cast<uint8_t *>(
69 Unmapped.back().RODataAllocs.back().getLocalAddress());
70 DEBUG(dbgs() << "Allocator " << Id << " allocated ro-data for "
71 << SectionName << ": " << Alloc << " (" << Size
72 << " bytes, alignment " << Alignment << ")\n");
76 Unmapped.back().RWDataAllocs.emplace_back(Size, Alignment);
77 uint8_t *Alloc = reinterpret_cast<uint8_t *>(
78 Unmapped.back().RWDataAllocs.back().getLocalAddress());
79 DEBUG(dbgs() << "Allocator " << Id << " allocated rw-data for "
80 << SectionName << ": " << Alloc << " (" << Size
81 << " bytes, alignment " << Alignment << "\n");
85 void reserveAllocationSpace(uintptr_t CodeSize, uint32_t CodeAlign,
86 uintptr_t RODataSize, uint32_t RODataAlign,
88 uint32_t RWDataAlign) override {
89 Unmapped.push_back(ObjectAllocs());
91 DEBUG(dbgs() << "Allocator " << Id << " reserved:\n");
94 if (auto EC = Client.reserveMem(Unmapped.back().RemoteCodeAddr, Id,
95 CodeSize, CodeAlign)) {
96 // FIXME; Add error to poll.
97 llvm_unreachable("Failed reserving remote memory.");
99 DEBUG(dbgs() << " code: "
100 << format("0x%016x", Unmapped.back().RemoteCodeAddr)
101 << " (" << CodeSize << " bytes, alignment " << CodeAlign
105 if (RODataSize != 0) {
106 if (auto EC = Client.reserveMem(Unmapped.back().RemoteRODataAddr, Id,
107 RODataSize, RODataAlign)) {
108 // FIXME; Add error to poll.
109 llvm_unreachable("Failed reserving remote memory.");
111 DEBUG(dbgs() << " ro-data: "
112 << format("0x%016x", Unmapped.back().RemoteRODataAddr)
113 << " (" << RODataSize << " bytes, alignment "
114 << RODataAlign << ")\n");
117 if (RWDataSize != 0) {
118 if (auto EC = Client.reserveMem(Unmapped.back().RemoteRWDataAddr, Id,
119 RWDataSize, RWDataAlign)) {
120 // FIXME; Add error to poll.
121 llvm_unreachable("Failed reserving remote memory.");
123 DEBUG(dbgs() << " rw-data: "
124 << format("0x%016x", Unmapped.back().RemoteRWDataAddr)
125 << " (" << RWDataSize << " bytes, alignment "
126 << RWDataAlign << ")\n");
130 bool needsToReserveAllocationSpace() override { return true; }
132 void registerEHFrames(uint8_t *Addr, uint64_t LoadAddr,
133 size_t Size) override {}
135 void deregisterEHFrames(uint8_t *addr, uint64_t LoadAddr,
136 size_t Size) override {}
138 void notifyObjectLoaded(RuntimeDyld &Dyld,
139 const object::ObjectFile &Obj) override {
140 DEBUG(dbgs() << "Allocator " << Id << " applied mappings:\n");
141 for (auto &ObjAllocs : Unmapped) {
143 TargetAddress NextCodeAddr = ObjAllocs.RemoteCodeAddr;
144 for (auto &Alloc : ObjAllocs.CodeAllocs) {
145 NextCodeAddr = RoundUpToAlignment(NextCodeAddr, Alloc.getAlign());
146 Dyld.mapSectionAddress(Alloc.getLocalAddress(), NextCodeAddr);
147 DEBUG(dbgs() << " code: "
148 << static_cast<void *>(Alloc.getLocalAddress())
149 << " -> " << format("0x%016x", NextCodeAddr) << "\n");
150 Alloc.setRemoteAddress(NextCodeAddr);
151 NextCodeAddr += Alloc.getSize();
155 TargetAddress NextRODataAddr = ObjAllocs.RemoteRODataAddr;
156 for (auto &Alloc : ObjAllocs.RODataAllocs) {
158 RoundUpToAlignment(NextRODataAddr, Alloc.getAlign());
159 Dyld.mapSectionAddress(Alloc.getLocalAddress(), NextRODataAddr);
160 DEBUG(dbgs() << " ro-data: "
161 << static_cast<void *>(Alloc.getLocalAddress())
162 << " -> " << format("0x%016x", NextRODataAddr)
164 Alloc.setRemoteAddress(NextRODataAddr);
165 NextRODataAddr += Alloc.getSize();
169 TargetAddress NextRWDataAddr = ObjAllocs.RemoteRWDataAddr;
170 for (auto &Alloc : ObjAllocs.RWDataAllocs) {
172 RoundUpToAlignment(NextRWDataAddr, Alloc.getAlign());
173 Dyld.mapSectionAddress(Alloc.getLocalAddress(), NextRWDataAddr);
174 DEBUG(dbgs() << " rw-data: "
175 << static_cast<void *>(Alloc.getLocalAddress())
176 << " -> " << format("0x%016x", NextRWDataAddr)
178 Alloc.setRemoteAddress(NextRWDataAddr);
179 NextRWDataAddr += Alloc.getSize();
182 Unfinalized.push_back(std::move(ObjAllocs));
187 bool finalizeMemory(std::string *ErrMsg = nullptr) override {
188 DEBUG(dbgs() << "Allocator " << Id << " finalizing:\n");
190 for (auto &ObjAllocs : Unfinalized) {
192 for (auto &Alloc : ObjAllocs.CodeAllocs) {
193 DEBUG(dbgs() << " copying code: "
194 << static_cast<void *>(Alloc.getLocalAddress()) << " -> "
195 << format("0x%016x", Alloc.getRemoteAddress()) << " ("
196 << Alloc.getSize() << " bytes)\n");
197 Client.writeMem(Alloc.getRemoteAddress(), Alloc.getLocalAddress(),
201 if (ObjAllocs.RemoteCodeAddr) {
202 DEBUG(dbgs() << " setting R-X permissions on code block: "
203 << format("0x%016x", ObjAllocs.RemoteCodeAddr) << "\n");
204 Client.setProtections(Id, ObjAllocs.RemoteCodeAddr,
205 sys::Memory::MF_READ | sys::Memory::MF_EXEC);
208 for (auto &Alloc : ObjAllocs.RODataAllocs) {
209 DEBUG(dbgs() << " copying ro-data: "
210 << static_cast<void *>(Alloc.getLocalAddress()) << " -> "
211 << format("0x%016x", Alloc.getRemoteAddress()) << " ("
212 << Alloc.getSize() << " bytes)\n");
213 Client.writeMem(Alloc.getRemoteAddress(), Alloc.getLocalAddress(),
217 if (ObjAllocs.RemoteRODataAddr) {
218 DEBUG(dbgs() << " setting R-- permissions on ro-data block: "
219 << format("0x%016x", ObjAllocs.RemoteRODataAddr)
221 Client.setProtections(Id, ObjAllocs.RemoteRODataAddr,
222 sys::Memory::MF_READ);
225 for (auto &Alloc : ObjAllocs.RWDataAllocs) {
226 DEBUG(dbgs() << " copying rw-data: "
227 << static_cast<void *>(Alloc.getLocalAddress()) << " -> "
228 << format("0x%016x", Alloc.getRemoteAddress()) << " ("
229 << Alloc.getSize() << " bytes)\n");
230 Client.writeMem(Alloc.getRemoteAddress(), Alloc.getLocalAddress(),
234 if (ObjAllocs.RemoteRWDataAddr) {
235 DEBUG(dbgs() << " setting RW- permissions on rw-data block: "
236 << format("0x%016x", ObjAllocs.RemoteRWDataAddr)
238 Client.setProtections(Id, ObjAllocs.RemoteRWDataAddr,
239 sys::Memory::MF_READ | sys::Memory::MF_WRITE);
250 Alloc(uint64_t Size, unsigned Align)
251 : Size(Size), Align(Align), Contents(new char[Size + Align - 1]),
254 uint64_t getSize() const { return Size; }
256 unsigned getAlign() const { return Align; }
258 char *getLocalAddress() const {
259 uintptr_t LocalAddr = reinterpret_cast<uintptr_t>(Contents.get());
260 LocalAddr = RoundUpToAlignment(LocalAddr, Align);
261 return reinterpret_cast<char *>(LocalAddr);
264 void setRemoteAddress(TargetAddress RemoteAddr) {
265 this->RemoteAddr = RemoteAddr;
268 TargetAddress getRemoteAddress() const { return RemoteAddr; }
273 std::unique_ptr<char[]> Contents;
274 TargetAddress RemoteAddr;
277 struct ObjectAllocs {
279 : RemoteCodeAddr(0), RemoteRODataAddr(0), RemoteRWDataAddr(0) {}
280 TargetAddress RemoteCodeAddr;
281 TargetAddress RemoteRODataAddr;
282 TargetAddress RemoteRWDataAddr;
283 std::vector<Alloc> CodeAllocs, RODataAllocs, RWDataAllocs;
286 OrcRemoteTargetClient &Client;
287 ResourceIdMgr::ResourceId Id;
288 std::vector<ObjectAllocs> Unmapped;
289 std::vector<ObjectAllocs> Unfinalized;
292 /// Remote indirect stubs manager.
293 class RCIndirectStubsManager : public IndirectStubsManager {
295 RCIndirectStubsManager(OrcRemoteTargetClient &Remote,
296 ResourceIdMgr::ResourceId Id)
297 : Remote(Remote), Id(Id) {}
299 ~RCIndirectStubsManager() { Remote.destroyIndirectStubsManager(Id); }
301 std::error_code createStub(StringRef StubName, TargetAddress StubAddr,
302 JITSymbolFlags StubFlags) override {
303 if (auto EC = reserveStubs(1))
306 return createStubInternal(StubName, StubAddr, StubFlags);
309 std::error_code createStubs(const StubInitsMap &StubInits) override {
310 if (auto EC = reserveStubs(StubInits.size()))
313 for (auto &Entry : StubInits)
314 if (auto EC = createStubInternal(Entry.first(), Entry.second.first,
315 Entry.second.second))
318 return std::error_code();
321 JITSymbol findStub(StringRef Name, bool ExportedStubsOnly) override {
322 auto I = StubIndexes.find(Name);
323 if (I == StubIndexes.end())
325 auto Key = I->second.first;
326 auto Flags = I->second.second;
327 auto StubSymbol = JITSymbol(getStubAddr(Key), Flags);
328 if (ExportedStubsOnly && !StubSymbol.isExported())
333 JITSymbol findPointer(StringRef Name) override {
334 auto I = StubIndexes.find(Name);
335 if (I == StubIndexes.end())
337 auto Key = I->second.first;
338 auto Flags = I->second.second;
339 return JITSymbol(getPtrAddr(Key), Flags);
342 std::error_code updatePointer(StringRef Name,
343 TargetAddress NewAddr) override {
344 auto I = StubIndexes.find(Name);
345 assert(I != StubIndexes.end() && "No stub pointer for symbol");
346 auto Key = I->second.first;
347 return Remote.writePointer(getPtrAddr(Key), NewAddr);
351 struct RemoteIndirectStubsInfo {
352 RemoteIndirectStubsInfo(TargetAddress StubBase, TargetAddress PtrBase,
354 : StubBase(StubBase), PtrBase(PtrBase), NumStubs(NumStubs) {}
355 TargetAddress StubBase;
356 TargetAddress PtrBase;
360 OrcRemoteTargetClient &Remote;
361 ResourceIdMgr::ResourceId Id;
362 std::vector<RemoteIndirectStubsInfo> RemoteIndirectStubsInfos;
363 typedef std::pair<uint16_t, uint16_t> StubKey;
364 std::vector<StubKey> FreeStubs;
365 StringMap<std::pair<StubKey, JITSymbolFlags>> StubIndexes;
367 std::error_code reserveStubs(unsigned NumStubs) {
368 if (NumStubs <= FreeStubs.size())
369 return std::error_code();
371 unsigned NewStubsRequired = NumStubs - FreeStubs.size();
372 TargetAddress StubBase;
373 TargetAddress PtrBase;
374 unsigned NumStubsEmitted;
376 Remote.emitIndirectStubs(StubBase, PtrBase, NumStubsEmitted, Id,
379 unsigned NewBlockId = RemoteIndirectStubsInfos.size();
380 RemoteIndirectStubsInfos.push_back(
381 RemoteIndirectStubsInfo(StubBase, PtrBase, NumStubsEmitted));
383 for (unsigned I = 0; I < NumStubsEmitted; ++I)
384 FreeStubs.push_back(std::make_pair(NewBlockId, I));
386 return std::error_code();
389 std::error_code createStubInternal(StringRef StubName,
390 TargetAddress InitAddr,
391 JITSymbolFlags StubFlags) {
392 auto Key = FreeStubs.back();
393 FreeStubs.pop_back();
394 StubIndexes[StubName] = std::make_pair(Key, StubFlags);
395 return Remote.writePointer(getPtrAddr(Key), InitAddr);
398 TargetAddress getStubAddr(StubKey K) {
399 assert(RemoteIndirectStubsInfos[K.first].StubBase != 0 &&
400 "Missing stub address");
401 return RemoteIndirectStubsInfos[K.first].StubBase +
402 K.second * Remote.getIndirectStubSize();
405 TargetAddress getPtrAddr(StubKey K) {
406 assert(RemoteIndirectStubsInfos[K.first].PtrBase != 0 &&
407 "Missing pointer address");
408 return RemoteIndirectStubsInfos[K.first].PtrBase +
409 K.second * Remote.getPointerSize();
413 /// Remote compile callback manager.
414 class RCCompileCallbackManager : public JITCompileCallbackManager {
416 RCCompileCallbackManager(TargetAddress ErrorHandlerAddress,
417 OrcRemoteTargetClient &Remote)
418 : JITCompileCallbackManager(ErrorHandlerAddress), Remote(Remote) {
419 assert(!Remote.CompileCallback && "Compile callback already set");
420 Remote.CompileCallback = [this](TargetAddress TrampolineAddr) {
421 return executeCompileCallback(TrampolineAddr);
423 Remote.emitResolverBlock();
428 TargetAddress BlockAddr = 0;
429 uint32_t NumTrampolines = 0;
430 auto EC = Remote.emitTrampolineBlock(BlockAddr, NumTrampolines);
431 assert(!EC && "Failed to create trampolines");
433 uint32_t TrampolineSize = Remote.getTrampolineSize();
434 for (unsigned I = 0; I < NumTrampolines; ++I)
435 this->AvailableTrampolines.push_back(BlockAddr + (I * TrampolineSize));
438 OrcRemoteTargetClient &Remote;
441 /// Create an OrcRemoteTargetClient.
442 /// Channel is the ChannelT instance to communicate on. It is assumed that
443 /// the channel is ready to be read from and written to.
444 static ErrorOr<OrcRemoteTargetClient> Create(ChannelT &Channel) {
446 OrcRemoteTargetClient H(Channel, EC);
452 /// Call the int(void) function at the given address in the target and return
454 std::error_code callIntVoid(int &Result, TargetAddress Addr) {
455 DEBUG(dbgs() << "Calling int(*)(void) " << format("0x%016x", Addr) << "\n");
457 if (auto EC = call<CallIntVoid>(Channel, Addr))
461 if (auto EC = listenForCompileRequests(NextProcId))
464 if (NextProcId != CallIntVoidResponseId)
465 return orcError(OrcErrorCode::UnexpectedRPCCall);
467 return handle<CallIntVoidResponse>(Channel, [&](int R) {
469 DEBUG(dbgs() << "Result: " << R << "\n");
470 return std::error_code();
474 /// Call the int(int, char*[]) function at the given address in the target and
475 /// return its result.
476 std::error_code callMain(int &Result, TargetAddress Addr,
477 const std::vector<std::string> &Args) {
478 DEBUG(dbgs() << "Calling int(*)(int, char*[]) " << format("0x%016x", Addr)
481 if (auto EC = call<CallMain>(Channel, Addr, Args))
485 if (auto EC = listenForCompileRequests(NextProcId))
488 if (NextProcId != CallMainResponseId)
489 return orcError(OrcErrorCode::UnexpectedRPCCall);
491 return handle<CallMainResponse>(Channel, [&](int R) {
493 DEBUG(dbgs() << "Result: " << R << "\n");
494 return std::error_code();
498 /// Call the void() function at the given address in the target and wait for
500 std::error_code callVoidVoid(TargetAddress Addr) {
501 DEBUG(dbgs() << "Calling void(*)(void) " << format("0x%016x", Addr)
504 if (auto EC = call<CallVoidVoid>(Channel, Addr))
508 if (auto EC = listenForCompileRequests(NextProcId))
511 if (NextProcId != CallVoidVoidResponseId)
512 return orcError(OrcErrorCode::UnexpectedRPCCall);
514 return handle<CallVoidVoidResponse>(Channel, doNothing);
517 /// Create an RCMemoryManager which will allocate its memory on the remote
520 createRemoteMemoryManager(std::unique_ptr<RCMemoryManager> &MM) {
521 assert(!MM && "MemoryManager should be null before creation.");
523 auto Id = AllocatorIds.getNext();
524 if (auto EC = call<CreateRemoteAllocator>(Channel, Id))
526 MM = llvm::make_unique<RCMemoryManager>(*this, Id);
527 return std::error_code();
530 /// Create an RCIndirectStubsManager that will allocate stubs on the remote
533 createIndirectStubsManager(std::unique_ptr<RCIndirectStubsManager> &I) {
534 assert(!I && "Indirect stubs manager should be null before creation.");
535 auto Id = IndirectStubOwnerIds.getNext();
536 if (auto EC = call<CreateIndirectStubsOwner>(Channel, Id))
538 I = llvm::make_unique<RCIndirectStubsManager>(*this, Id);
539 return std::error_code();
542 /// Search for symbols in the remote process. Note: This should be used by
543 /// symbol resolvers *after* they've searched the local symbol table in the
545 std::error_code getSymbolAddress(TargetAddress &Addr, StringRef Name) {
546 // Check for an 'out-of-band' error, e.g. from an MM destructor.
548 return ExistingError;
550 // Request remote symbol address.
551 if (auto EC = call<GetSymbolAddress>(Channel, Name))
554 return expect<GetSymbolAddressResponse>(Channel, [&](TargetAddress &A) {
556 DEBUG(dbgs() << "Remote address lookup " << Name << " = "
557 << format("0x%016x", Addr) << "\n");
558 return std::error_code();
562 /// Get the triple for the remote target.
563 const std::string &getTargetTriple() const { return RemoteTargetTriple; }
565 std::error_code terminateSession() { return call<TerminateSession>(Channel); }
568 OrcRemoteTargetClient(ChannelT &Channel, std::error_code &EC)
569 : Channel(Channel), RemotePointerSize(0), RemotePageSize(0),
570 RemoteTrampolineSize(0), RemoteIndirectStubSize(0) {
571 if ((EC = call<GetRemoteInfo>(Channel)))
574 EC = expect<GetRemoteInfoResponse>(
575 Channel, readArgs(RemoteTargetTriple, RemotePointerSize, RemotePageSize,
576 RemoteTrampolineSize, RemoteIndirectStubSize));
579 void destroyRemoteAllocator(ResourceIdMgr::ResourceId Id) {
580 if (auto EC = call<DestroyRemoteAllocator>(Channel, Id)) {
581 // FIXME: This will be triggered by a removeModuleSet call: Propagate
582 // error return up through that.
583 llvm_unreachable("Failed to destroy remote allocator.");
584 AllocatorIds.release(Id);
588 std::error_code destroyIndirectStubsManager(ResourceIdMgr::ResourceId Id) {
589 IndirectStubOwnerIds.release(Id);
590 return call<DestroyIndirectStubsOwner>(Channel, Id);
593 std::error_code emitIndirectStubs(TargetAddress &StubBase,
594 TargetAddress &PtrBase,
595 uint32_t &NumStubsEmitted,
596 ResourceIdMgr::ResourceId Id,
597 uint32_t NumStubsRequired) {
598 if (auto EC = call<EmitIndirectStubs>(Channel, Id, NumStubsRequired))
601 return expect<EmitIndirectStubsResponse>(
602 Channel, readArgs(StubBase, PtrBase, NumStubsEmitted));
605 std::error_code emitResolverBlock() {
606 // Check for an 'out-of-band' error, e.g. from an MM destructor.
608 return ExistingError;
610 return call<EmitResolverBlock>(Channel);
613 std::error_code emitTrampolineBlock(TargetAddress &BlockAddr,
614 uint32_t &NumTrampolines) {
615 // Check for an 'out-of-band' error, e.g. from an MM destructor.
617 return ExistingError;
619 if (auto EC = call<EmitTrampolineBlock>(Channel))
622 return expect<EmitTrampolineBlockResponse>(
623 Channel, [&](TargetAddress BAddr, uint32_t NTrampolines) {
625 NumTrampolines = NTrampolines;
626 return std::error_code();
630 uint32_t getIndirectStubSize() const { return RemoteIndirectStubSize; }
631 uint32_t getPageSize() const { return RemotePageSize; }
632 uint32_t getPointerSize() const { return RemotePointerSize; }
634 uint32_t getTrampolineSize() const { return RemoteTrampolineSize; }
636 std::error_code listenForCompileRequests(uint32_t &NextId) {
637 // Check for an 'out-of-band' error, e.g. from an MM destructor.
639 return ExistingError;
641 if (auto EC = getNextProcId(Channel, NextId))
644 while (NextId == RequestCompileId) {
645 TargetAddress TrampolineAddr = 0;
646 if (auto EC = handle<RequestCompile>(Channel, readArgs(TrampolineAddr)))
649 TargetAddress ImplAddr = CompileCallback(TrampolineAddr);
650 if (auto EC = call<RequestCompileResponse>(Channel, ImplAddr))
653 if (auto EC = getNextProcId(Channel, NextId))
657 return std::error_code();
660 std::error_code readMem(char *Dst, TargetAddress Src, uint64_t Size) {
661 // Check for an 'out-of-band' error, e.g. from an MM destructor.
663 return ExistingError;
665 if (auto EC = call<ReadMem>(Channel, Src, Size))
668 if (auto EC = expect<ReadMemResponse>(
669 Channel, [&]() { return Channel.readBytes(Dst, Size); }))
672 return std::error_code();
675 std::error_code reserveMem(TargetAddress &RemoteAddr,
676 ResourceIdMgr::ResourceId Id, uint64_t Size,
679 // Check for an 'out-of-band' error, e.g. from an MM destructor.
681 return ExistingError;
683 if (auto EC = call<ReserveMem>(Channel, Id, Size, Align))
686 if (auto EC = expect<ReserveMemResponse>(Channel, [&](TargetAddress Addr) {
688 return std::error_code();
692 return std::error_code();
695 std::error_code setProtections(ResourceIdMgr::ResourceId Id,
696 TargetAddress RemoteSegAddr,
697 unsigned ProtFlags) {
698 return call<SetProtections>(Channel, Id, RemoteSegAddr, ProtFlags);
701 std::error_code writeMem(TargetAddress Addr, const char *Src, uint64_t Size) {
702 // Check for an 'out-of-band' error, e.g. from an MM destructor.
704 return ExistingError;
706 // Make the send call.
707 if (auto EC = call<WriteMem>(Channel, Addr, Size))
710 // Follow this up with the section contents.
711 if (auto EC = Channel.appendBytes(Src, Size))
714 return Channel.send();
717 std::error_code writePointer(TargetAddress Addr, TargetAddress PtrVal) {
718 // Check for an 'out-of-band' error, e.g. from an MM destructor.
720 return ExistingError;
722 return call<WritePtr>(Channel, Addr, PtrVal);
725 static std::error_code doNothing() { return std::error_code(); }
728 std::error_code ExistingError;
729 std::string RemoteTargetTriple;
730 uint32_t RemotePointerSize;
731 uint32_t RemotePageSize;
732 uint32_t RemoteTrampolineSize;
733 uint32_t RemoteIndirectStubSize;
734 ResourceIdMgr AllocatorIds, IndirectStubOwnerIds;
735 std::function<TargetAddress(TargetAddress)> CompileCallback;
738 } // end namespace remote
739 } // end namespace orc
740 } // end namespace llvm