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:
parent
c5b069eb9d
commit
5c7524b1d8
1 changed files with 2 additions and 0 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue