summaryrefslogtreecommitdiff
path: root/arm9/lib/src/custom_allocator.c
diff options
context:
space:
mode:
authorRevo <projectrevotpp@hotmail.com>2020-05-24 07:00:57 -0400
committerGitHub <noreply@github.com>2020-05-24 07:00:57 -0400
commit94af15fab8e80f61326fc0427c5412e60b0d67ea (patch)
tree9542fdb55f9b183b54ec043aa9f8b2c685bbd7d1 /arm9/lib/src/custom_allocator.c
parent0b01c7d1c57c4e21fdb0069b3ac4f9c7276b3cc1 (diff)
parentb4743f04e30937b19aca974bf2222de8fe3eb36e (diff)
Merge pull request #107 from PikalaxALT/pikalax_work
Split rodata and bss
Diffstat (limited to 'arm9/lib/src/custom_allocator.c')
-rw-r--r--arm9/lib/src/custom_allocator.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/arm9/lib/src/custom_allocator.c b/arm9/lib/src/custom_allocator.c
new file mode 100644
index 00000000..869901ce
--- /dev/null
+++ b/arm9/lib/src/custom_allocator.c
@@ -0,0 +1,32 @@
+#include "global.h"
+
+typedef void * (* AllocFunc)(u32 size);
+typedef void (* FreeFunc)(void * ptr);
+
+static FreeFunc sDestructor;
+static AllocFunc sAllocator;
+
+// Custom allocator
+ARM_FUNC void* CallCustomAllocator(u32 size)
+{
+ if (sAllocator != NULL)
+ return sAllocator(size);
+ else
+ return OS_AllocFromHeap(OS_ARENA_MAIN, -1, size);
+}
+
+// Custom destructor
+ARM_FUNC void CallCustomDestructor(void * ptr)
+{
+ if (sDestructor != NULL)
+ sDestructor(ptr);
+ else
+ OS_FreeToHeap(OS_ARENA_MAIN, -1, ptr);
+}
+
+// Custom alloc/free setter
+ARM_FUNC void SetCustomAllocatorAndDestructor(AllocFunc allocator, FreeFunc destructor)
+{
+ sAllocator = allocator;
+ sDestructor = destructor;
+}