heap_t *create_heap(uint32_t start, uint32_t end_addr, uint32_t max, bool supervisor, bool readonly) { 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_addr % 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; // 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. heap->start_address = start; heap->end_address = end_addr; heap->max_address = max; heap->supervisor = supervisor; heap->readonly = readonly; // We start off with one large hole in the index. header_t *hole = (header_t *)start; hole->size = end_addr-start; hole->magic = HEAP_MAGIC; hole->is_hole = 1; insert_ordered_array((void*) hole, &heap->index); return heap; }
Heap *create_heap(uintptr_t start, uintptr_t end, uintptr_t max, bool supervisor, bool readonly) { Heap *heap = (Heap*)kmalloc(sizeof(Heap)); // Make sure start and end are page-aligned ASSERT(aligned(start)); ASSERT(aligned(end)); heap->index = place_ordered_array((void*)start, HEAP_INDEX_SIZE, header_comparer); start += sizeof(void*) * HEAP_INDEX_SIZE; align_up(start); heap->start_addr = start; heap->end_addr = end; heap->max_addr = max; heap->supervisor = supervisor; heap->readonly = readonly; // At the start, the whole thing is a hole Header *hole = make_header(start, end - start, true); ordered_array_insert(&heap->index, (void*)hole); return heap; }
heap_t* create_heap(u32int start, u32int end, u32int max) { heap_t *heap = (heap_t *)kmalloc(sizeof(heap_t)); ASSERT(start % 0x1000 == 0); ASSERT(end % 0x1000 == 0); heap->index = place_ordered_array((void *)start, HEAP_INDEX_SIZE, header_less_than); start += sizeof(type_t) * HEAP_INDEX_SIZE; if (start & ~0xfffff000) { start &= 0xfffff000; start += 0x1000; } heap->start_address = start; heap->end_address = end; heap->max_address = max; header_t *hole = (header_t *)start; hole->size = end - start; hole->magic = HEAP_MAGIC; hole->is_hole = 1; insert_ordered_array((type_t)hole, &heap->index); return heap; }
vmem_heap_t* create_heap(addr start, addr end_addr, addr max, unsigned char supervisor, unsigned char readonly) { struct vmem_heap* heap = (struct vmem_heap*)kmalloc(sizeof(struct vmem_heap)); /* All of our assumptions are made on start and end being page-aligned */ ASSERT(start % 0x1000 == 0); ASSERT(end_addr % 0x1000 == 0); /* Initalize the index */ heap->index = place_ordered_array((void*)start, VMEM_INDEX_SIZE, &vmem_header_less_than); /* Shift the start address forward to resemble where we can start putting data */ start += sizeof(type_t) * VMEM_INDEX_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 */ heap->start_address = start; heap->end_address = end_addr; heap->max_address = max; heap->supervisor = supervisor; heap->readonly = readonly; /* We start off with one large hole in the index */ struct vmem_header* hole = (struct vmem_header*)start; hole->size = end_addr - start; hole->magic = VMEM_MAGIC; hole->is_hole = 1; insert_ordered_array((void*)hole, &heap->index); return heap; }
heap_t *create_heap(u32 start, u32 end_addr, u32 max, u8 supervisor, u8 readonly) { heap_t *heap = (heap_t *)kmalloc(sizeof(heap_t)); /* Initialize the index */ heap->index = place_ordered_array((void *)start, HEAP_INDEX_SIZE, header_t_less_than); start += HEAP_INDEX_SIZE * sizeof(type_t); heap->start_address = start; heap->end_address = end_addr; heap->max_address = max; heap->supervisor = supervisor; heap->readonly = readonly; /* We start off with one large hole in the index */ header_t *hole = (header_t *)start; hole->size = end_addr - start; hole->magic = HEAP_MAGIC; hole->is_hole = 1; insert_ordered_array((void *)hole, &heap->index); return heap; }
Ordered_array create_ordered_array(size_t max_size, Comparer comparer) { size_t size = max_size * sizeof(void*); return place_ordered_array((void*)kmalloc(size), max_size, comparer); }