diff --git a/src/mem/physical.cc b/src/mem/physical.cc index a7e261ff5a..08707ebb8a 100644 --- a/src/mem/physical.cc +++ b/src/mem/physical.cc @@ -55,6 +55,7 @@ #include "debug/Checkpoint.hh" #include "mem/abstract_mem.hh" #include "sim/serialize.hh" +#include "sim/sim_exit.hh" /** * On Linux, MAP_NORESERVE allow us to simulate a very large memory @@ -77,10 +78,16 @@ namespace memory PhysicalMemory::PhysicalMemory(const std::string& _name, const std::vector& _memories, bool mmap_using_noreserve, - const std::string& shared_backstore) : + const std::string& shared_backstore, + bool auto_unlink_shared_backstore) : _name(_name), size(0), mmapUsingNoReserve(mmap_using_noreserve), sharedBackstore(shared_backstore), sharedBackstoreSize(0) { + // Register cleanup callback if requested. + if (auto_unlink_shared_backstore && !sharedBackstore.empty()) { + registerExitCallback([=]() { shm_unlink(shared_backstore.c_str()); }); + } + if (mmap_using_noreserve) warn("Not reserving swap space. May cause SIGSEGV on actual usage\n"); diff --git a/src/mem/physical.hh b/src/mem/physical.hh index bb90664dce..ff0dc61a3d 100644 --- a/src/mem/physical.hh +++ b/src/mem/physical.hh @@ -174,7 +174,8 @@ class PhysicalMemory : public Serializable PhysicalMemory(const std::string& _name, const std::vector& _memories, bool mmap_using_noreserve, - const std::string& shared_backstore); + const std::string& shared_backstore, + bool auto_unlink_shared_backstore); /** * Unmap all the backing store we have used. diff --git a/src/sim/System.py b/src/sim/System.py index 499cf9bd07..b5bd5df363 100644 --- a/src/sim/System.py +++ b/src/sim/System.py @@ -87,6 +87,9 @@ class System(SimObject): shared_backstore = Param.String("", "backstore's shmem segment filename, " "use to directly address the backstore from another host-OS process. " "Leave this empty to unset the MAP_SHARED flag.") + auto_unlink_shared_backstore = Param.Bool(False, "Automatically remove the " + "shmem segment file upon destruction. This is used only if " + "shared_backstore is non-empty.") cache_line_size = Param.Unsigned(64, "Cache line size in bytes") diff --git a/src/sim/system.cc b/src/sim/system.cc index d5e5e3f5a4..b7fba8a356 100644 --- a/src/sim/system.cc +++ b/src/sim/system.cc @@ -182,7 +182,7 @@ System::System(const Params &p) physProxy(_systemPort, p.cache_line_size), workload(p.workload), physmem(name() + ".physmem", p.memories, p.mmap_using_noreserve, - p.shared_backstore), + p.shared_backstore, p.auto_unlink_shared_backstore), ShadowRomRanges(p.shadow_rom_ranges.begin(), p.shadow_rom_ranges.end()), memoryMode(p.mem_mode),