/// <summary> /// Frees an allocate virtual address range and marks the corresponding physical addresses as free /// </summary> /// <param name="address">The starting address</param> /// <param name="size">The size</param> public static void UnMap(void *address, int size) { // Page align size uint sizeAligned = AlignUp((uint)size); int start = (int)AlignDown((uint)address) / 0x1000; int addressStart = (int)AlignDown((uint)address); int addressEnd = addressStart + (int)sizeAligned; // Free physical memory for (int i = addressStart; i < addressEnd; i += 0x1000) { void *phys = GetPhysicalFromVirtual((void *)i); PhysicalMemoryManager.Free(phys); } // Free virtual memory bitmap.ClearRange(start, (int)(sizeAligned / 0x1000)); }