117 lines
4.5 KiB
C++
117 lines
4.5 KiB
C++
//===- EPCGenericDylibManager.h -- Generic EPC Dylib management -*- C++ -*-===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// Implements dylib loading and searching by making calls to
|
|
// ExecutorProcessControl::callWrapper.
|
|
//
|
|
// This simplifies the implementaton of new ExecutorProcessControl instances,
|
|
// as this implementation will always work (at the cost of some performance
|
|
// overhead for the calls).
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LLVM_EXECUTIONENGINE_ORC_EPCGENERICDYLIBMANAGER_H
|
|
#define LLVM_EXECUTIONENGINE_ORC_EPCGENERICDYLIBMANAGER_H
|
|
|
|
#include "llvm/ExecutionEngine/Orc/DylibManager.h"
|
|
#include "llvm/ExecutionEngine/Orc/ExecutorProcessControl.h"
|
|
#include "llvm/ExecutionEngine/Orc/Shared/ExecutorSymbolDef.h"
|
|
#include "llvm/ExecutionEngine/Orc/Shared/OrcRTBridge.h"
|
|
#include "llvm/ExecutionEngine/Orc/Shared/SimpleRemoteEPCUtils.h"
|
|
#include "llvm/Support/Compiler.h"
|
|
|
|
namespace llvm {
|
|
namespace orc {
|
|
|
|
class JITDylib;
|
|
class SymbolLookupSet;
|
|
|
|
class LLVM_ABI EPCGenericDylibManager : public DylibManager {
|
|
public:
|
|
/// Function addresses for memory access.
|
|
struct SymbolAddrs {
|
|
ExecutorAddr Instance;
|
|
ExecutorAddr Open;
|
|
ExecutorAddr Resolve;
|
|
};
|
|
|
|
/// Create an EPCGenericDylibManager instance by looking up the LLVM-style
|
|
/// SimpleExecutorDylibManager symbol names in the EPC's bootstrap table.
|
|
static Expected<EPCGenericDylibManager>
|
|
CreateWithDefaultBootstrapSymbols(ExecutorProcessControl &EPC);
|
|
|
|
/// Create an EPCGenericDylibManager using the given implementation symbol
|
|
/// names. These will be looked up in the given JITDylib.
|
|
static Expected<EPCGenericDylibManager>
|
|
Create(JITDylib &JD, rt::SimpleExecutorDylibManagerSymbolNames SNs =
|
|
rt::orc_rt_NativeDylibManagerSPSSymbols);
|
|
|
|
/// Create an EPCGenericDylibManager using the given implementation symbol
|
|
/// names. These will be looked up in the given ExecutionSession's bootstrap
|
|
/// JITDylib.
|
|
static Expected<EPCGenericDylibManager>
|
|
Create(ExecutionSession &ES, rt::SimpleExecutorDylibManagerSymbolNames SNs =
|
|
rt::orc_rt_NativeDylibManagerSPSSymbols);
|
|
|
|
/// Create an EPCGenericDylibManager instance from a given set of function
|
|
/// addrs.
|
|
EPCGenericDylibManager(ExecutorProcessControl &EPC, SymbolAddrs SAs)
|
|
: EPC(EPC), SAs(SAs) {}
|
|
|
|
/// Loads the dylib with the given name.
|
|
Expected<tpctypes::DylibHandle> open(StringRef Path, uint64_t Mode);
|
|
|
|
/// Looks up symbols within the given dylib.
|
|
Expected<tpctypes::LookupResult> lookup(tpctypes::DylibHandle H,
|
|
const SymbolLookupSet &Lookup) {
|
|
std::promise<MSVCPExpected<tpctypes::LookupResult>> RP;
|
|
auto RF = RP.get_future();
|
|
lookupAsync(H, Lookup, [&RP](auto R) { RP.set_value(std::move(R)); });
|
|
return RF.get();
|
|
}
|
|
|
|
/// Looks up symbols within the given dylib.
|
|
Expected<tpctypes::LookupResult> lookup(tpctypes::DylibHandle H,
|
|
const RemoteSymbolLookupSet &Lookup) {
|
|
std::promise<MSVCPExpected<tpctypes::LookupResult>> RP;
|
|
auto RF = RP.get_future();
|
|
lookupAsync(H, Lookup, [&RP](auto R) { RP.set_value(std::move(R)); });
|
|
return RF.get();
|
|
}
|
|
|
|
using SymbolLookupCompleteFn =
|
|
unique_function<void(Expected<tpctypes::LookupResult>)>;
|
|
|
|
/// Looks up symbols within the given dylib.
|
|
void lookupAsync(tpctypes::DylibHandle H, const SymbolLookupSet &Lookup,
|
|
SymbolLookupCompleteFn Complete);
|
|
|
|
/// Looks up symbols within the given dylib.
|
|
void lookupAsync(tpctypes::DylibHandle H, const RemoteSymbolLookupSet &Lookup,
|
|
SymbolLookupCompleteFn Complete);
|
|
|
|
/// Load the dynamic library at the given path and return a handle to it.
|
|
/// If DylibPath is null this function will return the global handle for
|
|
/// the target process.
|
|
Expected<tpctypes::DylibHandle> loadDylib(const char *DylibPath) override;
|
|
|
|
/// Search for symbols in the target process.
|
|
void
|
|
lookupSymbolsAsync(tpctypes::DylibHandle H, const SymbolLookupSet &Symbols,
|
|
DylibManager::SymbolLookupCompleteFn Complete) override;
|
|
|
|
private:
|
|
ExecutorProcessControl &EPC;
|
|
SymbolAddrs SAs;
|
|
};
|
|
|
|
} // end namespace orc
|
|
} // end namespace llvm
|
|
|
|
#endif // LLVM_EXECUTIONENGINE_ORC_EPCGENERICDYLIBMANAGER_H
|