PhysicalPage.cpp 895 B

1234567891011121314151617181920212223242526272829303132333435
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <Kernel/Heap/kmalloc.h>
  7. #include <Kernel/VM/MemoryManager.h>
  8. #include <Kernel/VM/PhysicalPage.h>
  9. namespace Kernel {
  10. NonnullRefPtr<PhysicalPage> PhysicalPage::create(PhysicalAddress paddr, bool supervisor, bool may_return_to_freelist)
  11. {
  12. return adopt_ref(*new PhysicalPage(paddr, supervisor, may_return_to_freelist));
  13. }
  14. PhysicalPage::PhysicalPage(PhysicalAddress paddr, bool supervisor, bool may_return_to_freelist)
  15. : m_may_return_to_freelist(may_return_to_freelist)
  16. , m_supervisor(supervisor)
  17. , m_paddr(paddr)
  18. {
  19. }
  20. void PhysicalPage::return_to_freelist() const
  21. {
  22. VERIFY((paddr().get() & ~PAGE_MASK) == 0);
  23. if (m_supervisor)
  24. MM.deallocate_supervisor_physical_page(*this);
  25. else
  26. MM.deallocate_user_physical_page(*this);
  27. }
  28. }