23746a2918
Signed-off-by: Chloe M. <chloe@mensia.org>
66 lines
1.4 KiB
C
66 lines
1.4 KiB
C
/*
|
|
* Copyright (c) 2026, Chloe M.
|
|
* Provided under the BSD-3 clause.
|
|
*
|
|
* Description: Pool allocator
|
|
* Author: Chloe M.
|
|
*/
|
|
|
|
#include <ex/pool.h>
|
|
#include <ex/trace.h>
|
|
#include <mm/vmm.h>
|
|
#include <string.h>
|
|
|
|
#define DTRACE(Fmt, ...) \
|
|
TRACE("[ POOL ]: " Fmt, ##__VA_ARGS__)
|
|
|
|
/* Globals */
|
|
static USIZE PoolCount = 0;
|
|
|
|
static ST_STATUS
|
|
PoolInitBlock(MEMORY_BLOCK *Block)
|
|
{
|
|
if (Block == NULL) {
|
|
return STATUS_INVALID_PARAM;
|
|
}
|
|
|
|
Block->FirstPage = MmAllocPages(1);
|
|
if (Block->FirstPage == NULL) {
|
|
return STATUS_NO_MEMORY;
|
|
}
|
|
|
|
Block->LastPage = Block->FirstPage;
|
|
Block->PageCount = 1;
|
|
RtlMemSet(Block->FirstPage, 0, PAGESIZE);
|
|
return STATUS_SUCCESS;
|
|
}
|
|
|
|
ST_STATUS
|
|
ExPoolInit(MEMORY_POOL *Pool)
|
|
{
|
|
UCHAR LevelIdx;
|
|
MEMORY_BLOCK *Block;
|
|
ST_STATUS Status;
|
|
|
|
if (Pool == NULL) {
|
|
return STATUS_INVALID_PARAM;
|
|
}
|
|
|
|
/* Initialize the pools */
|
|
DTRACE("bringing up pool #%d\n", PoolCount);
|
|
for (LevelIdx = 0; LevelIdx < LEVEL_COUNT; ++LevelIdx) {
|
|
Block = &Pool->BlockLevels[LevelIdx];
|
|
Status = PoolInitBlock(Block);
|
|
|
|
/* XXX: We may wanna clean up our mess we made */
|
|
if (Status != STATUS_SUCCESS) {
|
|
DTRACE("critical: failed to initialize pool\n");
|
|
return STATUS_NO_MEMORY;
|
|
}
|
|
}
|
|
|
|
DTRACE("brought up %d levels for pool #%d : ok\n", LEVEL_COUNT, PoolCount);
|
|
++PoolCount;
|
|
return STATUS_SUCCESS;
|
|
}
|