]> Chaos Git - corbenik/ctrulib.git/commitdiff
Simplify application/linear heap size management
authorfincs <fincs.alt1@gmail.com>
Tue, 3 Jan 2017 17:36:37 +0000 (18:36 +0100)
committerfincs <fincs.alt1@gmail.com>
Tue, 3 Jan 2017 17:36:37 +0000 (18:36 +0100)
libctru/include/3ds/env.h
libctru/source/system/allocateHeaps.c

index eaefb98e17ce20e5ddd859f8e4ba77308ed6ff91..8456e3cbd9991865e8428e1e42b21ecbaed6e371 100644 (file)
@@ -36,21 +36,21 @@ static inline u32 envGetAptAppId(void) {
 }
 
 /**
- * @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;
 }
 
 /**
index 02c9964351f565740fc7a4833c083095e66e36cc..44dfdf3b1b423e399697531208ec6e01de2e6fb5 100644 (file)
@@ -7,22 +7,20 @@ extern char* fake_heap_start;
 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