1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 19:58:11 +00:00
serenity/Kernel
Daniel Bertalan 5491e0cdcc AK+Kernel: Make fallible allocations compiler-agnostic
In standard C++, operators `new` and `new[]` are guaranteed to return a
valid (non-null) pointer and throw an exception if the allocation
couldn't be performed. Based on this, compilers did not check the
returned pointer before attempting to use them for object construction.

To avoid this, the allocator operators were changed to be `noexcept` in
PR #7026, which made GCC emit the desired null checks. Unfortunately,
this is a non-standard feature which meant that Clang would not accept
these function definitions, as it did not match its expected
declaration.

To make compiling using Clang possible, the special "nothrow" versions
of `new` are implemented in this commit. These take a tag type of
`std::nothrow_t` (used for disambiguating from placement new/etc.), and
are allowed by the standard to return null. There is a global variable,
`std::nothrow`, declared with this type, which is also exported into the
global namespace.

To perform fallible allocations, the following syntax should be used:

```cpp
auto ptr = new (nothrow) T;
```

As we don't support exceptions in the kernel, the only way of uphold the
"throwing" new's guarantee is to abort if the allocation couldn't be
performed. Once we have proper OOM handling in the kernel, this should
only be used for critical allocations, where we wouldn't be able to
recover from allocation failures anyway.
2021-06-24 17:35:49 +04:30
..
ACPI Kernel: Move special sections into Sections.h 2021-06-24 00:38:23 +02:00
API Kernel: Add statvfs & fstatvfs Syscalls 2021-05-19 21:33:29 +02:00
Arch Kernel: Add stubs for missing x86_64 functionality 2021-06-24 09:27:13 +02:00
Devices Kernel: Move special sections into Sections.h 2021-06-24 00:38:23 +02:00
FileSystem Kernel: Fix compiling TmpFSInode::write_bytes on x86_64 2021-06-24 09:27:13 +02:00
Graphics Kernel: Move special sections into Sections.h 2021-06-24 00:38:23 +02:00
Heap AK+Kernel: Make fallible allocations compiler-agnostic 2021-06-24 17:35:49 +04:30
Interrupts Kernel: Move special sections into Sections.h 2021-06-24 00:38:23 +02:00
Modules Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
Net Kernel: Move special sections into Sections.h 2021-06-24 00:38:23 +02:00
PCI Kernel: Move special sections into Sections.h 2021-06-24 00:38:23 +02:00
Storage Kernel: Move special sections into Sections.h 2021-06-24 00:38:23 +02:00
Syscalls Kernel: Reimplement the dbgputch and dbgputstr syscalls 2021-06-24 10:29:09 +02:00
Tasks Kernel: Move special sections into Sections.h 2021-06-24 00:38:23 +02:00
Time Kernel: Move special sections into Sections.h 2021-06-24 00:38:23 +02:00
TTY Kernel: Move special sections into Sections.h 2021-06-24 00:38:23 +02:00
VirtIO Kernel: Move special sections into Sections.h 2021-06-24 00:38:23 +02:00
VM Kernel: Add stubs for missing x86_64 functionality 2021-06-24 09:27:13 +02:00
AddressSanitizer.cpp Everywhere: Use bgianf@serenityos.org for my copyright attribution 2021-04-22 21:15:54 +02:00
AddressSanitizer.h Everywhere: Use bgianf@serenityos.org for my copyright attribution 2021-04-22 21:15:54 +02:00
Assertions.h Kernel: Enable VERIFY() checks even if the DEBUG macro is not defined 2021-06-11 11:32:01 +02:00
CMakeLists.txt Kernel: Add stubs for missing x86_64 functionality 2021-06-24 09:27:13 +02:00
CMOS.cpp Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
CMOS.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
CommandLine.cpp Kernel: Move special sections into Sections.h 2021-06-24 00:38:23 +02:00
CommandLine.h Kernel/CommandLine: Add option to disable physical networking hardware 2021-06-09 22:44:09 +04:30
ConsoleDevice.cpp Kernel: Move special sections into Sections.h 2021-06-24 00:38:23 +02:00
ConsoleDevice.h Kernel: Rename Console => ConsoleDevice 2021-05-16 19:58:33 +02:00
CoreDump.cpp Kernel: Unnamed regions still need a null-terminator in core dumps 2021-05-30 20:00:03 +02:00
CoreDump.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
Debug.h.in USB: Further Implement USB Structures 2021-06-12 18:17:25 +04:30
DMI.cpp Kernel: Move special sections into Sections.h 2021-06-24 00:38:23 +02:00
DMI.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
DoubleBuffer.cpp Kernel: Pull apart CPU.h 2021-06-24 00:38:23 +02:00
DoubleBuffer.h Kernel: Use KResultOr<size_t> for the DoubleBuffer class 2021-06-16 21:29:36 +02:00
Forward.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
FutexQueue.cpp Everywhere: Use "the SerenityOS developers." in copyright headers 2021-04-29 00:59:26 +02:00
FutexQueue.h Everywhere: Use "the SerenityOS developers." in copyright headers 2021-04-29 00:59:26 +02:00
init.cpp Kernel: Move special sections into Sections.h 2021-06-24 00:38:23 +02:00
IO.h Kernel: Pull apart CPU.h 2021-06-24 00:38:23 +02:00
KBuffer.h Kernel: Make KBuffer APIs OOM safe 2021-05-29 09:04:05 +02:00
KBufferBuilder.cpp Kernel: Replace make<T>() with adopt_own_if_nonnull() in KBufferBuilder 2021-05-13 16:21:53 +02:00
KBufferBuilder.h Kernel: Avoid allocations in KBufferBuilder::appendff 2021-05-13 08:27:42 +02:00
kprintf.cpp Kernel: Add dbgputch() to kstdio.h 2021-06-24 10:29:09 +02:00
KResult.h Kernel: Add missing AK/Format.h include in KResult.h 2021-05-28 09:37:09 +02:00
kstdio.h Kernel: Add dbgputch() to kstdio.h 2021-06-24 10:29:09 +02:00
KString.cpp Kernel: Add operator delete for KString 2021-06-02 22:59:39 +01:00
KString.h Kernel: Add operator delete for KString 2021-06-02 22:59:39 +01:00
KSyms.cpp Kernel: Move special sections into Sections.h 2021-06-24 00:38:23 +02:00
KSyms.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
linker.ld Kernel: Make sure the kernel's ELF PHDRs don't use rwx 2021-06-19 12:54:33 +02:00
Lock.cpp Kernel: Utilize AK::SourceLocation for LOCK_DEBUG instrumentation. 2021-04-25 09:38:27 +02:00
Lock.h Kernel: Pull apart CPU.h 2021-06-24 00:38:23 +02:00
LockMode.h Everywhere: Use "the SerenityOS developers." in copyright headers 2021-04-29 00:59:26 +02:00
mkmap.sh Build: Switch to CMake :^) 2020-05-14 20:15:18 +02:00
Module.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
Multiboot.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
Panic.cpp Kernel: Pull apart CPU.h 2021-06-24 00:38:23 +02:00
Panic.h Kernel/Graphics + SystemServer: Support text mode properly 2021-05-16 19:58:33 +02:00
PerformanceEventBuffer.cpp Kernel: Make PerformanceEventBuffer creation API OOM safe 2021-05-29 09:04:05 +02:00
PerformanceEventBuffer.h Kernel: Add support for profiling kmalloc()/kfree() 2021-05-19 22:51:42 +02:00
PerformanceManager.h Kernel: Don't log profile data before/after the process/thread lifetime 2021-05-30 19:03:03 +02:00
PhysicalAddress.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
Process.cpp Kernel: Add stubs for missing x86_64 functionality 2021-06-24 09:27:13 +02:00
Process.h Kernel: Remove various other uses of ssize_t 2021-06-16 21:29:36 +02:00
ProcessGroup.cpp Kernel: Switch ProcessGroup to IntrusiveList from InlineLinkedList 2021-06-03 13:27:40 +02:00
ProcessGroup.h Kernel: Switch ProcessGroup to IntrusiveList from InlineLinkedList 2021-06-03 13:27:40 +02:00
Random.cpp Kernel: Don't use function-level static variables 2021-06-24 09:27:13 +02:00
Random.h Kernel: Pull apart CPU.h 2021-06-24 00:38:23 +02:00
RTC.cpp Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
RTC.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
Scheduler.cpp Kernel: Add stubs for missing x86_64 functionality 2021-06-24 09:27:13 +02:00
Scheduler.h Kernel: Don't log profile data before/after the process/thread lifetime 2021-05-30 19:03:03 +02:00
Sections.h Kernel: Move special sections into Sections.h 2021-06-24 00:38:23 +02:00
SpinLock.h Kernel: Pull apart CPU.h 2021-06-24 00:38:23 +02:00
StdLib.cpp Kernel: Remove unused CPU.h includes 2021-06-24 00:38:23 +02:00
StdLib.h Kernel: Add try_copy_kstring_from_user() 2021-05-28 09:37:09 +02:00
Syscall.cpp Kernel: Move special sections into Sections.h 2021-06-24 00:38:23 +02:00
Thread.cpp Kernel: Add stubs for missing x86_64 functionality 2021-06-24 09:27:13 +02:00
Thread.h Kernel: Pull apart CPU.h 2021-06-24 00:38:23 +02:00
ThreadBlockers.cpp Kernel: Fix error propagation if Thread::WaitBlocker constructor fails 2021-06-07 09:43:30 +02:00
ThreadTracer.cpp Kernel: Pull apart CPU.h 2021-06-24 00:38:23 +02:00
ThreadTracer.h Kernel: Make Process::start_tracing_from API OOM safe 2021-05-13 16:21:53 +02:00
TimerQueue.cpp Kernel: Move special sections into Sections.h 2021-06-24 00:38:23 +02:00
TimerQueue.h Kernel: Replace TimerQueue InlinedLinkedList usage with IntrusiveList 2021-06-16 10:40:01 +02:00
UBSanitizer.cpp Kernel: Pull apart CPU.h 2021-06-24 00:38:23 +02:00
UnixTypes.h LibC: Define MSG_OOB 2021-06-04 10:39:41 +02:00
UnveilNode.h Kernel: Allow unveiling subfolders regardless of parent's permissions 2021-06-08 12:15:04 +02:00
UserOrKernelBuffer.cpp Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
UserOrKernelBuffer.h Kernel: Remove obsolete size_t casts 2021-06-17 19:52:54 +02:00
VirtualAddress.h Everything: Move to SPDX license identifiers in all files. 2021-04-22 11:22:27 +02:00
WaitQueue.cpp Everywhere: Use "the SerenityOS developers." in copyright headers 2021-04-29 00:59:26 +02:00
WaitQueue.h Everywhere: Use "the SerenityOS developers." in copyright headers 2021-04-29 00:59:26 +02:00
WorkQueue.cpp Kernel: Move special sections into Sections.h 2021-06-24 00:38:23 +02:00
WorkQueue.h Kernel: Use plain Function objects for the WorkQueue 2021-05-19 21:36:57 +02:00