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]),
256 Alloc(const Alloc&) = delete;
257 Alloc& operator=(const Alloc&) = delete;
260 : Size(std::move(Other.Size)), Align(std::move(Other.Align)),
261 Contents(std::move(Other.Contents)),
262 RemoteAddr(std::move(Other.RemoteAddr)) {}
264 Alloc &operator=(Alloc &&Other) {
265 Size = std::move(Other.Size);
266 Align = std::move(Other.Align);
267 Contents = std::move(Other.Contents);
268 RemoteAddr = std::move(Other.RemoteAddr);
272 uint64_t getSize() const { return Size; }
274 unsigned getAlign() const { return Align; }
276 char *getLocalAddress() const {
277 uintptr_t LocalAddr = reinterpret_cast<uintptr_t>(Contents.get());
278 LocalAddr = RoundUpToAlignment(LocalAddr, Align);
279 return reinterpret_cast<char *>(LocalAddr);
282 void setRemoteAddress(TargetAddress RemoteAddr) {
283 this->RemoteAddr = RemoteAddr;
286 TargetAddress getRemoteAddress() const { return RemoteAddr; }
291 std::unique_ptr<char[]> Contents;
292 TargetAddress RemoteAddr;
295 struct ObjectAllocs {
297 : RemoteCodeAddr(0), RemoteRODataAddr(0), RemoteRWDataAddr(0) {}
298 TargetAddress RemoteCodeAddr;
299 TargetAddress RemoteRODataAddr;
300 TargetAddress RemoteRWDataAddr;
301 std::vector<Alloc> CodeAllocs, RODataAllocs, RWDataAllocs;
304 OrcRemoteTargetClient &Client;
305 ResourceIdMgr::ResourceId Id;
306 std::vector<ObjectAllocs> Unmapped;
307 std::vector<ObjectAllocs> Unfinalized;
310 /// Remote indirect stubs manager.
311 class RCIndirectStubsManager : public IndirectStubsManager {
313 RCIndirectStubsManager(OrcRemoteTargetClient &Remote,
314 ResourceIdMgr::ResourceId Id)
315 : Remote(Remote), Id(Id) {}
317 ~RCIndirectStubsManager() { Remote.destroyIndirectStubsManager(Id); }
319 std::error_code createStub(StringRef StubName, TargetAddress StubAddr,
320 JITSymbolFlags StubFlags) override {
321 if (auto EC = reserveStubs(1))
324 return createStubInternal(StubName, StubAddr, StubFlags);
327 std::error_code createStubs(const StubInitsMap &StubInits) override {
328 if (auto EC = reserveStubs(StubInits.size()))
331 for (auto &Entry : StubInits)
332 if (auto EC = createStubInternal(Entry.first(), Entry.second.first,
333 Entry.second.second))
336 return std::error_code();
339 JITSymbol findStub(StringRef Name, bool ExportedStubsOnly) override {
340 auto I = StubIndexes.find(Name);
341 if (I == StubIndexes.end())
343 auto Key = I->second.first;
344 auto Flags = I->second.second;
345 auto StubSymbol = JITSymbol(getStubAddr(Key), Flags);
346 if (ExportedStubsOnly && !StubSymbol.isExported())
351 JITSymbol findPointer(StringRef Name) override {
352 auto I = StubIndexes.find(Name);
353 if (I == StubIndexes.end())
355 auto Key = I->second.first;
356 auto Flags = I->second.second;
357 return JITSymbol(getPtrAddr(Key), Flags);
360 std::error_code updatePointer(StringRef Name,
361 TargetAddress NewAddr) override {
362 auto I = StubIndexes.find(Name);
363 assert(I != StubIndexes.end() && "No stub pointer for symbol");
364 auto Key = I->second.first;
365 return Remote.writePointer(getPtrAddr(Key), NewAddr);
369 struct RemoteIndirectStubsInfo {
370 RemoteIndirectStubsInfo(TargetAddress StubBase, TargetAddress PtrBase,
372 : StubBase(StubBase), PtrBase(PtrBase), NumStubs(NumStubs) {}
373 TargetAddress StubBase;
374 TargetAddress PtrBase;
378 OrcRemoteTargetClient &Remote;
379 ResourceIdMgr::ResourceId Id;
380 std::vector<RemoteIndirectStubsInfo> RemoteIndirectStubsInfos;
381 typedef std::pair<uint16_t, uint16_t> StubKey;
382 std::vector<StubKey> FreeStubs;
383 StringMap<std::pair<StubKey, JITSymbolFlags>> StubIndexes;
385 std::error_code reserveStubs(unsigned NumStubs) {
386 if (NumStubs <= FreeStubs.size())
387 return std::error_code();
389 unsigned NewStubsRequired = NumStubs - FreeStubs.size();
390 TargetAddress StubBase;
391 TargetAddress PtrBase;
392 unsigned NumStubsEmitted;
394 Remote.emitIndirectStubs(StubBase, PtrBase, NumStubsEmitted, Id,
397 unsigned NewBlockId = RemoteIndirectStubsInfos.size();
398 RemoteIndirectStubsInfos.push_back(
399 RemoteIndirectStubsInfo(StubBase, PtrBase, NumStubsEmitted));
401 for (unsigned I = 0; I < NumStubsEmitted; ++I)
402 FreeStubs.push_back(std::make_pair(NewBlockId, I));
404 return std::error_code();
407 std::error_code createStubInternal(StringRef StubName,
408 TargetAddress InitAddr,
409 JITSymbolFlags StubFlags) {
410 auto Key = FreeStubs.back();
411 FreeStubs.pop_back();
412 StubIndexes[StubName] = std::make_pair(Key, StubFlags);
413 return Remote.writePointer(getPtrAddr(Key), InitAddr);
416 TargetAddress getStubAddr(StubKey K) {
417 assert(RemoteIndirectStubsInfos[K.first].StubBase != 0 &&
418 "Missing stub address");
419 return RemoteIndirectStubsInfos[K.first].StubBase +
420 K.second * Remote.getIndirectStubSize();
423 TargetAddress getPtrAddr(StubKey K) {
424 assert(RemoteIndirectStubsInfos[K.first].PtrBase != 0 &&
425 "Missing pointer address");
426 return RemoteIndirectStubsInfos[K.first].PtrBase +
427 K.second * Remote.getPointerSize();
431 /// Remote compile callback manager.
432 class RCCompileCallbackManager : public JITCompileCallbackManager {
434 RCCompileCallbackManager(TargetAddress ErrorHandlerAddress,
435 OrcRemoteTargetClient &Remote)
436 : JITCompileCallbackManager(ErrorHandlerAddress), Remote(Remote) {
437 assert(!Remote.CompileCallback && "Compile callback already set");
438 Remote.CompileCallback = [this](TargetAddress TrampolineAddr) {
439 return executeCompileCallback(TrampolineAddr);
441 Remote.emitResolverBlock();
446 TargetAddress BlockAddr = 0;
447 uint32_t NumTrampolines = 0;
448 auto EC = Remote.emitTrampolineBlock(BlockAddr, NumTrampolines);
449 assert(!EC && "Failed to create trampolines");
451 uint32_t TrampolineSize = Remote.getTrampolineSize();
452 for (unsigned I = 0; I < NumTrampolines; ++I)
453 this->AvailableTrampolines.push_back(BlockAddr + (I * TrampolineSize));
456 OrcRemoteTargetClient &Remote;
459 /// Create an OrcRemoteTargetClient.
460 /// Channel is the ChannelT instance to communicate on. It is assumed that
461 /// the channel is ready to be read from and written to.
462 static ErrorOr<OrcRemoteTargetClient> Create(ChannelT &Channel) {
464 OrcRemoteTargetClient H(Channel, EC);
470 /// Call the int(void) function at the given address in the target and return
472 std::error_code callIntVoid(int &Result, TargetAddress Addr) {
473 DEBUG(dbgs() << "Calling int(*)(void) " << format("0x%016x", Addr) << "\n");
475 if (auto EC = call<CallIntVoid>(Channel, Addr))
479 if (auto EC = listenForCompileRequests(NextProcId))
482 if (NextProcId != CallIntVoidResponseId)
483 return orcError(OrcErrorCode::UnexpectedRPCCall);
485 return handle<CallIntVoidResponse>(Channel, [&](int R) {
487 DEBUG(dbgs() << "Result: " << R << "\n");
488 return std::error_code();
492 /// Call the int(int, char*[]) function at the given address in the target and
493 /// return its result.
494 std::error_code callMain(int &Result, TargetAddress Addr,
495 const std::vector<std::string> &Args) {
496 DEBUG(dbgs() << "Calling int(*)(int, char*[]) " << format("0x%016x", Addr)
499 if (auto EC = call<CallMain>(Channel, Addr, Args))
503 if (auto EC = listenForCompileRequests(NextProcId))
506 if (NextProcId != CallMainResponseId)
507 return orcError(OrcErrorCode::UnexpectedRPCCall);
509 return handle<CallMainResponse>(Channel, [&](int R) {
511 DEBUG(dbgs() << "Result: " << R << "\n");
512 return std::error_code();
516 /// Call the void() function at the given address in the target and wait for
518 std::error_code callVoidVoid(TargetAddress Addr) {
519 DEBUG(dbgs() << "Calling void(*)(void) " << format("0x%016x", Addr)
522 if (auto EC = call<CallVoidVoid>(Channel, Addr))
526 if (auto EC = listenForCompileRequests(NextProcId))
529 if (NextProcId != CallVoidVoidResponseId)
530 return orcError(OrcErrorCode::UnexpectedRPCCall);
532 return handle<CallVoidVoidResponse>(Channel, doNothing);
535 /// Create an RCMemoryManager which will allocate its memory on the remote
538 createRemoteMemoryManager(std::unique_ptr<RCMemoryManager> &MM) {
539 assert(!MM && "MemoryManager should be null before creation.");
541 auto Id = AllocatorIds.getNext();
542 if (auto EC = call<CreateRemoteAllocator>(Channel, Id))
544 MM = llvm::make_unique<RCMemoryManager>(*this, Id);
545 return std::error_code();
548 /// Create an RCIndirectStubsManager that will allocate stubs on the remote
551 createIndirectStubsManager(std::unique_ptr<RCIndirectStubsManager> &I) {
552 assert(!I && "Indirect stubs manager should be null before creation.");
553 auto Id = IndirectStubOwnerIds.getNext();
554 if (auto EC = call<CreateIndirectStubsOwner>(Channel, Id))
556 I = llvm::make_unique<RCIndirectStubsManager>(*this, Id);
557 return std::error_code();
560 /// Search for symbols in the remote process. Note: This should be used by
561 /// symbol resolvers *after* they've searched the local symbol table in the
563 std::error_code getSymbolAddress(TargetAddress &Addr, StringRef Name) {
564 // Check for an 'out-of-band' error, e.g. from an MM destructor.
566 return ExistingError;
568 // Request remote symbol address.
569 if (auto EC = call<GetSymbolAddress>(Channel, Name))
572 return expect<GetSymbolAddressResponse>(Channel, [&](TargetAddress &A) {
574 DEBUG(dbgs() << "Remote address lookup " << Name << " = "
575 << format("0x%016x", Addr) << "\n");
576 return std::error_code();
580 /// Get the triple for the remote target.
581 const std::string &getTargetTriple() const { return RemoteTargetTriple; }
583 std::error_code terminateSession() { return call<TerminateSession>(Channel); }
586 OrcRemoteTargetClient(ChannelT &Channel, std::error_code &EC)
587 : Channel(Channel), RemotePointerSize(0), RemotePageSize(0),
588 RemoteTrampolineSize(0), RemoteIndirectStubSize(0) {
589 if ((EC = call<GetRemoteInfo>(Channel)))
592 EC = expect<GetRemoteInfoResponse>(
593 Channel, readArgs(RemoteTargetTriple, RemotePointerSize, RemotePageSize,
594 RemoteTrampolineSize, RemoteIndirectStubSize));
597 void destroyRemoteAllocator(ResourceIdMgr::ResourceId Id) {
598 if (auto EC = call<DestroyRemoteAllocator>(Channel, Id)) {
599 // FIXME: This will be triggered by a removeModuleSet call: Propagate
600 // error return up through that.
601 llvm_unreachable("Failed to destroy remote allocator.");
602 AllocatorIds.release(Id);
606 std::error_code destroyIndirectStubsManager(ResourceIdMgr::ResourceId Id) {
607 IndirectStubOwnerIds.release(Id);
608 return call<DestroyIndirectStubsOwner>(Channel, Id);
611 std::error_code emitIndirectStubs(TargetAddress &StubBase,
612 TargetAddress &PtrBase,
613 uint32_t &NumStubsEmitted,
614 ResourceIdMgr::ResourceId Id,
615 uint32_t NumStubsRequired) {
616 if (auto EC = call<EmitIndirectStubs>(Channel, Id, NumStubsRequired))
619 return expect<EmitIndirectStubsResponse>(
620 Channel, readArgs(StubBase, PtrBase, NumStubsEmitted));
623 std::error_code emitResolverBlock() {
624 // Check for an 'out-of-band' error, e.g. from an MM destructor.
626 return ExistingError;
628 return call<EmitResolverBlock>(Channel);
631 std::error_code emitTrampolineBlock(TargetAddress &BlockAddr,
632 uint32_t &NumTrampolines) {
633 // Check for an 'out-of-band' error, e.g. from an MM destructor.
635 return ExistingError;
637 if (auto EC = call<EmitTrampolineBlock>(Channel))
640 return expect<EmitTrampolineBlockResponse>(
641 Channel, [&](TargetAddress BAddr, uint32_t NTrampolines) {
643 NumTrampolines = NTrampolines;
644 return std::error_code();
648 uint32_t getIndirectStubSize() const { return RemoteIndirectStubSize; }
649 uint32_t getPageSize() const { return RemotePageSize; }
650 uint32_t getPointerSize() const { return RemotePointerSize; }
652 uint32_t getTrampolineSize() const { return RemoteTrampolineSize; }
654 std::error_code listenForCompileRequests(uint32_t &NextId) {
655 // Check for an 'out-of-band' error, e.g. from an MM destructor.
657 return ExistingError;
659 if (auto EC = getNextProcId(Channel, NextId))
662 while (NextId == RequestCompileId) {
663 TargetAddress TrampolineAddr = 0;
664 if (auto EC = handle<RequestCompile>(Channel, readArgs(TrampolineAddr)))
667 TargetAddress ImplAddr = CompileCallback(TrampolineAddr);
668 if (auto EC = call<RequestCompileResponse>(Channel, ImplAddr))
671 if (auto EC = getNextProcId(Channel, NextId))
675 return std::error_code();
678 std::error_code readMem(char *Dst, TargetAddress Src, 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<ReadMem>(Channel, Src, Size))
686 if (auto EC = expect<ReadMemResponse>(
687 Channel, [&]() { return Channel.readBytes(Dst, Size); }))
690 return std::error_code();
693 std::error_code reserveMem(TargetAddress &RemoteAddr,
694 ResourceIdMgr::ResourceId Id, uint64_t Size,
697 // Check for an 'out-of-band' error, e.g. from an MM destructor.
699 return ExistingError;
701 if (auto EC = call<ReserveMem>(Channel, Id, Size, Align))
704 if (std::error_code EC =
705 expect<ReserveMemResponse>(Channel, [&](TargetAddress Addr) {
707 return std::error_code();
711 return std::error_code();
714 std::error_code setProtections(ResourceIdMgr::ResourceId Id,
715 TargetAddress RemoteSegAddr,
716 unsigned ProtFlags) {
717 return call<SetProtections>(Channel, Id, RemoteSegAddr, ProtFlags);
720 std::error_code writeMem(TargetAddress Addr, const char *Src, uint64_t Size) {
721 // Check for an 'out-of-band' error, e.g. from an MM destructor.
723 return ExistingError;
725 // Make the send call.
726 if (auto EC = call<WriteMem>(Channel, Addr, Size))
729 // Follow this up with the section contents.
730 if (auto EC = Channel.appendBytes(Src, Size))
733 return Channel.send();
736 std::error_code writePointer(TargetAddress Addr, TargetAddress PtrVal) {
737 // Check for an 'out-of-band' error, e.g. from an MM destructor.
739 return ExistingError;
741 return call<WritePtr>(Channel, Addr, PtrVal);
744 static std::error_code doNothing() { return std::error_code(); }
747 std::error_code ExistingError;
748 std::string RemoteTargetTriple;
749 uint32_t RemotePointerSize;
750 uint32_t RemotePageSize;
751 uint32_t RemoteTrampolineSize;
752 uint32_t RemoteIndirectStubSize;
753 ResourceIdMgr AllocatorIds, IndirectStubOwnerIds;
754 std::function<TargetAddress(TargetAddress)> CompileCallback;
757 } // end namespace remote
758 } // end namespace orc
759 } // end namespace llvm