Skip to content

Commit f2d5548

Browse files
committed
Kernel: Add MemoryManager::copy_physical_page()
This is a handy helper that copies out the full contents of a physical page into a caller-provided buffer. It uses quickmapping internally (and takes the MM lock for the duration.)
1 parent c4a7863 commit f2d5548

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

Kernel/Memory/MemoryManager.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,4 +1118,12 @@ void CommittedPhysicalPageSet::uncommit_one()
11181118
MM.uncommit_user_physical_pages({}, 1);
11191119
}
11201120

1121+
void MemoryManager::copy_physical_page(PhysicalPage& physical_page, u8 page_buffer[PAGE_SIZE])
1122+
{
1123+
SpinlockLocker locker(s_mm_lock);
1124+
auto* quickmapped_page = quickmap_page(physical_page);
1125+
memcpy(page_buffer, quickmapped_page, PAGE_SIZE);
1126+
unquickmap_page();
1127+
}
1128+
11211129
}

Kernel/Memory/MemoryManager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,8 @@ class MemoryManager {
240240
PhysicalPageEntry& get_physical_page_entry(PhysicalAddress);
241241
PhysicalAddress get_physical_address(PhysicalPage const&);
242242

243+
void copy_physical_page(PhysicalPage&, u8 page_buffer[PAGE_SIZE]);
244+
243245
private:
244246
MemoryManager();
245247
~MemoryManager();

0 commit comments

Comments
 (0)