/* * Copyright (c) 2018-2021, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #include #include #include namespace Kernel::Memory { static Singleton> s_all_instances; SpinLockProtectedValue& VMObject::all_instances() { return s_all_instances; } VMObject::VMObject(VMObject const& other) : m_physical_pages(other.m_physical_pages) { all_instances().with([&](auto& list) { list.append(*this); }); } VMObject::VMObject(size_t size) : m_physical_pages(ceil_div(size, static_cast(PAGE_SIZE))) { all_instances().with([&](auto& list) { list.append(*this); }); } VMObject::~VMObject() { { ScopedSpinLock lock(m_on_deleted_lock); for (auto& it : m_on_deleted) it->vmobject_deleted(*this); m_on_deleted.clear(); } VERIFY(m_regions.is_empty()); } }