summaryrefslogtreecommitdiff
path: root/src/kernel/mem/heap.basic.h
blob: b52be4e2a537cc1649f8c3013079b70d444ebe06 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#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