mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 03:57:44 +00:00
Kernel: Make Kernel::VMObject allocation functions return KResultOr
This makes for nicer handling of errors compared to checking whether a RefPtr is null. Additionally, this will give way to return different types of errors in the future.
This commit is contained in:
parent
61c0e3ca92
commit
4bfd6e41b9
26 changed files with 194 additions and 122 deletions
|
@ -28,10 +28,11 @@ KResult KCOVInstance::buffer_allocate(size_t buffer_size_in_entries)
|
|||
// - we allocate one kernel region using that vmobject
|
||||
// - when an mmap call comes in, we allocate another userspace region,
|
||||
// backed by the same vmobject
|
||||
this->vmobject = Memory::AnonymousVMObject::try_create_with_size(
|
||||
auto maybe_vmobject = Memory::AnonymousVMObject::try_create_with_size(
|
||||
this->m_buffer_size_in_bytes, AllocationStrategy::AllocateNow);
|
||||
if (!this->vmobject)
|
||||
return ENOMEM;
|
||||
if (maybe_vmobject.is_error())
|
||||
return maybe_vmobject.error();
|
||||
this->vmobject = maybe_vmobject.release_value();
|
||||
|
||||
this->m_kernel_region = MM.allocate_kernel_region_with_vmobject(
|
||||
*this->vmobject, this->m_buffer_size_in_bytes, String::formatted("kcov_{}", this->m_pid),
|
||||
|
|
|
@ -47,13 +47,14 @@ KResultOr<Memory::Region*> MemoryDevice::mmap(Process& process, FileDescription&
|
|||
return EINVAL;
|
||||
}
|
||||
|
||||
auto vmobject = Memory::AnonymousVMObject::try_create_for_physical_range(viewed_address, range.size());
|
||||
if (!vmobject)
|
||||
return ENOMEM;
|
||||
auto maybe_vmobject = Memory::AnonymousVMObject::try_create_for_physical_range(viewed_address, range.size());
|
||||
if (maybe_vmobject.is_error())
|
||||
return maybe_vmobject.error();
|
||||
|
||||
dbgln("MemoryDevice: Mapped physical memory at {} for range of {} bytes", viewed_address, range.size());
|
||||
return process.address_space().allocate_region_with_vmobject(
|
||||
range,
|
||||
vmobject.release_nonnull(),
|
||||
maybe_vmobject.release_value(),
|
||||
0,
|
||||
"Mapped Physical Memory",
|
||||
prot,
|
||||
|
|
|
@ -238,10 +238,11 @@ KResultOr<size_t> SB16::write(FileDescription&, u64, const UserOrKernelBuffer& d
|
|||
if (!page)
|
||||
return ENOMEM;
|
||||
auto nonnull_page = page.release_nonnull();
|
||||
auto vmobject = Memory::AnonymousVMObject::try_create_with_physical_pages({ &nonnull_page, 1 });
|
||||
if (!vmobject)
|
||||
return ENOMEM;
|
||||
m_dma_region = MM.allocate_kernel_region_with_vmobject(*vmobject, PAGE_SIZE, "SB16 DMA buffer", Memory::Region::Access::Write);
|
||||
auto maybe_vmobject = Memory::AnonymousVMObject::try_create_with_physical_pages({ &nonnull_page, 1 });
|
||||
if (maybe_vmobject.is_error())
|
||||
return maybe_vmobject.error();
|
||||
|
||||
m_dma_region = MM.allocate_kernel_region_with_vmobject(maybe_vmobject.release_value(), PAGE_SIZE, "SB16 DMA buffer", Memory::Region::Access::Write);
|
||||
if (!m_dma_region)
|
||||
return ENOMEM;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue