1/** 2 * \file 3 * \brief Simple heap allocator 4 */ 5 6/* 7 * Copyright (c) 2008, ETH Zurich. 8 * All rights reserved. 9 * 10 * This file is distributed under the terms in the attached LICENSE file. 11 * If you do not find this file, copies can be found by writing to: 12 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group. 13 */ 14 15#ifndef LIBBARRELFISH_HEAP_H 16#define LIBBARRELFISH_HEAP_H 17 18#include <sys/cdefs.h> 19 20__BEGIN_DECLS 21 22union heap_header { /* block header */ 23 struct { 24 union heap_header *ptr; /* next block if on free list */ 25 unsigned size; /* size of this block */ 26 } s; 27 uintptr_t x; /* force alignment of blocks */ 28}; 29 30struct heap; 31 32typedef union heap_header *(*Morecore_func_t)(struct heap *h, unsigned nu); 33 34struct heap { 35 union heap_header base; /* allocated list head */ 36 union heap_header *freep; /* start of free list */ 37 Morecore_func_t morecore_func; /* morecore function */ 38}; 39 40void heap_init(struct heap *heap, void *buf, size_t buflen, 41 Morecore_func_t morecore_func); 42void *heap_alloc(struct heap *heap, size_t nbytes); 43void heap_free(struct heap *heap, void *ap); 44union heap_header *heap_default_morecore(struct heap *h, unsigned nu); 45 46__END_DECLS 47 48#endif // LIBBARRELFISH_HEAP_H 49