13#ifndef LLVM_EXECUTIONENGINE_ORC_EXECUTORPROCESSCONTROL_H
14#define LLVM_EXECUTIONENGINE_ORC_EXECUTORPROCESSCONTROL_H
35class ExecutionSession;
52 explicit operator bool()
const {
return !!
H; }
69 template <
typename FnT>
84 template <
typename FnT>
87 [&
D = this->
D, Fn = std::move(Fn)]
91 [Fn = std::move(Fn), WFR = std::move(WFR)]()
mutable {
93 },
"WFR handler task"));
108 std::unique_ptr<TaskDispatcher>
D)
116 assert(ES &&
"No ExecutionSession associated yet");
139 assert(MemAccess &&
"No MemAccess object set.");
145 assert(MemMgr &&
"No MemMgr object set");
151 assert(DylibMgr &&
"No DylibMgr object set");
161 template <
typename T,
typename SPSTagT>
165 auto I = BootstrapMap.find(Key);
166 if (
I == BootstrapMap.end())
167 return Error::success();
172 return make_error<StringError>(
"Could not deserialize value for key " +
176 Val = std::move(Tmp);
177 return Error::success();
182 return BootstrapSymbols;
189 ArrayRef<std::pair<ExecutorAddr &, StringRef>> Pairs)
const {
190 for (
const auto &KV : Pairs) {
191 auto I = BootstrapSymbols.find(KV.second);
192 if (
I == BootstrapSymbols.end())
193 return make_error<StringError>(
"Symbol \"" + KV.second +
195 "in bootstrap symbols map",
198 KV.first =
I->second;
200 return Error::success();
230 template <
typename RunPolicyT,
typename FnT>
234 WrapperFnAddr, Runner(std::forward<FnT>(OnComplete)), ArgBuffer);
239 template <
typename FnT>
242 callWrapperAsync(
RunAsTask(*
D), WrapperFnAddr,
243 std::forward<FnT>(OnComplete), ArgBuffer);
254 std::promise<shared::WrapperFunctionResult> RP;
255 auto RF = RP.get_future();
259 RP.set_value(std::move(R));
266 template <
typename SPSSignature,
typename RunPolicyT,
typename SendResultT,
269 SendResultT &&SendResult,
const ArgTs &...Args) {
271 [
this, WrapperFnAddr, Runner = std::move(Runner)]
272 (
auto &&SendResult,
const char *ArgData,
size_t ArgSize)
mutable {
273 this->callWrapperAsync(std::move(Runner), WrapperFnAddr,
274 std::move(SendResult),
277 std::forward<SendResultT>(SendResult), Args...);
282 template <
typename SPSSignature,
typename SendResultT,
typename... ArgTs>
284 const ArgTs &...Args) {
285 callSPSWrapperAsync<SPSSignature>(
RunAsTask(*
D), WrapperFnAddr,
286 std::forward<SendResultT>(SendResult),
295 template <
typename SPSSignature,
typename... WrapperCallArgTs>
297 WrapperCallArgTs &&...WrapperCallArgs) {
299 [
this, WrapperFnAddr](
const char *ArgData,
size_t ArgSize) {
300 return callWrapper(WrapperFnAddr,
ArrayRef<char>(ArgData, ArgSize));
302 std::forward<WrapperCallArgTs>(WrapperCallArgs)...);
312 std::shared_ptr<SymbolStringPool>
SSP;
313 std::unique_ptr<TaskDispatcher>
D;
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static cl::opt< int > PageSize("imp-null-check-page-size", cl::desc("The page size of the target in bytes"), cl::init(4096), cl::Hidden)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Lightweight error class with error context and mandatory checking.
Tagged union holding either a T or a Error.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
StringRef - Represent a constant reference to a string, i.e.
Triple - Helper class for working with autoconf configuration names.
Manages allocations of JIT memory.
An ExecutionSession represents a running JIT program.
Represents an address in the executor process.
A handler or incoming WrapperFunctionResults – either return values from callWrapper* calls,...
void operator()(shared::WrapperFunctionResult WFR)
IncomingWFRHandler()=default
Constructs an IncomingWFRHandler from a function object by creating a new function object that dispat...
IncomingWFRHandler operator()(FnT &&Fn)
RunAsTask(TaskDispatcher &D)
Constructs an IncomingWFRHandler from a function object that is callable as void(shared::WrapperFunct...
IncomingWFRHandler operator()(FnT &&Fn)
ExecutorProcessControl supports interaction with a JIT target process.
jitlink::JITLinkMemoryManager & getMemMgr() const
Return a JITLinkMemoryManager for the target process.
shared::WrapperFunctionResult callWrapper(ExecutorAddr WrapperFnAddr, ArrayRef< char > ArgBuffer)
Run a wrapper function in the executor.
void callWrapperAsync(ExecutorAddr WrapperFnAddr, FnT &&OnComplete, ArrayRef< char > ArgBuffer)
Run a wrapper function in the executor.
virtual Expected< int32_t > runAsIntFunction(ExecutorAddr IntFnAddr, int Arg)=0
Run function with a int (*)(int) signature.
void callSPSWrapperAsync(RunPolicyT &&Runner, ExecutorAddr WrapperFnAddr, SendResultT &&SendResult, const ArgTs &...Args)
Run a wrapper function using SPS to serialize the arguments and deserialize the results.
virtual Expected< int32_t > runAsMain(ExecutorAddr MainFnAddr, ArrayRef< std::string > Args)=0
Run function with a main-like signature.
Error getBootstrapMapValue(StringRef Key, std::optional< T > &Val) const
Look up and SPS-deserialize a bootstrap map value.
std::unique_ptr< TaskDispatcher > D
void callSPSWrapperAsync(ExecutorAddr WrapperFnAddr, SendResultT &&SendResult, const ArgTs &...Args)
Run a wrapper function using SPS to serialize the arguments and deserialize the results.
virtual void callWrapperAsync(ExecutorAddr WrapperFnAddr, IncomingWFRHandler OnComplete, ArrayRef< char > ArgBuffer)=0
Run a wrapper function in the executor.
const StringMap< std::vector< char > > & getBootstrapMap() const
Returns the bootstrap map.
std::shared_ptr< SymbolStringPool > SSP
const Triple & getTargetTriple() const
Return the Triple for the target process.
StringMap< ExecutorAddr > BootstrapSymbols
SymbolStringPtr intern(StringRef SymName)
Intern a symbol name in the SymbolStringPool.
virtual Error disconnect()=0
Disconnect from the target process.
StringMap< std::vector< char > > BootstrapMap
std::shared_ptr< SymbolStringPool > getSymbolStringPool() const
Return a shared pointer to the SymbolStringPool for this instance.
const StringMap< ExecutorAddr > & getBootstrapSymbolsMap() const
Returns the bootstrap symbol map.
virtual Expected< int32_t > runAsVoidFunction(ExecutorAddr VoidFnAddr)=0
Run function with a int (*)(void) signature.
unsigned getPageSize() const
Get the page size for the target process.
const JITDispatchInfo & getJITDispatchInfo() const
Get the JIT dispatch function and context address for the executor.
Error callSPSWrapper(ExecutorAddr WrapperFnAddr, WrapperCallArgTs &&...WrapperCallArgs)
Run a wrapper function using SPS to serialize the arguments and deserialize the results.
void callWrapperAsync(RunPolicyT &&Runner, ExecutorAddr WrapperFnAddr, FnT &&OnComplete, ArrayRef< char > ArgBuffer)
Run a wrapper function in the executor using the given Runner to dispatch OnComplete when the result ...
Error getBootstrapSymbols(ArrayRef< std::pair< ExecutorAddr &, StringRef > > Pairs) const
For each (ExecutorAddr&, StringRef) pair, looks up the string in the bootstrap symbols map and writes...
ExecutionSession & getExecutionSession()
Return the ExecutionSession associated with this instance.
DylibManager & getDylibMgr() const
Return the DylibManager for the target process.
ExecutorProcessControl(std::shared_ptr< SymbolStringPool > SSP, std::unique_ptr< TaskDispatcher > D)
MemoryAccess & getMemoryAccess() const
Return a MemoryAccess object for the target process.
TaskDispatcher & getDispatcher()
virtual ~ExecutorProcessControl()
APIs for manipulating memory in the target process.
Pointer to a pooled string representing a symbol name.
Abstract base for classes that dispatch ORC Tasks.
A utility class for serializing to a blob from a variadic list.
C++ wrapper function result: Same as CWrapperFunctionResult but auto-releases memory.
unique_function is a type-erasing functor similar to std::function.
std::unique_ptr< GenericNamedTask > makeGenericNamedTask(FnT &&Fn, std::string Desc)
Create a generic named task from a std::string description.
LLVM_ABI std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Implement std::hash so that hash_code can be used in STL containers.
Contains the address of the dispatch function and context that the ORC runtime can use to call functi...
ExecutorAddr JITDispatchContext
ExecutorAddr JITDispatchFunction