VMObject.cpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. ErrorOr<FixedArray<RefPtr<PhysicalPage>>> VMObject::try_clone_physical_pages() const
  16. {
  17. return m_physical_pages.try_clone();
  18. }
  19. ErrorOr<FixedArray<RefPtr<PhysicalPage>>> VMObject::try_create_physical_pages(size_t size)
  20. {
  21. return FixedArray<RefPtr<PhysicalPage>>::try_create(ceil_div(size, static_cast<size_t>(PAGE_SIZE)));
  22. }
  23. VMObject::VMObject(FixedArray<RefPtr<PhysicalPage>>&& new_physical_pages)
  24. : m_physical_pages(move(new_physical_pages))
  25. {
  26. all_instances().with([&](auto& list) { list.append(*this); });
  27. }
  28. VMObject::~VMObject()
  29. {
  30. VERIFY(m_regions.is_empty());
  31. }
  32. }