| View previous topic :: View next topic |
| Author |
Message |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Sat Oct 13, 2007 3:58 pm Post subject: Possible bug in libc |
|
|
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 |
|
 |
Jim

Joined: 02 Jul 2005 Posts: 487 Location: Sydney
|
Posted: Sun Oct 14, 2007 10:45 am Post subject: |
|
|
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 |
|
 |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Sun Oct 14, 2007 4:55 pm Post subject: |
|
|
| 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 |
|
 |
jimparis
Joined: 10 Jun 2005 Posts: 1179 Location: Boston
|
Posted: Mon Oct 15, 2007 6:28 am Post subject: |
|
|
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 |
|
 |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Mon Oct 15, 2007 7:43 am Post subject: |
|
|
| 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 |
|
 |
|