aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/paging/kheap.h
blob: 7a929572952647b03099ae4226035c8b01373bd9 (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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#ifndef MELVIX_KHEAP_H
#define MELVIX_KHEAP_H

#include <stdbool.h>
#include <stddef.h>

#define KHEAP_MAGIC    0x13374242
#define KHEAP_MAGIC2 0xDEADBEEF
#define KHEAP_END 0xFFFFDEAD
#define MEM_END 0x8000000

extern unsigned int end;

typedef struct {
    unsigned int magic;
    bool free;
    unsigned int size;
    unsigned int magic2;
} heap_header_t;

typedef struct {
    unsigned int magic;
    unsigned int size;
    unsigned int magic2;
} heap_footer_t;

#define HEAP_S (sizeof(heap_header_t))
#define HEAP_TOTAL (sizeof(heap_footer_t) + HEAP_S)
#define HEAP_MINIMUM 1
#define HEAP_FIND_SIZE (HEAP_TOTAL + HEAP_MINIMUM)

void init_kheap();

void *fmalloc(unsigned int size);

void *kmalloc(unsigned int size);

void *kmalloc_a(unsigned int size);

void kfree(void *ptr);

void *umalloc(size_t size);

void ufree(void *address);

void init_heap(heap_header_t *heap, size_t size);

#define KHEAP_SIZE 0xFFFFF
#define UHEAP_SIZE 0xFFFFF

#endif