src/kernel/mm/vmm.c
/**
 * Unmapping the virtual address from the current page directory.
 * 
 * @param virt Virtual address to unmap.
 */
Unmapping the virtual address from the current page directory.

@param virt Virtual address to unmap.
Unmapping the virtual address from the current page directory . @param virt Virtual address to unmap .
bool vUnmapPage(void *virt) {
	if (((uint32_t)virt & 0xFFFFF000) != (uint32_t)virt)
		return false;
	uint32_t *pd = PD_VADDR;
	if (pd[PAGE_DIRECTORY_INDEX((uint32_t)virt)] & 1) {
		uint32_t *pt = (uint32_t *)(PT_BASE_VADDR + (PAGE_DIRECTORY_INDEX((uint32_t)virt) * 0x1000));
		if (pt[PAGE_TABLE_INDEX((uint32_t)virt)] & 1)
			pt[PAGE_TABLE_INDEX((uint32_t)virt)] = 0x2;		
		int i = 0;
		while (i < 1024 && !(pt[i] & 1)) {
			i++;
		}
		if (i == 1024)
			pFreePage(pd[PAGE_DIRECTORY_INDEX((uint32_t)virt)] & 0xFFFFF000);
		printf("virtual 0x%x unmapped\n", virt);
		return true;
	}
	return false;
}
bool vUnmapPage ( void * virt ) { if ( ( ( uint32_t ) virt & 0xFFFFF000 ) != ( uint32_t ) virt ) return false ; uint32_t * pd = PD_VADDR ; if ( pd [ PAGE_DIRECTORY_INDEX ( ( uint32_t ) virt ) ] & 1 ) { uint32_t * pt = ( uint32_t * ) ( PT_BASE_VADDR + ( PAGE_DIRECTORY_INDEX ( ( uint32_t ) virt ) * 0x1000 ) ) ; if ( pt [ PAGE_TABLE_INDEX ( ( uint32_t ) virt ) ] & 1 ) pt [ PAGE_TABLE_INDEX ( ( uint32_t ) virt ) ] = 0x2 ; int i = 0 ; while ( i < 1024 && ! ( pt [ i ] & 1 ) ) { i ++ ; } if ( i == 1024 ) pFreePage ( pd [ PAGE_DIRECTORY_INDEX ( ( uint32_t ) virt ) ] & 0xFFFFF000 ) ; printf ( " \n " , virt ) ; return true ; } return false ; }
Unmapping the virtual address from the current page directory.
Unmapping the virtual address from the current page directory .
// Verify that the address is page-aligned // The page table is present // The page is mapped, unmap it. // Set not-present, but r/w // Check if there are no more pages present // The page table is empty, free the memory