mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 06:07:44 +00:00
Kernel: Tidy up Memory::AddressSpace construction
- Return KResultOr<T> in places - Propagate errors - Use TRY()
This commit is contained in:
parent
0cf65cf7ec
commit
83fed5b2de
6 changed files with 16 additions and 30 deletions
|
@ -15,14 +15,10 @@
|
|||
|
||||
namespace Kernel::Memory {
|
||||
|
||||
OwnPtr<AddressSpace> AddressSpace::try_create(AddressSpace const* parent)
|
||||
KResultOr<NonnullOwnPtr<AddressSpace>> AddressSpace::try_create(AddressSpace const* parent)
|
||||
{
|
||||
auto page_directory = PageDirectory::try_create_for_userspace(parent ? &parent->page_directory().range_allocator() : nullptr);
|
||||
if (!page_directory)
|
||||
return {};
|
||||
auto space = adopt_own_if_nonnull(new (nothrow) AddressSpace(page_directory.release_nonnull()));
|
||||
if (!space)
|
||||
return {};
|
||||
auto page_directory = TRY(PageDirectory::try_create_for_userspace(parent ? &parent->page_directory().range_allocator() : nullptr));
|
||||
auto space = TRY(adopt_nonnull_own_or_enomem(new (nothrow) AddressSpace(page_directory)));
|
||||
space->page_directory().set_space({}, *space);
|
||||
return space;
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace Kernel::Memory {
|
|||
|
||||
class AddressSpace {
|
||||
public:
|
||||
static OwnPtr<AddressSpace> try_create(AddressSpace const* parent);
|
||||
static KResultOr<NonnullOwnPtr<AddressSpace>> try_create(AddressSpace const* parent);
|
||||
~AddressSpace();
|
||||
|
||||
PageDirectory& page_directory() { return *m_page_directory; }
|
||||
|
|
|
@ -42,14 +42,12 @@ UNMAP_AFTER_INIT NonnullRefPtr<PageDirectory> PageDirectory::must_create_kernel_
|
|||
return directory;
|
||||
}
|
||||
|
||||
RefPtr<PageDirectory> PageDirectory::try_create_for_userspace(VirtualRangeAllocator const* parent_range_allocator)
|
||||
KResultOr<NonnullRefPtr<PageDirectory>> PageDirectory::try_create_for_userspace(VirtualRangeAllocator const* parent_range_allocator)
|
||||
{
|
||||
constexpr FlatPtr userspace_range_base = 0x00800000;
|
||||
FlatPtr const userspace_range_ceiling = USER_RANGE_CEILING;
|
||||
|
||||
auto directory = adopt_ref_if_nonnull(new (nothrow) PageDirectory);
|
||||
if (!directory)
|
||||
return {};
|
||||
auto directory = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) PageDirectory));
|
||||
|
||||
if (parent_range_allocator) {
|
||||
directory->m_range_allocator.initialize_from_parent(*parent_range_allocator);
|
||||
|
@ -70,12 +68,12 @@ RefPtr<PageDirectory> PageDirectory::try_create_for_userspace(VirtualRangeAlloca
|
|||
|
||||
directory->m_directory_table = MM.allocate_user_physical_page();
|
||||
if (!directory->m_directory_table)
|
||||
return {};
|
||||
return ENOMEM;
|
||||
auto kernel_pd_index = (kernel_mapping_base >> 30) & 0x1ffu;
|
||||
for (size_t i = 0; i < kernel_pd_index; i++) {
|
||||
directory->m_directory_pages[i] = MM.allocate_user_physical_page();
|
||||
if (!directory->m_directory_pages[i])
|
||||
return {};
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
// Share the top 1 GiB of kernel-only mappings (>=kernel_mapping_base)
|
||||
|
|
|
@ -19,7 +19,7 @@ class PageDirectory : public RefCounted<PageDirectory> {
|
|||
friend class MemoryManager;
|
||||
|
||||
public:
|
||||
static RefPtr<PageDirectory> try_create_for_userspace(VirtualRangeAllocator const* parent_range_allocator = nullptr);
|
||||
static KResultOr<NonnullRefPtr<PageDirectory>> try_create_for_userspace(VirtualRangeAllocator const* parent_range_allocator = nullptr);
|
||||
static NonnullRefPtr<PageDirectory> must_create_kernel_page_directory();
|
||||
static RefPtr<PageDirectory> find_by_cr3(FlatPtr);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue