mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 22:07:34 +00:00
Kernel: Make ContiguousVMObject factory API OOM safe
This commit is contained in:
parent
cb45b2c001
commit
864b1a65e3
3 changed files with 17 additions and 11 deletions
|
@ -10,15 +10,17 @@
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
NonnullRefPtr<ContiguousVMObject> ContiguousVMObject::create_with_size(size_t size, size_t physical_alignment)
|
RefPtr<ContiguousVMObject> ContiguousVMObject::create_with_size(size_t size, size_t physical_alignment)
|
||||||
{
|
|
||||||
return adopt_ref(*new ContiguousVMObject(size, physical_alignment));
|
|
||||||
}
|
|
||||||
|
|
||||||
ContiguousVMObject::ContiguousVMObject(size_t size, size_t physical_alignment)
|
|
||||||
: VMObject(size)
|
|
||||||
{
|
{
|
||||||
auto contiguous_physical_pages = MM.allocate_contiguous_supervisor_physical_pages(size, physical_alignment);
|
auto contiguous_physical_pages = MM.allocate_contiguous_supervisor_physical_pages(size, physical_alignment);
|
||||||
|
if (contiguous_physical_pages.is_empty())
|
||||||
|
return {};
|
||||||
|
return adopt_ref_if_nonnull(new ContiguousVMObject(size, contiguous_physical_pages));
|
||||||
|
}
|
||||||
|
|
||||||
|
ContiguousVMObject::ContiguousVMObject(size_t size, NonnullRefPtrVector<PhysicalPage>& contiguous_physical_pages)
|
||||||
|
: VMObject(size)
|
||||||
|
{
|
||||||
for (size_t i = 0; i < page_count(); i++) {
|
for (size_t i = 0; i < page_count(); i++) {
|
||||||
physical_pages()[i] = contiguous_physical_pages[i];
|
physical_pages()[i] = contiguous_physical_pages[i];
|
||||||
dbgln_if(CONTIGUOUS_VMOBJECT_DEBUG, "Contiguous page[{}]: {}", i, physical_pages()[i]->paddr());
|
dbgln_if(CONTIGUOUS_VMOBJECT_DEBUG, "Contiguous page[{}]: {}", i, physical_pages()[i]->paddr());
|
||||||
|
|
|
@ -7,18 +7,18 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <Kernel/PhysicalAddress.h>
|
#include <Kernel/PhysicalAddress.h>
|
||||||
|
#include <Kernel/VM/MemoryManager.h>
|
||||||
#include <Kernel/VM/VMObject.h>
|
#include <Kernel/VM/VMObject.h>
|
||||||
|
|
||||||
namespace Kernel {
|
namespace Kernel {
|
||||||
|
|
||||||
class ContiguousVMObject final : public VMObject {
|
class ContiguousVMObject final : public VMObject {
|
||||||
public:
|
public:
|
||||||
virtual ~ContiguousVMObject() override;
|
virtual ~ContiguousVMObject() override;
|
||||||
|
|
||||||
static NonnullRefPtr<ContiguousVMObject> create_with_size(size_t, size_t physical_alignment = PAGE_SIZE);
|
static RefPtr<ContiguousVMObject> create_with_size(size_t, size_t physical_alignment = PAGE_SIZE);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit ContiguousVMObject(size_t, size_t physical_alignment);
|
explicit ContiguousVMObject(size_t, NonnullRefPtrVector<PhysicalPage>&);
|
||||||
explicit ContiguousVMObject(const ContiguousVMObject&);
|
explicit ContiguousVMObject(const ContiguousVMObject&);
|
||||||
|
|
||||||
virtual const char* class_name() const override { return "ContiguousVMObject"; }
|
virtual const char* class_name() const override { return "ContiguousVMObject"; }
|
||||||
|
|
|
@ -464,7 +464,11 @@ OwnPtr<Region> MemoryManager::allocate_contiguous_kernel_region(size_t size, Str
|
||||||
if (!range.has_value())
|
if (!range.has_value())
|
||||||
return {};
|
return {};
|
||||||
auto vmobject = ContiguousVMObject::create_with_size(size, physical_alignment);
|
auto vmobject = ContiguousVMObject::create_with_size(size, physical_alignment);
|
||||||
return allocate_kernel_region_with_vmobject(range.value(), vmobject, name, access, cacheable);
|
if (!vmobject) {
|
||||||
|
kernel_page_directory().range_allocator().deallocate(range.value());
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
return allocate_kernel_region_with_vmobject(range.value(), *vmobject, name, access, cacheable);
|
||||||
}
|
}
|
||||||
|
|
||||||
OwnPtr<Region> MemoryManager::allocate_kernel_region(size_t size, StringView name, Region::Access access, AllocationStrategy strategy, Region::Cacheable cacheable)
|
OwnPtr<Region> MemoryManager::allocate_kernel_region(size_t size, StringView name, Region::Access access, AllocationStrategy strategy, Region::Cacheable cacheable)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue