Skip to content

Commit

Permalink
mem: fix image loading in raw cpt mode (#153)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
notlqr authored Jul 16, 2024
1 parent fbb3093 commit 13142f9
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/mem/physical.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand Down

0 comments on commit 13142f9

Please sign in to comment.