src/platform/3ds/ctru-heap.c (view raw)
1/* This code is mostly from ctrulib, which contains the following license:
2
3 This software is provided 'as-is', without any express or implied
4 warranty. In no event will the authors be held liable for any damages
5 arising from the use of this software.
6
7 Permission is granted to anyone to use this software for any purpose,
8 including commercial applications, and to alter it and redistribute it
9 freely, subject to the following restrictions:
10
11 * The origin of this software must not be misrepresented; you must not
12 claim that you wrote the original software. If you use this software in
13 a product, an acknowledgment in the product documentation would be
14 appreciated but is not required.
15
16 * Altered source versions must be plainly marked as such, and must not be
17 misrepresented as being the original software.
18
19 * This notice may not be removed or altered from any source distribution.
20*/
21
22#include <3ds/types.h>
23#include <3ds/svc.h>
24
25#include "util/common.h"
26
27extern char* fake_heap_start;
28extern char* fake_heap_end;
29extern u32 __ctru_linear_heap;
30extern u32 __ctru_heap;
31extern u32 __ctru_heap_size;
32extern u32 __ctru_linear_heap_size;
33static u32 __custom_heap_size = 0x02400000;
34static u32 __custom_linear_heap_size = 0x01400000;
35
36uint32_t* romBuffer;
37size_t romBufferSize;
38
39bool allocateRomBuffer(void) {
40 romBuffer = malloc(0x02000000);
41 if (romBuffer) {
42 romBufferSize = 0x02000000;
43 return true;
44 }
45 romBuffer = malloc(0x01000000);
46 if (romBuffer) {
47 romBufferSize = 0x01000000;
48 return true;
49 }
50 return false;
51}
52
53void __system_allocateHeaps() {
54 u32 tmp=0;
55
56 __ctru_heap_size = __custom_heap_size;
57 __ctru_linear_heap_size = __custom_linear_heap_size;
58
59 // Allocate the application heap
60 __ctru_heap = 0x08000000;
61 svcControlMemory(&tmp, __ctru_heap, 0x0, __ctru_heap_size, MEMOP_ALLOC, MEMPERM_READ | MEMPERM_WRITE);
62
63 // Allocate the linear heap
64 svcControlMemory(&__ctru_linear_heap, 0x0, 0x0, __ctru_linear_heap_size, MEMOP_ALLOC_LINEAR, MEMPERM_READ | MEMPERM_WRITE);
65 // Set up newlib heap
66 fake_heap_start = (char*)__ctru_heap;
67 fake_heap_end = fake_heap_start + __ctru_heap_size;
68}