mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 13:48:12 +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
|
@ -14,6 +14,7 @@
|
|||
#include <bits/pthread_integration.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <mallocdefs.h>
|
||||
#include <pthread.h>
|
||||
#include <serenity.h>
|
||||
#include <signal.h>
|
||||
|
@ -43,6 +44,9 @@ extern "C" {
|
|||
|
||||
static void* pthread_create_helper(void* (*routine)(void*), void* argument, void* stack_location, size_t stack_size)
|
||||
{
|
||||
// HACK: This is a __thread - marked thread-local variable. If we initialize it globally, VERY weird errors happen.
|
||||
// Therefore, we need to do the initialization here and in __malloc_init().
|
||||
s_allocation_enabled = true;
|
||||
s_stack_location = stack_location;
|
||||
s_stack_size = stack_size;
|
||||
void* ret_val = routine(argument);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue