1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 09:48:11 +00:00

Kernel: Tidy up Memory::AddressSpace construction

- Return KResultOr<T> in places
- Propagate errors
- Use TRY()
This commit is contained in:
Andreas Kling 2021-09-05 15:13:20 +02:00
parent 0cf65cf7ec
commit 83fed5b2de
6 changed files with 16 additions and 30 deletions

View file

@ -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)