mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 01:27:43 +00:00
Kernel: Remove some Region construction helpers
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.
This commit is contained in:
parent
fddc3c957b
commit
88b334135b
4 changed files with 5 additions and 30 deletions
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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)
|
||||
|
@ -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);
|
||||
|
@ -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];
|
||||
|
|
|
@ -55,9 +55,7 @@ public:
|
|||
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();
|
||||
|
@ -160,7 +158,6 @@ public:
|
|||
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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue