2020-01-18 11:38:21 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 11:38:21 +03:00
|
|
|
*/
|
|
|
|
|
2019-06-07 12:43:58 +03:00
|
|
|
#include <Kernel/VM/MemoryManager.h>
|
|
|
|
#include <Kernel/VM/VMObject.h>
|
2019-04-03 16:13:07 +03:00
|
|
|
|
2020-02-16 03:27:42 +03:00
|
|
|
namespace Kernel {
|
|
|
|
|
2019-08-07 19:06:17 +03:00
|
|
|
VMObject::VMObject(const VMObject& other)
|
2019-08-07 21:12:50 +03:00
|
|
|
: m_physical_pages(other.m_physical_pages)
|
2019-04-03 16:13:07 +03:00
|
|
|
{
|
2019-12-19 21:13:44 +03:00
|
|
|
MM.register_vmobject(*this);
|
2019-04-03 16:13:07 +03:00
|
|
|
}
|
|
|
|
|
2021-02-26 15:32:43 +03:00
|
|
|
VMObject::VMObject()
|
|
|
|
{
|
|
|
|
MM.register_vmobject(*this);
|
|
|
|
}
|
|
|
|
|
2019-08-07 21:12:50 +03:00
|
|
|
VMObject::VMObject(size_t size)
|
2019-04-03 16:13:07 +03:00
|
|
|
{
|
2021-03-04 19:50:05 +03:00
|
|
|
m_physical_pages.resize(ceil_div(size, static_cast<size_t>(PAGE_SIZE)));
|
2019-12-19 21:13:44 +03:00
|
|
|
MM.register_vmobject(*this);
|
2019-04-03 16:13:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
VMObject::~VMObject()
|
|
|
|
{
|
2020-12-22 09:21:58 +03:00
|
|
|
{
|
|
|
|
ScopedSpinLock lock(m_on_deleted_lock);
|
|
|
|
for (auto& it : m_on_deleted)
|
|
|
|
it->vmobject_deleted(*this);
|
|
|
|
m_on_deleted.clear();
|
|
|
|
}
|
|
|
|
|
2019-12-19 21:13:44 +03:00
|
|
|
MM.unregister_vmobject(*this);
|
2021-02-23 22:42:32 +03:00
|
|
|
VERIFY(m_regions_count.load(AK::MemoryOrder::memory_order_relaxed) == 0);
|
2019-04-03 16:13:07 +03:00
|
|
|
}
|
2020-02-16 03:27:42 +03:00
|
|
|
|
|
|
|
}
|