summaryrefslogtreecommitdiff
path: root/AK/kmalloc.h
AgeCommit message (Collapse)Author
2022-11-27AK: Fully qualify some usages of AK features outside of the AK namespaceTim Schumacher
2022-10-10Everywhere: Replace uses of __serenity__ with AK_OS_SERENITYAndrew Kaster
Now that we have OS macros for essentially every supported OS, let's try to use them everywhere.
2022-03-15AK+Kernel: Avoid double memory clearing of HashTable bucketsDaniel Bertalan
Since the allocated memory is going to be zeroed immediately anyway, let's avoid redundantly scrubbing it with MALLOC_SCRUB_BYTE just before that. The latest versions of gcc and Clang can automatically do this malloc + memset -> calloc optimization, but I've seen a couple of places where it failed to be done. This commit also adds a naive kcalloc function to the kernel that doesn't (yet) eliminate the redundancy like the userland does.
2022-01-16AK: Remove `kfree` definitionMichel Hermier
2022-01-16AK: Remove `kcalloc` definitionMichel Hermier
2021-12-28Kernel: Remove the kmalloc_eternal heap :^)Andreas Kling
This was a premature optimization from the early days of SerenityOS. The eternal heap was a simple bump pointer allocator over a static byte array. My original idea was to avoid heap fragmentation and improve data locality, but both ideas were rooted in cargo culting, not data. We would reserve 4 MiB at boot and only ended up using ~256 KiB, wasting the rest. This patch replaces all kmalloc_eternal() usage by regular kmalloc().
2021-08-30AK: Add operator delete stub to all AK_MAKE_ETERNAL objectsBrian Gianforcaro
Static analysis correctly flags that we are missing an implementation for `operator delete` for all classes which are annotated with AK_MAKE_ETERNAL. To appease static analysis define an implementation which asserts to make sure no one ever calls delete on the object.
2021-08-08AK: Add kmalloc_array() to trap multiplication overflowsAndreas Kling
This pattern is no good: kmalloc(elements * sizeof(T)); Since it silently swallows any multiplication overflow. This patch adds a simple kmalloc_array() that stops the program if overflow occurs: kmalloc_array(elements, sizeof(T));
2021-07-11Kernel: Remove krealloc()Andreas Kling
This was only used by a single class (AK::ByteBuffer) in the kernel and not in an OOM-safe way. Now that ByteBuffer no longer uses it, there's no need for the kernel heap to burden itself with supporting this.
2021-07-11AK: Make kfree_sized() forward to kfree() in non-kernel code for nowAndreas Kling
2021-07-05AK: Declare operators `new` and `delete` as global functionsDaniel Bertalan
This fixes a build issue introduced in 23d66fe, where the compiler statically detected that that mismatching new and delete operators were used. Clang generates a warning for this, for the reasons described in the comment in `AK/kmalloc.cpp`, but GCC does not. Besides moving the allocator functions into a `.cpp` file, declarations in `AK/kmalloc.cpp` were reordered to have imports at the top, in order to make the code more readable.
2021-06-24AK+Kernel: Make fallible allocations compiler-agnosticDaniel Bertalan
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-05-30AK: Declare malloc_good_size as extern "C"sin-ack
This would otherwise cause an error with clang when __serenity__ wasn't defined.
2021-05-15AK+LibC: Implement malloc_good_size() and use it for Vector/HashTableGunnar Beutner
This implements the macOS API malloc_good_size() which returns the true allocation size for a given requested allocation size. This allows us to make use of all the available memory in a malloc chunk. For example, for a malloc request of 35 bytes our malloc would internally use a chunk of size 64, however the remaining 29 bytes would be unused. Knowing the true allocation size allows us to request more usable memory that would otherwise be wasted and make that available for Vector, HashTable and potentially other callers in the future.
2021-04-22Everything: Move to SPDX license identifiers in all files.Brian Gianforcaro
SPDX License Identifiers are a more compact / standardized way of representing file license information. See: https://spdx.dev/resources/use/#identifiers This was done with the `ambr` search and replace tool. ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2020-11-05AK: Always include <new> from compiler before our operators newAndreas Kling
We had competing inline definitions of the placement operators new. Avoid this by having <AK/kmalloc.h> pull in <new> from the compiler and always using their definitions instead. I feel like there must be an elegant solution to this whole situation with the operators, but I'm not sure what it is.
2020-08-04Revert "AK: Let the compiler provide the default new and delete operators"Andreas Kling
This reverts commit 45b05e9734962b07f95630e76b9a680e1775f002. I forgot about the Toolchain build again. :^(
2020-08-04AK: Let the compiler provide the default new and delete operatorsAndreas Kling
...except in kernelspace.
2020-05-20Revert "AK+LibC: Move non-placement new/delete into LibC"Andreas Kling
This reverts commit 2c823473930121aecbacf0422c8372a0912e581b.
2020-05-20AK+LibC: Move non-placement new/delete into LibCAndrew Kaster
This allows operator new and operator delete to be available to anyone that links -lc (everyone) rather than just people that include kmalloc.h (almost no one).
2020-05-16Kernel: Absorb LibBareMetal back into the kernelAndreas Kling
This was supposed to be the foundation for some kind of pre-kernel environment, but nobody is working on it right now, so let's move everything back into the kernel and remove all the confusion.
2020-02-25AK: Have AK/kmalloc.h #include <new> on other platformsAndreas Kling
This should make stuff like placement new work correctly when building outside of Serenity. This stuff is a bit delicate due to the weirdly staged toolchain build at the moment. Hopefully we can unify this stuff in the future.
2020-02-18Kernel: Add placement new[] operatorSergey Bugaev
2020-02-09AK: Apply changes for the Bootstrapper environmentLiav A
2020-01-25Build: Remove -fno-sized-deallocation -Wno-sized-deallocationAndreas Kling
Add sized variants of the global operator delete functions so we don't have to use these GCC options anymore.
2020-01-18Meta: Add license header to source filesAndreas Kling
As suggested by Joshua, this commit adds the 2-clause BSD license as a comment block to the top of every source file. For the first pass, I've just added myself for simplicity. I encourage everyone to add themselves as copyright holders of any file they've added or modified in some significant way. If I've added myself in error somewhere, feel free to replace it with the appropriate copyright holder instead. Going forward, all new source files should include a license header.
2019-09-16Kernel: Move kmalloc() into a Kernel/Heap/ directoryAndreas Kling
2019-05-28Add clang-format fileRobin Burchell
Also run it across the whole tree to get everything using the One True Style. We don't yet run this in an automated fashion as it's a little slow, but there is a snippet to do so in makeall.sh.
2019-04-20Get rid of SERENITY macro since the compiler already defines __serenity__Andreas Kling
This makes it a bit easier to use AK templates out-of-tree.
2019-04-05AK: Revert Eternal<T> for now since it doesn't work as intended.Andreas Kling
2019-04-05AK: Fix problem when building i686-pc-serenity toolchain from scratch.Andreas Kling
2019-04-03AK: Add Eternal<T> and use it in various places.Andreas Kling
This is useful for static locals that never need to be destroyed: Thing& Thing::the() { static Eternal<Thing> the; return the; } The object will be allocated in data segment memory and will never have its destructor invoked.
2019-04-03AK: Clean up some of the confusion that is AK/kmalloc.{cpp,h}Andreas Kling
2019-03-27LibC: Run constructors on process startup.Andreas Kling
Cooperate with the compiler to generate and execute the _init_array list of constructor functions on userspace program statup. This took two days to get working, my goodness. :^)
2019-02-15Use modern C++ attributes instead of __attribute__ voodoo.Andreas Kling
This is quite nice, although I wish [[gnu::always_inline]] implied inline. Also "gnu::" is kind of a wart, but whatcha gonna do.
2019-01-17Get rid of #ifdef SERENITY. We're past that phase of bootstrapping.Andreas Kling
2018-11-09Build LibC and Userland with clang as well.Andreas Kling
2018-10-31Add a kmalloc_eternal() for things that will never be destroyed.Andreas Kling
2018-10-28Canonicalize the path used by sh.Andreas Kling
With a bunch of LibC work to support the feature. LibC now initializes AK::StringImpl by default. It's now fine to use AK in LibC/Userland! :^)
2018-10-26Implement /proc/PID/vm.Andreas Kling
Refactored SyntheticFileSystem to maintain an arbitrary directory structure. ProcFileSystem creates a directory entry in /proc for each new process.
2018-10-25ELFLoader should fail with an error message for unresolved symbols.Andreas Kling
2018-10-22Import very modest Userland.Andreas Kling
2018-10-17Integrate ext2 from VFS into Kernel.Andreas Kling
2018-10-16Start fixing up AK to work inside the kernel.Andreas Kling
2018-10-10Import all this stuff into a single repo called Serenity.Andreas Kling