LLVM 22.0.0git
SimpleRemoteMemoryMapper.cpp
Go to the documentation of this file.
1//===---- SimpleRemoteMemoryMapper.cpp - Remote memory mapper ----*- C++ -*-==//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10
13
14namespace llvm::orc {
15
19
21 OnReservedFunction OnReserved) {
22 EPC.callSPSWrapperAsync<rt::SPSSimpleRemoteMemoryMapReserveSignature>(
23 SAs.Reserve,
24 [NumBytes, OnReserved = std::move(OnReserved)](
25 Error SerializationErr, Expected<ExecutorAddr> Result) mutable {
26 if (SerializationErr) {
27 cantFail(Result.takeError());
28 return OnReserved(std::move(SerializationErr));
29 }
30
31 if (Result)
32 OnReserved(ExecutorAddrRange(*Result, NumBytes));
33 else
34 OnReserved(Result.takeError());
35 },
36 SAs.Instance, static_cast<uint64_t>(NumBytes));
37}
38
40 ExecutorAddr Addr, size_t ContentSize) {
41 return G.allocateBuffer(ContentSize).data();
42}
43
45 OnInitializedFunction OnInitialized) {
46
48
50 FR.Segments.reserve(AI.Segments.size());
51
52 for (auto Seg : AI.Segments)
53 FR.Segments.push_back({Seg.AG, AI.MappingBase + Seg.Offset,
54 Seg.ContentSize + Seg.ZeroFillSize,
55 ArrayRef<char>(Seg.WorkingMem, Seg.ContentSize)});
56
58 SAs.Initialize,
59 [OnInitialized = std::move(OnInitialized)](
60 Error SerializationErr, Expected<ExecutorAddr> Result) mutable {
61 if (SerializationErr) {
62 cantFail(Result.takeError());
63 return OnInitialized(std::move(SerializationErr));
64 }
65
66 OnInitialized(std::move(Result));
67 },
68 SAs.Instance, std::move(FR));
69}
70
72 ArrayRef<ExecutorAddr> Allocations,
75 SAs.Deinitialize,
76 [OnDeinitialized = std::move(OnDeinitialized)](Error SerializationErr,
77 Error Result) mutable {
78 if (SerializationErr) {
79 cantFail(std::move(Result));
80 return OnDeinitialized(std::move(SerializationErr));
81 }
82
83 OnDeinitialized(std::move(Result));
84 },
85 SAs.Instance, Allocations);
86}
87
89 OnReleasedFunction OnReleased) {
90 EPC.callSPSWrapperAsync<rt::SPSSimpleRemoteMemoryMapReleaseSignature>(
91 SAs.Release,
92 [OnReleased = std::move(OnReleased)](Error SerializationErr,
93 Error Result) mutable {
94 if (SerializationErr) {
95 cantFail(std::move(Result));
96 return OnReleased(std::move(SerializationErr));
97 }
98
99 return OnReleased(std::move(Result));
100 },
101 SAs.Instance, Bases);
102}
103
104} // namespace llvm::orc
#define G(x, y, z)
Definition MD5.cpp:56
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:41
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
Tagged union holding either a T or a Error.
Definition Error.h:485
Represents an address in the executor process.
ExecutorProcessControl supports interaction with a JIT target process.
unique_function< void(Error)> OnReleasedFunction
unique_function< void(Expected< ExecutorAddr >)> OnInitializedFunction
unique_function< void(Expected< ExecutorAddrRange >)> OnReservedFunction
unique_function< void(Error)> OnDeinitializedFunction
void initialize(AllocInfo &AI, OnInitializedFunction OnInitialized) override
Initializes memory within a previously reserved region (applying protections and running any finaliza...
char * prepare(jitlink::LinkGraph &G, ExecutorAddr Addr, size_t ContentSize) override
Provides working memory The LinkGraph parameter is included to allow implementations to allocate work...
void deinitialize(ArrayRef< ExecutorAddr > Allocations, OnDeinitializedFunction OnDeInitialized) override
Given a series of keys from previous initialize calls, deinitialize previously initialized memory reg...
void release(ArrayRef< ExecutorAddr > Reservations, OnReleasedFunction OnRelease) override
Given a sequence of base addresses from previous reserve calls, release the underlying ranges (deinit...
void reserve(size_t NumBytes, OnReservedFunction OnReserved) override
Reserves memory in the remote process by calling a remote SPS-wrapper-function with signature.
SimpleRemoteMemoryMapper(ExecutorProcessControl &EPC, SymbolAddrs SAs)
shared::SPSExpected< shared::SPSExecutorAddr >(shared::SPSExecutorAddr, shared::SPSFinalizeRequest) SPSSimpleRemoteMemoryMapInitializeSignature
shared::SPSError( shared::SPSExecutorAddr, shared::SPSSequence< shared::SPSExecutorAddr >) SPSSimpleRemoteMemoryMapReleaseSignature
shared::SPSExpected< shared::SPSExecutorAddr >(shared::SPSExecutorAddr, uint64_t) SPSSimpleRemoteMemoryMapReserveSignature
shared::SPSError( shared::SPSExecutorAddr, shared::SPSSequence< shared::SPSExecutorAddr >) SPSSimpleRemoteMemoryMapDeinitializeSignature
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
Definition Error.h:769
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition BitVector.h:869
Represents an address range in the exceutor process.
Represents a single allocation containing multiple segments and initialization and deinitialization a...
std::vector< SegInfo > Segments
std::vector< SegFinalizeRequest > Segments