#ifndef DEF_HEAP_H #define DEF_HEAP_H /* This heap implementation is extra-simple and extra-slow. */ #include "types.h" #define HH_FREE_MAGIC 0xFEE0FEE0 #define HH_ALLOC_MAGIC 0xA110A110 #define HEAP_EXTEND_QUANTITY 0x00080000 // each time we extend the heap, extend it 512 k #define MIN_BLK_SIZE 0x20 // 32 bytes struct heap_header { uint32_t magic; struct heap_header *prev, *next; }; struct heap { struct heap_header *first, *first_free; // first_free is not necessarily free, it's just an indication size_t start_addr, end_addr, max_end; uint32_t mutex; }; void heap_create(struct heap *heap, size_t start, size_t datasize, size_t maxdatasize); void *heap_alloc(struct heap *heap, size_t sz); void heap_free(struct heap *heap, void *ptr); #endif