PhysicalPage.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include <Kernel/VM/PhysicalPage.h>
  2. #include <Kernel/VM/MemoryManager.h>
  3. #include <Kernel/kmalloc.h>
  4. Retained<PhysicalPage> PhysicalPage::create_eternal(PhysicalAddress paddr, bool supervisor)
  5. {
  6. void* slot = kmalloc_eternal(sizeof(PhysicalPage));
  7. new (slot) PhysicalPage(paddr, supervisor);
  8. return adopt(*(PhysicalPage*)slot);
  9. }
  10. Retained<PhysicalPage> PhysicalPage::create(PhysicalAddress paddr, bool supervisor)
  11. {
  12. void* slot = kmalloc(sizeof(PhysicalPage));
  13. new (slot) PhysicalPage(paddr, supervisor, false);
  14. return adopt(*(PhysicalPage*)slot);
  15. }
  16. PhysicalPage::PhysicalPage(PhysicalAddress paddr, bool supervisor, bool may_return_to_freelist)
  17. : m_may_return_to_freelist(may_return_to_freelist)
  18. , m_supervisor(supervisor)
  19. , m_paddr(paddr)
  20. {
  21. if (supervisor)
  22. ++MemoryManager::s_super_physical_pages_in_existence;
  23. else
  24. ++MemoryManager::s_user_physical_pages_in_existence;
  25. }
  26. void PhysicalPage::return_to_freelist()
  27. {
  28. ASSERT((paddr().get() & ~PAGE_MASK) == 0);
  29. InterruptDisabler disabler;
  30. m_retain_count = 1;
  31. if (m_supervisor)
  32. MM.m_free_supervisor_physical_pages.append(adopt(*this));
  33. else
  34. MM.m_free_physical_pages.append(adopt(*this));
  35. #ifdef MM_DEBUG
  36. dbgprintf("MM: P%x released to freelist\n", m_paddr.get());
  37. #endif
  38. }