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 

Possible bug in libc

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



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Sat Oct 13, 2007 3:58 pm    Post subject: Possible bug in libc Reply with quote

Me and someone else have been working on a prorgam that takes a lot of memory, however, we've been having problems setting the memory via PSP_HEAP_SIZE_KB and PSP_HEAP_SIZE_MAX. I went to look at the code for PSP_HEAP_SIZE_MAX because I knew it was new.

First look at where it is applied to the module info:

Code:
/* Declare the size of the heap (in KB) that the program wants to allocate from. */
#define PSP_HEAP_SIZE_KB(size_kb) \
   unsigned int sce_newlib_heap_kb_size = (size_kb)

/* Declare to allocate maximum heap area */
#define PSP_HEAP_SIZE_MAX() \
   PSP_HEAP_SIZE_KB(-1)


As you can see, for MAX, sce_newlib_heap_kb is set to -1. Now look at the relavent code in libcglue.c:

Code:
                if (&sce_newlib_heap_kb_size != NULL) {
                        heap_size = sce_newlib_heap_kb_size * 1024;
                } else {
                        if (&__pspsdk_is_prx != NULL) {
                                heap_size = DEFAULT_PRX_HEAP_SIZE_KB * 1024;
                        } else {
                                heap_size = sceKernelMaxFreeMemSize();
                        }
                }

-1 is not NULL, so heap_size appears to be set to -1024 in this case when it should be sceKernelMaxFreeMemSize().

Looks like whatever check there was for MAX didn't make it into libc like it was supposed to.

EDIT: Looking a bit more, the check is in libcglue.c for newlib, but not in the psplibc.
Back to top
View user's profile Send private message AIM Address
Jim



Joined: 02 Jul 2005
Posts: 487
Location: Sydney

PostPosted: Sun Oct 14, 2007 10:45 am    Post subject: Reply with quote

Not saying you have or haven't found a bug - but it's checking the address of the variable == NULL, not the value. I assume our linker is setting undefined symbols to 0?

Jim
_________________
http://www.dbfinteractive.com
Back to top
View user's profile Send private message Visit poster's website
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Sun Oct 14, 2007 4:55 pm    Post subject: Reply with quote

Oh, yeah. Missed the & there. But it still doesn't seem right. It certainly doesn't match the code in newlib which clearly looks for -1. I think it would probably be best simply to cut the code from there and paste it in the other.
Back to top
View user's profile Send private message AIM Address
jimparis



Joined: 10 Jun 2005
Posts: 1179
Location: Boston

PostPosted: Mon Oct 15, 2007 6:28 am    Post subject: Reply with quote

Undefined symbols are set to 0 when they're weakly linked with __attribute__((weak)), and they aren't defined at runtime, hence the NULL checks.

JF, you're correct, Tyranid added the check to newlib but not libc (rev 2320). I dunno if many people use psplibc, but I just added his changes there too (rev 2327). I'm too lazy to even compile it so please check that it works and provide a patch if I screwed up. :)
Back to top
View user's profile Send private message
J.F.



Joined: 22 Feb 2004
Posts: 2906

PostPosted: Mon Oct 15, 2007 7:43 am    Post subject: Reply with quote

That seems to have done the trick. I wouldn't have noticed it myself if I hadn't switched from newlib to psplibc while checking if the libc was causing a problem. :)
Back to top
View user's profile Send private message AIM Address
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