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");
47 RCMemoryManager(RCMemoryManager &&Other)
48 : Client(std::move(Other.Client)), Id(std::move(Other.Id)),
49 Unmapped(std::move(Other.Unmapped)),
50 Unfinalized(std::move(Other.Unfinalized)) {}
52 RCMemoryManager operator=(RCMemoryManager &&Other) {
53 Client = std::move(Other.Client);
54 Id = std::move(Other.Id);
55 Unmapped = std::move(Other.Unmapped);
56 Unfinalized = std::move(Other.Unfinalized);
61 Client.destroyRemoteAllocator(Id);
62 DEBUG(dbgs() << "Destroyed remote allocator " << Id << "\n");
65 uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment,
67 StringRef SectionName) override {
68 Unmapped.back().CodeAllocs.emplace_back(Size, Alignment);
69 uint8_t *Alloc = reinterpret_cast<uint8_t *>(
70 Unmapped.back().CodeAllocs.back().getLocalAddress());
71 DEBUG(dbgs() << "Allocator " << Id << " allocated code for "
72 << SectionName << ": " << Alloc << " (" << Size
73 << " bytes, alignment " << Alignment << ")\n");
77 uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment,
78 unsigned SectionID, StringRef SectionName,
79 bool IsReadOnly) override {
81 Unmapped.back().RODataAllocs.emplace_back(Size, Alignment);
82 uint8_t *Alloc = reinterpret_cast<uint8_t *>(
83 Unmapped.back().RODataAllocs.back().getLocalAddress());
84 DEBUG(dbgs() << "Allocator " << Id << " allocated ro-data for "
85 << SectionName << ": " << Alloc << " (" << Size
86 << " bytes, alignment " << Alignment << ")\n");
90 Unmapped.back().RWDataAllocs.emplace_back(Size, Alignment);
91 uint8_t *Alloc = reinterpret_cast<uint8_t *>(
92 Unmapped.back().RWDataAllocs.back().getLocalAddress());
93 DEBUG(dbgs() << "Allocator " << Id << " allocated rw-data for "
94 << SectionName << ": " << Alloc << " (" << Size
95 << " bytes, alignment " << Alignment << "\n");
99 void reserveAllocationSpace(uintptr_t CodeSize, uint32_t CodeAlign,
100 uintptr_t RODataSize, uint32_t RODataAlign,
101 uintptr_t RWDataSize,
102 uint32_t RWDataAlign) override {
103 Unmapped.push_back(ObjectAllocs());
105 DEBUG(dbgs() << "Allocator " << Id << " reserved:\n");
108 if (std::error_code EC = Client.reserveMem(
109 Unmapped.back().RemoteCodeAddr, Id, CodeSize, CodeAlign)) {
111 // FIXME; Add error to poll.
112 llvm_unreachable("Failed reserving remote memory.");
114 DEBUG(dbgs() << " code: "
115 << format("0x%016x", Unmapped.back().RemoteCodeAddr)
116 << " (" << CodeSize << " bytes, alignment " << CodeAlign
120 if (RODataSize != 0) {
121 if (auto EC = Client.reserveMem(Unmapped.back().RemoteRODataAddr, Id,
122 RODataSize, RODataAlign)) {
123 // FIXME; Add error to poll.
124 llvm_unreachable("Failed reserving remote memory.");
126 DEBUG(dbgs() << " ro-data: "
127 << format("0x%016x", Unmapped.back().RemoteRODataAddr)
128 << " (" << RODataSize << " bytes, alignment "
129 << RODataAlign << ")\n");
132 if (RWDataSize != 0) {
133 if (auto EC = Client.reserveMem(Unmapped.back().RemoteRWDataAddr, Id,
134 RWDataSize, RWDataAlign)) {
135 // FIXME; Add error to poll.
136 llvm_unreachable("Failed reserving remote memory.");
138 DEBUG(dbgs() << " rw-data: "
139 << format("0x%016x", Unmapped.back().RemoteRWDataAddr)
140 << " (" << RWDataSize << " bytes, alignment "
141 << RWDataAlign << ")\n");
145 bool needsToReserveAllocationSpace() override { return true; }
147 void registerEHFrames(uint8_t *Addr, uint64_t LoadAddr,
148 size_t Size) override {}
150 void deregisterEHFrames(uint8_t *addr, uint64_t LoadAddr,
151 size_t Size) override {}
153 void notifyObjectLoaded(RuntimeDyld &Dyld,
154 const object::ObjectFile &Obj) override {
155 DEBUG(dbgs() << "Allocator " << Id << " applied mappings:\n");
156 for (auto &ObjAllocs : Unmapped) {
158 TargetAddress NextCodeAddr = ObjAllocs.RemoteCodeAddr;
159 for (auto &Alloc : ObjAllocs.CodeAllocs) {
160 NextCodeAddr = RoundUpToAlignment(NextCodeAddr, Alloc.getAlign());
161 Dyld.mapSectionAddress(Alloc.getLocalAddress(), NextCodeAddr);
162 DEBUG(dbgs() << " code: "
163 << static_cast<void *>(Alloc.getLocalAddress())
164 << " -> " << format("0x%016x", NextCodeAddr) << "\n");
165 Alloc.setRemoteAddress(NextCodeAddr);
166 NextCodeAddr += Alloc.getSize();
170 TargetAddress NextRODataAddr = ObjAllocs.RemoteRODataAddr;
171 for (auto &Alloc : ObjAllocs.RODataAllocs) {
173 RoundUpToAlignment(NextRODataAddr, Alloc.getAlign());
174 Dyld.mapSectionAddress(Alloc.getLocalAddress(), NextRODataAddr);
175 DEBUG(dbgs() << " ro-data: "
176 << static_cast<void *>(Alloc.getLocalAddress())
177 << " -> " << format("0x%016x", NextRODataAddr)
179 Alloc.setRemoteAddress(NextRODataAddr);
180 NextRODataAddr += Alloc.getSize();
184 TargetAddress NextRWDataAddr = ObjAllocs.RemoteRWDataAddr;
185 for (auto &Alloc : ObjAllocs.RWDataAllocs) {
187 RoundUpToAlignment(NextRWDataAddr, Alloc.getAlign());
188 Dyld.mapSectionAddress(Alloc.getLocalAddress(), NextRWDataAddr);
189 DEBUG(dbgs() << " rw-data: "
190 << static_cast<void *>(Alloc.getLocalAddress())
191 << " -> " << format("0x%016x", NextRWDataAddr)
193 Alloc.setRemoteAddress(NextRWDataAddr);
194 NextRWDataAddr += Alloc.getSize();
197 Unfinalized.push_back(std::move(ObjAllocs));
202 bool finalizeMemory(std::string *ErrMsg = nullptr) override {
203 DEBUG(dbgs() << "Allocator " << Id << " finalizing:\n");
205 for (auto &ObjAllocs : Unfinalized) {
207 for (auto &Alloc : ObjAllocs.CodeAllocs) {
208 DEBUG(dbgs() << " copying code: "
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.RemoteCodeAddr) {
217 DEBUG(dbgs() << " setting R-X permissions on code block: "
218 << format("0x%016x", ObjAllocs.RemoteCodeAddr) << "\n");
219 Client.setProtections(Id, ObjAllocs.RemoteCodeAddr,
220 sys::Memory::MF_READ | sys::Memory::MF_EXEC);
223 for (auto &Alloc : ObjAllocs.RODataAllocs) {
224 DEBUG(dbgs() << " copying ro-data: "
225 << static_cast<void *>(Alloc.getLocalAddress()) << " -> "
226 << format("0x%016x", Alloc.getRemoteAddress()) << " ("
227 << Alloc.getSize() << " bytes)\n");
228 Client.writeMem(Alloc.getRemoteAddress(), Alloc.getLocalAddress(),
232 if (ObjAllocs.RemoteRODataAddr) {
233 DEBUG(dbgs() << " setting R-- permissions on ro-data block: "
234 << format("0x%016x", ObjAllocs.RemoteRODataAddr)
236 Client.setProtections(Id, ObjAllocs.RemoteRODataAddr,
237 sys::Memory::MF_READ);
240 for (auto &Alloc : ObjAllocs.RWDataAllocs) {
241 DEBUG(dbgs() << " copying rw-data: "
242 << static_cast<void *>(Alloc.getLocalAddress()) << " -> "
243 << format("0x%016x", Alloc.getRemoteAddress()) << " ("
244 << Alloc.getSize() << " bytes)\n");
245 Client.writeMem(Alloc.getRemoteAddress(), Alloc.getLocalAddress(),
249 if (ObjAllocs.RemoteRWDataAddr) {
250 DEBUG(dbgs() << " setting RW- permissions on rw-data block: "
251 << format("0x%016x", ObjAllocs.RemoteRWDataAddr)
253 Client.setProtections(Id, ObjAllocs.RemoteRWDataAddr,
254 sys::Memory::MF_READ | sys::Memory::MF_WRITE);
265 Alloc(uint64_t Size, unsigned Align)
266 : Size(Size), Align(Align), Contents(new char[Size + Align - 1]),
270 : Size(std::move(Other.Size)), Align(std::move(Other.Align)),
271 Contents(std::move(Other.Contents)),
272 RemoteAddr(std::move(Other.RemoteAddr)) {}
274 Alloc &operator=(Alloc &&Other) {
275 Size = std::move(Other.Size);
276 Align = std::move(Other.Align);
277 Contents = std::move(Other.Contents);
278 RemoteAddr = std::move(Other.RemoteAddr);
282 uint64_t getSize() const { return Size; }
284 unsigned getAlign() const { return Align; }
286 char *getLocalAddress() const {
287 uintptr_t LocalAddr = reinterpret_cast<uintptr_t>(Contents.get());
288 LocalAddr = RoundUpToAlignment(LocalAddr, Align);
289 return reinterpret_cast<char *>(LocalAddr);
292 void setRemoteAddress(TargetAddress RemoteAddr) {
293 this->RemoteAddr = RemoteAddr;
296 TargetAddress getRemoteAddress() const { return RemoteAddr; }
301 std::unique_ptr<char[]> Contents;
302 TargetAddress RemoteAddr;
305 struct ObjectAllocs {
307 : RemoteCodeAddr(0), RemoteRODataAddr(0), RemoteRWDataAddr(0) {}
309 ObjectAllocs(ObjectAllocs &&Other)
310 : RemoteCodeAddr(std::move(Other.RemoteCodeAddr)),
311 RemoteRODataAddr(std::move(Other.RemoteRODataAddr)),
312 RemoteRWDataAddr(std::move(Other.RemoteRWDataAddr)),
313 CodeAllocs(std::move(Other.CodeAllocs)),
314 RODataAllocs(std::move(Other.RODataAllocs)),
315 RWDataAllocs(std::move(Other.RWDataAllocs)) {}
317 ObjectAllocs &operator=(ObjectAllocs &&Other) {
318 RemoteCodeAddr = std::move(Other.RemoteCodeAddr);
319 RemoteRODataAddr = std::move(Other.RemoteRODataAddr);
320 RemoteRWDataAddr = std::move(Other.RemoteRWDataAddr);
321 CodeAllocs = std::move(Other.CodeAllocs);
322 RODataAllocs = std::move(Other.RODataAllocs);
323 RWDataAllocs = std::move(Other.RWDataAllocs);
327 TargetAddress RemoteCodeAddr;
328 TargetAddress RemoteRODataAddr;
329 TargetAddress RemoteRWDataAddr;
330 std::vector<Alloc> CodeAllocs, RODataAllocs, RWDataAllocs;
333 OrcRemoteTargetClient &Client;
334 ResourceIdMgr::ResourceId Id;
335 std::vector<ObjectAllocs> Unmapped;
336 std::vector<ObjectAllocs> Unfinalized;
339 /// Remote indirect stubs manager.
340 class RCIndirectStubsManager : public IndirectStubsManager {
342 RCIndirectStubsManager(OrcRemoteTargetClient &Remote,
343 ResourceIdMgr::ResourceId Id)
344 : Remote(Remote), Id(Id) {}
346 ~RCIndirectStubsManager() { Remote.destroyIndirectStubsManager(Id); }
348 std::error_code createStub(StringRef StubName, TargetAddress StubAddr,
349 JITSymbolFlags StubFlags) override {
350 if (auto EC = reserveStubs(1))
353 return createStubInternal(StubName, StubAddr, StubFlags);
356 std::error_code createStubs(const StubInitsMap &StubInits) override {
357 if (auto EC = reserveStubs(StubInits.size()))
360 for (auto &Entry : StubInits)
361 if (auto EC = createStubInternal(Entry.first(), Entry.second.first,
362 Entry.second.second))
365 return std::error_code();
368 JITSymbol findStub(StringRef Name, bool ExportedStubsOnly) override {
369 auto I = StubIndexes.find(Name);
370 if (I == StubIndexes.end())
372 auto Key = I->second.first;
373 auto Flags = I->second.second;
374 auto StubSymbol = JITSymbol(getStubAddr(Key), Flags);
375 if (ExportedStubsOnly && !StubSymbol.isExported())
380 JITSymbol findPointer(StringRef Name) override {
381 auto I = StubIndexes.find(Name);
382 if (I == StubIndexes.end())
384 auto Key = I->second.first;
385 auto Flags = I->second.second;
386 return JITSymbol(getPtrAddr(Key), Flags);
389 std::error_code updatePointer(StringRef Name,
390 TargetAddress NewAddr) override {
391 auto I = StubIndexes.find(Name);
392 assert(I != StubIndexes.end() && "No stub pointer for symbol");
393 auto Key = I->second.first;
394 return Remote.writePointer(getPtrAddr(Key), NewAddr);
398 struct RemoteIndirectStubsInfo {
399 RemoteIndirectStubsInfo(TargetAddress StubBase, TargetAddress PtrBase,
401 : StubBase(StubBase), PtrBase(PtrBase), NumStubs(NumStubs) {}
402 TargetAddress StubBase;
403 TargetAddress PtrBase;
407 OrcRemoteTargetClient &Remote;
408 ResourceIdMgr::ResourceId Id;
409 std::vector<RemoteIndirectStubsInfo> RemoteIndirectStubsInfos;
410 typedef std::pair<uint16_t, uint16_t> StubKey;
411 std::vector<StubKey> FreeStubs;
412 StringMap<std::pair<StubKey, JITSymbolFlags>> StubIndexes;
414 std::error_code reserveStubs(unsigned NumStubs) {
415 if (NumStubs <= FreeStubs.size())
416 return std::error_code();
418 unsigned NewStubsRequired = NumStubs - FreeStubs.size();
419 TargetAddress StubBase;
420 TargetAddress PtrBase;
421 unsigned NumStubsEmitted;
423 Remote.emitIndirectStubs(StubBase, PtrBase, NumStubsEmitted, Id,
426 unsigned NewBlockId = RemoteIndirectStubsInfos.size();
427 RemoteIndirectStubsInfos.push_back(
428 RemoteIndirectStubsInfo(StubBase, PtrBase, NumStubsEmitted));
430 for (unsigned I = 0; I < NumStubsEmitted; ++I)
431 FreeStubs.push_back(std::make_pair(NewBlockId, I));
433 return std::error_code();
436 std::error_code createStubInternal(StringRef StubName,
437 TargetAddress InitAddr,
438 JITSymbolFlags StubFlags) {
439 auto Key = FreeStubs.back();
440 FreeStubs.pop_back();
441 StubIndexes[StubName] = std::make_pair(Key, StubFlags);
442 return Remote.writePointer(getPtrAddr(Key), InitAddr);
445 TargetAddress getStubAddr(StubKey K) {
446 assert(RemoteIndirectStubsInfos[K.first].StubBase != 0 &&
447 "Missing stub address");
448 return RemoteIndirectStubsInfos[K.first].StubBase +
449 K.second * Remote.getIndirectStubSize();
452 TargetAddress getPtrAddr(StubKey K) {
453 assert(RemoteIndirectStubsInfos[K.first].PtrBase != 0 &&
454 "Missing pointer address");
455 return RemoteIndirectStubsInfos[K.first].PtrBase +
456 K.second * Remote.getPointerSize();
460 /// Remote compile callback manager.
461 class RCCompileCallbackManager : public JITCompileCallbackManager {
463 RCCompileCallbackManager(TargetAddress ErrorHandlerAddress,
464 OrcRemoteTargetClient &Remote)
465 : JITCompileCallbackManager(ErrorHandlerAddress), Remote(Remote) {
466 assert(!Remote.CompileCallback && "Compile callback already set");
467 Remote.CompileCallback = [this](TargetAddress TrampolineAddr) {
468 return executeCompileCallback(TrampolineAddr);
470 Remote.emitResolverBlock();
475 TargetAddress BlockAddr = 0;
476 uint32_t NumTrampolines = 0;
477 auto EC = Remote.emitTrampolineBlock(BlockAddr, NumTrampolines);
478 assert(!EC && "Failed to create trampolines");
480 uint32_t TrampolineSize = Remote.getTrampolineSize();
481 for (unsigned I = 0; I < NumTrampolines; ++I)
482 this->AvailableTrampolines.push_back(BlockAddr + (I * TrampolineSize));
485 OrcRemoteTargetClient &Remote;
488 /// Create an OrcRemoteTargetClient.
489 /// Channel is the ChannelT instance to communicate on. It is assumed that
490 /// the channel is ready to be read from and written to.
491 static ErrorOr<OrcRemoteTargetClient> Create(ChannelT &Channel) {
493 OrcRemoteTargetClient H(Channel, EC);
499 /// Call the int(void) function at the given address in the target and return
501 std::error_code callIntVoid(int &Result, TargetAddress Addr) {
502 DEBUG(dbgs() << "Calling int(*)(void) " << format("0x%016x", Addr) << "\n");
504 if (auto EC = call<CallIntVoid>(Channel, Addr))
508 if (auto EC = listenForCompileRequests(NextProcId))
511 if (NextProcId != CallIntVoidResponseId)
512 return orcError(OrcErrorCode::UnexpectedRPCCall);
514 return handle<CallIntVoidResponse>(Channel, [&](int R) {
516 DEBUG(dbgs() << "Result: " << R << "\n");
517 return std::error_code();
521 /// Call the int(int, char*[]) function at the given address in the target and
522 /// return its result.
523 std::error_code callMain(int &Result, TargetAddress Addr,
524 const std::vector<std::string> &Args) {
525 DEBUG(dbgs() << "Calling int(*)(int, char*[]) " << format("0x%016x", Addr)
528 if (auto EC = call<CallMain>(Channel, Addr, Args))
532 if (auto EC = listenForCompileRequests(NextProcId))
535 if (NextProcId != CallMainResponseId)
536 return orcError(OrcErrorCode::UnexpectedRPCCall);
538 return handle<CallMainResponse>(Channel, [&](int R) {
540 DEBUG(dbgs() << "Result: " << R << "\n");
541 return std::error_code();
545 /// Call the void() function at the given address in the target and wait for
547 std::error_code callVoidVoid(TargetAddress Addr) {
548 DEBUG(dbgs() << "Calling void(*)(void) " << format("0x%016x", Addr)
551 if (auto EC = call<CallVoidVoid>(Channel, Addr))
555 if (auto EC = listenForCompileRequests(NextProcId))
558 if (NextProcId != CallVoidVoidResponseId)
559 return orcError(OrcErrorCode::UnexpectedRPCCall);
561 return handle<CallVoidVoidResponse>(Channel, doNothing);
564 /// Create an RCMemoryManager which will allocate its memory on the remote
567 createRemoteMemoryManager(std::unique_ptr<RCMemoryManager> &MM) {
568 assert(!MM && "MemoryManager should be null before creation.");
570 auto Id = AllocatorIds.getNext();
571 if (auto EC = call<CreateRemoteAllocator>(Channel, Id))
573 MM = llvm::make_unique<RCMemoryManager>(*this, Id);
574 return std::error_code();
577 /// Create an RCIndirectStubsManager that will allocate stubs on the remote
580 createIndirectStubsManager(std::unique_ptr<RCIndirectStubsManager> &I) {
581 assert(!I && "Indirect stubs manager should be null before creation.");
582 auto Id = IndirectStubOwnerIds.getNext();
583 if (auto EC = call<CreateIndirectStubsOwner>(Channel, Id))
585 I = llvm::make_unique<RCIndirectStubsManager>(*this, Id);
586 return std::error_code();
589 /// Search for symbols in the remote process. Note: This should be used by
590 /// symbol resolvers *after* they've searched the local symbol table in the
592 std::error_code getSymbolAddress(TargetAddress &Addr, StringRef Name) {
593 // Check for an 'out-of-band' error, e.g. from an MM destructor.
595 return ExistingError;
597 // Request remote symbol address.
598 if (auto EC = call<GetSymbolAddress>(Channel, Name))
601 return expect<GetSymbolAddressResponse>(Channel, [&](TargetAddress &A) {
603 DEBUG(dbgs() << "Remote address lookup " << Name << " = "
604 << format("0x%016x", Addr) << "\n");
605 return std::error_code();
609 /// Get the triple for the remote target.
610 const std::string &getTargetTriple() const { return RemoteTargetTriple; }
612 std::error_code terminateSession() { return call<TerminateSession>(Channel); }
615 OrcRemoteTargetClient(ChannelT &Channel, std::error_code &EC)
616 : Channel(Channel), RemotePointerSize(0), RemotePageSize(0),
617 RemoteTrampolineSize(0), RemoteIndirectStubSize(0) {
618 if ((EC = call<GetRemoteInfo>(Channel)))
621 EC = expect<GetRemoteInfoResponse>(
622 Channel, readArgs(RemoteTargetTriple, RemotePointerSize, RemotePageSize,
623 RemoteTrampolineSize, RemoteIndirectStubSize));
626 void destroyRemoteAllocator(ResourceIdMgr::ResourceId Id) {
627 if (auto EC = call<DestroyRemoteAllocator>(Channel, Id)) {
628 // FIXME: This will be triggered by a removeModuleSet call: Propagate
629 // error return up through that.
630 llvm_unreachable("Failed to destroy remote allocator.");
631 AllocatorIds.release(Id);
635 std::error_code destroyIndirectStubsManager(ResourceIdMgr::ResourceId Id) {
636 IndirectStubOwnerIds.release(Id);
637 return call<DestroyIndirectStubsOwner>(Channel, Id);
640 std::error_code emitIndirectStubs(TargetAddress &StubBase,
641 TargetAddress &PtrBase,
642 uint32_t &NumStubsEmitted,
643 ResourceIdMgr::ResourceId Id,
644 uint32_t NumStubsRequired) {
645 if (auto EC = call<EmitIndirectStubs>(Channel, Id, NumStubsRequired))
648 return expect<EmitIndirectStubsResponse>(
649 Channel, readArgs(StubBase, PtrBase, NumStubsEmitted));
652 std::error_code emitResolverBlock() {
653 // Check for an 'out-of-band' error, e.g. from an MM destructor.
655 return ExistingError;
657 return call<EmitResolverBlock>(Channel);
660 std::error_code emitTrampolineBlock(TargetAddress &BlockAddr,
661 uint32_t &NumTrampolines) {
662 // Check for an 'out-of-band' error, e.g. from an MM destructor.
664 return ExistingError;
666 if (auto EC = call<EmitTrampolineBlock>(Channel))
669 return expect<EmitTrampolineBlockResponse>(
670 Channel, [&](TargetAddress BAddr, uint32_t NTrampolines) {
672 NumTrampolines = NTrampolines;
673 return std::error_code();
677 uint32_t getIndirectStubSize() const { return RemoteIndirectStubSize; }
678 uint32_t getPageSize() const { return RemotePageSize; }
679 uint32_t getPointerSize() const { return RemotePointerSize; }
681 uint32_t getTrampolineSize() const { return RemoteTrampolineSize; }
683 std::error_code listenForCompileRequests(uint32_t &NextId) {
684 // Check for an 'out-of-band' error, e.g. from an MM destructor.
686 return ExistingError;
688 if (auto EC = getNextProcId(Channel, NextId))
691 while (NextId == RequestCompileId) {
692 TargetAddress TrampolineAddr = 0;
693 if (auto EC = handle<RequestCompile>(Channel, readArgs(TrampolineAddr)))
696 TargetAddress ImplAddr = CompileCallback(TrampolineAddr);
697 if (auto EC = call<RequestCompileResponse>(Channel, ImplAddr))
700 if (auto EC = getNextProcId(Channel, NextId))
704 return std::error_code();
707 std::error_code readMem(char *Dst, TargetAddress Src, uint64_t Size) {
708 // Check for an 'out-of-band' error, e.g. from an MM destructor.
710 return ExistingError;
712 if (auto EC = call<ReadMem>(Channel, Src, Size))
715 if (auto EC = expect<ReadMemResponse>(
716 Channel, [&]() { return Channel.readBytes(Dst, Size); }))
719 return std::error_code();
722 std::error_code reserveMem(TargetAddress &RemoteAddr,
723 ResourceIdMgr::ResourceId Id, uint64_t Size,
726 // Check for an 'out-of-band' error, e.g. from an MM destructor.
728 return ExistingError;
730 if (auto EC = call<ReserveMem>(Channel, Id, Size, Align))
733 if (std::error_code EC =
734 expect<ReserveMemResponse>(Channel, [&](TargetAddress Addr) {
736 return std::error_code();
740 return std::error_code();
743 std::error_code setProtections(ResourceIdMgr::ResourceId Id,
744 TargetAddress RemoteSegAddr,
745 unsigned ProtFlags) {
746 return call<SetProtections>(Channel, Id, RemoteSegAddr, ProtFlags);
749 std::error_code writeMem(TargetAddress Addr, const char *Src, uint64_t Size) {
750 // Check for an 'out-of-band' error, e.g. from an MM destructor.
752 return ExistingError;
754 // Make the send call.
755 if (auto EC = call<WriteMem>(Channel, Addr, Size))
758 // Follow this up with the section contents.
759 if (auto EC = Channel.appendBytes(Src, Size))
762 return Channel.send();
765 std::error_code writePointer(TargetAddress Addr, TargetAddress PtrVal) {
766 // Check for an 'out-of-band' error, e.g. from an MM destructor.
768 return ExistingError;
770 return call<WritePtr>(Channel, Addr, PtrVal);
773 static std::error_code doNothing() { return std::error_code(); }
776 std::error_code ExistingError;
777 std::string RemoteTargetTriple;
778 uint32_t RemotePointerSize;
779 uint32_t RemotePageSize;
780 uint32_t RemoteTrampolineSize;
781 uint32_t RemoteIndirectStubSize;
782 ResourceIdMgr AllocatorIds, IndirectStubOwnerIds;
783 std::function<TargetAddress(TargetAddress)> CompileCallback;
786 } // end namespace remote
787 } // end namespace orc
788 } // end namespace llvm