Files
PluralTechnology/service/ptos/ex/pool.c
T
2026-07-13 18:35:39 -04:00

67 lines
1.3 KiB
C

/*
* Copyright (c) 2026, Chloe M.
* Provided under the BSD-3 clause.
*
* Description: Pool allocator
* Author: Chloe M.
*/
#include <ex/pool.h>
#include <ke/bugcheck.h>
#include <mm/vm.h>
#include <ptapi/status.h>
/*
* Initialize a pool segment
*
* @Segment: Pool segment to initialize
*/
static PT_STATUS
PoolSegmentInit(POOL_SEGMENT *Segment)
{
PT_STATUS Status;
MM_RANGE Range;
if (Segment == NULL) {
return STATUS_INVALID_PARAM;
}
Status = MmAllocatePages(1, &Range);
if (Status != STATUS_SUCCESS) {
return Status;
}
Segment->PageCount = 1;
Segment->LastPage = RANGE_PTR(&Range);
return STATUS_SUCCESS;
}
VOID
ExPoolRegionInit(POOL_REGION *Region)
{
UCHAR Level;
POOL_SEGMENT *Segment;
PT_STATUS Status;
if (Region == NULL) {
KeBugCheck(
BUGCHECK_UNBOUND_RESRC,
"unbound region in ExPoolRegionInit()\n"
);
}
/* Initialize each segment level */
for (Level = 0; Level < POOL_LEVEL_MAX; ++Level) {
Segment = &Region->Level[Level];
Status = PoolSegmentInit(Segment);
if (PT_ERROR(Status)) {
KeBugCheck(
BUGCHECK_MISC,
"failed to initialize segment level %d\n",
Level
);
}
}
}