| 1 | //===-- SelfExecutorProcessControl.h - EPC for in-process JITs --*- 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 | // |
| 9 | // Executor process control implementation for JITs that run JIT'd code in the |
| 10 | // same process. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef LLVM_EXECUTIONENGINE_ORC_SELFEXECUTORPROCESSCONTROL_H |
| 15 | #define LLVM_EXECUTIONENGINE_ORC_SELFEXECUTORPROCESSCONTROL_H |
| 16 | |
| 17 | #include "llvm/ExecutionEngine/Orc/ExecutorProcessControl.h" |
| 18 | #include "llvm/ExecutionEngine/Orc/InProcessMemoryAccess.h" |
| 19 | |
| 20 | #include <memory> |
| 21 | |
| 22 | namespace llvm::orc { |
| 23 | |
| 24 | /// A ExecutorProcessControl implementation targeting the current process. |
| 25 | class LLVM_ABI SelfExecutorProcessControl : public ExecutorProcessControl, |
| 26 | private DylibManager { |
| 27 | public: |
| 28 | SelfExecutorProcessControl( |
| 29 | std::shared_ptr<SymbolStringPool> SSP, std::unique_ptr<TaskDispatcher> D, |
| 30 | Triple TargetTriple, unsigned PageSize, |
| 31 | std::unique_ptr<jitlink::JITLinkMemoryManager> MemMgr); |
| 32 | |
| 33 | /// Create a SelfExecutorProcessControl with the given symbol string pool and |
| 34 | /// memory manager. |
| 35 | /// If no symbol string pool is given then one will be created. |
| 36 | /// If no memory manager is given a jitlink::InProcessMemoryManager will |
| 37 | /// be created and used by default. |
| 38 | static Expected<std::unique_ptr<SelfExecutorProcessControl>> |
| 39 | Create(std::shared_ptr<SymbolStringPool> SSP = nullptr, |
| 40 | std::unique_ptr<TaskDispatcher> D = nullptr, |
| 41 | std::unique_ptr<jitlink::JITLinkMemoryManager> MemMgr = nullptr); |
| 42 | |
| 43 | Expected<int32_t> runAsMain(ExecutorAddr MainFnAddr, |
| 44 | ArrayRef<std::string> Args) override; |
| 45 | |
| 46 | Expected<int32_t> runAsVoidFunction(ExecutorAddr VoidFnAddr) override; |
| 47 | |
| 48 | Expected<int32_t> runAsIntFunction(ExecutorAddr IntFnAddr, int Arg) override; |
| 49 | |
| 50 | void callWrapperAsync(ExecutorAddr WrapperFnAddr, |
| 51 | IncomingWFRHandler OnComplete, |
| 52 | ArrayRef<char> ArgBuffer) override; |
| 53 | |
| 54 | Error disconnect() override; |
| 55 | |
| 56 | private: |
| 57 | static shared::CWrapperFunctionResult |
| 58 | jitDispatchViaWrapperFunctionManager(void *Ctx, const void *FnTag, |
| 59 | const char *Data, size_t Size); |
| 60 | |
| 61 | Expected<tpctypes::DylibHandle> loadDylib(const char *DylibPath) override; |
| 62 | |
| 63 | void lookupSymbolsAsync(ArrayRef<LookupRequest> Request, |
| 64 | SymbolLookupCompleteFn F) override; |
| 65 | |
| 66 | std::unique_ptr<jitlink::JITLinkMemoryManager> OwnedMemMgr; |
| 67 | #ifdef __APPLE__ |
| 68 | std::unique_ptr<UnwindInfoManager> UnwindInfoMgr; |
| 69 | #endif // __APPLE__ |
| 70 | char GlobalManglingPrefix = 0; |
| 71 | InProcessMemoryAccess IPMA; |
| 72 | }; |
| 73 | |
| 74 | } // namespace llvm::orc |
| 75 | |
| 76 | #endif // LLVM_EXECUTIONENGINE_ORC_SELFEXECUTORPROCESSCONTROL_H |
| 77 | |