[Orc] Provide correct Reservation address for slab allocations
authorAnubhab Ghosh <anubhabghosh.me@gmail.com>
Sat, 20 Aug 2022 20:13:20 +0000 (01:43 +0530)
committerAnubhab Ghosh <anubhabghosh.me@gmail.com>
Sun, 21 Aug 2022 11:06:37 +0000 (16:36 +0530)
When slab allocator is used, the MappingBase is not necessarily
the same as the original reservation base as the allocation could
be a part of the whole reservation.

In this case the original reservation address needs to be passed to
ExecutorSharedMemoryMapperService to associate the new allocation
with the original reservation.

Differential Revision: https://reviews.llvm.org/D132313

llvm/lib/ExecutionEngine/Orc/MemoryMapper.cpp

index 734b5f0..773e6d2 100644 (file)
@@ -11,6 +11,8 @@
 #include "llvm/ExecutionEngine/Orc/Shared/OrcRTBridge.h"
 #include "llvm/Support/WindowsError.h"
 
+#include <algorithm>
+
 #if defined(LLVM_ON_UNIX) && !defined(__ANDROID__)
 #include <fcntl.h>
 #include <sys/mman.h>
@@ -300,8 +302,10 @@ char *SharedMemoryMapper::prepare(ExecutorAddr Addr, size_t ContentSize) {
 
 void SharedMemoryMapper::initialize(MemoryMapper::AllocInfo &AI,
                                     OnInitializedFunction OnInitialized) {
-  auto Reservation = Reservations.find(AI.MappingBase);
-  assert(Reservation != Reservations.end() &&
+  auto Reservation = std::lower_bound(
+      Reservations.rbegin(), Reservations.rend(), AI.MappingBase,
+      [](const auto &A, const auto &B) { return A.first > B; });
+  assert(Reservation != Reservations.rend() &&
          "Attempt to initialize unreserved range");
 
   tpctypes::SharedMemoryFinalizeRequest FR;
@@ -336,7 +340,7 @@ void SharedMemoryMapper::initialize(MemoryMapper::AllocInfo &AI,
 
         OnInitialized(std::move(Result));
       },
-      SAs.Instance, AI.MappingBase, std::move(FR));
+      SAs.Instance, Reservation->first, std::move(FR));
 }
 
 void SharedMemoryMapper::deinitialize(
@@ -418,7 +422,6 @@ SharedMemoryMapper::~SharedMemoryMapper() {
     UnmapViewOfFile(R.second.LocalAddr);
 
 #endif
-
   }
 }