-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmemory.h
50 lines (38 loc) · 1.05 KB
/
memory.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
48
49
50
#ifndef _MEMORY_H
#define _MEMORY_H
#include <stddef.h>
// Aligns size to 8 bytes
#define ALIGN_8(size) (((size) + 0x7) & ~0x7)
extern struct HeapSegment* gFirstHeapSegment;
#define MALLOC_FREE_BLOCK 0xFEEE
#define MALLOC_USED_BLOCK 0xEEEF
#define MALLOC_BLOCK_HEAD 0xEEAD0000
#define MALLOC_BLOCK_FOOT 0xF0000000
struct HeapUsedSegment
{
unsigned int header;
void* segmentEnd;
};
struct HeapSegment
{
unsigned int header;
void* segmentEnd;
struct HeapSegment* nextSegment;
struct HeapSegment* prevSegment;
};
struct HeapSegmentFooter
{
struct HeapSegment* header;
unsigned int footer;
};
#define MIN_HEAP_BLOCK_SIZE (sizeof(struct HeapSegment) + sizeof(struct HeapSegmentFooter))
void initHeap(void* heapEnd);
void *cacheFreePointer(void* target);
void *malloc(unsigned int size);
void *realloc(void* target, unsigned int size);
void free(void* target);
int calculateBytesFree();
int calculateLargestFreeChunk();
extern void zeroMemory(void* memory, int size);
extern void memCopy(void* target, const void* src, int size);
#endif