1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 08:54:58 +00:00

LibC: Don't format strings when asserting with an unstable heap

If we hit an assertion while the heap isn't in a stable state, we can't
rely on dynamic memory allocation because the malloc mutex is already
held and the heap is most likely corrupted. Instead, we need to bail
out fast before we make the situation even worse.
This commit is contained in:
Jean-Baptiste Boric 2021-09-17 18:13:50 +02:00 committed by Brian Gianforcaro
parent e215580147
commit 8043fcd466
3 changed files with 13 additions and 4 deletions

View file

@ -26,8 +26,13 @@ public:
: m_mutex(mutex)
{
lock();
__heap_is_stable = false;
}
ALWAYS_INLINE ~PthreadMutexLocker()
{
__heap_is_stable = true;
unlock();
}
ALWAYS_INLINE ~PthreadMutexLocker() { unlock(); }
ALWAYS_INLINE void lock() { pthread_mutex_lock(&m_mutex); }
ALWAYS_INLINE void unlock() { pthread_mutex_unlock(&m_mutex); }
@ -38,6 +43,7 @@ private:
#define RECYCLE_BIG_ALLOCATIONS
static pthread_mutex_t s_malloc_mutex = PTHREAD_MUTEX_INITIALIZER;
bool __heap_is_stable = true;
constexpr size_t number_of_hot_chunked_blocks_to_keep_around = 16;
constexpr size_t number_of_cold_chunked_blocks_to_keep_around = 16;