LLVM: lib/ExecutionEngine/Orc/SelfExecutorProcessControl.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
10
17
18#define DEBUG_TYPE "orc"
19
21
23 std::shared_ptr SSP, std::unique_ptr D,
25 std::unique_ptrjitlink::JITLinkMemoryManager MemMgr)
28
29 OwnedMemMgr = std::move(MemMgr);
30 if (!OwnedMemMgr)
31 OwnedMemMgr = std::make_uniquejitlink::InProcessMemoryManager(
33
36 this->MemMgr = OwnedMemMgr.get();
41
43 GlobalManglingPrefix = '_';
44
46
47#ifdef __APPLE__
48
49
50
53#endif
54}
55
58 std::shared_ptr SSP, std::unique_ptr D,
59 std::unique_ptrjitlink::JITLinkMemoryManager MemMgr) {
60
62 SSP = std::make_shared();
63
64 if ()
65 D = std::make_unique();
66
70
72
73 return std::make_unique(
74 std::move(SSP), std::move(D), std::move(TT), *PageSize,
76}
77
79SelfExecutorProcessControl::loadDylib(const char *DylibPath) {
80 std::string ErrMsg;
82 if (!Dylib.isValid())
85}
86
87void SelfExecutorProcessControl::lookupSymbolsAsync(
90 std::vectortpctypes::LookupResult R;
91
92 for (auto &Elem : Request) {
95 for (auto &KV : Elem.Symbols) {
96 auto &Sym = KV.first;
97 std::string Tmp((*Sym).data() + !!GlobalManglingPrefix,
98 (*Sym).size() - !!GlobalManglingPrefix);
99 void *Addr = Dylib.getAddressOfSymbol(Tmp.c_str());
101 R.back().emplace_back();
102 else
103
106 }
107 }
108
109 Complete(std::move(R));
110}
111
112Expected<int32_t>
115 using MainTy = int (*)(int, char *[]);
117}
118
121 using VoidTy = int (*)();
123}
124
127 using IntTy = int (*)(int);
129}
130
134 using WrapperFnTy =
136 auto *WrapperFn = WrapperFnAddr.toPtr();
137 SendResult(WrapperFn(ArgBuffer.data(), ArgBuffer.size()));
138}
139
144
146SelfExecutorProcessControl::jitDispatchViaWrapperFunctionManager(
147 void *Ctx, const void *FnTag, const char *Data, size_t Size) {
148
150 dbgs() << "jit-dispatch call with tag " << FnTag << " and " << Size
151 << " byte payload.\n";
152 });
153
154 std::promiseshared::WrapperFunctionResult ResultP;
155 auto ResultF = ResultP.get_future();
159 [ResultP = std::move(ResultP)](
160 shared::WrapperFunctionResult Result) mutable {
161 ResultP.set_value(std::move(Result));
162 },
164
165 return ResultF.get().release();
166}
167
168}
Provides a library for accessing information about this process and other processes on the operating ...
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
Triple - Helper class for working with autoconf configuration names.
bool isOSBinFormatMachO() const
Tests whether the environment is MachO.
unique_function< void(Expected< std::vector< tpctypes::LookupResult > >)> SymbolLookupCompleteFn
LLVM_ABI void runJITDispatchHandler(SendResultFunction SendResult, ExecutorAddr HandlerFnTagAddr, ArrayRef< char > ArgBuffer)
Run a registered jit-side wrapper function.
Represents an address in the executor process.
static ExecutorAddr fromPtr(T *Ptr, UnwrapFn &&Unwrap=UnwrapFn())
Create an ExecutorAddr from the given pointer.
std::enable_if_t< std::is_pointer< T >::value, T > toPtr(WrapFn &&Wrap=WrapFn()) const
Cast this ExecutorAddr to a pointer of the given type.
A handler or incoming WrapperFunctionResults – either return values from callWrapper* calls,...
std::unique_ptr< TaskDispatcher > D
std::shared_ptr< SymbolStringPool > SSP
StringMap< ExecutorAddr > BootstrapSymbols
StringMap< std::vector< char > > BootstrapMap
jitlink::JITLinkMemoryManager * MemMgr
ExecutionSession & getExecutionSession()
Return the ExecutionSession associated with this instance.
ExecutorProcessControl(std::shared_ptr< SymbolStringPool > SSP, std::unique_ptr< TaskDispatcher > D)
SelfExecutorProcessControl(std::shared_ptr< SymbolStringPool > SSP, std::unique_ptr< TaskDispatcher > D, Triple TargetTriple, unsigned PageSize, std::unique_ptr< jitlink::JITLinkMemoryManager > MemMgr)
Definition SelfExecutorProcessControl.cpp:22
Error disconnect() override
Disconnect from the target process.
Definition SelfExecutorProcessControl.cpp:140
Expected< int32_t > runAsVoidFunction(ExecutorAddr VoidFnAddr) override
Run function with a int (*)(void) signature.
Definition SelfExecutorProcessControl.cpp:120
Expected< int32_t > runAsMain(ExecutorAddr MainFnAddr, ArrayRef< std::string > Args) override
Run function with a main-like signature.
Definition SelfExecutorProcessControl.cpp:113
void callWrapperAsync(ExecutorAddr WrapperFnAddr, IncomingWFRHandler OnComplete, ArrayRef< char > ArgBuffer) override
Run a wrapper function in the executor.
Definition SelfExecutorProcessControl.cpp:131
static Expected< std::unique_ptr< SelfExecutorProcessControl > > Create(std::shared_ptr< SymbolStringPool > SSP=nullptr, std::unique_ptr< TaskDispatcher > D=nullptr, std::unique_ptr< jitlink::JITLinkMemoryManager > MemMgr=nullptr)
Create a SelfExecutorProcessControl with the given symbol string pool and memory manager.
Definition SelfExecutorProcessControl.cpp:57
Expected< int32_t > runAsIntFunction(ExecutorAddr IntFnAddr, int Arg) override
Run function with a int (*)(int) signature.
Definition SelfExecutorProcessControl.cpp:126
static LLVM_ABI bool TryEnable()
If the libunwind find-dynamic-unwind-info callback registration APIs are available then this method w...
static LLVM_ABI void addBootstrapSymbols(StringMap< ExecutorAddr > &M)
This class provides a portable interface to dynamic libraries which also might be known as shared lib...
static LLVM_ABI DynamicLibrary getPermanentLibrary(const char *filename, std::string *errMsg=nullptr)
This function permanently loads the dynamic library at the given path using the library load operatio...
static LLVM_ABI Expected< unsigned > getPageSize()
Get the process's page size.
static unsigned getPageSizeEstimate()
Get the process's estimated page size.
std::vector< std::optional< ExecutorSymbolDef > > LookupResult
LLVM_ABI void addDefaultBootstrapValuesForHostProcess(StringMap< std::vector< char > > &BootstrapMap, StringMap< ExecutorAddr > &BootstrapSymbols)
LLVM_ABI int runAsVoidFunction(int(*Func)(void))
LLVM_ABI int runAsIntFunction(int(*Func)(int), int Arg)
LLVM_ABI int runAsMain(int(*Main)(int, char *[]), ArrayRef< std::string > Args, std::optional< StringRef > ProgramName=std::nullopt)
Run a main function, returning the result.
LLVM_ABI std::string getProcessTriple()
getProcessTriple() - Return an appropriate target triple for generating code to be loaded into the cu...
LLVM_ABI std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
FunctionAddr VTableAddr uintptr_t uintptr_t Data
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.