I'm updating my prx so it can read from a text file but am having problems because in Kernel Mode it complains that malloc and free are undefined when compiling...
If I change the makefile to use PSPSDK_LIBC and PSPSDK_LIBS it compiles fine but that's no use for what i'm doing...
Does anyone know what the problem might be or if their are API alternatives I should be using...?
Here is the makefile i'm using that has the problem,
kernel doesn't use the psp sdk libc but the psp builtin kernel libc which doesn't use malloc and free.
the psp has only a bunch of own function to do malloch and freeing and they work a bit differently:
first of all you need to malloc part of the partition
int memid = sceKernelAllocPartitionMemory(1, "mybuffer", 0, howmuchtoalloch, NULL);
this will alloc the ram you need:
arg1: in the kernel partition (1 or 3(mirror)) if you want user use 2
arg2: buffer name not much interesting if you only need to alloch usefull to search for allocations in the uid lists
arg3: this can be 0 => alloc in the lowest adress 1 alloc in the highest adress 2 alloc in a user determined adress
arg4: num*byte of space to alloc
arg5: if arg3 = 2 adress to alloc to
but you aren't done you need the adress were your allocation starts :)
mypointer = sceKernelGetBlockHeadAddr(memid);
and you are done you can use it as a normal malloched adress.
then to free it:
sceKernelFreePartitionMemory(memid);
so you need to keep the memid data if you don't want to search for your allocation trought the uids lists
Well, that all sounded quite straight forward but it crashed when I try to read into the pointer... See the bellow snipit of code... It crashes the PSP on the line highlighted in bold...
Little help...
-----> CODE SNIPPIT
int size = 0;
int fd;
int flen = 0;
char* Text;
char* Line;
// Returns number of bytes in file (I know this works)
size = getFileSize(filename);
// Allocate memory to hold file contents
int memid = sceKernelAllocPartitionMemory(1, "inibuffer", 0, size, NULL);
Text = sceKernelGetBlockHeadAddr(memid);
// Open file and read contents into pointer
fd = sceIoOpen(filename, PSP_O_RDONLY, 0777); flen = sceIoRead(fd, Text, size);
sceIoClose(fd);
weltall wrote:what is memid?
maybe you are out of memory and it doesn't alloc it (so you are reading in a NULL pointer)
It was my filesize function allocating too big a number... I've changed the code to allocate 5k but does the sceKernelAllocPartitionMemory function set all the allocated space to 0...? If not is there an equivalent of the memset function...?
well you must do it by yourself if you want a memset function. after all it's simple doing it you just need to make a for loop which copies the second argument over all memory