mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
Kernel: Return nullptr instead of PANICking in KmallocSlabHeap
I dared to return nullptr :^)
This commit is contained in:
parent
4828f0b636
commit
8e8ea99bf3
Notes:
sideshowbarker
2024-07-18 00:54:03 +09:00
Author: https://github.com/thomasqueirozb 🔰 Commit: https://github.com/SerenityOS/serenity/commit/8e8ea99bf3 Pull-request: https://github.com/SerenityOS/serenity/pull/16350 Reviewed-by: https://github.com/linusg
1 changed files with 8 additions and 7 deletions
|
@ -130,8 +130,8 @@ public:
|
||||||
// Handle this with a custom VM+page allocator instead of using kmalloc_aligned().
|
// Handle this with a custom VM+page allocator instead of using kmalloc_aligned().
|
||||||
auto* slot = kmalloc_aligned(KmallocSlabBlock::block_size, KmallocSlabBlock::block_size);
|
auto* slot = kmalloc_aligned(KmallocSlabBlock::block_size, KmallocSlabBlock::block_size);
|
||||||
if (!slot) {
|
if (!slot) {
|
||||||
// FIXME: Dare to return nullptr!
|
dbgln_if(KMALLOC_DEBUG, "OOM while growing slabheap ({})", m_slab_size);
|
||||||
PANIC("OOM while growing slabheap ({})", m_slab_size);
|
return nullptr;
|
||||||
}
|
}
|
||||||
auto* block = new (slot) KmallocSlabBlock(m_slab_size);
|
auto* block = new (slot) KmallocSlabBlock(m_slab_size);
|
||||||
m_usable_blocks.append(*block);
|
m_usable_blocks.append(*block);
|
||||||
|
@ -253,7 +253,8 @@ struct KmallocGlobalData {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!try_expand(size)) {
|
if (!try_expand(size)) {
|
||||||
PANIC("OOM when trying to expand kmalloc heap.");
|
dbgln_if(KMALLOC_DEBUG, "OOM when trying to expand kmalloc heap");
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return allocate(size, caller_will_initialize_memory);
|
return allocate(size, caller_will_initialize_memory);
|
||||||
|
@ -320,14 +321,14 @@ struct KmallocGlobalData {
|
||||||
dbgln_if(KMALLOC_DEBUG, "Unable to allocate {}, expanding kmalloc heap", allocation_request);
|
dbgln_if(KMALLOC_DEBUG, "Unable to allocate {}, expanding kmalloc heap", allocation_request);
|
||||||
|
|
||||||
if (!expansion_data->virtual_range.contains(new_subheap_base, new_subheap_size)) {
|
if (!expansion_data->virtual_range.contains(new_subheap_base, new_subheap_size)) {
|
||||||
// FIXME: Dare to return false and allow kmalloc() to fail!
|
dbgln_if(KMALLOC_DEBUG, "Out of address space when expanding kmalloc heap");
|
||||||
PANIC("Out of address space when expanding kmalloc heap.");
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto physical_pages_or_error = MM.commit_physical_pages(new_subheap_size / PAGE_SIZE);
|
auto physical_pages_or_error = MM.commit_physical_pages(new_subheap_size / PAGE_SIZE);
|
||||||
if (physical_pages_or_error.is_error()) {
|
if (physical_pages_or_error.is_error()) {
|
||||||
// FIXME: Dare to return false!
|
dbgln_if(KMALLOC_DEBUG, "Out of address space when expanding kmalloc heap");
|
||||||
PANIC("Out of physical pages when expanding kmalloc heap.");
|
return false;
|
||||||
}
|
}
|
||||||
auto physical_pages = physical_pages_or_error.release_value();
|
auto physical_pages = physical_pages_or_error.release_value();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue