Page allocator functionnal #67

This commit is contained in:
Adrien Bourmault 2020-01-14 16:58:38 +01:00
parent 2df15a1488
commit 2bec082b2d
2 changed files with 16 additions and 14 deletions

View File

@ -39,7 +39,9 @@ typedef struct AllocatedPage_t{
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
error_t MmGetFreePageFrame(void **framePtr, size_t *pageNumber, size_t size); ulong MmAllocPageFrame(void **frameListPtr, size_t *pageNumber, size_t size, bool contiguous);
void MmFreePageFrame(ulong id);
error_t MmTestBusyPage(void); error_t MmTestBusyPage(void);
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//

View File

@ -100,9 +100,9 @@ static void removePageFromBusyList(void *phyPageAddr)
} }
// //
// Returns an id to identify a page frame allocated // Returns an id to identify a page frame allocated (kernel)
// //
ulong MmAllocKernelPageFrame(void **frameListPtr, size_t *pageNumber, size_t size, bool contiguous) ulong MmAllocPageFrame(void **frameListPtr, size_t *pageNumber, size_t size, bool contiguous)
{ {
static ulong id = 0; static ulong id = 0;
*pageNumber = (((ulong)size - 1) / KPAGESIZE) + 1; *pageNumber = (((ulong)size - 1) / KPAGESIZE) + 1;
@ -143,7 +143,7 @@ ulong MmAllocKernelPageFrame(void **frameListPtr, size_t *pageNumber, size_t siz
return id; return id;
} }
void MmFreeKernelPageFrame(ulong id) void MmFreePageFrame(ulong id)
{ {
AllocatedPage_t *busyPage = &busyPagesList; AllocatedPage_t *busyPage = &busyPagesList;
@ -164,50 +164,50 @@ error_t MmTestBusyPage(void)
DebugLog("\nAlloc 6677 bytes\n"); DebugLog("\nAlloc 6677 bytes\n");
void **ptr = NULL; void **ptr = NULL;
size_t n = 0; size_t n = 0;
ulong id1 = MmAllocKernelPageFrame (ptr, &n, 6677, false); ulong id1 = MmAllocPageFrame (ptr, &n, 6677, false);
DebugLog("\nAlloc 9045 bytes\n"); DebugLog("\nAlloc 9045 bytes\n");
void **ptr2 = NULL; void **ptr2 = NULL;
size_t n2 = 0; size_t n2 = 0;
ulong id2 = MmAllocKernelPageFrame (ptr2, &n2, 9045, false); ulong id2 = MmAllocPageFrame (ptr2, &n2, 9045, false);
DebugLog("\nAlloc 1200 bytes\n"); DebugLog("\nAlloc 1200 bytes\n");
void **ptr3 = NULL; void **ptr3 = NULL;
size_t n3 = 0; size_t n3 = 0;
ulong id3 = MmAllocKernelPageFrame (ptr3, &n3, 1200, false); ulong id3 = MmAllocPageFrame (ptr3, &n3, 1200, false);
DebugLog("\nAlloc 4096 bytes\n"); DebugLog("\nAlloc 4096 bytes\n");
void **ptr4 = NULL; void **ptr4 = NULL;
size_t n4 = 0; size_t n4 = 0;
ulong id4 = MmAllocKernelPageFrame (ptr3, &n3, 4096, false); ulong id4 = MmAllocPageFrame (ptr3, &n3, 4096, false);
DebugLog("\nAlloc 4097 bytes\n"); DebugLog("\nAlloc 4097 bytes\n");
void **ptr5 = NULL; void **ptr5 = NULL;
size_t n5 = 0; size_t n5 = 0;
ulong id5 = MmAllocKernelPageFrame (ptr3, &n3, 4097, false); ulong id5 = MmAllocPageFrame (ptr3, &n3, 4097, false);
printBusyPages(); printBusyPages();
DebugLog("\nFree 6677 and 1200 bytes\n"); DebugLog("\nFree 6677 and 1200 bytes\n");
MmFreeKernelPageFrame(id1); MmFreePageFrame(id1);
MmFreeKernelPageFrame(id3); MmFreePageFrame(id3);
DebugLog("\nAlloc 10000 bytes\n"); DebugLog("\nAlloc 10000 bytes\n");
void **ptr6 = NULL; void **ptr6 = NULL;
size_t n6 = 0; size_t n6 = 0;
ulong id6 = MmAllocKernelPageFrame (ptr3, &n3, 10000, false); ulong id6 = MmAllocPageFrame (ptr3, &n3, 10000, false);
printBusyPages(); printBusyPages();
DebugLog("\nFree 10000 bytes\n"); DebugLog("\nFree 10000 bytes\n");
MmFreeKernelPageFrame(id6); MmFreePageFrame(id6);
printBusyPages(); printBusyPages();
DebugLog("\nAlloc 10000 bytes contiguous\n"); DebugLog("\nAlloc 10000 bytes contiguous\n");
void **ptr7 = NULL; void **ptr7 = NULL;
size_t n7 = 0; size_t n7 = 0;
ulong id7 = MmAllocKernelPageFrame (ptr3, &n3, 10000, true); ulong id7 = MmAllocPageFrame (ptr3, &n3, 10000, true);
printBusyPages(); printBusyPages();