Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:51

0001 //===----------- ExecutorSharedMemoryMapperService.h ------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_EXECUTIONENGINE_ORC_TARGETPROCESS_EXECUTORSHAREDMEMORYMAPPERSERVICE_H
0010 #define LLVM_EXECUTIONENGINE_ORC_TARGETPROCESS_EXECUTORSHAREDMEMORYMAPPERSERVICE_H
0011 
0012 #include "llvm/ADT/DenseMap.h"
0013 #include "llvm/Config/llvm-config.h" // for LLVM_ON_UNIX
0014 #include "llvm/ExecutionEngine/Orc/Shared/TargetProcessControlTypes.h"
0015 #include "llvm/ExecutionEngine/Orc/TargetProcess/ExecutorBootstrapService.h"
0016 
0017 #include <atomic>
0018 #include <mutex>
0019 
0020 #if defined(_WIN32)
0021 #include <windows.h>
0022 #endif
0023 
0024 namespace llvm {
0025 namespace orc {
0026 namespace rt_bootstrap {
0027 
0028 class ExecutorSharedMemoryMapperService final
0029     : public ExecutorBootstrapService {
0030 public:
0031   ~ExecutorSharedMemoryMapperService(){};
0032 
0033   Expected<std::pair<ExecutorAddr, std::string>> reserve(uint64_t Size);
0034   Expected<ExecutorAddr> initialize(ExecutorAddr Reservation,
0035                                     tpctypes::SharedMemoryFinalizeRequest &FR);
0036 
0037   Error deinitialize(const std::vector<ExecutorAddr> &Bases);
0038   Error release(const std::vector<ExecutorAddr> &Bases);
0039 
0040   Error shutdown() override;
0041   void addBootstrapSymbols(StringMap<ExecutorAddr> &M) override;
0042 
0043 private:
0044   struct Allocation {
0045     std::vector<shared::WrapperFunctionCall> DeinitializationActions;
0046   };
0047   using AllocationMap = DenseMap<ExecutorAddr, Allocation>;
0048 
0049   struct Reservation {
0050     size_t Size;
0051     std::vector<ExecutorAddr> Allocations;
0052 #if defined(_WIN32)
0053     HANDLE SharedMemoryFile;
0054 #endif
0055   };
0056   using ReservationMap = DenseMap<void *, Reservation>;
0057 
0058   static llvm::orc::shared::CWrapperFunctionResult
0059   reserveWrapper(const char *ArgData, size_t ArgSize);
0060 
0061   static llvm::orc::shared::CWrapperFunctionResult
0062   initializeWrapper(const char *ArgData, size_t ArgSize);
0063 
0064   static llvm::orc::shared::CWrapperFunctionResult
0065   deinitializeWrapper(const char *ArgData, size_t ArgSize);
0066 
0067   static llvm::orc::shared::CWrapperFunctionResult
0068   releaseWrapper(const char *ArgData, size_t ArgSize);
0069 
0070 #if (defined(LLVM_ON_UNIX) && !defined(__ANDROID__)) || defined(_WIN32)
0071   std::atomic<int> SharedMemoryCount{0};
0072 #endif
0073 
0074   std::mutex Mutex;
0075   ReservationMap Reservations;
0076   AllocationMap Allocations;
0077 };
0078 
0079 } // namespace rt_bootstrap
0080 } // namespace orc
0081 } // namespace llvm
0082 #endif // LLVM_EXECUTIONENGINE_ORC_TARGETPROCESS_EXECUTORSHAREDMEMORYMAPPERSERVICE_H