stos: pool: Protect pool structures with lock

Signed-off-by: Chloe M. <chloe@mensia.org>
This commit is contained in:
Chloe M.
2026-06-24 17:43:45 +00:00
parent 995da1df2d
commit ed2d4744d7
2 changed files with 11 additions and 1 deletions
+8 -1
View File
@@ -179,6 +179,7 @@ ExAllocatePoolWithTag(POOL_TYPE Type, USIZE ByteCount, ULONG Tag)
{ {
KPCR *ThisCore; KPCR *ThisCore;
MEMORY_POOL *AllocPool; MEMORY_POOL *AllocPool;
VOID *Base;
if (ByteCount == 0) { if (ByteCount == 0) {
return NULL; return NULL;
@@ -195,6 +196,7 @@ ExAllocatePoolWithTag(POOL_TYPE Type, USIZE ByteCount, ULONG Tag)
ThisCore = HalKpcrCurrent(); ThisCore = HalKpcrCurrent();
AllocPool = &ThisCore->AllocPool; AllocPool = &ThisCore->AllocPool;
KeSpinLockAcquire(&AllocPool->Lock, false);
/* /*
* Ensure that the byte count is aligned by the minimum granularity * Ensure that the byte count is aligned by the minimum granularity
@@ -207,10 +209,14 @@ ExAllocatePoolWithTag(POOL_TYPE Type, USIZE ByteCount, ULONG Tag)
"allocation in pool #%d exceeds page size\n", "allocation in pool #%d exceeds page size\n",
AllocPool->Id AllocPool->Id
); );
KeSpinLockRelease(&AllocPool->Lock);
return NULL; return NULL;
} }
return AllocatePoolWithTag(AllocPool, Type, ByteCount, Tag); Base = AllocatePoolWithTag(AllocPool, Type, ByteCount, Tag);
KeSpinLockRelease(&AllocPool->Lock);
return Base;
} }
ST_STATUS ST_STATUS
@@ -225,6 +231,7 @@ ExPoolInit(MEMORY_POOL *Pool)
} }
Pool->Id = PoolCount; Pool->Id = PoolCount;
KeSpinLockInit(&Pool->Lock, "ex-pool");
DTRACE("bringing up pool #%d\n", Pool->Id); DTRACE("bringing up pool #%d\n", Pool->Id);
/* Initialize the pools */ /* Initialize the pools */
+3
View File
@@ -11,6 +11,7 @@
#include <hal/page.h> #include <hal/page.h>
#include <stapi/status.h> #include <stapi/status.h>
#include <ke/spinlock.h>
#include <stdef.h> #include <stdef.h>
/* Minimum log2 allocation size */ /* Minimum log2 allocation size */
@@ -71,10 +72,12 @@ typedef struct {
* *
* @BlockLevels: Block levels [granularity : GRAN(level)] * @BlockLevels: Block levels [granularity : GRAN(level)]
* @Id: Pool ID * @Id: Pool ID
* @Lock: Lock protecting this pool
*/ */
typedef struct { typedef struct {
MEMORY_BLOCK BlockLevels[LEVEL_COUNT]; MEMORY_BLOCK BlockLevels[LEVEL_COUNT];
USIZE Id; USIZE Id;
SPINLOCK Lock;
} MEMORY_POOL; } MEMORY_POOL;
/* /*