I want to use the "sceKernelLoadModuleBuffer" function from a kernel mode module, so i need to extract and read the binary (data.psp) into user memory with sceKernelAllocPartitionMemory, then load it. Some help would be great.
Here is the non-working code i writed for now, crashing when the module is loaded :
main.c :
Code: Select all
/*
* PSP Software Development Kit - http://www.pspdev.org
* -----------------------------------------------------------------------
* Licensed under the BSD license, see LICENSE in PSPSDK root for details.
*
* main.c - Basic ELF template
*
* Copyright (c) 2005 Marcus R. Brown <[email protected]>
* Copyright (c) 2005 James Forshaw <[email protected]>
* Copyright (c) 2005 John Kelley <[email protected]>
*
* $Id: main.c 1888 2006-05-01 08:47:04Z tyranid $
* $HeadURL$
*/
#include <pspkernel.h>
#include <pspdebug.h>
#include <psploadexec_kernel.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
/* Define the module info section */
PSP_MODULE_INFO("test", 0x1000, 1, 1);
PSP_MAIN_THREAD_ATTR(0);
PSP_MAIN_THREAD_STACK_SIZE_KB(0);
char PBPMagic[] = { 0x00, 0x50, 0x42, 0x50 };
char PsfMagic[] = "\0PSF";
char PsfDefaultFile[] = "PARAM.SFO";
typedef struct {
char signature[4];
int version;
int offset[8];
} HEADER;
char *filename[8] = { "PARAM.SFO", "ICON0.PNG", "ICON1.PMF", "UKNOWN.PNG", "PIC1.PNG", "SND0.AT3", "UNKNOWN.PSP", "UNKNOWN.PSAR" };
int extractStartBin(char *filename)
{
printf("extractStartBin started\n");
HEADER header;
int loop0, infile, size;
printf("sceIoOpen(%s,PSP_O_RDONLY, 0777);\n", filename);
if(!(infile = sceIoOpen(filename, PSP_O_RDONLY, 0777)))
{
printf("FAIL => sceIoOpen(%s,PSP_O_RDONLY, 0777);\n", filename);
return -1;
}
printf("Reading %d bytes to memory\n", sizeof(HEADER));
if(memset(&header, 0, sizeof(HEADER)) < 0) printf("FAIL => memset(&header, 0, sizeof(HEADER))\n");
if (sceIoRead(infile, &header, sizeof(HEADER)) < 0)
{
printf("FAIL => sceIoRead(infile, &header, sizeof(HEADER))\n");
return -1;
}
if (memcmp(header.signature, PBPMagic, 4))
{
printf("FAIL => memcmp(header.signature,PBPMagic,4)\n");
return -1;
}
for (loop0=0; loop0<7; loop0++)
{
size = header.offset[loop0 + 1] - header.offset[loop0];
printf("loop=%i\n", loop0);
printf("Allocating %i byte of memory\n", size);
SceUID mem = sceKernelAllocPartitionMemory(2, "block", 0, size, NULL);
void *buffer = (void*)sceKernelGetBlockHeadAddr(mem);
if (!buffer)
{
printf("Could not allocate buffer (size = %i)\n", size);
}
else
{
if (sceIoRead(infile, buffer, size) < 0)
{
printf("Could not read %s (size = %i)\n", filename, size);
}
else
{
if (loop0==6)
{
if(size < 1)
{
sceIoClose(infile);
}
else
{
printf("DATA.PSP FOUND\n");
sceIoClose(infile);
printf("Loading module\n");
SceUID modid = sceKernelLoadModuleBuffer(buffer, size, 0, NULL);
if(modid >= 0)
{
//modid = sceKernelStartModule(modid, len, (void *) args, &status, NULL);
printf("SUCCESS => sceKernelStartModule\n");
}
else
{
printf("FAIL => could not load module || Error => %x\n", modid);
return 0;
}
}
}
}
}
//sceKernelFreePartitionMemory(mem);
}
if (sceIoClose(infile) < 0) printf("infile already closed\n");
printf("getPSP done\n");
return 0;
}
int threadMain(SceSize args, void *argp)
{
sceKernelDelayThread(10000);
printf("\n\n");
extractStartBin("host0:/EBOOT.PBP");
printf("done.\n");
sceKernelSelfStopUnloadModule(0, 0, NULL);
return 0;
}
int module_start(SceSize args, void *argp)
{
SceUID main_thid = sceKernelCreateThread("test_main", threadMain, 6, 64*1024, 0, NULL);
if(main_thid >= 0) sceKernelStartThread(main_thid, args, argp);
return 0;
}
int module_stop(SceSize args, void *argp)
{
return 0;
}
Code: Select all
TARGET = test
OBJS = main.o
BUILD_PRX=1
USE_KERNEL_LIBC=1
USE_KERNEL_LIBS=1
INCDIR = ../include
LIBDIR = ../lib
CFLAGS = -Os -G0 -Wall -fno-strict-aliasing -fno-builtin-printf
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
LDFLAGS = -mno-crt0 -nostartfiles
LIBS = -lpspsysmem_kernel -lpspmodulemgr_kernel -lpspkubridge
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build_prx.mak