VMObject.cpp 1016 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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<SpinLockProtectedValue<VMObject::AllInstancesList>> s_all_instances;
  11. SpinLockProtectedValue<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. {
  28. ScopedSpinLock lock(m_on_deleted_lock);
  29. for (auto& it : m_on_deleted)
  30. it->vmobject_deleted(*this);
  31. m_on_deleted.clear();
  32. }
  33. VERIFY(m_regions.is_empty());
  34. }
  35. }