From a09435398ce09e16437d3bddf3c12f39f6ac5fcb Mon Sep 17 00:00:00 2001 From: Roberto Rosmaninho Date: Tue, 11 Mar 2025 16:26:33 -0300 Subject: [PATCH] Adding `munmap_arena_and_reset` and calling it to all semispaces when `free_all_kore_mem` --- include/runtime/arena.h | 14 ++++++++++++++ runtime/collect/collect.cpp | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/include/runtime/arena.h b/include/runtime/arena.h index ba18ff966..8949b3cca 100644 --- a/include/runtime/arena.h +++ b/include/runtime/arena.h @@ -111,6 +111,20 @@ class arena { // allocated within an arena. static char get_arena_semispace_id_of_object(void *ptr); + // Unmaps the current and collection address spaces and resets them and the tripwire. + // This is needed when the client switches thread contexts without properly deallocating + // them. This is not a common use case and shoul be used carefully. + void munmap_arena_and_reset() { + if (current_addr_ptr) + munmap(current_addr_ptr, HYPERBLOCK_SIZE); + if (collection_addr_ptr) + munmap(collection_addr_ptr, HYPERBLOCK_SIZE); + + current_addr_ptr = nullptr; + collection_addr_ptr = nullptr; + tripwire = nullptr; + } + private: void initialize_semispace(); // diff --git a/runtime/collect/collect.cpp b/runtime/collect/collect.cpp index 981b29955..5112c9a71 100644 --- a/runtime/collect/collect.cpp +++ b/runtime/collect/collect.cpp @@ -12,6 +12,7 @@ extern "C" { extern thread_local arena youngspace; extern thread_local arena oldspace; +extern thread_local arena alwaysgcspace; char *youngspace_ptr(void); char *oldspace_ptr(void); @@ -345,5 +346,8 @@ void kore_collect( void free_all_kore_mem() { kore_collect(nullptr, 0, nullptr, true); kore_clear(); + youngspace.munmap_arena_and_reset(); + oldspace.munmap_arena_and_reset(); + alwaysgcspace.munmap_arena_and_reset(); } }