1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-10 05:47:34 +00:00

Kernel: Allow aligned operator new to return nullptr

In e7fb70b05, regular kmalloc was changed to return nullptr on
allocation failure instead of crashing. The `kmalloc_aligned_cxx`
wrapper used by the aligned operator new should do the same.
This commit is contained in:
Daniel Bertalan 2021-08-13 12:39:14 +02:00 committed by Andreas Kling
parent c5b069eb9d
commit 5c7524b1d8

View file

@ -302,6 +302,8 @@ size_t kmalloc_good_size(size_t size)
{
VERIFY(alignment <= 4096);
void* ptr = kmalloc(size + alignment + sizeof(ptrdiff_t));
if (ptr == nullptr)
return nullptr;
size_t max_addr = (size_t)ptr + alignment;
void* aligned_ptr = (void*)(max_addr - (max_addr % alignment));
((ptrdiff_t*)aligned_ptr)[-1] = (ptrdiff_t)((u8*)aligned_ptr - (u8*)ptr);