heap *create_heap(UINT start, UINT end, UINT memend, UINT pageflags) { heap *newheap = (heap *)_kmalloc(sizeof(heap)); mm_header *initholestart; mm_footer *initholeend; ASSERT_ALIGN(start); ASSERT_ALIGN(end); ASSERT_ALIGN(memend); newheap->entries = (mm_header **)start; start += MM_INDEX_COUNT * sizeof(mm_header *); ASSERT_ALIGN(start); newheap->start = start; newheap->end = end; newheap->memend = memend; newheap->pageflags = pageflags; initholestart = (mm_header *) start; initholestart->magic = MM_MAGIC; initholestart->size = end - start; initholestart->flag = MM_FLAG_HOLE; newheap->entries[0] = initholestart; initholeend = (mm_footer *) (end - sizeof(mm_footer)); initholeend->magic = MM_MAGIC; initholeend->header = newheap->entries[0]; newheap->entrycount = 1; newheap->maxentries = MM_INDEX_COUNT; return newheap; }
void* kmalloc_a(size_t size, uint32_t align, uint32_t* phys) { return _kmalloc(size, align, phys); };
void* kmalloc(size_t size) { return _kmalloc(size, KMALLOC_MIN_ALIGN, NULL); };
/** * Allocates a memory block * * @param[in] size The size of memory block to be allocated. * @param[in] flags Flags. * @return The pointer to the allocated memory block on success or * NULL on failure. * */ void *kmalloc(size_t size, int flags) { struct chunk *chunks; chunks = (IS_WITHIN_LARGE_CHUNK_SIZE(size))? large_chunks : small_chunks; return _kmalloc(chunks, size, flags); }
void *malloc(UINT size) { if (!kheap) return (void *)_kmalloc(size); else return heap_malloc(size, 0, kheap); }
void * kmalloc_ap (size_t sz, uintptr_t *phys) { return _kmalloc(sz, 1, phys); }
void * kmalloc_a (size_t sz) { return _kmalloc(sz, 1, 0); }
void * kmalloc (size_t sz) { return _kmalloc(sz, 0, 0); }