From 13142f98750d56d511aeb3668a72adfb973c0cfb Mon Sep 17 00:00:00 2001 From: lqr Date: Tue, 16 Jul 2024 14:17:19 +0800 Subject: [PATCH] mem: fix image loading in raw cpt mode (#153) Previously, the image file is read into a cow branch of memory, instead of root. When difftesting, nemu cannot read the contents of memory image Change-Id: Id261f189008a34c080be52496a712217c4e8e8e0 --- src/mem/physical.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/mem/physical.cc b/src/mem/physical.cc index 1c73e0e14f..148f235dbe 100644 --- a/src/mem/physical.cc +++ b/src/mem/physical.cc @@ -567,9 +567,7 @@ PhysicalMemory::unserializeStoreFrom(std::string filepath, // For small file, anonymous map + file copy if (enableDedup) { // Create a common ``root'' memory - dedupMemManager->createSharedReadOnlyRoot(size); - // map pmem to one of a branch memory, whose update is not visable to other branches (PRIVATE) - backingStore[store_id].pmem = dedupMemManager->createCopyOnWriteBranch(); + backingStore[store_id].pmem = dedupMemManager->createSharedReadOnlyRoot(size); } else { backingStore[store_id].pmem = (uint8_t*)mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); @@ -582,6 +580,9 @@ PhysicalMemory::unserializeStoreFrom(std::string filepath, lseek(fd, 0, SEEK_SET); auto bytes = read(fd, backingStore[store_id].pmem, file_len); assert(bytes == file_len); + if (enableDedup) { + backingStore[store_id].pmem = dedupMemManager->createCopyOnWriteBranch(); + } } else { // For large file, map to file directly if (enableDedup) {