diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2017-12-18 20:10:56 +0000 | 
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2017-12-18 20:10:56 +0000 | 
| commit | 044eb2f6afba375a914ac9d8024f8f5142bb912e (patch) | |
| tree | 1475247dc9f9fe5be155ebd4c9069c75aadf8c20 /include/llvm/ExecutionEngine/Orc/OrcRemoteTargetRPCAPI.h | |
| parent | eb70dddbd77e120e5d490bd8fbe7ff3f8fa81c6b (diff) | |
Notes
Diffstat (limited to 'include/llvm/ExecutionEngine/Orc/OrcRemoteTargetRPCAPI.h')
| -rw-r--r-- | include/llvm/ExecutionEngine/Orc/OrcRemoteTargetRPCAPI.h | 263 | 
1 files changed, 185 insertions, 78 deletions
| diff --git a/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetRPCAPI.h b/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetRPCAPI.h index 07ae7f04d1a0..bc0da0f9a730 100644 --- a/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetRPCAPI.h +++ b/include/llvm/ExecutionEngine/Orc/OrcRemoteTargetRPCAPI.h @@ -25,6 +25,37 @@ namespace orc {  namespace remote { +/// Template error for missing resources. +template <typename ResourceIdT> +class ResourceNotFound +  : public ErrorInfo<ResourceNotFound<ResourceIdT>> { +public: +  static char ID; + +  ResourceNotFound(ResourceIdT ResourceId, +                   std::string ResourceDescription = "") +    : ResourceId(std::move(ResourceId)), +      ResourceDescription(std::move(ResourceDescription)) {} + +  std::error_code convertToErrorCode() const override { +    return orcError(OrcErrorCode::UnknownResourceHandle); +  } + +  void log(raw_ostream &OS) const override { +    OS << (ResourceDescription.empty() +             ? "Remote resource with id " +               : ResourceDescription) +       << " " << ResourceId << " not found"; +  } + +private: +  ResourceIdT ResourceId; +  std::string ResourceDescription; +}; + +template <typename ResourceIdT> +char ResourceNotFound<ResourceIdT>::ID = 0; +  class DirectBufferWriter {  public:    DirectBufferWriter() = default; @@ -45,6 +76,32 @@ private:  namespace rpc { +template <> +class RPCTypeName<JITSymbolFlags> { +public: +  static const char *getName() { return "JITSymbolFlags"; } +}; + +template <typename ChannelT> +class SerializationTraits<ChannelT, JITSymbolFlags> { +public: + +  static Error serialize(ChannelT &C, const JITSymbolFlags &Flags) { +    return serializeSeq(C, static_cast<JITSymbolFlags::UnderlyingType>(Flags), +                        Flags.getTargetFlags()); +  } + +  static Error deserialize(ChannelT &C, JITSymbolFlags &Flags) { +    JITSymbolFlags::UnderlyingType JITFlags; +    JITSymbolFlags::TargetFlagsType TargetFlags; +    if (auto Err = deserializeSeq(C, JITFlags, TargetFlags)) +      return Err; +    Flags = JITSymbolFlags(static_cast<JITSymbolFlags::FlagNames>(JITFlags), +                           TargetFlags); +    return Error::success(); +  } +}; +  template <> class RPCTypeName<remote::DirectBufferWriter> {  public:    static const char *getName() { return "DirectBufferWriter"; } @@ -83,41 +140,66 @@ public:  namespace remote { -class OrcRemoteTargetRPCAPI -    : public rpc::SingleThreadedRPCEndpoint<rpc::RawByteChannel> { -protected: -  class ResourceIdMgr { -  public: -    using ResourceId = uint64_t; -    static const ResourceId InvalidId = ~0U; - -    ResourceId getNext() { -      if (!FreeIds.empty()) { -        ResourceId I = FreeIds.back(); -        FreeIds.pop_back(); -        return I; -      } -      return NextId++; +class ResourceIdMgr { +public: +  using ResourceId = uint64_t; +  static const ResourceId InvalidId = ~0U; + +  ResourceIdMgr() = default; +  explicit ResourceIdMgr(ResourceId FirstValidId) +    : NextId(std::move(FirstValidId)) {} + +  ResourceId getNext() { +    if (!FreeIds.empty()) { +      ResourceId I = FreeIds.back(); +      FreeIds.pop_back(); +      return I;      } +    assert(NextId + 1 != ~0ULL && "All ids allocated"); +    return NextId++; +  } + +  void release(ResourceId I) { FreeIds.push_back(I); } + +private: +  ResourceId NextId = 1; +  std::vector<ResourceId> FreeIds; +}; -    void release(ResourceId I) { FreeIds.push_back(I); } +/// Registers EH frames on the remote. +namespace eh { -  private: -    ResourceId NextId = 0; -    std::vector<ResourceId> FreeIds; +  /// Registers EH frames on the remote. +  class RegisterEHFrames +      : public rpc::Function<RegisterEHFrames, +                             void(JITTargetAddress Addr, uint32_t Size)> { +  public: +    static const char *getName() { return "RegisterEHFrames"; }    }; -public: -  // FIXME: Remove constructors once MSVC supports synthesizing move-ops. -  OrcRemoteTargetRPCAPI(rpc::RawByteChannel &C) -      : rpc::SingleThreadedRPCEndpoint<rpc::RawByteChannel>(C, true) {} +  /// Deregisters EH frames on the remote. +  class DeregisterEHFrames +      : public rpc::Function<DeregisterEHFrames, +                             void(JITTargetAddress Addr, uint32_t Size)> { +  public: +    static const char *getName() { return "DeregisterEHFrames"; } +  }; + +} // end namespace eh + +/// RPC functions for executing remote code. +namespace exec { +  /// Call an 'int32_t()'-type function on the remote, returns the called +  /// function's return value.    class CallIntVoid        : public rpc::Function<CallIntVoid, int32_t(JITTargetAddress Addr)> {    public:      static const char *getName() { return "CallIntVoid"; }    }; +  /// Call an 'int32_t(int32_t, char**)'-type function on the remote, returns the +  /// called function's return value.    class CallMain        : public rpc::Function<CallMain, int32_t(JITTargetAddress Addr,                                                 std::vector<std::string> Args)> { @@ -125,12 +207,20 @@ public:      static const char *getName() { return "CallMain"; }    }; +  /// Calls a 'void()'-type function on the remote, returns when the called +  /// function completes.    class CallVoidVoid        : public rpc::Function<CallVoidVoid, void(JITTargetAddress FnAddr)> {    public:      static const char *getName() { return "CallVoidVoid"; }    }; +} // end namespace exec + +/// RPC functions for remote memory management / inspection / modification. +namespace mem { + +  /// Creates a memory allocator on the remote.    class CreateRemoteAllocator        : public rpc::Function<CreateRemoteAllocator,                               void(ResourceIdMgr::ResourceId AllocatorID)> { @@ -138,27 +228,68 @@ public:      static const char *getName() { return "CreateRemoteAllocator"; }    }; -  class CreateIndirectStubsOwner -      : public rpc::Function<CreateIndirectStubsOwner, -                             void(ResourceIdMgr::ResourceId StubOwnerID)> { +  /// Destroys a remote allocator, freeing any memory allocated by it. +  class DestroyRemoteAllocator +      : public rpc::Function<DestroyRemoteAllocator, +                             void(ResourceIdMgr::ResourceId AllocatorID)> {    public: -    static const char *getName() { return "CreateIndirectStubsOwner"; } +    static const char *getName() { return "DestroyRemoteAllocator"; }    }; -  class DeregisterEHFrames -      : public rpc::Function<DeregisterEHFrames, -                             void(JITTargetAddress Addr, uint32_t Size)> { +  /// Read a remote memory block. +  class ReadMem +      : public rpc::Function<ReadMem, std::vector<uint8_t>(JITTargetAddress Src, +                                                           uint64_t Size)> {    public: -    static const char *getName() { return "DeregisterEHFrames"; } +    static const char *getName() { return "ReadMem"; }    }; -  class DestroyRemoteAllocator -      : public rpc::Function<DestroyRemoteAllocator, -                             void(ResourceIdMgr::ResourceId AllocatorID)> { +  /// Reserve a block of memory on the remote via the given allocator. +  class ReserveMem +      : public rpc::Function<ReserveMem, +                             JITTargetAddress(ResourceIdMgr::ResourceId AllocID, +                                              uint64_t Size, uint32_t Align)> {    public: -    static const char *getName() { return "DestroyRemoteAllocator"; } +    static const char *getName() { return "ReserveMem"; } +  }; + +  /// Set the memory protection on a memory block. +  class SetProtections +      : public rpc::Function<SetProtections, +                             void(ResourceIdMgr::ResourceId AllocID, +                                  JITTargetAddress Dst, uint32_t ProtFlags)> { +  public: +    static const char *getName() { return "SetProtections"; } +  }; + +  /// Write to a remote memory block. +  class WriteMem +      : public rpc::Function<WriteMem, void(remote::DirectBufferWriter DB)> { +  public: +    static const char *getName() { return "WriteMem"; } +  }; + +  /// Write to a remote pointer. +  class WritePtr : public rpc::Function<WritePtr, void(JITTargetAddress Dst, +                                                       JITTargetAddress Val)> { +  public: +    static const char *getName() { return "WritePtr"; } +  }; + +} // end namespace mem + +/// RPC functions for remote stub and trampoline management. +namespace stubs { + +  /// Creates an indirect stub owner on the remote. +  class CreateIndirectStubsOwner +      : public rpc::Function<CreateIndirectStubsOwner, +                             void(ResourceIdMgr::ResourceId StubOwnerID)> { +  public: +    static const char *getName() { return "CreateIndirectStubsOwner"; }    }; +  /// RPC function for destroying an indirect stubs owner.    class DestroyIndirectStubsOwner        : public rpc::Function<DestroyIndirectStubsOwner,                               void(ResourceIdMgr::ResourceId StubsOwnerID)> { @@ -177,6 +308,7 @@ public:      static const char *getName() { return "EmitIndirectStubs"; }    }; +  /// RPC function to emit the resolver block and return its address.    class EmitResolverBlock : public rpc::Function<EmitResolverBlock, void()> {    public:      static const char *getName() { return "EmitResolverBlock"; } @@ -190,12 +322,10 @@ public:      static const char *getName() { return "EmitTrampolineBlock"; }    }; -  class GetSymbolAddress -      : public rpc::Function<GetSymbolAddress, -                             JITTargetAddress(std::string SymbolName)> { -  public: -    static const char *getName() { return "GetSymbolAddress"; } -  }; +} // end namespace stubs + +/// Miscelaneous RPC functions for dealing with remotes. +namespace utils {    /// GetRemoteInfo result is (Triple, PointerSize, PageSize, TrampolineSize,    ///                          IndirectStubsSize). @@ -207,28 +337,15 @@ public:      static const char *getName() { return "GetRemoteInfo"; }    }; -  class ReadMem -      : public rpc::Function<ReadMem, std::vector<uint8_t>(JITTargetAddress Src, -                                                           uint64_t Size)> { -  public: -    static const char *getName() { return "ReadMem"; } -  }; - -  class RegisterEHFrames -      : public rpc::Function<RegisterEHFrames, -                             void(JITTargetAddress Addr, uint32_t Size)> { -  public: -    static const char *getName() { return "RegisterEHFrames"; } -  }; - -  class ReserveMem -      : public rpc::Function<ReserveMem, -                             JITTargetAddress(ResourceIdMgr::ResourceId AllocID, -                                              uint64_t Size, uint32_t Align)> { +  /// Get the address of a remote symbol. +  class GetSymbolAddress +      : public rpc::Function<GetSymbolAddress, +                             JITTargetAddress(std::string SymbolName)> {    public: -    static const char *getName() { return "ReserveMem"; } +    static const char *getName() { return "GetSymbolAddress"; }    }; +  /// Request that the host execute a compile callback.    class RequestCompile        : public rpc::Function<              RequestCompile, JITTargetAddress(JITTargetAddress TrampolineAddr)> { @@ -236,30 +353,20 @@ public:      static const char *getName() { return "RequestCompile"; }    }; -  class SetProtections -      : public rpc::Function<SetProtections, -                             void(ResourceIdMgr::ResourceId AllocID, -                                  JITTargetAddress Dst, uint32_t ProtFlags)> { -  public: -    static const char *getName() { return "SetProtections"; } -  }; - +  /// Notify the remote and terminate the session.    class TerminateSession : public rpc::Function<TerminateSession, void()> {    public:      static const char *getName() { return "TerminateSession"; }    }; -  class WriteMem -      : public rpc::Function<WriteMem, void(remote::DirectBufferWriter DB)> { -  public: -    static const char *getName() { return "WriteMem"; } -  }; +} // namespace utils -  class WritePtr : public rpc::Function<WritePtr, void(JITTargetAddress Dst, -                                                       JITTargetAddress Val)> { -  public: -    static const char *getName() { return "WritePtr"; } -  }; +class OrcRemoteTargetRPCAPI +    : public rpc::SingleThreadedRPCEndpoint<rpc::RawByteChannel> { +public: +  // FIXME: Remove constructors once MSVC supports synthesizing move-ops. +  OrcRemoteTargetRPCAPI(rpc::RawByteChannel &C) +      : rpc::SingleThreadedRPCEndpoint<rpc::RawByteChannel>(C, true) {}  };  } // end namespace remote | 
