Explorar el Código

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.
Daniel Bertalan hace 3 años
padre
commit
5c7524b1d8
Se han modificado 1 ficheros con 2 adiciones y 0 borrados
  1. 2 0
      Kernel/Heap/kmalloc.cpp

+ 2 - 0
Kernel/Heap/kmalloc.cpp

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