Skip to content

Commit

Permalink
Create readme.md
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas789 authored Jun 13, 2024
1 parent c197e6a commit afdcb0e
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Implementation

1. Allocate and Deallocate Physical Pages
**Functionality**:

- `allocatePhysicalPage()` uses `mmap` to allocate a 4KB physical page.
- Destructor `~MemoryManager()` uses `munmap` to deallocate physical pages.

```
void* allocatePhysicalPage() {
void* page = mmap(nullptr, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (page == MAP_FAILED) {
std::cerr << "Error while mmapping page " << page << ": " << std::strerror(errno) << std::endl;
return nullptr;
}
physicalPages_.push_back(page);
return page;
}
MemoryManager::~MemoryManager() {
for (void* page : physicalPages_) {
if (munmap(page, PAGE_SIZE) != 0) {
std::cerr << "Error unmapping page at " << page << ": " << std::strerror(errno) << std::endl;
}
}
}
```

0 comments on commit afdcb0e

Please sign in to comment.