}
/**
- * @brief Gets the environment-recommended heap size.
- * @return The heap size.
+ * @brief Gets the size of the application heap.
+ * @return The application heap size.
*/
static inline u32 envGetHeapSize(void) {
- extern u32 __heap_size;
- return __heap_size;
+ extern u32 __ctru_heap_size;
+ return __ctru_heap_size;
}
/**
- * @brief Gets the environment-recommended linear heap size.
+ * @brief Gets the size of the linear heap.
* @return The linear heap size.
*/
static inline u32 envGetLinearHeapSize(void) {
- extern u32 __linear_heap_size;
- return __linear_heap_size;
+ extern u32 __ctru_linear_heap_size;
+ return __ctru_linear_heap_size;
}
/**
extern char* fake_heap_end;
u32 __ctru_heap;
-u32 __ctru_heap_size;
u32 __ctru_linear_heap;
-u32 __ctru_linear_heap_size;
+
+__attribute__((weak)) u32 __ctru_heap_size = 0;
+__attribute__((weak)) u32 __ctru_linear_heap_size = 32*1024*1024;
void __attribute__((weak)) __system_allocateHeaps(void) {
u32 tmp=0;
- if(envIsHomebrew()) {
- // Use launcher-provided heap information.
- __ctru_heap_size = envGetHeapSize();
- __ctru_linear_heap_size = envGetLinearHeapSize();
- } else {
- // Distribute available memory into halves, aligning to page size.
- u32 size = (osGetMemRegionFree(MEMREGION_APPLICATION) / 2) & 0xFFFFF000;
- __ctru_heap_size = size;
- __ctru_linear_heap_size = size;
+ if (!__ctru_heap_size) {
+ // Automatically allocate all remaining free memory, aligning to page size.
+ __ctru_heap_size = osGetMemRegionFree(MEMREGION_APPLICATION) &~ 0xFFF;
+ if (__ctru_heap_size <= __ctru_linear_heap_size)
+ svcBreak(USERBREAK_PANIC);
+ __ctru_heap_size -= __ctru_linear_heap_size;
}
// Allocate the application heap