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

Add an InterruptDisabler helper class and use that for kmalloc.

The naive spinlock was not nearly enough to protect kmalloc from
reentrancy problems.

I don't want to deal with coming up with a fancy lock for kmalloc
right now, so I made an InterruptDisabler thingy instead.
It does CLI and then STI iff interrupts were previously enabled.
This commit is contained in:
Andreas Kling 2018-10-24 11:07:53 +02:00
parent 9a296d63f3
commit 0c5bbac86e
4 changed files with 35 additions and 14 deletions

View file

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