mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-06 16:45:03 +00:00
For Kernel OOM hardening to work correctly, we need to be able to call a "nothrow" version of operator new. Unfortunately the default "throwing" version of operator new assumes that the allocation will never return on failure and will always throw an exception. This isn't true in the Kernel, as we don't have exceptions. So if we call the normal/throwing new and kmalloc returns NULL, the generated code will happily go and dereference that NULL pointer by invoking the constructor before we have a chance to handle the failure. To fix this we declare operator new as noexcept in the Kernel headers, which will allow the caller to actually handle allocation failure. The delete implementations need to match the prototype of the new which allocated them, so we need define delete as noexcept as well. GCC then errors out declaring that you should implement sized delete as well, so this change provides those stubs in order to compile cleanly. Finally the new operator definitions have been standardized as being declared with [[nodiscard]] to avoid potential memory leaks. So lets declares the kernel versions that way as well.
11 KiB
11 KiB