mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 06:37:44 +00:00
Kernel: Make Region single-owner instead of ref-counted
This simplifies the ownership model and makes Region easier to reason about. Userspace Regions are now primarily kept by Process::m_regions. Kernel Regions are kept in various OwnPtr<Regions>'s. Regions now only ever get unmapped when they are destroyed.
This commit is contained in:
parent
7a7f6a24e9
commit
7f9a33dba1
9 changed files with 44 additions and 41 deletions
|
@ -444,13 +444,13 @@ PageFaultResponse MemoryManager::handle_page_fault(const PageFault& fault)
|
|||
return PageFaultResponse::ShouldCrash;
|
||||
}
|
||||
|
||||
RefPtr<Region> MemoryManager::allocate_kernel_region(size_t size, const StringView& name, bool user_accessible, bool should_commit)
|
||||
OwnPtr<Region> MemoryManager::allocate_kernel_region(size_t size, const StringView& name, bool user_accessible, bool should_commit)
|
||||
{
|
||||
InterruptDisabler disabler;
|
||||
ASSERT(!(size % PAGE_SIZE));
|
||||
auto range = kernel_page_directory().range_allocator().allocate_anywhere(size);
|
||||
ASSERT(range.is_valid());
|
||||
RefPtr<Region> region;
|
||||
OwnPtr<Region> region;
|
||||
if (user_accessible)
|
||||
region = Region::create_user_accessible(range, name, PROT_READ | PROT_WRITE | PROT_EXEC, false);
|
||||
else
|
||||
|
@ -462,7 +462,7 @@ RefPtr<Region> MemoryManager::allocate_kernel_region(size_t size, const StringVi
|
|||
return region;
|
||||
}
|
||||
|
||||
RefPtr<Region> MemoryManager::allocate_user_accessible_kernel_region(size_t size, const StringView& name)
|
||||
OwnPtr<Region> MemoryManager::allocate_user_accessible_kernel_region(size_t size, const StringView& name)
|
||||
{
|
||||
return allocate_kernel_region(size, name, true);
|
||||
}
|
||||
|
|
|
@ -71,8 +71,8 @@ public:
|
|||
|
||||
void map_for_kernel(VirtualAddress, PhysicalAddress);
|
||||
|
||||
RefPtr<Region> allocate_kernel_region(size_t, const StringView& name, bool user_accessible = false, bool should_commit = true);
|
||||
RefPtr<Region> allocate_user_accessible_kernel_region(size_t, const StringView& name);
|
||||
OwnPtr<Region> allocate_kernel_region(size_t, const StringView& name, bool user_accessible = false, bool should_commit = true);
|
||||
OwnPtr<Region> allocate_user_accessible_kernel_region(size_t, const StringView& name);
|
||||
void map_region_at_address(PageDirectory&, Region&, VirtualAddress);
|
||||
|
||||
unsigned user_physical_pages() const { return m_user_physical_pages; }
|
||||
|
|
|
@ -50,7 +50,7 @@ Region::~Region()
|
|||
MM.unregister_region(*this);
|
||||
}
|
||||
|
||||
NonnullRefPtr<Region> Region::clone()
|
||||
NonnullOwnPtr<Region> Region::clone()
|
||||
{
|
||||
ASSERT(current);
|
||||
|
||||
|
@ -123,30 +123,30 @@ size_t Region::amount_shared() const
|
|||
return bytes;
|
||||
}
|
||||
|
||||
NonnullRefPtr<Region> Region::create_user_accessible(const Range& range, const StringView& name, u8 access, bool cow)
|
||||
NonnullOwnPtr<Region> Region::create_user_accessible(const Range& range, const StringView& name, u8 access, bool cow)
|
||||
{
|
||||
auto region = adopt(*new Region(range, name, access, cow));
|
||||
auto region = make<Region>(range, name, access, cow);
|
||||
region->m_user_accessible = true;
|
||||
return region;
|
||||
}
|
||||
|
||||
NonnullRefPtr<Region> Region::create_user_accessible(const Range& range, NonnullRefPtr<VMObject> vmobject, size_t offset_in_vmobject, const StringView& name, u8 access, bool cow)
|
||||
NonnullOwnPtr<Region> Region::create_user_accessible(const Range& range, NonnullRefPtr<VMObject> vmobject, size_t offset_in_vmobject, const StringView& name, u8 access, bool cow)
|
||||
{
|
||||
auto region = adopt(*new Region(range, move(vmobject), offset_in_vmobject, name, access, cow));
|
||||
auto region = make<Region>(range, move(vmobject), offset_in_vmobject, name, access, cow);
|
||||
region->m_user_accessible = true;
|
||||
return region;
|
||||
}
|
||||
|
||||
NonnullRefPtr<Region> Region::create_user_accessible(const Range& range, NonnullRefPtr<Inode> inode, const StringView& name, u8 access, bool cow)
|
||||
NonnullOwnPtr<Region> Region::create_user_accessible(const Range& range, NonnullRefPtr<Inode> inode, const StringView& name, u8 access, bool cow)
|
||||
{
|
||||
auto region = adopt(*new Region(range, move(inode), name, access, cow));
|
||||
auto region = make<Region>(range, move(inode), name, access, cow);
|
||||
region->m_user_accessible = true;
|
||||
return region;
|
||||
}
|
||||
|
||||
NonnullRefPtr<Region> Region::create_kernel_only(const Range& range, const StringView& name, u8 access, bool cow)
|
||||
NonnullOwnPtr<Region> Region::create_kernel_only(const Range& range, const StringView& name, u8 access, bool cow)
|
||||
{
|
||||
auto region = adopt(*new Region(range, name, access, cow));
|
||||
auto region = make<Region>(range, name, access, cow);
|
||||
region->m_user_accessible = false;
|
||||
return region;
|
||||
}
|
||||
|
|
|
@ -10,8 +10,7 @@
|
|||
class Inode;
|
||||
class VMObject;
|
||||
|
||||
class Region final : public RefCounted<Region>
|
||||
, public InlineLinkedListNode<Region> {
|
||||
class Region final : public InlineLinkedListNode<Region> {
|
||||
friend class MemoryManager;
|
||||
|
||||
MAKE_SLAB_ALLOCATED(Region)
|
||||
|
@ -22,10 +21,10 @@ public:
|
|||
Execute = 4,
|
||||
};
|
||||
|
||||
static NonnullRefPtr<Region> create_user_accessible(const Range&, const StringView& name, u8 access, bool cow = false);
|
||||
static NonnullRefPtr<Region> create_user_accessible(const Range&, NonnullRefPtr<VMObject>, size_t offset_in_vmobject, const StringView& name, u8 access, bool cow = false);
|
||||
static NonnullRefPtr<Region> create_user_accessible(const Range&, NonnullRefPtr<Inode>, const StringView& name, u8 access, bool cow = false);
|
||||
static NonnullRefPtr<Region> create_kernel_only(const Range&, const StringView& name, u8 access, bool cow = false);
|
||||
static NonnullOwnPtr<Region> create_user_accessible(const Range&, const StringView& name, u8 access, bool cow = false);
|
||||
static NonnullOwnPtr<Region> create_user_accessible(const Range&, NonnullRefPtr<VMObject>, size_t offset_in_vmobject, const StringView& name, u8 access, bool cow = false);
|
||||
static NonnullOwnPtr<Region> create_user_accessible(const Range&, NonnullRefPtr<Inode>, const StringView& name, u8 access, bool cow = false);
|
||||
static NonnullOwnPtr<Region> create_kernel_only(const Range&, const StringView& name, u8 access, bool cow = false);
|
||||
|
||||
~Region();
|
||||
|
||||
|
@ -48,7 +47,7 @@ public:
|
|||
|
||||
bool is_user_accessible() const { return m_user_accessible; }
|
||||
|
||||
NonnullRefPtr<Region> clone();
|
||||
NonnullOwnPtr<Region> clone();
|
||||
|
||||
bool contains(VirtualAddress vaddr) const
|
||||
{
|
||||
|
@ -114,11 +113,12 @@ public:
|
|||
Region* m_next { nullptr };
|
||||
Region* m_prev { nullptr };
|
||||
|
||||
private:
|
||||
// NOTE: These are public so we can make<> them.
|
||||
Region(const Range&, const String&, u8 access, bool cow = false);
|
||||
Region(const Range&, NonnullRefPtr<VMObject>, size_t offset_in_vmo, const String&, u8 access, bool cow = false);
|
||||
Region(const Range&, RefPtr<Inode>&&, const String&, u8 access, bool cow = false);
|
||||
|
||||
private:
|
||||
RefPtr<PageDirectory> m_page_directory;
|
||||
Range m_range;
|
||||
size_t m_offset_in_vmo { 0 };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue