Strange problem with malloc & sceKernelLoadModule
Strange problem with malloc & sceKernelLoadModule
I'm having some trouble with the prx loader sample. It seems that any time I call malloc in the same thread OR if I create a user thread and call malloc from there, when it goes to load the prx file it fails.
I have narrowed it down to calling malloc, and it doesnt matter how much memory you allocate. 100 bytes or 7MB, its all the same.
The call to sceKernelLoadModule() fails with:
block.c : _allocSysMemory : Low : no more space, can not alloc
block.c : _allocSysMemory : Low : request nblocks 14690 (max 2394)
block.c : sceKernelAllocPartitionMemory failed
SceModmgrLoadModuleFileBufferPRX, size 0x39618d
modulemgr.c exec_thread : LoadModule failed : 0x800200d9
modulemgr.c : sceKernelLoadModuleWithApitype : sceKernelLoadModule failed 0x800200d9
Its very strange because this was working just fine about a month ago, and then after I got a new version of the toolchain & PSPSDK it stopped working.
The prx I'm trying to load is approximately 3.5MB, if that matters.
Any help would be very much appreciated!! Thanks!
Ohh, and the point of doing this is so I can load up modules before loading up a WiFi project I'm working on, meaning I cant use sceKernelLoadExec because it resets all of the modules... or something, I really dont know how it works. :)
-Bill
I have narrowed it down to calling malloc, and it doesnt matter how much memory you allocate. 100 bytes or 7MB, its all the same.
The call to sceKernelLoadModule() fails with:
block.c : _allocSysMemory : Low : no more space, can not alloc
block.c : _allocSysMemory : Low : request nblocks 14690 (max 2394)
block.c : sceKernelAllocPartitionMemory failed
SceModmgrLoadModuleFileBufferPRX, size 0x39618d
modulemgr.c exec_thread : LoadModule failed : 0x800200d9
modulemgr.c : sceKernelLoadModuleWithApitype : sceKernelLoadModule failed 0x800200d9
Its very strange because this was working just fine about a month ago, and then after I got a new version of the toolchain & PSPSDK it stopped working.
The prx I'm trying to load is approximately 3.5MB, if that matters.
Any help would be very much appreciated!! Thanks!
Ohh, and the point of doing this is so I can load up modules before loading up a WiFi project I'm working on, meaning I cant use sceKernelLoadExec because it resets all of the modules... or something, I really dont know how it works. :)
-Bill
By default, PSPSDK will reserve all of available memory for the application's heap. This leaves only about 1MB or less (IIRC) to load modules into. You can set a specific amount to reserve by doing:
which will reserve 1MB for your heap the first time malloc() is called.
Code: Select all
#include <pspmoduleinfo.h>
PSP_HEAP_SIZE_KB(1024);
There wouldnt happen to be any way to disable this behavior, would there? Id really like my application that I'm launching to have all available RAM, instead of my launcher taking up a bunch that its not even using.
I need to be able to make a buffer, transfer the file into it, output it, and launch it.
Also, where is this code actually used? I mean, I do a search for PSP_HEAP_SIZE_KB and it comes up thats just a #define for unsigned int sce_newlib_heap_kb_size. So, I do a search for that... and nothing comes up anywhere in the SDK. This is very confusing...
I'm assuming this is part of the toolchain rather than the SDK... but who knows.
Thanks!!
I need to be able to make a buffer, transfer the file into it, output it, and launch it.
Also, where is this code actually used? I mean, I do a search for PSP_HEAP_SIZE_KB and it comes up thats just a #define for unsigned int sce_newlib_heap_kb_size. So, I do a search for that... and nothing comes up anywhere in the SDK. This is very confusing...
I'm assuming this is part of the toolchain rather than the SDK... but who knows.
Thanks!!
I just did a quick grep and here are my results:
and in svn (not the latest, but only about 2 weeks old)
That may help out on where to look next.
Cheers!
Code: Select all
$ grep -R "sce_newlib_heap" *
Binary file psp/lib/libc.a matches
Binary file psp/lib/libg.a matches
psp/sdk/include/pspmoduleinfo.h: unsigned int sce_newlib_heap_kb_size = (size_kb)
Binary file psp/sdk/lib/libpsplibc.a matches
Code: Select all
$ grep -R "sce_newlib_heap_kb_size" *
pspsdk/sdk/libc/.svn/text-base/libcglue.c.svn-base:extern unsigned int sce_newlib_heap_kb_size __attribute__((weak));
pspsdk/sdk/libc/.svn/text-base/libcglue.c.svn-base: if (&sce_newlib_heap_kb_size != NULL) {
pspsdk/sdk/libc/.svn/text-base/libcglue.c.svn-base: heap_size = sce_newlib_heap_kb_size * 1024;
pspsdk/sdk/libc/libcglue.c:extern unsigned int sce_newlib_heap_kb_size __attribute__((weak));
pspsdk/sdk/libc/libcglue.c: if (&sce_newlib_heap_kb_size != NULL) {
pspsdk/sdk/libc/libcglue.c: heap_size = sce_newlib_heap_kb_size * 1024;
pspsdk/sdk/user/.svn/text-base/pspmoduleinfo.h.svn-base: unsigned int sce_newlib_heap_kb_size = (size_kb)
pspsdk/sdk/user/pspmoduleinfo.h: unsigned int sce_newlib_heap_kb_size = (size_kb)
psptoolchain/.svn/text-base/newlib-1.13.0.patch.svn-base:+extern unsigned int sce_newlib_heap_kb_size __attribute__((weak));
psptoolchain/.svn/text-base/newlib-1.13.0.patch.svn-base:+ if (&sce_newlib_heap_kb_size != NULL) {
psptoolchain/.svn/text-base/newlib-1.13.0.patch.svn-base:+ heap_size = sce_newlib_heap_kb_size * 1024;
psptoolchain/newlib-1.13.0.patch:+extern unsigned int sce_newlib_heap_kb_size __attribute__((weak));
psptoolchain/newlib-1.13.0.patch:+ if (&sce_newlib_heap_kb_size != NULL) {
psptoolchain/newlib-1.13.0.patch:+ heap_size = sce_newlib_heap_kb_size * 1024;
Cheers!
Lego of my Ago!
I'm am having a similar problem in my application too. I am trying to implement a reload mechanism that reloads the elf. When I call sceKernelLoadModuleMs, I get the 800020d9 error, with a message that it is failing to alloc mem of size 0x181250. I've tried PSP_HEAP_SIZE_KB(1024), but I get exactly the same problem. Any other ideas?
Yes they are ;-)
Just add the Fpl prototypes to your code and it works...
I wrote a malloc wrapper using Variable PooL (VPL) memory management functions and it works perfectly within the PRX. It allows you to easily manage closely the memory allocated in your PRX and free it while unloading.
Before I did many tries using the Heap and sce Partitons memory allcoations but I found lotsa troubles :
- difficlty to manage the heap withinh the PRX (look at previous messages)
- sceKernelAllocPartitionMemory cannot aloocate infinite numbers of partitons (seems restrict to 255 of a fixex number) and each partition seems to be bigger than the desired size (probably a minimum size) so it is not usable for multiple small mallocs.
... so use the VPL ! (or the FPL is you want to each time allocate blocks of the same size).
hope that helps...
Just add the Fpl prototypes to your code and it works...
I wrote a malloc wrapper using Variable PooL (VPL) memory management functions and it works perfectly within the PRX. It allows you to easily manage closely the memory allocated in your PRX and free it while unloading.
Before I did many tries using the Heap and sce Partitons memory allcoations but I found lotsa troubles :
- difficlty to manage the heap withinh the PRX (look at previous messages)
- sceKernelAllocPartitionMemory cannot aloocate infinite numbers of partitons (seems restrict to 255 of a fixex number) and each partition seems to be bigger than the desired size (probably a minimum size) so it is not usable for multiple small mallocs.
... so use the VPL ! (or the FPL is you want to each time allocate blocks of the same size).
hope that helps...
- TiTAN Art Division -
http://www.titandemo.org
http://www.titandemo.org