xref: /freebsd/contrib/llvm-project/llvm/include/llvm/ExecutionEngine/Orc/EPCGenericDylibManager.h (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
1 //===- EPCGenericDylibManager.h -- Generic EPC Dylib management -*- 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 // Implements dylib loading and searching by making calls to
10 // ExecutorProcessControl::callWrapper.
11 //
12 // This simplifies the implementaton of new ExecutorProcessControl instances,
13 // as this implementation will always work (at the cost of some performance
14 // overhead for the calls).
15 //
16 //===----------------------------------------------------------------------===//
17 
18 #ifndef LLVM_EXECUTIONENGINE_ORC_EPCGENERICDYLIBMANAGER_H
19 #define LLVM_EXECUTIONENGINE_ORC_EPCGENERICDYLIBMANAGER_H
20 
21 #include "llvm/ExecutionEngine/Orc/ExecutorProcessControl.h"
22 #include "llvm/ExecutionEngine/Orc/Shared/ExecutorSymbolDef.h"
23 #include "llvm/ExecutionEngine/Orc/Shared/SimpleRemoteEPCUtils.h"
24 
25 namespace llvm {
26 namespace orc {
27 
28 class SymbolLookupSet;
29 
30 class EPCGenericDylibManager {
31 public:
32   /// Function addresses for memory access.
33   struct SymbolAddrs {
34     ExecutorAddr Instance;
35     ExecutorAddr Open;
36     ExecutorAddr Lookup;
37   };
38 
39   /// Create an EPCGenericMemoryAccess instance from a given set of
40   /// function addrs.
41   static Expected<EPCGenericDylibManager>
42   CreateWithDefaultBootstrapSymbols(ExecutorProcessControl &EPC);
43 
44   /// Create an EPCGenericMemoryAccess instance from a given set of
45   /// function addrs.
EPCGenericDylibManager(ExecutorProcessControl & EPC,SymbolAddrs SAs)46   EPCGenericDylibManager(ExecutorProcessControl &EPC, SymbolAddrs SAs)
47       : EPC(EPC), SAs(SAs) {}
48 
49   /// Loads the dylib with the given name.
50   Expected<tpctypes::DylibHandle> open(StringRef Path, uint64_t Mode);
51 
52   /// Looks up symbols within the given dylib.
53   Expected<std::vector<ExecutorSymbolDef>>
lookup(tpctypes::DylibHandle H,const SymbolLookupSet & Lookup)54   lookup(tpctypes::DylibHandle H, const SymbolLookupSet &Lookup) {
55     std::promise<MSVCPExpected<std::vector<ExecutorSymbolDef>>> RP;
56     auto RF = RP.get_future();
57     lookupAsync(H, Lookup, [&RP](auto R) { RP.set_value(std::move(R)); });
58     return RF.get();
59   }
60 
61   /// Looks up symbols within the given dylib.
62   Expected<std::vector<ExecutorSymbolDef>>
lookup(tpctypes::DylibHandle H,const RemoteSymbolLookupSet & Lookup)63   lookup(tpctypes::DylibHandle H, const RemoteSymbolLookupSet &Lookup) {
64     std::promise<MSVCPExpected<std::vector<ExecutorSymbolDef>>> RP;
65     auto RF = RP.get_future();
66     lookupAsync(H, Lookup, [&RP](auto R) { RP.set_value(std::move(R)); });
67     return RF.get();
68   }
69 
70   using SymbolLookupCompleteFn =
71       unique_function<void(Expected<std::vector<ExecutorSymbolDef>>)>;
72 
73   /// Looks up symbols within the given dylib.
74   void lookupAsync(tpctypes::DylibHandle H, const SymbolLookupSet &Lookup,
75                    SymbolLookupCompleteFn Complete);
76 
77   /// Looks up symbols within the given dylib.
78   void lookupAsync(tpctypes::DylibHandle H, const RemoteSymbolLookupSet &Lookup,
79                    SymbolLookupCompleteFn Complete);
80 
81 private:
82   ExecutorProcessControl &EPC;
83   SymbolAddrs SAs;
84 };
85 
86 } // end namespace orc
87 } // end namespace llvm
88 
89 #endif // LLVM_EXECUTIONENGINE_ORC_EPCGENERICDYLIBMANAGER_H
90