EPCGenericDylibManager.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. //===------- EPCGenericDylibManager.cpp -- Dylib management via EPC -------===//
  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. #include "llvm/ExecutionEngine/Orc/EPCGenericDylibManager.h"
  9. #include "llvm/ExecutionEngine/Orc/Core.h"
  10. #include "llvm/ExecutionEngine/Orc/Shared/OrcRTBridge.h"
  11. #include "llvm/ExecutionEngine/Orc/Shared/SimpleRemoteEPCUtils.h"
  12. namespace llvm {
  13. namespace orc {
  14. namespace shared {
  15. template <>
  16. class SPSSerializationTraits<SPSRemoteSymbolLookupSetElement,
  17. SymbolLookupSet::value_type> {
  18. public:
  19. static size_t size(const SymbolLookupSet::value_type &V) {
  20. return SPSArgList<SPSString, bool>::size(
  21. *V.first, V.second == SymbolLookupFlags::RequiredSymbol);
  22. }
  23. static bool serialize(SPSOutputBuffer &OB,
  24. const SymbolLookupSet::value_type &V) {
  25. return SPSArgList<SPSString, bool>::serialize(
  26. OB, *V.first, V.second == SymbolLookupFlags::RequiredSymbol);
  27. }
  28. };
  29. template <>
  30. class TrivialSPSSequenceSerialization<SPSRemoteSymbolLookupSetElement,
  31. SymbolLookupSet> {
  32. public:
  33. static constexpr bool available = true;
  34. };
  35. template <>
  36. class SPSSerializationTraits<SPSRemoteSymbolLookup,
  37. ExecutorProcessControl::LookupRequest> {
  38. using MemberSerialization =
  39. SPSArgList<SPSExecutorAddr, SPSRemoteSymbolLookupSet>;
  40. public:
  41. static size_t size(const ExecutorProcessControl::LookupRequest &LR) {
  42. return MemberSerialization::size(ExecutorAddr(LR.Handle), LR.Symbols);
  43. }
  44. static bool serialize(SPSOutputBuffer &OB,
  45. const ExecutorProcessControl::LookupRequest &LR) {
  46. return MemberSerialization::serialize(OB, ExecutorAddr(LR.Handle),
  47. LR.Symbols);
  48. }
  49. };
  50. } // end namespace shared
  51. Expected<EPCGenericDylibManager>
  52. EPCGenericDylibManager::CreateWithDefaultBootstrapSymbols(
  53. ExecutorProcessControl &EPC) {
  54. SymbolAddrs SAs;
  55. if (auto Err = EPC.getBootstrapSymbols(
  56. {{SAs.Instance, rt::SimpleExecutorDylibManagerInstanceName},
  57. {SAs.Open, rt::SimpleExecutorDylibManagerOpenWrapperName},
  58. {SAs.Lookup, rt::SimpleExecutorDylibManagerLookupWrapperName}}))
  59. return std::move(Err);
  60. return EPCGenericDylibManager(EPC, std::move(SAs));
  61. }
  62. Expected<tpctypes::DylibHandle> EPCGenericDylibManager::open(StringRef Path,
  63. uint64_t Mode) {
  64. Expected<tpctypes::DylibHandle> H((ExecutorAddr()));
  65. if (auto Err =
  66. EPC.callSPSWrapper<rt::SPSSimpleExecutorDylibManagerOpenSignature>(
  67. SAs.Open, H, SAs.Instance, Path, Mode))
  68. return std::move(Err);
  69. return H;
  70. }
  71. Expected<std::vector<ExecutorAddr>>
  72. EPCGenericDylibManager::lookup(tpctypes::DylibHandle H,
  73. const SymbolLookupSet &Lookup) {
  74. Expected<std::vector<ExecutorAddr>> Result((std::vector<ExecutorAddr>()));
  75. if (auto Err =
  76. EPC.callSPSWrapper<rt::SPSSimpleExecutorDylibManagerLookupSignature>(
  77. SAs.Lookup, Result, SAs.Instance, H, Lookup))
  78. return std::move(Err);
  79. return Result;
  80. }
  81. Expected<std::vector<ExecutorAddr>>
  82. EPCGenericDylibManager::lookup(tpctypes::DylibHandle H,
  83. const RemoteSymbolLookupSet &Lookup) {
  84. Expected<std::vector<ExecutorAddr>> Result((std::vector<ExecutorAddr>()));
  85. if (auto Err =
  86. EPC.callSPSWrapper<rt::SPSSimpleExecutorDylibManagerLookupSignature>(
  87. SAs.Lookup, Result, SAs.Instance, H, Lookup))
  88. return std::move(Err);
  89. return Result;
  90. }
  91. } // end namespace orc
  92. } // end namespace llvm