Exemple #1
0
int main(){
	int a[2],*p;
	int *max_address(int []);
	for(p=a;p<a+2;p++)
		scanf("%d",p);
	printf("Address of the bigger is %d",*max_address(a));
	return 0;
}
Exemple #2
0
void KHeap::install(uint32_t start, const uint32_t &end, const uint32_t &max, const bool &supervisor, const bool &readonly)
{
    index=new Ordered_array<header_t*>( (void*)(start), KHEAP_INDEX_SIZE );
////	index=(Ordered_array<header_t*>*)( kmalloc( sizeof(index) ) );
////	index->init( (void*)(start), KHEAP_INDEX_SIZE );
//	heap_t *heap = (heap_t*)( kmalloc(sizeof(heap_t)) );

    // All our assumptions are made on startAddress and endAddress being page-aligned.
    ASSERT(start%0x1000 == 0);
    ASSERT(end_address()%0x1000 == 0);

    // Initialise the index.
//	heap->index = place_ordered_array( (void*)start, HEAP_INDEX_SIZE, &header_t_less_than);

    // Shift the start address forward to resemble where we can start putting data.
//	start += sizeof(type_t)*HEAP_INDEX_SIZE;
    start += index->abs_size();

    // Make sure the start address is page-aligned.
    if( (start&0xFFFFF000)!=0 ) {
        start &= 0xFFFFF000;
        start += 0x1000;
    }
    // Write the start, end and max addresses into the heap structure.
    start_address(start);
    end_address(end);
    max_address(max);
    this->supervisor(supervisor);
    this->readonly(readonly);

    // We start off with one large hole in the index.
    header_t *hole=(header_t *)(start);
    hole->size=end_address()-start_address();
    hole->magic=KHEAP_MAGIC;
    hole->is_hole=true;
    /*
    	kprintf("FREEEEEEEE!!! header->magic=%p\n",hole->magic);
    	kprintf("FREEEEEEEE! header->size=%u\n",hole->size);
    	kprintf("FREEEEEEEE! header=%p\n",hole);
    */
    index->insert(hole);

    kheap_kfree_handler=this;
    kfree_set_handler(kheap_kfree);

    kheap_kmalloc_handler=this;
    kmalloc_set_handler(kheap_kmalloc);

    paging.current_directory=paging.clone_directory(paging.kernel_directory);
    paging.switch_page_directory(paging.current_directory);

//	kprintf("Sai!!!\n");
//	halt_machine();

}
Exemple #3
0
void KHeap::expand( uint32_t new_size ) {
    // Sanity check.
    ASSERT(new_size>end_address()-start_address());
    // Get the nearest following page boundary.
    if( (new_size&0xFFFFF000)!=0 ) {
        new_size &= 0xFFFFF000;
        new_size += 0x1000;
    }
    // Make sure we are not overreaching ourselves.
    ASSERT( start_address()+new_size<=max_address());

    // This should always be on a page boundary.
    uint32_t old_size=end_address()-start_address();
    uint32_t i=old_size;
    while( i<new_size ) {
        paging.alloc_frame( paging.get_page(start_address()+i, true, paging.kernel_directory),
                            supervisor(), !readonly() );
        i += 0x1000 /* page size */;
    }
    end_address( start_address()+new_size );
}