forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Strange problem with malloc & sceKernelLoadModule

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
CyberBill



Joined: 26 Jul 2005
Posts: 86
Location: Redmond, WA

PostPosted: Sun Aug 28, 2005 4:16 pm    Post subject: Strange problem with malloc & sceKernelLoadModule Reply with quote

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
Back to top
View user's profile Send private message AIM Address MSN Messenger
mrbrown



Joined: 17 Jan 2004
Posts: 1536

PostPosted: Sun Aug 28, 2005 5:34 pm    Post subject: Reply with quote

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:
Code:
#include <pspmoduleinfo.h>

PSP_HEAP_SIZE_KB(1024);

which will reserve 1MB for your heap the first time malloc() is called.
Back to top
View user's profile Send private message
CyberBill



Joined: 26 Jul 2005
Posts: 86
Location: Redmond, WA

PostPosted: Mon Aug 29, 2005 4:15 am    Post subject: Reply with quote

mrbrown is a GENIUS!

Thank you so much! :)
Back to top
View user's profile Send private message AIM Address MSN Messenger
CyberBill



Joined: 26 Jul 2005
Posts: 86
Location: Redmond, WA

PostPosted: Mon Aug 29, 2005 5:01 am    Post subject: Reply with quote

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!!
Back to top
View user's profile Send private message AIM Address MSN Messenger
Agoln



Joined: 08 Jun 2005
Posts: 326
Location: Fort Wayne, IN

PostPosted: Mon Aug 29, 2005 12:49 pm    Post subject: Reply with quote

I just did a quick grep and here are my results:
Code:
$ 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


and in svn (not the latest, but only about 2 weeks old)

Code:
$ 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;



That may help out on where to look next.

Cheers!
_________________
Lego of my Ago!
Back to top
View user's profile Send private message AIM Address
urchin



Joined: 02 Jun 2005
Posts: 121

PostPosted: Wed Sep 14, 2005 10:42 pm    Post subject: Reply with quote

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?
Back to top
View user's profile Send private message
CyberBill



Joined: 26 Jul 2005
Posts: 86
Location: Redmond, WA

PostPosted: Thu Sep 15, 2005 1:51 am    Post subject: Reply with quote

Use sceKernelCreateFpl if its been added to the SDK yet... if not, there is a sceKernelCreateMemoryPool I think. Use the first if you can. It allows you to allocate -real- memory, but you shouldnt call it often.
Back to top
View user's profile Send private message AIM Address MSN Messenger
urchin



Joined: 02 Jun 2005
Posts: 121

PostPosted: Thu Sep 15, 2005 6:22 pm    Post subject: Reply with quote

Unfortunately, a quick grep reveals neither of those in the sdk (from the day before yesterday)

Oh well, not a massive issue for now, just a nice to have.
Back to top
View user's profile Send private message
Shazz



Joined: 31 Aug 2004
Posts: 244
Location: Somewhere over the rainbow

PostPosted: Tue Oct 04, 2005 4:23 pm    Post subject: Reply with quote

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...
_________________
- TiTAN Art Division -
http://www.titandemo.org
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group