summaryrefslogtreecommitdiff
path: root/src/boot_O2/system_malloc.c
blob: 61906ce4284668cb1397cf711bc09ada1b165958 (plain)
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
#include "global.h"

Arena gSystemArena;

void* SystemArena_Malloc(u32 size) {
    return __osMalloc(&gSystemArena, size);
}

void* SystemArena_MallocR(u32 size) {
    return __osMallocR(&gSystemArena, size);
}

void* SystemArena_Realloc(void* oldPtr, u32 newSize) {
    return __osRealloc(&gSystemArena, oldPtr, newSize);
}

void SystemArena_Free(void* ptr) {
    __osFree(&gSystemArena, ptr);
}

void* SystemArena_Calloc(u32 elements, u32 size) {
    void* ptr;
    u32 totalSize = elements * size;

    ptr = __osMalloc(&gSystemArena, totalSize);
    if (ptr != NULL) {
        bzero(ptr, totalSize);
    }
    return ptr;
}

void SystemArena_AnalyzeArena(u32* maxFreeBlock, u32* bytesFree, u32* bytesAllocated) {
    __osAnalyzeArena(&gSystemArena, maxFreeBlock, bytesFree, bytesAllocated);
}

u32 SystemArena_CheckArena(void) {
    return __osCheckArena(&gSystemArena);
}

void SystemArena_InitArena(void* start, u32 size) {
    __osMallocInit(&gSystemArena, start, size);
}

void SystemArena_Cleanup(void) {
    __osMallocCleanup(&gSystemArena);
}

u8 SystemArena_IsInitialized(void) {
    return __osMallocIsInitalized(&gSystemArena);
}