VMObject.cpp 836 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/Singleton.h>
  7. #include <Kernel/Memory/MemoryManager.h>
  8. #include <Kernel/Memory/VMObject.h>
  9. namespace Kernel::Memory {
  10. static Singleton<SpinlockProtected<VMObject::AllInstancesList>> s_all_instances;
  11. SpinlockProtected<VMObject::AllInstancesList>& VMObject::all_instances()
  12. {
  13. return s_all_instances;
  14. }
  15. VMObject::VMObject(VMObject const& other)
  16. : m_physical_pages(other.m_physical_pages)
  17. {
  18. all_instances().with([&](auto& list) { list.append(*this); });
  19. }
  20. VMObject::VMObject(size_t size)
  21. : m_physical_pages(ceil_div(size, static_cast<size_t>(PAGE_SIZE)))
  22. {
  23. all_instances().with([&](auto& list) { list.append(*this); });
  24. }
  25. VMObject::~VMObject()
  26. {
  27. VERIFY(m_regions.is_empty());
  28. }
  29. }