From b3316fea351f980c8c7e13892e6cfbd43a9bbf9a Mon Sep 17 00:00:00 2001 From: Rinnegatamante Date: Fri, 4 Oct 2019 12:11:52 +0200 Subject: [PATCH] [VITA] Make newlib heap allocation dynamic. --- Makefile.vita | 2 +- Makefile.vita.salamander | 2 +- bootstrap/vita/sbrk.c | 11 +++++++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Makefile.vita b/Makefile.vita index b439a29468..90b3f0a118 100644 --- a/Makefile.vita +++ b/Makefile.vita @@ -158,7 +158,7 @@ $(TARGET).elf: $(OBJ) libretro_vita.a vita-make-fself -c -s $< $@ %.vpk: %.self - vita-mksfoex -s TITLE_ID=$(VITA_TITLE_ID) "$(VITA_TITLE_NAME)" param.sfo + vita-mksfoex -s TITLE_ID=$(VITA_TITLE_ID) "$(VITA_TITLE_NAME)" -d ATTRIBUTE2=12 param.sfo vita-pack-vpk -s param.sfo -b $< $@ clean: diff --git a/Makefile.vita.salamander b/Makefile.vita.salamander index 7a7959ed8b..eaee618249 100644 --- a/Makefile.vita.salamander +++ b/Makefile.vita.salamander @@ -55,7 +55,7 @@ OBJS = frontend/frontend_salamander.o \ all: $(TARGET).vpk %.vpk: eboot.bin - vita-mksfoex -s TITLE_ID=$(TITLE_ID) "$(TARGET)" param.sfo + vita-mksfoex -s TITLE_ID=$(TITLE_ID) "$(TARGET)" -d ATTRIBUTE2=12 param.sfo vita-pack-vpk -s param.sfo -b eboot.bin $@ eboot.bin: $(TARGET).velf diff --git a/bootstrap/vita/sbrk.c b/bootstrap/vita/sbrk.c index 991e2f6c18..11164c9c89 100644 --- a/bootstrap/vita/sbrk.c +++ b/bootstrap/vita/sbrk.c @@ -4,9 +4,11 @@ #include #include +#define RAM_THRESHOLD 0xA00000 // Memory left to the system for threads and other internal stuffs + static int _newlib_heap_memblock; static unsigned _newlib_heap_size; -static char *_newlib_heap_base, *_newlib_heap_end, *_newlib_heap_cur; +char *_newlib_heap_base, *_newlib_heap_end, *_newlib_heap_cur; static char _newlib_sbrk_mutex[32] __attribute__ ((aligned (8))); static int _newlib_vm_memblock; @@ -50,11 +52,16 @@ void _init_vita_heap(void) { if (sceKernelCreateLwMutex((struct SceKernelLwMutexWork*)_newlib_sbrk_mutex, "sbrk mutex", 0, 0, 0) < 0) { goto failure; } + + // Always allocating the max avaliable USER_RW mem on the system + SceKernelFreeMemorySizeInfo info; + info.size = sizeof(SceKernelFreeMemorySizeInfo); + sceKernelGetFreeMemorySize(&info); if (&_newlib_heap_size_user != NULL) { _newlib_heap_size = _newlib_heap_size_user; }else{ - _newlib_heap_size = 256 * 1024 * 1024; + _newlib_heap_size = info.size_user - RAM_THRESHOLD; } _newlib_heap_size -= _newlib_vm_size;