src/kernel/mm/vmm.c
/**
 * Allocate n virtual page and sets them to zero.
 * 
 * @see vMapPage()
 * @see vAllocPage()
 * 
 * @param virt Start address to map
 * @param n Number of contiguous pages to map
 * @param man If that address is mandatory or could be anyone else
 * 
 * @return returns the starting virtual mapped address
 */
Allocate n virtual page and sets them to zero.



@param virt Start address to map
@param n Number of contiguous pages to map
@param man If that address is mandatory or could be anyone else

@return returns the starting virtual mapped address
Allocate n virtual page and sets them to zero . @param virt Start address to map @param n Number of contiguous pages to map @param man If that address is mandatory or could be anyone else @return returns the starting virtual mapped address
void *vAllocPages(void *virt, uint32_t flags, uint32_t n, bool man) {
	uint32_t paddr[n];
	uint32_t vaddr = (uint32_t)virt;
	paddr[0] =  pAllocPage();
	if (vMapPage(paddr[0], vaddr, flags)) {
		int32_t i;
		for (i = 1, vaddr += PAGE_SIZE; i < (int32_t)n; i++, vaddr += PAGE_SIZE) {
			paddr[i] = pAllocPage();
			if (!vMapPage(paddr[i], vaddr, flags)) {
				for (vaddr -= PAGE_SIZE; i >= 0; i--, vaddr -= PAGE_SIZE) {
					if (i != 0)
						vUnmapPage(vaddr);
					pFreePage(paddr[i]);
				}
				return (void *)0;
			}
		}
		return virt;
	} else if (man) 
		return (void *)0;
	else {
		uint32_t new_vaddr = vAllocPage(virt, flags, false);
		int32_t i;
		for (i = 1, new_vaddr += PAGE_SIZE; i < (int32_t)n; i++, new_vaddr += PAGE_SIZE) {
			paddr[i] = pAllocPage();
			if (!vMapPage(paddr[i], new_vaddr, flags)) {
				for (new_vaddr -= PAGE_SIZE; i >= 0; i--, new_vaddr -= PAGE_SIZE) {
					if (i != 0)
						vUnmapPage(new_vaddr);
					pFreePage(paddr[i]);
				}
				return (void *)0;
			}
		}
		return new_vaddr;
	}
}
void * vAllocPages ( void * virt , uint32_t flags , uint32_t n , bool man ) { uint32_t paddr [ n ] ; uint32_t vaddr = ( uint32_t ) virt ; paddr [ 0 ] = pAllocPage ( ) ; if ( vMapPage ( paddr [ 0 ] , vaddr , flags ) ) { int32_t i ; for ( i = 1 , vaddr += PAGE_SIZE ; i < ( int32_t ) n ; i ++ , vaddr += PAGE_SIZE ) { paddr [ i ] = pAllocPage ( ) ; if ( ! vMapPage ( paddr [ i ] , vaddr , flags ) ) { for ( vaddr -= PAGE_SIZE ; i >= 0 ; i -- , vaddr -= PAGE_SIZE ) { if ( i != 0 ) vUnmapPage ( vaddr ) ; pFreePage ( paddr [ i ] ) ; } return ( void * ) 0 ; } } return virt ; } else if ( man ) return ( void * ) 0 ; else { uint32_t new_vaddr = vAllocPage ( virt , flags , false ) ; int32_t i ; for ( i = 1 , new_vaddr += PAGE_SIZE ; i < ( int32_t ) n ; i ++ , new_vaddr += PAGE_SIZE ) { paddr [ i ] = pAllocPage ( ) ; if ( ! vMapPage ( paddr [ i ] , new_vaddr , flags ) ) { for ( new_vaddr -= PAGE_SIZE ; i >= 0 ; i -- , new_vaddr -= PAGE_SIZE ) { if ( i != 0 ) vUnmapPage ( new_vaddr ) ; pFreePage ( paddr [ i ] ) ; } return ( void * ) 0 ; } } return new_vaddr ; } }
Allocate n virtual page and sets them to zero.
Allocate n virtual page and sets them to zero .
// Continue to map for the remaining n // Unmap all the mapping // Find the frist free page and then starts mapping // Unmap all the mapping