Forráskód Böngészése

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.)
Andreas Kling 3 éve
szülő
commit
f2d5548d7a
2 módosított fájl, 10 hozzáadás és 0 törlés
  1. 8 0
      Kernel/Memory/MemoryManager.cpp
  2. 2 0
      Kernel/Memory/MemoryManager.h

+ 8 - 0
Kernel/Memory/MemoryManager.cpp

@@ -1118,4 +1118,12 @@ void CommittedPhysicalPageSet::uncommit_one()
     MM.uncommit_user_physical_pages({}, 1);
 }
 
+void MemoryManager::copy_physical_page(PhysicalPage& physical_page, u8 page_buffer[PAGE_SIZE])
+{
+    SpinlockLocker locker(s_mm_lock);
+    auto* quickmapped_page = quickmap_page(physical_page);
+    memcpy(page_buffer, quickmapped_page, PAGE_SIZE);
+    unquickmap_page();
+}
+
 }

+ 2 - 0
Kernel/Memory/MemoryManager.h

@@ -240,6 +240,8 @@ public:
     PhysicalPageEntry& get_physical_page_entry(PhysicalAddress);
     PhysicalAddress get_physical_address(PhysicalPage const&);
 
+    void copy_physical_page(PhysicalPage&, u8 page_buffer[PAGE_SIZE]);
+
 private:
     MemoryManager();
     ~MemoryManager();