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 (std::error_code EC = Client.reserveMem(
95 Unmapped.back().RemoteCodeAddr, Id, CodeSize, CodeAlign)) {
97 // FIXME; Add error to poll.
98 llvm_unreachable("Failed reserving remote memory.");
100 DEBUG(dbgs() << " code: "
101 << format("0x%016x", Unmapped.back().RemoteCodeAddr)
102 << " (" << CodeSize << " bytes, alignment " << CodeAlign
106 if (RODataSize != 0) {
107 if (auto EC = Client.reserveMem(Unmapped.back().RemoteRODataAddr, Id,
108 RODataSize, RODataAlign)) {
109 // FIXME; Add error to poll.
110 llvm_unreachable("Failed reserving remote memory.");
112 DEBUG(dbgs() << " ro-data: "
113 << format("0x%016x", Unmapped.back().RemoteRODataAddr)
114 << " (" << RODataSize << " bytes, alignment "
115 << RODataAlign << ")\n");
118 if (RWDataSize != 0) {
119 if (auto EC = Client.reserveMem(Unmapped.back().RemoteRWDataAddr, Id,
120 RWDataSize, RWDataAlign)) {
121 // FIXME; Add error to poll.
122 llvm_unreachable("Failed reserving remote memory.");
124 DEBUG(dbgs() << " rw-data: "
125 << format("0x%016x", Unmapped.back().RemoteRWDataAddr)
126 << " (" << RWDataSize << " bytes, alignment "
127 << RWDataAlign << ")\n");
131 bool needsToReserveAllocationSpace() override { return true; }
133 void registerEHFrames(uint8_t *Addr, uint64_t LoadAddr,
134 size_t Size) override {}
136 void deregisterEHFrames(uint8_t *addr, uint64_t LoadAddr,
137 size_t Size) override {}
139 void notifyObjectLoaded(RuntimeDyld &Dyld,
140 const object::ObjectFile &Obj) override {
141 DEBUG(dbgs() << "Allocator " << Id << " applied mappings:\n");
142 for (auto &ObjAllocs : Unmapped) {
144 TargetAddress NextCodeAddr = ObjAllocs.RemoteCodeAddr;
145 for (auto &Alloc : ObjAllocs.CodeAllocs) {
146 NextCodeAddr = RoundUpToAlignment(NextCodeAddr, Alloc.getAlign());
147 Dyld.mapSectionAddress(Alloc.getLocalAddress(), NextCodeAddr);
148 DEBUG(dbgs() << " code: "
149 << static_cast<void *>(Alloc.getLocalAddress())
150 << " -> " << format("0x%016x", NextCodeAddr) << "\n");
151 Alloc.setRemoteAddress(NextCodeAddr);
152 NextCodeAddr += Alloc.getSize();
156 TargetAddress NextRODataAddr = ObjAllocs.RemoteRODataAddr;
157 for (auto &Alloc : ObjAllocs.RODataAllocs) {
159 RoundUpToAlignment(NextRODataAddr, Alloc.getAlign());
160 Dyld.mapSectionAddress(Alloc.getLocalAddress(), NextRODataAddr);
161 DEBUG(dbgs() << " ro-data: "
162 << static_cast<void *>(Alloc.getLocalAddress())
163 << " -> " << format("0x%016x", NextRODataAddr)
165 Alloc.setRemoteAddress(NextRODataAddr);
166 NextRODataAddr += Alloc.getSize();
170 TargetAddress NextRWDataAddr = ObjAllocs.RemoteRWDataAddr;
171 for (auto &Alloc : ObjAllocs.RWDataAllocs) {
173 RoundUpToAlignment(NextRWDataAddr, Alloc.getAlign());
174 Dyld.mapSectionAddress(Alloc.getLocalAddress(), NextRWDataAddr);
175 DEBUG(dbgs() << " rw-data: "
176 << static_cast<void *>(Alloc.getLocalAddress())
177 << " -> " << format("0x%016x", NextRWDataAddr)
179 Alloc.setRemoteAddress(NextRWDataAddr);
180 NextRWDataAddr += Alloc.getSize();
183 Unfinalized.push_back(std::move(ObjAllocs));
188 bool finalizeMemory(std::string *ErrMsg = nullptr) override {
189 DEBUG(dbgs() << "Allocator " << Id << " finalizing:\n");
191 for (auto &ObjAllocs : Unfinalized) {
193 for (auto &Alloc : ObjAllocs.CodeAllocs) {
194 DEBUG(dbgs() << " copying code: "
195 << static_cast<void *>(Alloc.getLocalAddress()) << " -> "
196 << format("0x%016x", Alloc.getRemoteAddress()) << " ("
197 << Alloc.getSize() << " bytes)\n");
198 Client.writeMem(Alloc.getRemoteAddress(), Alloc.getLocalAddress(),
202 if (ObjAllocs.RemoteCodeAddr) {
203 DEBUG(dbgs() << " setting R-X permissions on code block: "
204 << format("0x%016x", ObjAllocs.RemoteCodeAddr) << "\n");
205 Client.setProtections(Id, ObjAllocs.RemoteCodeAddr,
206 sys::Memory::MF_READ | sys::Memory::MF_EXEC);
209 for (auto &Alloc : ObjAllocs.RODataAllocs) {
210 DEBUG(dbgs() << " copying ro-data: "
211 << static_cast<void *>(Alloc.getLocalAddress()) << " -> "
212 << format("0x%016x", Alloc.getRemoteAddress()) << " ("
213 << Alloc.getSize() << " bytes)\n");
214 Client.writeMem(Alloc.getRemoteAddress(), Alloc.getLocalAddress(),
218 if (ObjAllocs.RemoteRODataAddr) {
219 DEBUG(dbgs() << " setting R-- permissions on ro-data block: "
220 << format("0x%016x", ObjAllocs.RemoteRODataAddr)
222 Client.setProtections(Id, ObjAllocs.RemoteRODataAddr,
223 sys::Memory::MF_READ);
226 for (auto &Alloc : ObjAllocs.RWDataAllocs) {
227 DEBUG(dbgs() << " copying rw-data: "
228 << static_cast<void *>(Alloc.getLocalAddress()) << " -> "
229 << format("0x%016x", Alloc.getRemoteAddress()) << " ("
230 << Alloc.getSize() << " bytes)\n");
231 Client.writeMem(Alloc.getRemoteAddress(), Alloc.getLocalAddress(),
235 if (ObjAllocs.RemoteRWDataAddr) {
236 DEBUG(dbgs() << " setting RW- permissions on rw-data block: "
237 << format("0x%016x", ObjAllocs.RemoteRWDataAddr)
239 Client.setProtections(Id, ObjAllocs.RemoteRWDataAddr,
240 sys::Memory::MF_READ | sys::Memory::MF_WRITE);
251 Alloc(uint64_t Size, unsigned Align)
252 : Size(Size), Align(Align), Contents(new char[Size + Align - 1]),
255 uint64_t getSize() const { return Size; }
257 unsigned getAlign() const { return Align; }
259 char *getLocalAddress() const {
260 uintptr_t LocalAddr = reinterpret_cast<uintptr_t>(Contents.get());
261 LocalAddr = RoundUpToAlignment(LocalAddr, Align);
262 return reinterpret_cast<char *>(LocalAddr);
265 void setRemoteAddress(TargetAddress RemoteAddr) {
266 this->RemoteAddr = RemoteAddr;
269 TargetAddress getRemoteAddress() const { return RemoteAddr; }
274 std::unique_ptr<char[]> Contents;
275 TargetAddress RemoteAddr;
278 struct ObjectAllocs {
280 : RemoteCodeAddr(0), RemoteRODataAddr(0), RemoteRWDataAddr(0) {}
281 TargetAddress RemoteCodeAddr;
282 TargetAddress RemoteRODataAddr;
283 TargetAddress RemoteRWDataAddr;
284 std::vector<Alloc> CodeAllocs, RODataAllocs, RWDataAllocs;
287 OrcRemoteTargetClient &Client;
288 ResourceIdMgr::ResourceId Id;
289 std::vector<ObjectAllocs> Unmapped;
290 std::vector<ObjectAllocs> Unfinalized;
293 /// Remote indirect stubs manager.
294 class RCIndirectStubsManager : public IndirectStubsManager {
296 RCIndirectStubsManager(OrcRemoteTargetClient &Remote,
297 ResourceIdMgr::ResourceId Id)
298 : Remote(Remote), Id(Id) {}
300 ~RCIndirectStubsManager() { Remote.destroyIndirectStubsManager(Id); }
302 std::error_code createStub(StringRef StubName, TargetAddress StubAddr,
303 JITSymbolFlags StubFlags) override {
304 if (auto EC = reserveStubs(1))
307 return createStubInternal(StubName, StubAddr, StubFlags);
310 std::error_code createStubs(const StubInitsMap &StubInits) override {
311 if (auto EC = reserveStubs(StubInits.size()))
314 for (auto &Entry : StubInits)
315 if (auto EC = createStubInternal(Entry.first(), Entry.second.first,
316 Entry.second.second))
319 return std::error_code();
322 JITSymbol findStub(StringRef Name, bool ExportedStubsOnly) override {
323 auto I = StubIndexes.find(Name);
324 if (I == StubIndexes.end())
326 auto Key = I->second.first;
327 auto Flags = I->second.second;
328 auto StubSymbol = JITSymbol(getStubAddr(Key), Flags);
329 if (ExportedStubsOnly && !StubSymbol.isExported())
334 JITSymbol findPointer(StringRef Name) override {
335 auto I = StubIndexes.find(Name);
336 if (I == StubIndexes.end())
338 auto Key = I->second.first;
339 auto Flags = I->second.second;
340 return JITSymbol(getPtrAddr(Key), Flags);
343 std::error_code updatePointer(StringRef Name,
344 TargetAddress NewAddr) override {
345 auto I = StubIndexes.find(Name);
346 assert(I != StubIndexes.end() && "No stub pointer for symbol");
347 auto Key = I->second.first;
348 return Remote.writePointer(getPtrAddr(Key), NewAddr);
352 struct RemoteIndirectStubsInfo {
353 RemoteIndirectStubsInfo(TargetAddress StubBase, TargetAddress PtrBase,
355 : StubBase(StubBase), PtrBase(PtrBase), NumStubs(NumStubs) {}
356 TargetAddress StubBase;
357 TargetAddress PtrBase;
361 OrcRemoteTargetClient &Remote;
362 ResourceIdMgr::ResourceId Id;
363 std::vector<RemoteIndirectStubsInfo> RemoteIndirectStubsInfos;
364 typedef std::pair<uint16_t, uint16_t> StubKey;
365 std::vector<StubKey> FreeStubs;
366 StringMap<std::pair<StubKey, JITSymbolFlags>> StubIndexes;
368 std::error_code reserveStubs(unsigned NumStubs) {
369 if (NumStubs <= FreeStubs.size())
370 return std::error_code();
372 unsigned NewStubsRequired = NumStubs - FreeStubs.size();
373 TargetAddress StubBase;
374 TargetAddress PtrBase;
375 unsigned NumStubsEmitted;
377 Remote.emitIndirectStubs(StubBase, PtrBase, NumStubsEmitted, Id,
380 unsigned NewBlockId = RemoteIndirectStubsInfos.size();
381 RemoteIndirectStubsInfos.push_back(
382 RemoteIndirectStubsInfo(StubBase, PtrBase, NumStubsEmitted));
384 for (unsigned I = 0; I < NumStubsEmitted; ++I)
385 FreeStubs.push_back(std::make_pair(NewBlockId, I));
387 return std::error_code();
390 std::error_code createStubInternal(StringRef StubName,
391 TargetAddress InitAddr,
392 JITSymbolFlags StubFlags) {
393 auto Key = FreeStubs.back();
394 FreeStubs.pop_back();
395 StubIndexes[StubName] = std::make_pair(Key, StubFlags);
396 return Remote.writePointer(getPtrAddr(Key), InitAddr);
399 TargetAddress getStubAddr(StubKey K) {
400 assert(RemoteIndirectStubsInfos[K.first].StubBase != 0 &&
401 "Missing stub address");
402 return RemoteIndirectStubsInfos[K.first].StubBase +
403 K.second * Remote.getIndirectStubSize();
406 TargetAddress getPtrAddr(StubKey K) {
407 assert(RemoteIndirectStubsInfos[K.first].PtrBase != 0 &&
408 "Missing pointer address");
409 return RemoteIndirectStubsInfos[K.first].PtrBase +
410 K.second * Remote.getPointerSize();
414 /// Remote compile callback manager.
415 class RCCompileCallbackManager : public JITCompileCallbackManager {
417 RCCompileCallbackManager(TargetAddress ErrorHandlerAddress,
418 OrcRemoteTargetClient &Remote)
419 : JITCompileCallbackManager(ErrorHandlerAddress), Remote(Remote) {
420 assert(!Remote.CompileCallback && "Compile callback already set");
421 Remote.CompileCallback = [this](TargetAddress TrampolineAddr) {
422 return executeCompileCallback(TrampolineAddr);
424 Remote.emitResolverBlock();
429 TargetAddress BlockAddr = 0;
430 uint32_t NumTrampolines = 0;
431 auto EC = Remote.emitTrampolineBlock(BlockAddr, NumTrampolines);
432 assert(!EC && "Failed to create trampolines");
434 uint32_t TrampolineSize = Remote.getTrampolineSize();
435 for (unsigned I = 0; I < NumTrampolines; ++I)
436 this->AvailableTrampolines.push_back(BlockAddr + (I * TrampolineSize));
439 OrcRemoteTargetClient &Remote;
442 /// Create an OrcRemoteTargetClient.
443 /// Channel is the ChannelT instance to communicate on. It is assumed that
444 /// the channel is ready to be read from and written to.
445 static ErrorOr<OrcRemoteTargetClient> Create(ChannelT &Channel) {
447 OrcRemoteTargetClient H(Channel, EC);
453 /// Call the int(void) function at the given address in the target and return
455 std::error_code callIntVoid(int &Result, TargetAddress Addr) {
456 DEBUG(dbgs() << "Calling int(*)(void) " << format("0x%016x", Addr) << "\n");
458 if (auto EC = call<CallIntVoid>(Channel, Addr))
462 if (auto EC = listenForCompileRequests(NextProcId))
465 if (NextProcId != CallIntVoidResponseId)
466 return orcError(OrcErrorCode::UnexpectedRPCCall);
468 return handle<CallIntVoidResponse>(Channel, [&](int R) {
470 DEBUG(dbgs() << "Result: " << R << "\n");
471 return std::error_code();
475 /// Call the int(int, char*[]) function at the given address in the target and
476 /// return its result.
477 std::error_code callMain(int &Result, TargetAddress Addr,
478 const std::vector<std::string> &Args) {
479 DEBUG(dbgs() << "Calling int(*)(int, char*[]) " << format("0x%016x", Addr)
482 if (auto EC = call<CallMain>(Channel, Addr, Args))
486 if (auto EC = listenForCompileRequests(NextProcId))
489 if (NextProcId != CallMainResponseId)
490 return orcError(OrcErrorCode::UnexpectedRPCCall);
492 return handle<CallMainResponse>(Channel, [&](int R) {
494 DEBUG(dbgs() << "Result: " << R << "\n");
495 return std::error_code();
499 /// Call the void() function at the given address in the target and wait for
501 std::error_code callVoidVoid(TargetAddress Addr) {
502 DEBUG(dbgs() << "Calling void(*)(void) " << format("0x%016x", Addr)
505 if (auto EC = call<CallVoidVoid>(Channel, Addr))
509 if (auto EC = listenForCompileRequests(NextProcId))
512 if (NextProcId != CallVoidVoidResponseId)
513 return orcError(OrcErrorCode::UnexpectedRPCCall);
515 return handle<CallVoidVoidResponse>(Channel, doNothing);
518 /// Create an RCMemoryManager which will allocate its memory on the remote
521 createRemoteMemoryManager(std::unique_ptr<RCMemoryManager> &MM) {
522 assert(!MM && "MemoryManager should be null before creation.");
524 auto Id = AllocatorIds.getNext();
525 if (auto EC = call<CreateRemoteAllocator>(Channel, Id))
527 MM = llvm::make_unique<RCMemoryManager>(*this, Id);
528 return std::error_code();
531 /// Create an RCIndirectStubsManager that will allocate stubs on the remote
534 createIndirectStubsManager(std::unique_ptr<RCIndirectStubsManager> &I) {
535 assert(!I && "Indirect stubs manager should be null before creation.");
536 auto Id = IndirectStubOwnerIds.getNext();
537 if (auto EC = call<CreateIndirectStubsOwner>(Channel, Id))
539 I = llvm::make_unique<RCIndirectStubsManager>(*this, Id);
540 return std::error_code();
543 /// Search for symbols in the remote process. Note: This should be used by
544 /// symbol resolvers *after* they've searched the local symbol table in the
546 std::error_code getSymbolAddress(TargetAddress &Addr, StringRef Name) {
547 // Check for an 'out-of-band' error, e.g. from an MM destructor.
549 return ExistingError;
551 // Request remote symbol address.
552 if (auto EC = call<GetSymbolAddress>(Channel, Name))
555 return expect<GetSymbolAddressResponse>(Channel, [&](TargetAddress &A) {
557 DEBUG(dbgs() << "Remote address lookup " << Name << " = "
558 << format("0x%016x", Addr) << "\n");
559 return std::error_code();
563 /// Get the triple for the remote target.
564 const std::string &getTargetTriple() const { return RemoteTargetTriple; }
566 std::error_code terminateSession() { return call<TerminateSession>(Channel); }
569 OrcRemoteTargetClient(ChannelT &Channel, std::error_code &EC)
570 : Channel(Channel), RemotePointerSize(0), RemotePageSize(0),
571 RemoteTrampolineSize(0), RemoteIndirectStubSize(0) {
572 if ((EC = call<GetRemoteInfo>(Channel)))
575 EC = expect<GetRemoteInfoResponse>(
576 Channel, readArgs(RemoteTargetTriple, RemotePointerSize, RemotePageSize,
577 RemoteTrampolineSize, RemoteIndirectStubSize));
580 void destroyRemoteAllocator(ResourceIdMgr::ResourceId Id) {
581 if (auto EC = call<DestroyRemoteAllocator>(Channel, Id)) {
582 // FIXME: This will be triggered by a removeModuleSet call: Propagate
583 // error return up through that.
584 llvm_unreachable("Failed to destroy remote allocator.");
585 AllocatorIds.release(Id);
589 std::error_code destroyIndirectStubsManager(ResourceIdMgr::ResourceId Id) {
590 IndirectStubOwnerIds.release(Id);
591 return call<DestroyIndirectStubsOwner>(Channel, Id);
594 std::error_code emitIndirectStubs(TargetAddress &StubBase,
595 TargetAddress &PtrBase,
596 uint32_t &NumStubsEmitted,
597 ResourceIdMgr::ResourceId Id,
598 uint32_t NumStubsRequired) {
599 if (auto EC = call<EmitIndirectStubs>(Channel, Id, NumStubsRequired))
602 return expect<EmitIndirectStubsResponse>(
603 Channel, readArgs(StubBase, PtrBase, NumStubsEmitted));
606 std::error_code emitResolverBlock() {
607 // Check for an 'out-of-band' error, e.g. from an MM destructor.
609 return ExistingError;
611 return call<EmitResolverBlock>(Channel);
614 std::error_code emitTrampolineBlock(TargetAddress &BlockAddr,
615 uint32_t &NumTrampolines) {
616 // Check for an 'out-of-band' error, e.g. from an MM destructor.
618 return ExistingError;
620 if (auto EC = call<EmitTrampolineBlock>(Channel))
623 return expect<EmitTrampolineBlockResponse>(
624 Channel, [&](TargetAddress BAddr, uint32_t NTrampolines) {
626 NumTrampolines = NTrampolines;
627 return std::error_code();
631 uint32_t getIndirectStubSize() const { return RemoteIndirectStubSize; }
632 uint32_t getPageSize() const { return RemotePageSize; }
633 uint32_t getPointerSize() const { return RemotePointerSize; }
635 uint32_t getTrampolineSize() const { return RemoteTrampolineSize; }
637 std::error_code listenForCompileRequests(uint32_t &NextId) {
638 // Check for an 'out-of-band' error, e.g. from an MM destructor.
640 return ExistingError;
642 if (auto EC = getNextProcId(Channel, NextId))
645 while (NextId == RequestCompileId) {
646 TargetAddress TrampolineAddr = 0;
647 if (auto EC = handle<RequestCompile>(Channel, readArgs(TrampolineAddr)))
650 TargetAddress ImplAddr = CompileCallback(TrampolineAddr);
651 if (auto EC = call<RequestCompileResponse>(Channel, ImplAddr))
654 if (auto EC = getNextProcId(Channel, NextId))
658 return std::error_code();
661 std::error_code readMem(char *Dst, TargetAddress Src, uint64_t Size) {
662 // Check for an 'out-of-band' error, e.g. from an MM destructor.
664 return ExistingError;
666 if (auto EC = call<ReadMem>(Channel, Src, Size))
669 if (auto EC = expect<ReadMemResponse>(
670 Channel, [&]() { return Channel.readBytes(Dst, Size); }))
673 return std::error_code();
676 std::error_code reserveMem(TargetAddress &RemoteAddr,
677 ResourceIdMgr::ResourceId Id, uint64_t Size,
680 // Check for an 'out-of-band' error, e.g. from an MM destructor.
682 return ExistingError;
684 if (auto EC = call<ReserveMem>(Channel, Id, Size, Align))
687 if (auto EC = expect<ReserveMemResponse>(Channel, [&](TargetAddress Addr) {
689 return std::error_code();
693 return std::error_code();
696 std::error_code setProtections(ResourceIdMgr::ResourceId Id,
697 TargetAddress RemoteSegAddr,
698 unsigned ProtFlags) {
699 return call<SetProtections>(Channel, Id, RemoteSegAddr, ProtFlags);
702 std::error_code writeMem(TargetAddress Addr, const char *Src, uint64_t Size) {
703 // Check for an 'out-of-band' error, e.g. from an MM destructor.
705 return ExistingError;
707 // Make the send call.
708 if (auto EC = call<WriteMem>(Channel, Addr, Size))
711 // Follow this up with the section contents.
712 if (auto EC = Channel.appendBytes(Src, Size))
715 return Channel.send();
718 std::error_code writePointer(TargetAddress Addr, TargetAddress PtrVal) {
719 // Check for an 'out-of-band' error, e.g. from an MM destructor.
721 return ExistingError;
723 return call<WritePtr>(Channel, Addr, PtrVal);
726 static std::error_code doNothing() { return std::error_code(); }
729 std::error_code ExistingError;
730 std::string RemoteTargetTriple;
731 uint32_t RemotePointerSize;
732 uint32_t RemotePageSize;
733 uint32_t RemoteTrampolineSize;
734 uint32_t RemoteIndirectStubSize;
735 ResourceIdMgr AllocatorIds, IndirectStubOwnerIds;
736 std::function<TargetAddress(TargetAddress)> CompileCallback;
739 } // end namespace remote
740 } // end namespace orc
741 } // end namespace llvm