MCPcopy Create free account
hub / github.com/LemonOSProject/LemonOS / KernelAllocate2MPages

Function KernelAllocate2MPages

Kernel/src/arch/x86_64/paging.cpp:431–461  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

429 }
430
431 void* KernelAllocate2MPages(uint64_t amount){
432 uint64_t address = 0;
433 uint64_t offset = 0;
434 uint64_t counter = 0;
435 uint64_t pdptIndex = KERNEL_HEAP_PDPT_INDEX;
436 uint64_t pml4Index = KERNEL_HEAP_PML4_INDEX;
437
438 for(int i = 0; i < TABLES_PER_DIR; i++){
439 if(kernelHeapDir[i] & 0x1){
440 offset = i+1;
441 counter = 0;
442 continue;
443 }
444 counter++;
445
446 if(counter >= amount){
447 address = (PDPT_SIZE * pml4Index) + (pdptIndex * PAGE_SIZE_1G) + offset * PAGE_SIZE_2M;
448 address |= 0xFFFF000000000000;
449 while(counter--){
450 kernelHeapDir[offset] = 0x83;
451 offset++;
452 }
453 return (void*)address;
454 }
455 }
456
457 Log::Error("Kernel Out of Virtual Memory");
458 const char* reasons[1] = {"Kernel Out of Virtual Memory!"};
459 KernelPanic(reasons, 1);
460 for(;;);
461 }
462
463 void KernelFree4KPages(void* addr, uint64_t amount){
464 uint64_t pageDirIndex, pageIndex;

Callers

nothing calls this directly

Calls 2

ErrorFunction · 0.85
KernelPanicFunction · 0.85

Tested by

no test coverage detected