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 "OrcRemoteTargetRPCAPI.h"
21 #define DEBUG_TYPE "orc-remote"
27 /// This class provides utilities (including memory manager, indirect stubs
28 /// manager, and compile callback manager types) that support remote JITing
31 /// Each of the utility classes talks to a JIT server (an instance of the
32 /// OrcRemoteTargetServer class) via an RPC system (see RPCUtils.h) to carry out
34 template <typename ChannelT>
35 class OrcRemoteTargetClient : public OrcRemoteTargetRPCAPI {
37 /// Remote memory manager.
38 class RCMemoryManager : public RuntimeDyld::MemoryManager {
40 RCMemoryManager(OrcRemoteTargetClient &Client, ResourceIdMgr::ResourceId Id)
41 : Client(Client), Id(Id) {
42 DEBUG(dbgs() << "Created remote allocator " << Id << "\n");
46 Client.destroyRemoteAllocator(Id);
47 DEBUG(dbgs() << "Destroyed remote allocator " << Id << "\n");
50 uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment,
52 StringRef SectionName) override {
53 Unmapped.back().CodeAllocs.emplace_back(Size, Alignment);
54 uint8_t *Alloc = reinterpret_cast<uint8_t *>(
55 Unmapped.back().CodeAllocs.back().getLocalAddress());
56 DEBUG(dbgs() << "Allocator " << Id << " allocated code for "
57 << SectionName << ": " << Alloc << " (" << Size
58 << " bytes, alignment " << Alignment << ")\n");
62 uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment,
63 unsigned SectionID, StringRef SectionName,
64 bool IsReadOnly) override {
66 Unmapped.back().RODataAllocs.emplace_back(Size, Alignment);
67 uint8_t *Alloc = reinterpret_cast<uint8_t *>(
68 Unmapped.back().RODataAllocs.back().getLocalAddress());
69 DEBUG(dbgs() << "Allocator " << Id << " allocated ro-data for "
70 << SectionName << ": " << Alloc << " (" << Size
71 << " bytes, alignment " << Alignment << ")\n");
75 Unmapped.back().RWDataAllocs.emplace_back(Size, Alignment);
76 uint8_t *Alloc = reinterpret_cast<uint8_t *>(
77 Unmapped.back().RWDataAllocs.back().getLocalAddress());
78 DEBUG(dbgs() << "Allocator " << Id << " allocated rw-data for "
79 << SectionName << ": " << Alloc << " (" << Size
80 << " bytes, alignment " << Alignment << "\n");
84 void reserveAllocationSpace(uintptr_t CodeSize, uint32_t CodeAlign,
85 uintptr_t RODataSize, uint32_t RODataAlign,
87 uint32_t RWDataAlign) override {
88 Unmapped.push_back(ObjectAllocs());
90 DEBUG(dbgs() << "Allocator " << Id << " reserved:\n");
93 if (auto EC = Client.reserveMem(Unmapped.back().RemoteCodeAddr, Id,
94 CodeSize, CodeAlign)) {
95 // FIXME; Add error to poll.
96 llvm_unreachable("Failed reserving remote memory.");
98 DEBUG(dbgs() << " code: "
99 << format("0x%016x", Unmapped.back().RemoteCodeAddr)
100 << " (" << CodeSize << " bytes, alignment " << CodeAlign
104 if (RODataSize != 0) {
105 if (auto EC = Client.reserveMem(Unmapped.back().RemoteRODataAddr, Id,
106 RODataSize, RODataAlign)) {
107 // FIXME; Add error to poll.
108 llvm_unreachable("Failed reserving remote memory.");
110 DEBUG(dbgs() << " ro-data: "
111 << format("0x%016x", Unmapped.back().RemoteRODataAddr)
112 << " (" << RODataSize << " bytes, alignment "
113 << RODataAlign << ")\n");
116 if (RWDataSize != 0) {
117 if (auto EC = Client.reserveMem(Unmapped.back().RemoteRWDataAddr, Id,
118 RWDataSize, RWDataAlign)) {
119 // FIXME; Add error to poll.
120 llvm_unreachable("Failed reserving remote memory.");
122 DEBUG(dbgs() << " rw-data: "
123 << format("0x%016x", Unmapped.back().RemoteRWDataAddr)
124 << " (" << RWDataSize << " bytes, alignment "
125 << RWDataAlign << ")\n");
129 bool needsToReserveAllocationSpace() override { return true; }
131 void registerEHFrames(uint8_t *Addr, uint64_t LoadAddr,
132 size_t Size) override {}
134 void deregisterEHFrames(uint8_t *addr, uint64_t LoadAddr,
135 size_t Size) override {}
137 void notifyObjectLoaded(RuntimeDyld &Dyld,
138 const object::ObjectFile &Obj) override {
139 DEBUG(dbgs() << "Allocator " << Id << " applied mappings:\n");
140 for (auto &ObjAllocs : Unmapped) {
142 TargetAddress NextCodeAddr = ObjAllocs.RemoteCodeAddr;
143 for (auto &Alloc : ObjAllocs.CodeAllocs) {
144 NextCodeAddr = RoundUpToAlignment(NextCodeAddr, Alloc.getAlign());
145 Dyld.mapSectionAddress(Alloc.getLocalAddress(), NextCodeAddr);
146 DEBUG(dbgs() << " code: "
147 << static_cast<void *>(Alloc.getLocalAddress())
148 << " -> " << format("0x%016x", NextCodeAddr) << "\n");
149 Alloc.setRemoteAddress(NextCodeAddr);
150 NextCodeAddr += Alloc.getSize();
154 TargetAddress NextRODataAddr = ObjAllocs.RemoteRODataAddr;
155 for (auto &Alloc : ObjAllocs.RODataAllocs) {
157 RoundUpToAlignment(NextRODataAddr, Alloc.getAlign());
158 Dyld.mapSectionAddress(Alloc.getLocalAddress(), NextRODataAddr);
159 DEBUG(dbgs() << " ro-data: "
160 << static_cast<void *>(Alloc.getLocalAddress())
161 << " -> " << format("0x%016x", NextRODataAddr)
163 Alloc.setRemoteAddress(NextRODataAddr);
164 NextRODataAddr += Alloc.getSize();
168 TargetAddress NextRWDataAddr = ObjAllocs.RemoteRWDataAddr;
169 for (auto &Alloc : ObjAllocs.RWDataAllocs) {
171 RoundUpToAlignment(NextRWDataAddr, Alloc.getAlign());
172 Dyld.mapSectionAddress(Alloc.getLocalAddress(), NextRWDataAddr);
173 DEBUG(dbgs() << " rw-data: "
174 << static_cast<void *>(Alloc.getLocalAddress())
175 << " -> " << format("0x%016x", NextRWDataAddr)
177 Alloc.setRemoteAddress(NextRWDataAddr);
178 NextRWDataAddr += Alloc.getSize();
181 Unfinalized.push_back(std::move(ObjAllocs));
186 bool finalizeMemory(std::string *ErrMsg = nullptr) override {
187 DEBUG(dbgs() << "Allocator " << Id << " finalizing:\n");
189 for (auto &ObjAllocs : Unfinalized) {
191 for (auto &Alloc : ObjAllocs.CodeAllocs) {
192 DEBUG(dbgs() << " copying code: "
193 << static_cast<void *>(Alloc.getLocalAddress()) << " -> "
194 << format("0x%016x", Alloc.getRemoteAddress()) << " ("
195 << Alloc.getSize() << " bytes)\n");
196 Client.writeMem(Alloc.getRemoteAddress(), Alloc.getLocalAddress(),
200 if (ObjAllocs.RemoteCodeAddr) {
201 DEBUG(dbgs() << " setting R-X permissions on code block: "
202 << format("0x%016x", ObjAllocs.RemoteCodeAddr) << "\n");
203 Client.setProtections(Id, ObjAllocs.RemoteCodeAddr,
204 sys::Memory::MF_READ | sys::Memory::MF_EXEC);
207 for (auto &Alloc : ObjAllocs.RODataAllocs) {
208 DEBUG(dbgs() << " copying ro-data: "
209 << static_cast<void *>(Alloc.getLocalAddress()) << " -> "
210 << format("0x%016x", Alloc.getRemoteAddress()) << " ("
211 << Alloc.getSize() << " bytes)\n");
212 Client.writeMem(Alloc.getRemoteAddress(), Alloc.getLocalAddress(),
216 if (ObjAllocs.RemoteRODataAddr) {
217 DEBUG(dbgs() << " setting R-- permissions on ro-data block: "
218 << format("0x%016x", ObjAllocs.RemoteRODataAddr)
220 Client.setProtections(Id, ObjAllocs.RemoteRODataAddr,
221 sys::Memory::MF_READ);
224 for (auto &Alloc : ObjAllocs.RWDataAllocs) {
225 DEBUG(dbgs() << " copying rw-data: "
226 << static_cast<void *>(Alloc.getLocalAddress()) << " -> "
227 << format("0x%016x", Alloc.getRemoteAddress()) << " ("
228 << Alloc.getSize() << " bytes)\n");
229 Client.writeMem(Alloc.getRemoteAddress(), Alloc.getLocalAddress(),
233 if (ObjAllocs.RemoteRWDataAddr) {
234 DEBUG(dbgs() << " setting RW- permissions on rw-data block: "
235 << format("0x%016x", ObjAllocs.RemoteRWDataAddr)
237 Client.setProtections(Id, ObjAllocs.RemoteRWDataAddr,
238 sys::Memory::MF_READ | sys::Memory::MF_WRITE);
249 Alloc(uint64_t Size, unsigned Align)
250 : Size(Size), Align(Align), Contents(new char[Size + Align - 1]),
253 uint64_t getSize() const { return Size; }
255 unsigned getAlign() const { return Align; }
257 char *getLocalAddress() const {
258 uintptr_t LocalAddr = reinterpret_cast<uintptr_t>(Contents.get());
259 LocalAddr = RoundUpToAlignment(LocalAddr, Align);
260 return reinterpret_cast<char *>(LocalAddr);
263 void setRemoteAddress(TargetAddress RemoteAddr) {
264 this->RemoteAddr = RemoteAddr;
267 TargetAddress getRemoteAddress() const { return RemoteAddr; }
272 std::unique_ptr<char[]> Contents;
273 TargetAddress RemoteAddr;
276 struct ObjectAllocs {
278 : RemoteCodeAddr(0), RemoteRODataAddr(0), RemoteRWDataAddr(0) {}
279 TargetAddress RemoteCodeAddr;
280 TargetAddress RemoteRODataAddr;
281 TargetAddress RemoteRWDataAddr;
282 std::vector<Alloc> CodeAllocs, RODataAllocs, RWDataAllocs;
285 OrcRemoteTargetClient &Client;
286 ResourceIdMgr::ResourceId Id;
287 std::vector<ObjectAllocs> Unmapped;
288 std::vector<ObjectAllocs> Unfinalized;
291 /// Remote indirect stubs manager.
292 class RCIndirectStubsManager : public IndirectStubsManager {
294 RCIndirectStubsManager(OrcRemoteTargetClient &Remote,
295 ResourceIdMgr::ResourceId Id)
296 : Remote(Remote), Id(Id) {}
298 ~RCIndirectStubsManager() { Remote.destroyIndirectStubsManager(Id); }
300 std::error_code createStub(StringRef StubName, TargetAddress StubAddr,
301 JITSymbolFlags StubFlags) override {
302 if (auto EC = reserveStubs(1))
305 return createStubInternal(StubName, StubAddr, StubFlags);
308 std::error_code createStubs(const StubInitsMap &StubInits) override {
309 if (auto EC = reserveStubs(StubInits.size()))
312 for (auto &Entry : StubInits)
313 if (auto EC = createStubInternal(Entry.first(), Entry.second.first,
314 Entry.second.second))
317 return std::error_code();
320 JITSymbol findStub(StringRef Name, bool ExportedStubsOnly) override {
321 auto I = StubIndexes.find(Name);
322 if (I == StubIndexes.end())
324 auto Key = I->second.first;
325 auto Flags = I->second.second;
326 auto StubSymbol = JITSymbol(getStubAddr(Key), Flags);
327 if (ExportedStubsOnly && !StubSymbol.isExported())
332 JITSymbol findPointer(StringRef Name) override {
333 auto I = StubIndexes.find(Name);
334 if (I == StubIndexes.end())
336 auto Key = I->second.first;
337 auto Flags = I->second.second;
338 return JITSymbol(getPtrAddr(Key), Flags);
341 std::error_code updatePointer(StringRef Name,
342 TargetAddress NewAddr) override {
343 auto I = StubIndexes.find(Name);
344 assert(I != StubIndexes.end() && "No stub pointer for symbol");
345 auto Key = I->second.first;
346 return Remote.writePointer(getPtrAddr(Key), NewAddr);
350 struct RemoteIndirectStubsInfo {
351 RemoteIndirectStubsInfo(TargetAddress StubBase, TargetAddress PtrBase,
353 : StubBase(StubBase), PtrBase(PtrBase), NumStubs(NumStubs) {}
354 TargetAddress StubBase;
355 TargetAddress PtrBase;
359 OrcRemoteTargetClient &Remote;
360 ResourceIdMgr::ResourceId Id;
361 std::vector<RemoteIndirectStubsInfo> RemoteIndirectStubsInfos;
362 typedef std::pair<uint16_t, uint16_t> StubKey;
363 std::vector<StubKey> FreeStubs;
364 StringMap<std::pair<StubKey, JITSymbolFlags>> StubIndexes;
366 std::error_code reserveStubs(unsigned NumStubs) {
367 if (NumStubs <= FreeStubs.size())
368 return std::error_code();
370 unsigned NewStubsRequired = NumStubs - FreeStubs.size();
371 TargetAddress StubBase;
372 TargetAddress PtrBase;
373 unsigned NumStubsEmitted;
375 Remote.emitIndirectStubs(StubBase, PtrBase, NumStubsEmitted, Id,
378 unsigned NewBlockId = RemoteIndirectStubsInfos.size();
379 RemoteIndirectStubsInfos.push_back(
380 RemoteIndirectStubsInfo(StubBase, PtrBase, NumStubsEmitted));
382 for (unsigned I = 0; I < NumStubsEmitted; ++I)
383 FreeStubs.push_back(std::make_pair(NewBlockId, I));
385 return std::error_code();
388 std::error_code createStubInternal(StringRef StubName,
389 TargetAddress InitAddr,
390 JITSymbolFlags StubFlags) {
391 auto Key = FreeStubs.back();
392 FreeStubs.pop_back();
393 StubIndexes[StubName] = std::make_pair(Key, StubFlags);
394 return Remote.writePointer(getPtrAddr(Key), InitAddr);
397 TargetAddress getStubAddr(StubKey K) {
398 assert(RemoteIndirectStubsInfos[K.first].StubBase != 0 &&
399 "Missing stub address");
400 return RemoteIndirectStubsInfos[K.first].StubBase +
401 K.second * Remote.getIndirectStubSize();
404 TargetAddress getPtrAddr(StubKey K) {
405 assert(RemoteIndirectStubsInfos[K.first].PtrBase != 0 &&
406 "Missing pointer address");
407 return RemoteIndirectStubsInfos[K.first].PtrBase +
408 K.second * Remote.getPointerSize();
412 /// Remote compile callback manager.
413 class RCCompileCallbackManager : public JITCompileCallbackManager {
415 RCCompileCallbackManager(TargetAddress ErrorHandlerAddress,
416 OrcRemoteTargetClient &Remote)
417 : JITCompileCallbackManager(ErrorHandlerAddress), Remote(Remote) {
418 assert(!Remote.CompileCallback && "Compile callback already set");
419 Remote.CompileCallback = [this](TargetAddress TrampolineAddr) {
420 return executeCompileCallback(TrampolineAddr);
422 Remote.emitResolverBlock();
427 TargetAddress BlockAddr = 0;
428 uint32_t NumTrampolines = 0;
429 auto EC = Remote.emitTrampolineBlock(BlockAddr, NumTrampolines);
430 assert(!EC && "Failed to create trampolines");
432 uint32_t TrampolineSize = Remote.getTrampolineSize();
433 for (unsigned I = 0; I < NumTrampolines; ++I)
434 this->AvailableTrampolines.push_back(BlockAddr + (I * TrampolineSize));
437 OrcRemoteTargetClient &Remote;
440 /// Create an OrcRemoteTargetClient.
441 /// Channel is the ChannelT instance to communicate on. It is assumed that
442 /// the channel is ready to be read from and written to.
443 static ErrorOr<OrcRemoteTargetClient> Create(ChannelT &Channel) {
445 OrcRemoteTargetClient H(Channel, EC);
451 /// Call the int(void) function at the given address in the target and return
453 std::error_code callIntVoid(int &Result, TargetAddress Addr) {
454 DEBUG(dbgs() << "Calling int(*)(void) " << format("0x%016x", Addr) << "\n");
456 if (auto EC = call<CallIntVoid>(Channel, Addr))
460 if (auto EC = listenForCompileRequests(NextProcId))
463 if (NextProcId != CallIntVoidResponseId)
464 return orcError(OrcErrorCode::UnexpectedRPCCall);
466 return handle<CallIntVoidResponse>(Channel, [&](int R) {
468 DEBUG(dbgs() << "Result: " << R << "\n");
469 return std::error_code();
473 /// Call the int(int, char*[]) function at the given address in the target and
474 /// return its result.
475 std::error_code callMain(int &Result, TargetAddress Addr,
476 const std::vector<std::string> &Args) {
477 DEBUG(dbgs() << "Calling int(*)(int, char*[]) " << format("0x%016x", Addr)
480 if (auto EC = call<CallMain>(Channel, Addr, Args))
484 if (auto EC = listenForCompileRequests(NextProcId))
487 if (NextProcId != CallMainResponseId)
488 return orcError(OrcErrorCode::UnexpectedRPCCall);
490 return handle<CallMainResponse>(Channel, [&](int R) {
492 DEBUG(dbgs() << "Result: " << R << "\n");
493 return std::error_code();
497 /// Call the void() function at the given address in the target and wait for
499 std::error_code callVoidVoid(TargetAddress Addr) {
500 DEBUG(dbgs() << "Calling void(*)(void) " << format("0x%016x", Addr)
503 if (auto EC = call<CallVoidVoid>(Channel, Addr))
507 if (auto EC = listenForCompileRequests(NextProcId))
510 if (NextProcId != CallVoidVoidResponseId)
511 return orcError(OrcErrorCode::UnexpectedRPCCall);
513 return handle<CallVoidVoidResponse>(Channel, doNothing);
516 /// Create an RCMemoryManager which will allocate its memory on the remote
519 createRemoteMemoryManager(std::unique_ptr<RCMemoryManager> &MM) {
520 assert(!MM && "MemoryManager should be null before creation.");
522 auto Id = AllocatorIds.getNext();
523 if (auto EC = call<CreateRemoteAllocator>(Channel, Id))
525 MM = llvm::make_unique<RCMemoryManager>(*this, Id);
526 return std::error_code();
529 /// Create an RCIndirectStubsManager that will allocate stubs on the remote
532 createIndirectStubsManager(std::unique_ptr<RCIndirectStubsManager> &I) {
533 assert(!I && "Indirect stubs manager should be null before creation.");
534 auto Id = IndirectStubOwnerIds.getNext();
535 if (auto EC = call<CreateIndirectStubsOwner>(Channel, Id))
537 I = llvm::make_unique<RCIndirectStubsManager>(*this, Id);
538 return std::error_code();
541 /// Search for symbols in the remote process. Note: This should be used by
542 /// symbol resolvers *after* they've searched the local symbol table in the
544 std::error_code getSymbolAddress(TargetAddress &Addr, StringRef Name) {
545 // Check for an 'out-of-band' error, e.g. from an MM destructor.
547 return ExistingError;
549 // Request remote symbol address.
550 if (auto EC = call<GetSymbolAddress>(Channel, Name))
553 return expect<GetSymbolAddressResponse>(Channel, [&](TargetAddress &A) {
555 DEBUG(dbgs() << "Remote address lookup " << Name << " = "
556 << format("0x%016x", Addr) << "\n");
557 return std::error_code();
561 /// Get the triple for the remote target.
562 const std::string &getTargetTriple() const { return RemoteTargetTriple; }
564 std::error_code terminateSession() { return call<TerminateSession>(Channel); }
567 OrcRemoteTargetClient(ChannelT &Channel, std::error_code &EC)
568 : Channel(Channel), RemotePointerSize(0), RemotePageSize(0),
569 RemoteTrampolineSize(0), RemoteIndirectStubSize(0) {
570 if ((EC = call<GetRemoteInfo>(Channel)))
573 EC = expect<GetRemoteInfoResponse>(
574 Channel, readArgs(RemoteTargetTriple, RemotePointerSize, RemotePageSize,
575 RemoteTrampolineSize, RemoteIndirectStubSize));
578 void destroyRemoteAllocator(ResourceIdMgr::ResourceId Id) {
579 if (auto EC = call<DestroyRemoteAllocator>(Channel, Id)) {
580 // FIXME: This will be triggered by a removeModuleSet call: Propagate
581 // error return up through that.
582 llvm_unreachable("Failed to destroy remote allocator.");
583 AllocatorIds.release(Id);
587 std::error_code destroyIndirectStubsManager(ResourceIdMgr::ResourceId Id) {
588 IndirectStubOwnerIds.release(Id);
589 return call<DestroyIndirectStubsOwner>(Channel, Id);
592 std::error_code emitIndirectStubs(TargetAddress &StubBase,
593 TargetAddress &PtrBase,
594 uint32_t &NumStubsEmitted,
595 ResourceIdMgr::ResourceId Id,
596 uint32_t NumStubsRequired) {
597 if (auto EC = call<EmitIndirectStubs>(Channel, Id, NumStubsRequired))
600 return expect<EmitIndirectStubsResponse>(
601 Channel, readArgs(StubBase, PtrBase, NumStubsEmitted));
604 std::error_code emitResolverBlock() {
605 // Check for an 'out-of-band' error, e.g. from an MM destructor.
607 return ExistingError;
609 return call<EmitResolverBlock>(Channel);
612 std::error_code emitTrampolineBlock(TargetAddress &BlockAddr,
613 uint32_t &NumTrampolines) {
614 // Check for an 'out-of-band' error, e.g. from an MM destructor.
616 return ExistingError;
618 if (auto EC = call<EmitTrampolineBlock>(Channel))
621 return expect<EmitTrampolineBlockResponse>(
622 Channel, [&](TargetAddress BAddr, uint32_t NTrampolines) {
624 NumTrampolines = NTrampolines;
625 return std::error_code();
629 uint32_t getIndirectStubSize() const { return RemoteIndirectStubSize; }
630 uint32_t getPageSize() const { return RemotePageSize; }
631 uint32_t getPointerSize() const { return RemotePointerSize; }
633 uint32_t getTrampolineSize() const { return RemoteTrampolineSize; }
635 std::error_code listenForCompileRequests(uint32_t &NextId) {
636 // Check for an 'out-of-band' error, e.g. from an MM destructor.
638 return ExistingError;
640 if (auto EC = getNextProcId(Channel, NextId))
643 while (NextId == RequestCompileId) {
644 TargetAddress TrampolineAddr = 0;
645 if (auto EC = handle<RequestCompile>(Channel, readArgs(TrampolineAddr)))
648 TargetAddress ImplAddr = CompileCallback(TrampolineAddr);
649 if (auto EC = call<RequestCompileResponse>(Channel, ImplAddr))
652 if (auto EC = getNextProcId(Channel, NextId))
656 return std::error_code();
659 std::error_code readMem(char *Dst, TargetAddress Src, uint64_t Size) {
660 // Check for an 'out-of-band' error, e.g. from an MM destructor.
662 return ExistingError;
664 if (auto EC = call<ReadMem>(Channel, Src, Size))
667 if (auto EC = expect<ReadMemResponse>(
668 Channel, [&]() { return Channel.readBytes(Dst, Size); }))
671 return std::error_code();
674 std::error_code reserveMem(TargetAddress &RemoteAddr,
675 ResourceIdMgr::ResourceId Id, uint64_t Size,
678 // Check for an 'out-of-band' error, e.g. from an MM destructor.
680 return ExistingError;
682 if (auto EC = call<ReserveMem>(Channel, Id, Size, Align))
685 if (auto EC = expect<ReserveMemResponse>(Channel, [&](TargetAddress Addr) {
687 return std::error_code();
691 return std::error_code();
694 std::error_code setProtections(ResourceIdMgr::ResourceId Id,
695 TargetAddress RemoteSegAddr,
696 unsigned ProtFlags) {
697 return call<SetProtections>(Channel, Id, RemoteSegAddr, ProtFlags);
700 std::error_code writeMem(TargetAddress Addr, const char *Src, uint64_t Size) {
701 // Check for an 'out-of-band' error, e.g. from an MM destructor.
703 return ExistingError;
705 // Make the send call.
706 if (auto EC = call<WriteMem>(Channel, Addr, Size))
709 // Follow this up with the section contents.
710 if (auto EC = Channel.appendBytes(Src, Size))
713 return Channel.send();
716 std::error_code writePointer(TargetAddress Addr, TargetAddress PtrVal) {
717 // Check for an 'out-of-band' error, e.g. from an MM destructor.
719 return ExistingError;
721 return call<WritePtr>(Channel, Addr, PtrVal);
724 static std::error_code doNothing() { return std::error_code(); }
727 std::error_code ExistingError;
728 std::string RemoteTargetTriple;
729 uint32_t RemotePointerSize;
730 uint32_t RemotePageSize;
731 uint32_t RemoteTrampolineSize;
732 uint32_t RemoteIndirectStubSize;
733 ResourceIdMgr AllocatorIds, IndirectStubOwnerIds;
734 std::function<TargetAddress(TargetAddress)> CompileCallback;
737 } // end namespace remote
738 } // end namespace orc
739 } // end namespace llvm