From 7ca72c15bac362447669d38188250705423c138d Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Mon, 13 Oct 2025 11:39:51 +1100 Subject: [PATCH] [orc-rt] Rename SimpleNativeMemoryMap finalize & deallocate. NFCI. This commit renames the "finalize" operation to "initialize", and "deallocate" to "deinitialize". The new names are chosen to better fit the point of view of the ORC-runtime and executor-process: After memory is *reserved* it can be *initialized* with some content, and *deinitialized* to return that memory to the reserved region. This seems more understandable to me than the original scheme, which named these operations after the controller-side JITLinkMemoryManager operations that they partially implemented. I.e. SimpleNativeMemoryMap::finalize implemented the final step of JITLinkMemoryManager::finalize, initializing the memory in the executor; and SimpleNativeMemoryMap::deallocate implemented the final step of JITLinkMemoryManager::deallocate, running dealloc actions and releasing the finalized region. The proper way to think of the relationship between these operations now is that: 1. The final step of finalization is to initialize the memory in the executor. 2. The final step of deallocation is to deinitialize the memory in the executor. --- orc-rt/include/orc-rt/SimpleNativeMemoryMap.h | 35 +++--- orc-rt/lib/executor/SimpleNativeMemoryMap.cpp | 92 +++++++------- .../unittests/SimpleNativeMemoryMapTest.cpp | 115 +++++++++--------- 3 files changed, 125 insertions(+), 117 deletions(-) diff --git a/orc-rt/include/orc-rt/SimpleNativeMemoryMap.h b/orc-rt/include/orc-rt/SimpleNativeMemoryMap.h index 0e516eeaaea60..c0d11e9e752f6 100644 --- a/orc-rt/include/orc-rt/SimpleNativeMemoryMap.h +++ b/orc-rt/include/orc-rt/SimpleNativeMemoryMap.h @@ -31,13 +31,13 @@ namespace orc_rt { /// /// Intances can: /// 1. Reserve address space. -/// 2. Finalize memory regions within reserved memory (copying content, +/// 2. Initialize memory regions within reserved memory (copying content, /// applying permissions, running finalize actions, and recording /// deallocate actions). -/// 3. Deallocate memory regions within reserved memory (running +/// 3. Deinitialize memory regions within reserved memory (running /// deallocate actions and making memory available for future -/// finalize calls (if the system permits this). -/// 4. Release address space, deallocating any not-yet-deallocated finalized +/// initialize calls (if the system permits this). +/// 4. Release address space, deinitializing any remaining initialized /// regions, and returning the address space to the system for reuse (if /// the system permits). class SimpleNativeMemoryMap : public ResourceManager { @@ -58,7 +58,7 @@ class SimpleNativeMemoryMap : public ResourceManager { void releaseMultiple(OnReleaseCompleteFn &&OnComplete, std::vector Addrs); - struct FinalizeRequest { + struct InitializeRequest { struct Segment { AllocGroup AG; char *Address = nullptr; @@ -72,19 +72,19 @@ class SimpleNativeMemoryMap : public ResourceManager { /// Writes content into the requested ranges, applies permissions, and /// performs allocation actions. - using OnFinalizeCompleteFn = move_only_function)>; - void finalize(OnFinalizeCompleteFn &&OnComplete, FinalizeRequest FR); + using OnInitializeCompleteFn = move_only_function)>; + void initialize(OnInitializeCompleteFn &&OnComplete, InitializeRequest FR); /// Runs deallocation actions and resets memory permissions for the requested /// memory. - using OnDeallocateCompleteFn = move_only_function; - void deallocate(OnDeallocateCompleteFn &&OnComplete, void *Base); + using OnDeinitializeCompleteFn = move_only_function; + void deinitialize(OnDeinitializeCompleteFn &&OnComplete, void *Base); - /// Convenience method to deallocate multiple regions with one call. This can - /// be used to save on interprocess communication at the cost of less + /// Convenience method to deinitialize multiple regions with one call. This + /// can be used to save on interprocess communication at the cost of less /// expressive errors. - void deallocateMultiple(OnDeallocateCompleteFn &&OnComplete, - std::vector Bases); + void deinitializeMultiple(OnDeinitializeCompleteFn &&OnComplete, + std::vector Bases); void detach(ResourceManager::OnCompleteFn OnComplete) override; void shutdown(ResourceManager::OnCompleteFn OnComplete) override; @@ -98,8 +98,9 @@ class SimpleNativeMemoryMap : public ResourceManager { void releaseNext(OnReleaseCompleteFn &&OnComplete, std::vector Addrs, bool AnyError, Error LastErr); - void deallocateNext(OnDeallocateCompleteFn &&OnComplete, - std::vector Bases, bool AnyError, Error LastErr); + void deinitializeNext(OnDeinitializeCompleteFn &&OnComplete, + std::vector Bases, bool AnyError, + Error LastErr); void shutdownNext(OnCompleteFn OnComplete, std::vector Bases); Error makeBadSlabError(void *Base, const char *Op); SlabInfo *findSlabInfoFor(void *Base); @@ -121,12 +122,12 @@ orc_rt_SimpleNativeMemoryMap_releaseMultiple_sps_wrapper( orc_rt_SessionRef Session, void *CallCtx, orc_rt_WrapperFunctionReturn Return, orc_rt_WrapperFunctionBuffer ArgBytes); -ORC_RT_SPS_INTERFACE void orc_rt_SimpleNativeMemoryMap_finalize_sps_wrapper( +ORC_RT_SPS_INTERFACE void orc_rt_SimpleNativeMemoryMap_initialize_sps_wrapper( orc_rt_SessionRef Session, void *CallCtx, orc_rt_WrapperFunctionReturn Return, orc_rt_WrapperFunctionBuffer ArgBytes); ORC_RT_SPS_INTERFACE void -orc_rt_SimpleNativeMemoryMap_deallocateMultiple_sps_wrapper( +orc_rt_SimpleNativeMemoryMap_deinitializeMultiple_sps_wrapper( orc_rt_SessionRef Session, void *CallCtx, orc_rt_WrapperFunctionReturn Return, orc_rt_WrapperFunctionBuffer ArgBytes); diff --git a/orc-rt/lib/executor/SimpleNativeMemoryMap.cpp b/orc-rt/lib/executor/SimpleNativeMemoryMap.cpp index 987bd857defe6..bce5c1daa8eea 100644 --- a/orc-rt/lib/executor/SimpleNativeMemoryMap.cpp +++ b/orc-rt/lib/executor/SimpleNativeMemoryMap.cpp @@ -8,8 +8,8 @@ // // SimpleNativeMemoryMap and related APIs. // -// TODO: We don't reset / uncommit pages on deallocate, or on failure during -// finalize. We should do that to reduce memory pressure. +// TODO: We don't reset / uncommit pages on deinitialize, or on failure during +// initialize. We should do that to reduce memory pressure. // //===----------------------------------------------------------------------===// @@ -29,14 +29,16 @@ namespace orc_rt { struct SPSSimpleNativeMemoryMapSegment; template <> -class SPSSerializationTraits { +class SPSSerializationTraits< + SPSSimpleNativeMemoryMapSegment, + SimpleNativeMemoryMap::InitializeRequest::Segment> { using SPSType = SPSTuple>; public: - static bool deserialize(SPSInputBuffer &IB, - SimpleNativeMemoryMap::FinalizeRequest::Segment &S) { + static bool + deserialize(SPSInputBuffer &IB, + SimpleNativeMemoryMap::InitializeRequest::Segment &S) { AllocGroup AG; ExecutorAddr Address; uint64_t Size; @@ -50,17 +52,17 @@ class SPSSerializationTraits -class SPSSerializationTraits { +class SPSSerializationTraits { using SPSType = SPSTuple, SPSSequence>; public: static bool deserialize(SPSInputBuffer &IB, - SimpleNativeMemoryMap::FinalizeRequest &FR) { + SimpleNativeMemoryMap::InitializeRequest &FR) { return SPSType::AsArgList::deserialize(IB, FR.Segments, FR.AAPs); } }; @@ -121,13 +123,13 @@ void SimpleNativeMemoryMap::releaseMultiple(OnReleaseCompleteFn &&OnComplete, releaseNext(std::move(OnComplete), std::move(Addrs), false, Error::success()); } -void SimpleNativeMemoryMap::finalize(OnFinalizeCompleteFn &&OnComplete, - FinalizeRequest FR) { +void SimpleNativeMemoryMap::initialize(OnInitializeCompleteFn &&OnComplete, + InitializeRequest FR) { void *Base = nullptr; - // TODO: Record finalize segments for release. - // std::vector> FinalizeSegments; + // TODO: Record initialize segments for release. + // std::vector> InitializeSegments; // Check segment validity before proceeding. for (auto &S : FR.Segments) { @@ -166,9 +168,10 @@ void SimpleNativeMemoryMap::finalize(OnFinalizeCompleteFn &&OnComplete, } if (!Base) - return OnComplete(make_error( - "SimpleNativeMemoryMap finalize error: finalization requires at least " - "one standard-lifetime segment")); + return OnComplete( + make_error("SimpleNativeMemoryMap initialize error: " + "finalization requires at least " + "one standard-lifetime segment")); auto DeallocActions = runFinalizeActions(std::move(FR.AAPs)); if (!DeallocActions) @@ -182,8 +185,8 @@ void SimpleNativeMemoryMap::finalize(OnFinalizeCompleteFn &&OnComplete, OnComplete(Base); } -void SimpleNativeMemoryMap::deallocate(OnDeallocateCompleteFn &&OnComplete, - void *Base) { +void SimpleNativeMemoryMap::deinitialize(OnDeinitializeCompleteFn &&OnComplete, + void *Base) { std::vector DAAs; { @@ -191,16 +194,17 @@ void SimpleNativeMemoryMap::deallocate(OnDeallocateCompleteFn &&OnComplete, auto *SI = findSlabInfoFor(Base); if (!SI) { Lock.unlock(); - return OnComplete(makeBadSlabError(Base, "finalize")); + return OnComplete(makeBadSlabError(Base, "deinitialize")); } auto I = SI->DeallocActions.find(Base); if (I == SI->DeallocActions.end()) { Lock.unlock(); std::ostringstream ErrMsg; - ErrMsg << "SimpleNativeMemoryMap deallocate error: no deallocate actions " - "registered for segment base address " - << Base; + ErrMsg + << "SimpleNativeMemoryMap deinitialize error: no deallocate actions " + "registered for segment base address " + << Base; return OnComplete(make_error(ErrMsg.str())); } @@ -212,10 +216,10 @@ void SimpleNativeMemoryMap::deallocate(OnDeallocateCompleteFn &&OnComplete, OnComplete(Error::success()); } -void SimpleNativeMemoryMap::deallocateMultiple( - OnDeallocateCompleteFn &&OnComplete, std::vector Bases) { - deallocateNext(std::move(OnComplete), std::move(Bases), false, - Error::success()); +void SimpleNativeMemoryMap::deinitializeMultiple( + OnDeinitializeCompleteFn &&OnComplete, std::vector Bases) { + deinitializeNext(std::move(OnComplete), std::move(Bases), false, + Error::success()); } void SimpleNativeMemoryMap::detach(ResourceManager::OnCompleteFn OnComplete) { @@ -268,9 +272,9 @@ void SimpleNativeMemoryMap::releaseNext(OnReleaseCompleteFn &&OnComplete, NextAddr); } -void SimpleNativeMemoryMap::deallocateNext(OnDeallocateCompleteFn &&OnComplete, - std::vector Addrs, - bool AnyError, Error LastErr) { +void SimpleNativeMemoryMap::deinitializeNext( + OnDeinitializeCompleteFn &&OnComplete, std::vector Addrs, + bool AnyError, Error LastErr) { // TODO: Log error? if (LastErr) { consumeError(std::move(LastErr)); @@ -282,17 +286,17 @@ void SimpleNativeMemoryMap::deallocateNext(OnDeallocateCompleteFn &&OnComplete, return OnComplete(Error::success()); return OnComplete( - make_error("Failed to deallocate some addresses")); + make_error("Failed to deinitialize some addresses")); } void *NextAddr = Addrs.back(); Addrs.pop_back(); - deallocate( + deinitialize( [this, OnComplete = std::move(OnComplete), AnyError = AnyError, Addrs = std::move(Addrs)](Error Err) mutable { - deallocateNext(std::move(OnComplete), std::move(Addrs), AnyError, - std::move(Err)); + deinitializeNext(std::move(OnComplete), std::move(Addrs), AnyError, + std::move(Err)); }, NextAddr); } @@ -346,15 +350,15 @@ Error SimpleNativeMemoryMap::recordDeallocActions( auto *SI = findSlabInfoFor(Base); if (!SI) { Lock.unlock(); - return makeBadSlabError(Base, "deallocate"); + return makeBadSlabError(Base, "deinitialize"); } auto I = SI->DeallocActions.find(Base); if (I != SI->DeallocActions.end()) { Lock.unlock(); std::ostringstream ErrMsg; - ErrMsg << "SimpleNativeMemoryMap finalize error: segment base address " - "reused in subsequent finalize call"; + ErrMsg << "SimpleNativeMemoryMap initialize error: segment base address " + "reused in subsequent initialize call"; return make_error(ErrMsg.str()); } @@ -383,19 +387,19 @@ orc_rt_SimpleNativeMemoryMap_releaseMultiple_sps_wrapper( &SimpleNativeMemoryMap::releaseMultiple)); } -ORC_RT_SPS_INTERFACE void orc_rt_SimpleNativeMemoryMap_finalize_sps_wrapper( +ORC_RT_SPS_INTERFACE void orc_rt_SimpleNativeMemoryMap_initialize_sps_wrapper( orc_rt_SessionRef Session, void *CallCtx, orc_rt_WrapperFunctionReturn Return, orc_rt_WrapperFunctionBuffer ArgBytes) { using Sig = SPSExpected( - SPSExecutorAddr, SPSSimpleNativeMemoryMapFinalizeRequest); - SPSWrapperFunction::handle( - Session, CallCtx, Return, ArgBytes, - WrapperFunction::handleWithAsyncMethod(&SimpleNativeMemoryMap::finalize)); + SPSExecutorAddr, SPSSimpleNativeMemoryMapInitializeRequest); + SPSWrapperFunction::handle(Session, CallCtx, Return, ArgBytes, + WrapperFunction::handleWithAsyncMethod( + &SimpleNativeMemoryMap::initialize)); } ORC_RT_SPS_INTERFACE void -orc_rt_SimpleNativeMemoryMap_deallocateMultiple_sps_wrapper( +orc_rt_SimpleNativeMemoryMap_deinitializeMultiple_sps_wrapper( orc_rt_SessionRef Session, void *CallCtx, orc_rt_WrapperFunctionReturn Return, orc_rt_WrapperFunctionBuffer ArgBytes) { @@ -403,7 +407,7 @@ orc_rt_SimpleNativeMemoryMap_deallocateMultiple_sps_wrapper( SPSWrapperFunction::handle( Session, CallCtx, Return, ArgBytes, WrapperFunction::handleWithAsyncMethod( - &SimpleNativeMemoryMap::deallocateMultiple)); + &SimpleNativeMemoryMap::deinitializeMultiple)); } } // namespace orc_rt diff --git a/orc-rt/unittests/SimpleNativeMemoryMapTest.cpp b/orc-rt/unittests/SimpleNativeMemoryMapTest.cpp index c54d79154cc30..c79388665498c 100644 --- a/orc-rt/unittests/SimpleNativeMemoryMapTest.cpp +++ b/orc-rt/unittests/SimpleNativeMemoryMapTest.cpp @@ -26,14 +26,14 @@ namespace orc_rt { struct SPSSimpleNativeMemoryMapSegment; -/// A SimpleNativeMemoryMap::FinalizeRequest::Segment plus segment content (if +/// A SimpleNativeMemoryMap::InitializeRequest::Segment plus segment content (if /// segment content type is regular). struct TestSNMMSegment - : public SimpleNativeMemoryMap::FinalizeRequest::Segment { + : public SimpleNativeMemoryMap::InitializeRequest::Segment { TestSNMMSegment(AllocGroup AG, char *Address, size_t Size, std::vector C = {}) - : SimpleNativeMemoryMap::FinalizeRequest::Segment( + : SimpleNativeMemoryMap::InitializeRequest::Segment( {AG, Address, Size, {}}), OwnedContent(std::move(C)) { this->Content = {OwnedContent.data(), OwnedContent.size()}; @@ -60,25 +60,25 @@ class SPSSerializationTraits { } }; -struct SPSSimpleNativeMemoryMapFinalizeRequest; +struct SPSSimpleNativeMemoryMapInitializeRequest; -struct TestSNMMFinalizeRequest { +struct TestSNMMInitializeRequest { std::vector Segments; std::vector AAPs; }; template <> -class SPSSerializationTraits { +class SPSSerializationTraits { using SPSType = SPSTuple, SPSSequence>; public: - static size_t size(const TestSNMMFinalizeRequest &FR) { + static size_t size(const TestSNMMInitializeRequest &FR) { return SPSType::AsArgList::size(FR.Segments, FR.AAPs); } static bool serialize(SPSOutputBuffer &OB, - const TestSNMMFinalizeRequest &FR) { + const TestSNMMInitializeRequest &FR) { return SPSType::AsArgList::serialize(OB, FR.Segments, FR.AAPs); } }; @@ -118,24 +118,26 @@ static void snmm_releaseMultiple(OnCompleteFn &&OnComplete, } template -static void snmm_finalize(OnCompleteFn &&OnComplete, - SimpleNativeMemoryMap *Instance, - TestSNMMFinalizeRequest FR) { +static void snmm_initialize(OnCompleteFn &&OnComplete, + SimpleNativeMemoryMap *Instance, + TestSNMMInitializeRequest FR) { using SPSSig = SPSExpected( - SPSExecutorAddr, SPSSimpleNativeMemoryMapFinalizeRequest); + SPSExecutorAddr, SPSSimpleNativeMemoryMapInitializeRequest); SPSWrapperFunction::call( - DirectCaller(nullptr, orc_rt_SimpleNativeMemoryMap_finalize_sps_wrapper), + DirectCaller(nullptr, + orc_rt_SimpleNativeMemoryMap_initialize_sps_wrapper), std::forward(OnComplete), Instance, std::move(FR)); } template -static void snmm_deallocateMultiple(OnCompleteFn &&OnComplete, - SimpleNativeMemoryMap *Instance, - span Base) { +static void snmm_deinitializeMultiple(OnCompleteFn &&OnComplete, + SimpleNativeMemoryMap *Instance, + span Base) { using SPSSig = SPSError(SPSExecutorAddr, SPSSequence); SPSWrapperFunction::call( - DirectCaller(nullptr, - orc_rt_SimpleNativeMemoryMap_deallocateMultiple_sps_wrapper), + DirectCaller( + nullptr, + orc_rt_SimpleNativeMemoryMap_deinitializeMultiple_sps_wrapper), std::forward(OnComplete), Instance, Base); } @@ -180,9 +182,9 @@ read_value_sps_allocaction(const char *ArgData, size_t ArgSize) { TEST(SimpleNativeMemoryMap, FullPipelineForOneRWSegment) { // Test that we can: // 1. reserve some address space. - // 2. finalize a range within it as read/write, and that finalize actions + // 2. initialize a range within it as read/write, and that finalize actions // are applied as expected. - // 3. deallocate the finalized range, with deallocation actions applied as + // 3. deinitialize the initialized range, with deallocation actions applied as // expected. // 4. release the address range. @@ -191,12 +193,13 @@ TEST(SimpleNativeMemoryMap, FullPipelineForOneRWSegment) { snmm_reserve(waitFor(ReserveAddr), SNMM.get(), 1024 * 1024 * 1024); void *Addr = cantFail(cantFail(ReserveAddr.get())); - std::future>> FinalizeKey; - TestSNMMFinalizeRequest FR; - char *FinalizeBase = // Finalize addr at non-zero (64kb) offset from base. + std::future>> InitializeKey; + TestSNMMInitializeRequest FR; + char *InitializeBase = // Initialize addr at non-zero (64kb) offset from base. reinterpret_cast(Addr) + 64 * 1024; uint64_t SentinelValue1 = 0; // Read from pre-filled content - uint64_t SentinelValue2 = 0; // Written in finalize, read back during dealloc. + uint64_t SentinelValue2 = + 0; // Written in initialize, read back during dealloc. uint64_t SentinelValue3 = 42; // Read from zero-filled region. // Build initial content vector. @@ -205,14 +208,14 @@ TEST(SimpleNativeMemoryMap, FullPipelineForOneRWSegment) { memcpy(Content.data(), &SentinelValue3, sizeof(uint64_t)); memcpy(Content.data() + sizeof(uint64_t), &SentinelValue1, sizeof(uint64_t)); - FR.Segments.push_back({MemProt::Read | MemProt::Write, FinalizeBase, + FR.Segments.push_back({MemProt::Read | MemProt::Write, InitializeBase, 64 * 1024, std::move(Content)}); // Read initial content into Sentinel 1. FR.AAPs.push_back({ *MakeAllocAction::from( read_value_sps_allocaction, ExecutorAddr::fromPtr(&SentinelValue1), - ExecutorAddr::fromPtr(FinalizeBase)), + ExecutorAddr::fromPtr(InitializeBase)), {} // No dealloc action. }); @@ -220,30 +223,30 @@ TEST(SimpleNativeMemoryMap, FullPipelineForOneRWSegment) { FR.AAPs.push_back( {*MakeAllocAction::from( write_value_sps_allocaction, - ExecutorAddr::fromPtr(FinalizeBase) + sizeof(uint64_t), + ExecutorAddr::fromPtr(InitializeBase) + sizeof(uint64_t), uint64_t(42)), *MakeAllocAction::from( read_value_sps_allocaction, ExecutorAddr::fromPtr(&SentinelValue2), - ExecutorAddr::fromPtr(FinalizeBase) + sizeof(uint64_t))}); + ExecutorAddr::fromPtr(InitializeBase) + sizeof(uint64_t))}); // Read first 64 bits of the zero-fill region. FR.AAPs.push_back({ *MakeAllocAction::from( read_value_sps_allocaction, ExecutorAddr::fromPtr(&SentinelValue3), - ExecutorAddr::fromPtr(FinalizeBase) + sizeof(uint64_t) * 2), + ExecutorAddr::fromPtr(InitializeBase) + sizeof(uint64_t) * 2), {} // No dealloc action. }); - snmm_finalize(waitFor(FinalizeKey), SNMM.get(), std::move(FR)); - void *FinalizeKeyAddr = cantFail(cantFail(FinalizeKey.get())); + snmm_initialize(waitFor(InitializeKey), SNMM.get(), std::move(FR)); + void *InitializeKeyAddr = cantFail(cantFail(InitializeKey.get())); EXPECT_EQ(SentinelValue1, 42U); EXPECT_EQ(SentinelValue2, 0U); EXPECT_EQ(SentinelValue3, 0U); std::future> DeallocResult; - snmm_deallocateMultiple(waitFor(DeallocResult), SNMM.get(), - {&FinalizeKeyAddr, 1}); + snmm_deinitializeMultiple(waitFor(DeallocResult), SNMM.get(), + {&InitializeKeyAddr, 1}); cantFail(cantFail(DeallocResult.get())); EXPECT_EQ(SentinelValue1, 42U); @@ -255,33 +258,33 @@ TEST(SimpleNativeMemoryMap, FullPipelineForOneRWSegment) { cantFail(cantFail(ReleaseResult.get())); } -TEST(SimpleNativeMemoryMap, ReserveFinalizeShutdown) { - // Test that memory is deallocated in the case where we reserve and finalize - // some memory, then just shut down the memory manager. +TEST(SimpleNativeMemoryMap, ReserveInitializeShutdown) { + // Test that memory is deinitialized in the case where we reserve and + // initialize some memory, then just shut down the memory manager. auto SNMM = std::make_unique(); std::future>> ReserveAddr; snmm_reserve(waitFor(ReserveAddr), SNMM.get(), 1024 * 1024 * 1024); void *Addr = cantFail(cantFail(ReserveAddr.get())); - std::future>> FinalizeKey; - TestSNMMFinalizeRequest FR; - char *FinalizeBase = // Finalize addr at non-zero (64kb) offset from base. + std::future>> InitializeKey; + TestSNMMInitializeRequest FR; + char *InitializeBase = // Initialize addr at non-zero (64kb) offset from base. reinterpret_cast(Addr) + 64 * 1024; uint64_t SentinelValue = 0; FR.Segments.push_back( - {MemProt::Read | MemProt::Write, FinalizeBase, 64 * 1024}); + {MemProt::Read | MemProt::Write, InitializeBase, 64 * 1024}); FR.AAPs.push_back( {*MakeAllocAction::from( - write_value_sps_allocaction, ExecutorAddr::fromPtr(FinalizeBase), + write_value_sps_allocaction, ExecutorAddr::fromPtr(InitializeBase), uint64_t(42)), *MakeAllocAction::from( read_value_sps_allocaction, ExecutorAddr::fromPtr(&SentinelValue), - ExecutorAddr::fromPtr(FinalizeBase))}); - snmm_finalize(waitFor(FinalizeKey), SNMM.get(), std::move(FR)); - cantFail(cantFail(FinalizeKey.get())); + ExecutorAddr::fromPtr(InitializeBase))}); + snmm_initialize(waitFor(InitializeKey), SNMM.get(), std::move(FR)); + cantFail(cantFail(InitializeKey.get())); EXPECT_EQ(SentinelValue, 0U); @@ -292,33 +295,33 @@ TEST(SimpleNativeMemoryMap, ReserveFinalizeShutdown) { EXPECT_EQ(SentinelValue, 42); } -TEST(SimpleNativeMemoryMap, ReserveFinalizeDetachShutdown) { - // Test that memory is deallocated in the case where we reserve and finalize - // some memory, then just shut down the memory manager. +TEST(SimpleNativeMemoryMap, ReserveInitializeDetachShutdown) { + // Test that memory is deinitialized in the case where we reserve and + // initialize some memory, then just shut down the memory manager. auto SNMM = std::make_unique(); std::future>> ReserveAddr; snmm_reserve(waitFor(ReserveAddr), SNMM.get(), 1024 * 1024 * 1024); void *Addr = cantFail(cantFail(ReserveAddr.get())); - std::future>> FinalizeKey; - TestSNMMFinalizeRequest FR; - char *FinalizeBase = // Finalize addr at non-zero (64kb) offset from base. + std::future>> InitializeKey; + TestSNMMInitializeRequest FR; + char *InitializeBase = // Initialize addr at non-zero (64kb) offset from base. reinterpret_cast(Addr) + 64 * 1024; uint64_t SentinelValue = 0; FR.Segments.push_back( - {MemProt::Read | MemProt::Write, FinalizeBase, 64 * 1024}); + {MemProt::Read | MemProt::Write, InitializeBase, 64 * 1024}); FR.AAPs.push_back( {*MakeAllocAction::from( - write_value_sps_allocaction, ExecutorAddr::fromPtr(FinalizeBase), + write_value_sps_allocaction, ExecutorAddr::fromPtr(InitializeBase), uint64_t(42)), *MakeAllocAction::from( read_value_sps_allocaction, ExecutorAddr::fromPtr(&SentinelValue), - ExecutorAddr::fromPtr(FinalizeBase))}); - snmm_finalize(waitFor(FinalizeKey), SNMM.get(), std::move(FR)); - cantFail(cantFail(FinalizeKey.get())); + ExecutorAddr::fromPtr(InitializeBase))}); + snmm_initialize(waitFor(InitializeKey), SNMM.get(), std::move(FR)); + cantFail(cantFail(InitializeKey.get())); EXPECT_EQ(SentinelValue, 0U);