[3DS] Free memory in 1MB blocks

When freeing large blocks of memory, the 3DS may kernel panic. Freeing
in smaller blocks seems to avoid the crashes.
This commit is contained in:
Justin Weiss 2020-09-28 19:12:15 -07:00
parent d34c427f3f
commit 5756ff0b16

View File

@ -141,9 +141,12 @@ void* _sbrk_r(struct _reent *ptr, ptrdiff_t incr)
__heap_size += diff;
if (diff < 0)
svcControlMemory(&tmp, __heapBase + __heap_size,
0x0, -diff, MEMOP_FREE, MEMPERM_READ | MEMPERM_WRITE);
while (diff < 0) {
int size = -diff < 0x100000 ? -diff : 0x100000;
diff += size;
svcControlMemory(&tmp, __heapBase + __heap_size - diff,
0x0, size, MEMOP_FREE, 0);
}
sbrk_top += incr;