Simplify application/linear heap size management
This commit is contained in:
parent
635d3e6640
commit
d42efe636b
@ -36,21 +36,21 @@ static inline u32 envGetAptAppId(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Gets the environment-recommended heap size.
|
* @brief Gets the size of the application heap.
|
||||||
* @return The heap size.
|
* @return The application heap size.
|
||||||
*/
|
*/
|
||||||
static inline u32 envGetHeapSize(void) {
|
static inline u32 envGetHeapSize(void) {
|
||||||
extern u32 __heap_size;
|
extern u32 __ctru_heap_size;
|
||||||
return __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.
|
* @return The linear heap size.
|
||||||
*/
|
*/
|
||||||
static inline u32 envGetLinearHeapSize(void) {
|
static inline u32 envGetLinearHeapSize(void) {
|
||||||
extern u32 __linear_heap_size;
|
extern u32 __ctru_linear_heap_size;
|
||||||
return __linear_heap_size;
|
return __ctru_linear_heap_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -7,22 +7,20 @@ extern char* fake_heap_start;
|
|||||||
extern char* fake_heap_end;
|
extern char* fake_heap_end;
|
||||||
|
|
||||||
u32 __ctru_heap;
|
u32 __ctru_heap;
|
||||||
u32 __ctru_heap_size;
|
|
||||||
u32 __ctru_linear_heap;
|
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) {
|
void __attribute__((weak)) __system_allocateHeaps(void) {
|
||||||
u32 tmp=0;
|
u32 tmp=0;
|
||||||
|
|
||||||
if(envIsHomebrew()) {
|
if (!__ctru_heap_size) {
|
||||||
// Use launcher-provided heap information.
|
// Automatically allocate all remaining free memory, aligning to page size.
|
||||||
__ctru_heap_size = envGetHeapSize();
|
__ctru_heap_size = osGetMemRegionFree(MEMREGION_APPLICATION) &~ 0xFFF;
|
||||||
__ctru_linear_heap_size = envGetLinearHeapSize();
|
if (__ctru_heap_size <= __ctru_linear_heap_size)
|
||||||
} else {
|
svcBreak(USERBREAK_PANIC);
|
||||||
// Distribute available memory into halves, aligning to page size.
|
__ctru_heap_size -= __ctru_linear_heap_size;
|
||||||
u32 size = (osGetMemRegionFree(MEMREGION_APPLICATION) / 2) & 0xFFFFF000;
|
|
||||||
__ctru_heap_size = size;
|
|
||||||
__ctru_linear_heap_size = size;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allocate the application heap
|
// Allocate the application heap
|
||||||
|
Loading…
Reference in New Issue
Block a user