(VITA) Allow cores to define heap size

This commit is contained in:
Francisco José García García 2016-10-11 09:40:55 +02:00
parent f0d1a733e3
commit adfbd233ee
2 changed files with 15 additions and 12 deletions

View File

@ -8,6 +8,7 @@ static char _newlib_sbrk_mutex[32] __attribute__ ((aligned (8)));
static int _newlib_vm_memblock; static int _newlib_vm_memblock;
extern int _newlib_heap_size_user __attribute__((weak));
extern int _newlib_vm_size_user __attribute__((weak)); extern int _newlib_vm_size_user __attribute__((weak));
void * _sbrk_r(struct _reent *reent, ptrdiff_t incr) { void * _sbrk_r(struct _reent *reent, ptrdiff_t incr) {
@ -28,7 +29,7 @@ fail:
} }
void _init_vita_heap(void) { void _init_vita_heap(void) {
int _newlib_vm_size = 0; int _newlib_vm_size = 0;
if (&_newlib_vm_size_user != NULL) { if (&_newlib_vm_size_user != NULL) {
_newlib_vm_size = _newlib_vm_size_user; _newlib_vm_size = _newlib_vm_size_user;
@ -41,17 +42,21 @@ void _init_vita_heap(void) {
}else{ }else{
_newlib_vm_memblock = 0; _newlib_vm_memblock = 0;
} }
// Create a mutex to use inside _sbrk_r // Create a mutex to use inside _sbrk_r
if (sceKernelCreateLwMutex((struct SceKernelLwMutexWork*)_newlib_sbrk_mutex, "sbrk mutex", 0, 0, 0) < 0) { if (sceKernelCreateLwMutex((struct SceKernelLwMutexWork*)_newlib_sbrk_mutex, "sbrk mutex", 0, 0, 0) < 0) {
goto failure; goto failure;
} }
_newlib_heap_size = _newlib_heap_size_user; if (&_newlib_heap_size_user != NULL) {
_newlib_heap_size = _newlib_heap_size_user;
_newlib_heap_size -= _newlib_vm_size; }else{
_newlib_heap_size = 192 * 1024 * 1024;
}
_newlib_heap_size -= _newlib_vm_size;
_newlib_heap_memblock = sceKernelAllocMemBlock("Newlib heap", 0x0c20d060, _newlib_heap_size, 0); _newlib_heap_memblock = sceKernelAllocMemBlock("Newlib heap", 0x0c20d060, _newlib_heap_size, 0);
if (_newlib_heap_memblock < 0) { if (_newlib_heap_memblock < 0) {
goto failure; goto failure;
@ -75,13 +80,13 @@ int getVMBlock(){
} }
void _free_vita_heap(void) { void _free_vita_heap(void) {
// Destroy the sbrk mutex // Destroy the sbrk mutex
sceKernelDeleteLwMutex((struct SceKernelLwMutexWork*)_newlib_sbrk_mutex); sceKernelDeleteLwMutex((struct SceKernelLwMutexWork*)_newlib_sbrk_mutex);
// Free the heap memblock to avoid memory leakage. // Free the heap memblock to avoid memory leakage.
sceKernelFreeMemBlock(_newlib_heap_memblock); sceKernelFreeMemBlock(_newlib_heap_memblock);
if(_newlib_vm_memblock) if(_newlib_vm_memblock)
sceKernelFreeMemBlock(_newlib_vm_memblock); sceKernelFreeMemBlock(_newlib_vm_memblock);

View File

@ -29,8 +29,6 @@
#include <psp2/appmgr.h> #include <psp2/appmgr.h>
#include <pthread.h> #include <pthread.h>
int _newlib_heap_size_user = 192 * 1024 * 1024;
#include "../../bootstrap/vita/sbrk.c" #include "../../bootstrap/vita/sbrk.c"
#else #else