SSUOS_P6/src/kernel/mem/palloc.c
/* Obtains and returns a group of PAGE_CNT contiguous free pages. */
Obtains and returns a group of PAGE_CNT contiguous free pages.
Obtains and returns a group of PAGE_CNT contiguous free pages .
void *palloc_get_multiple_page(enum palloc_flags flags,size_t page_cnt)
{
	int i;
	struct memory_pool *pool;
	void * pages = NULL;
	size_t from,page_idx,bit_count;
	if(page_cnt <= 0) 
		return (void *)NULL;
	if(flags == kernel_area) 
		pool = &kernel_pool;
	else 
		pool = &user_pool;
	bit_count = bitmap_size(pool->bitmap);
	for(i = 0; i < bit_count; i++)
	{
		if(test_bitmap(pool->bitmap,i) == 0) 
		{
			from = i;
			break;
		}
	}
	page_idx = find_set_bitmap(pool->bitmap,from,page_cnt,false); 
	if(flags == kernel_area)
		pages = (void *)(KERNEL_ADDR + PAGE_SIZE * page_idx);
	else
		pages = (void *)(USER_POOL_START + PAGE_SIZE * page_idx);
	if(pages != NULL)
		memset((void *)pages,0,page_cnt*PAGE_SIZE);
	return (void *)pages;
}
void * palloc_get_multiple_page ( enum palloc_flags flags , size_t page_cnt ) { int i ; struct memory_pool * pool ; void * pages = NULL ; size_t from , page_idx , bit_count ; if ( page_cnt <= 0 ) return ( void * ) NULL ; if ( flags == kernel_area ) pool = & kernel_pool ; else pool = & user_pool ; bit_count = bitmap_size ( pool -> bitmap ) ; for ( i = 0 ; i < bit_count ; i ++ ) { if ( test_bitmap ( pool -> bitmap , i ) == 0 ) { from = i ; break ; } } page_idx = find_set_bitmap ( pool -> bitmap , from , page_cnt , false ) ; if ( flags == kernel_area ) pages = ( void * ) ( KERNEL_ADDR + PAGE_SIZE * page_idx ) ; else pages = ( void * ) ( USER_POOL_START + PAGE_SIZE * page_idx ) ; if ( pages != NULL ) memset ( ( void * ) pages , 0 , page_cnt * PAGE_SIZE ) ; return ( void * ) pages ; }
Obtains and returns a group of PAGE_CNT contiguous free pages.
Obtains and returns a group of PAGE_CNT contiguous free pages .
// error handling // kernel? // user? // find the starting index // get a page index