OrcRTBootstrap.cpp 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //===------------------------ OrcRTBootstrap.cpp --------------------------===//
  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 "OrcRTBootstrap.h"
  9. #include "llvm/ExecutionEngine/Orc/Shared/OrcRTBridge.h"
  10. #include "llvm/ExecutionEngine/Orc/Shared/WrapperFunctionUtils.h"
  11. #include "llvm/ExecutionEngine/Orc/TargetProcess/RegisterEHFrames.h"
  12. #include "llvm/ExecutionEngine/Orc/TargetProcess/TargetExecutionUtils.h"
  13. #define DEBUG_TYPE "orc"
  14. using namespace llvm::orc::shared;
  15. namespace llvm {
  16. namespace orc {
  17. namespace rt_bootstrap {
  18. template <typename WriteT, typename SPSWriteT>
  19. static llvm::orc::shared::CWrapperFunctionResult
  20. writeUIntsWrapper(const char *ArgData, size_t ArgSize) {
  21. return WrapperFunction<void(SPSSequence<SPSWriteT>)>::handle(
  22. ArgData, ArgSize,
  23. [](std::vector<WriteT> Ws) {
  24. for (auto &W : Ws)
  25. *W.Addr.template toPtr<decltype(W.Value) *>() = W.Value;
  26. })
  27. .release();
  28. }
  29. static llvm::orc::shared::CWrapperFunctionResult
  30. writeBuffersWrapper(const char *ArgData, size_t ArgSize) {
  31. return WrapperFunction<void(SPSSequence<SPSMemoryAccessBufferWrite>)>::handle(
  32. ArgData, ArgSize,
  33. [](std::vector<tpctypes::BufferWrite> Ws) {
  34. for (auto &W : Ws)
  35. memcpy(W.Addr.template toPtr<char *>(), W.Buffer.data(),
  36. W.Buffer.size());
  37. })
  38. .release();
  39. }
  40. static llvm::orc::shared::CWrapperFunctionResult
  41. runAsMainWrapper(const char *ArgData, size_t ArgSize) {
  42. return WrapperFunction<rt::SPSRunAsMainSignature>::handle(
  43. ArgData, ArgSize,
  44. [](ExecutorAddr MainAddr,
  45. std::vector<std::string> Args) -> int64_t {
  46. return runAsMain(MainAddr.toPtr<int (*)(int, char *[])>(), Args);
  47. })
  48. .release();
  49. }
  50. void addTo(StringMap<ExecutorAddr> &M) {
  51. M[rt::MemoryWriteUInt8sWrapperName] = ExecutorAddr::fromPtr(
  52. &writeUIntsWrapper<tpctypes::UInt8Write,
  53. shared::SPSMemoryAccessUInt8Write>);
  54. M[rt::MemoryWriteUInt16sWrapperName] = ExecutorAddr::fromPtr(
  55. &writeUIntsWrapper<tpctypes::UInt16Write,
  56. shared::SPSMemoryAccessUInt16Write>);
  57. M[rt::MemoryWriteUInt32sWrapperName] = ExecutorAddr::fromPtr(
  58. &writeUIntsWrapper<tpctypes::UInt32Write,
  59. shared::SPSMemoryAccessUInt32Write>);
  60. M[rt::MemoryWriteUInt64sWrapperName] = ExecutorAddr::fromPtr(
  61. &writeUIntsWrapper<tpctypes::UInt64Write,
  62. shared::SPSMemoryAccessUInt64Write>);
  63. M[rt::MemoryWriteBuffersWrapperName] =
  64. ExecutorAddr::fromPtr(&writeBuffersWrapper);
  65. M[rt::RegisterEHFrameSectionWrapperName] =
  66. ExecutorAddr::fromPtr(&llvm_orc_registerEHFrameSectionWrapper);
  67. M[rt::DeregisterEHFrameSectionWrapperName] =
  68. ExecutorAddr::fromPtr(&llvm_orc_deregisterEHFrameSectionWrapper);
  69. M[rt::RunAsMainWrapperName] = ExecutorAddr::fromPtr(&runAsMainWrapper);
  70. }
  71. } // end namespace rt_bootstrap
  72. } // end namespace orc
  73. } // end namespace llvm