1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 20:07:34 +00:00

Add a kmalloc lock. This definitely reduces flakiness.

This commit is contained in:
Andreas Kling 2018-10-24 00:51:19 +02:00
parent 8e27cf2428
commit 82dae8fc90
2 changed files with 13 additions and 0 deletions

View file

@ -33,6 +33,11 @@ public:
m_lock = 0; m_lock = 0;
} }
void init()
{
m_lock = 0;
}
private: private:
volatile dword m_lock { 0 }; volatile dword m_lock { 0 };
}; };

View file

@ -10,6 +10,7 @@
#include "VGA.h" #include "VGA.h"
#include "system.h" #include "system.h"
#include "Assertions.h" #include "Assertions.h"
#include <AK/Lock.h>
#define SANITIZE_KMALLOC #define SANITIZE_KMALLOC
@ -29,9 +30,12 @@ PRIVATE BYTE alloc_map[POOL_SIZE / CHUNK_SIZE / 8];
DWORD sum_alloc = 0; DWORD sum_alloc = 0;
DWORD sum_free = POOL_SIZE; DWORD sum_free = POOL_SIZE;
static SpinLock s_kmallocLock;
PUBLIC void PUBLIC void
kmalloc_init() kmalloc_init()
{ {
s_kmallocLock.init();
memset( &alloc_map, 0, sizeof(alloc_map) ); memset( &alloc_map, 0, sizeof(alloc_map) );
memset( (void *)BASE_PHYS, 0, POOL_SIZE ); memset( (void *)BASE_PHYS, 0, POOL_SIZE );
@ -42,6 +46,8 @@ kmalloc_init()
PUBLIC void * PUBLIC void *
kmalloc( DWORD size ) kmalloc( DWORD size )
{ {
Locker locker(s_kmallocLock);
DWORD chunks_needed, chunks_here, first_chunk; DWORD chunks_needed, chunks_here, first_chunk;
DWORD real_size; DWORD real_size;
DWORD i, j, k; DWORD i, j, k;
@ -117,6 +123,8 @@ kfree( void *ptr )
if( !ptr ) if( !ptr )
return; return;
Locker locker(s_kmallocLock);
allocation_t *a = (allocation_t *)((((BYTE *)ptr) - sizeof(allocation_t))); allocation_t *a = (allocation_t *)((((BYTE *)ptr) - sizeof(allocation_t)));
#if 0 #if 0