mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 01:27:34 +00:00
AK+LibC+LibPthread: Introduce NoAllocationGuard
NoAllocationGuard is an RAII stack guard that prevents allocations while it exists. This is done through a thread-local global flag which causes malloc to crash on a VERIFY if it is false. The guard allows for recursion. The intended use case for this class is in real-time audio code. In such code, allocations are really bad, and this is an easy way of dynamically enforcing the no-allocations rule while giving the user good feedback if it is violated. Before real-time audio code is executed, e.g. in LibDSP, a NoAllocationGuard is instantiated. This is not done with this commit, as currently some code in LibDSP may still incorrectly allocate in real- time situations. Other use cases for the Kernel have also been added, so this commit builds on the previous to add the support both in Userland and in the Kernel.
This commit is contained in:
parent
e2c9578390
commit
2f50d8f4d3
4 changed files with 91 additions and 0 deletions
|
@ -19,6 +19,12 @@
|
|||
static constexpr unsigned short size_classes[] = { 16, 32, 64, 128, 256, 496, 1008, 2032, 4080, 8176, 16368, 32752, 0 };
|
||||
static constexpr size_t num_size_classes = (sizeof(size_classes) / sizeof(unsigned short)) - 1;
|
||||
|
||||
#ifndef NO_TLS
|
||||
extern "C" {
|
||||
extern __thread bool s_allocation_enabled;
|
||||
}
|
||||
#endif
|
||||
|
||||
consteval bool check_size_classes_alignment()
|
||||
{
|
||||
for (size_t i = 0; i < num_size_classes; i++) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue