ptos: pool: Add freeing of allocated memory

Signed-off-by: Chloe M <chloe@mensia.org>
This commit is contained in:
2026-07-13 20:19:09 -04:00
parent aae870e874
commit 93acc859af
2 changed files with 43 additions and 0 deletions
+35
View File
@@ -268,6 +268,41 @@ ExAllocatePoolWithTag(POOL_TYPE Type, USIZE ByteCount, ULONG Tag)
return Base; return Base;
} }
VOID
ExFreePoolWithTag(VOID *Ptr, ULONG Tag)
{
POOL_HEADER *Header;
POOL_PAGE *Page;
USHORT BitOff, BitMax;
if (Ptr == NULL) {
return;
}
Header = PTR_NOFFSET(Ptr, sizeof(POOL_HEADER));
if (Header->Tag != Tag) {
KeBugCheck(
BUGCHECK_MISC,
"tag does not match pool header\n"
);
}
Page = Header->Page;
if (Page == NULL) {
KeBugCheck(
BUGCHECK_MISC,
"attempted free on malformed header\n"
);
}
BitMax = Header->SizeBytes / Header->Gran;
BitMax *= 8;
for (BitOff = Header->BitBase; BitOff < BitMax; ++BitOff) {
CLRBIT(&Page->Bitmap, BitOff);
}
}
VOID VOID
ExPoolRegionInit(POOL_REGION *Region) ExPoolRegionInit(POOL_REGION *Region)
{ {
+8
View File
@@ -89,6 +89,14 @@ typedef struct {
*/ */
VOID ExPoolRegionInit(POOL_REGION *Region); VOID ExPoolRegionInit(POOL_REGION *Region);
/*
* Free a pool with an associated tag
*
* @Ptr: Base of memory to free
* @Tag: Tag associated with allocated memory
*/
VOID ExFreePoolWithTag(VOID *Ptr, ULONG Tag);
/* /*
* Allocate a memory pool of a specific type and assign a tag * Allocate a memory pool of a specific type and assign a tag
* to it for verifying frees among other debugging needs. * to it for verifying frees among other debugging needs.