Skip to content

Commit

Permalink
Kernel: Remove some Region construction helpers
Browse files Browse the repository at this point in the history
It's now up to the caller to provide a VMObject when constructing a new
Region object. This will make it easier to handle things going wrong,
like allocation failures, etc.
  • Loading branch information
awesomekling committed Mar 1, 2020
1 parent fddc3c9 commit 88b3341
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 30 deletions.
3 changes: 2 additions & 1 deletion Kernel/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ Region& Process::allocate_split_region(const Region& source_region, const Range&
Region* Process::allocate_region(const Range& range, const String& name, int prot, bool commit)
{
ASSERT(range.is_valid());
auto& region = add_region(Region::create_user_accessible(range, name, prot_to_region_access_flags(prot)));
auto vmobject = AnonymousVMObject::create_with_size(range.size());
auto& region = add_region(Region::create_user_accessible(range, vmobject, 0, name, prot_to_region_access_flags(prot)));
region.map(page_directory());
if (commit)
region.commit();
Expand Down
5 changes: 3 additions & 2 deletions Kernel/VM/MemoryManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,11 +314,12 @@ OwnPtr<Region> MemoryManager::allocate_kernel_region(size_t size, const StringVi
ASSERT(!(size % PAGE_SIZE));
auto range = kernel_page_directory().range_allocator().allocate_anywhere(size);
ASSERT(range.is_valid());
auto vmobject = AnonymousVMObject::create_with_size(size);
OwnPtr<Region> region;
if (user_accessible)
region = Region::create_user_accessible(range, name, access, cacheable);
region = Region::create_user_accessible(range, vmobject, 0, name, access, cacheable);
else
region = Region::create_kernel_only(range, name, access, cacheable);
region = Region::create_kernel_only(range, vmobject, 0, name, access, cacheable);
region->map(kernel_page_directory());
if (should_commit)
region->commit();
Expand Down
24 changes: 0 additions & 24 deletions Kernel/VM/Region.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,6 @@

namespace Kernel {

Region::Region(const Range& range, const String& name, u8 access, bool cacheable)
: m_range(range)
, m_vmobject(AnonymousVMObject::create_with_size(size()))
, m_name(name)
, m_access(access)
, m_cacheable(cacheable)
{
MM.register_region(*this);
}

Region::Region(const Range& range, NonnullRefPtr<VMObject> vmobject, size_t offset_in_vmobject, const String& name, u8 access, bool cacheable)
: m_range(range)
, m_offset_in_vmobject(offset_in_vmobject)
Expand Down Expand Up @@ -175,13 +165,6 @@ size_t Region::amount_shared() const
return bytes;
}

NonnullOwnPtr<Region> Region::create_user_accessible(const Range& range, const StringView& name, u8 access, bool cacheable)
{
auto region = make<Region>(range, name, access, cacheable);
region->m_user_accessible = true;
return region;
}

NonnullOwnPtr<Region> Region::create_user_accessible(const Range& range, NonnullRefPtr<VMObject> vmobject, size_t offset_in_vmobject, const StringView& name, u8 access, bool cacheable)
{
auto region = make<Region>(range, move(vmobject), offset_in_vmobject, name, access, cacheable);
Expand All @@ -196,13 +179,6 @@ NonnullOwnPtr<Region> Region::create_kernel_only(const Range& range, NonnullRefP
return region;
}

NonnullOwnPtr<Region> Region::create_kernel_only(const Range& range, const StringView& name, u8 access, bool cacheable)
{
auto region = make<Region>(range, name, access, cacheable);
region->m_user_accessible = false;
return region;
}

bool Region::should_cow(size_t page_index) const
{
auto& slot = vmobject().physical_pages()[page_index];
Expand Down
3 changes: 0 additions & 3 deletions Kernel/VM/Region.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ class Region final
Execute = 4,
};

static NonnullOwnPtr<Region> create_user_accessible(const Range&, const StringView& name, u8 access, bool cacheable = true);
static NonnullOwnPtr<Region> create_user_accessible(const Range&, NonnullRefPtr<VMObject>, size_t offset_in_vmobject, const StringView& name, u8 access, bool cacheable = true);
static NonnullOwnPtr<Region> create_kernel_only(const Range&, const StringView& name, u8 access, bool cacheable = true);
static NonnullOwnPtr<Region> create_kernel_only(const Range&, NonnullRefPtr<VMObject>, size_t offset_in_vmobject, const StringView& name, u8 access, bool cacheable = true);

~Region();
Expand Down Expand Up @@ -160,7 +158,6 @@ class Region final
Region* m_prev { nullptr };

// NOTE: These are public so we can make<> them.
Region(const Range&, const String&, u8 access, bool cacheable);
Region(const Range&, NonnullRefPtr<VMObject>, size_t offset_in_vmobject, const String&, u8 access, bool cacheable);

private:
Expand Down

0 comments on commit 88b3341

Please sign in to comment.