-
Notifications
You must be signed in to change notification settings - Fork 1
/
heap.h
47 lines (36 loc) · 1.2 KB
/
heap.h
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/* heap.h
* interface for creating a heap
*/
#ifndef HEAP_H
#define HEAP_H
#include "config.h"
#include <stdint.h>
#include <stddef.h>
#define HEAP_BLOCK_TABLE_ENTRY_FREE 0x00
#define HEAP_BLOCK_TABLE_ENTRY_TAKEN 0x01
#define HEAP_BLOCK_IS_FIRST 0b01000000
#define HEAP_BLOCK_HAS_NEXT 0b10000000
/* TODO: The goal is to make this heap block table entry type completely opaque,
* that way it is easy to alter in the future. Making it opaques requires writing
* functions for interacting with it.
* hbte_t = heap block table entry typedef
*/
typedef unsigned char hbte_t;
/* TODO: rename heap entry table to something else. Entry table is confusing and redundant */
struct heap_entry_table {
//hbte_t *first_entry;
hbte_t *entries;
size_t total_entries;
};
struct heap_desc {
struct heap_entry_table* table;
void *start_addr;
};
/*
* pass in unitialized heap_desc but a valid heap_entry_table. we will determine if table is valid
* tbh could make this simpler for caller
*/
int heap_create(struct heap_desc *heap, void *start_addr, void *end_addr, struct heap_entry_table *table);
void* heap_malloc(struct heap_desc *heap, size_t size);
int heap_free(struct heap_desc *heap, void *ptr);
#endif