Prx loading issue

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
Devun_06
Posts: 15
Joined: Sat Jun 17, 2006 7:01 pm

Prx loading issue

Post by Devun_06 »

Okay, I'm using a very old method I found long before now that by source, claimed you could launch a module in user mode supplying NULL into your "optional" option parameter. This made made complete sense reading the library. But, I keep getting problems.

First, the module loading process would crash, and kill the psp each and every time I attempted to load them in kernel mode. I then attempted to run the module procedures in user mode so that my functions would supply the object, instead of NULL, this worked; for a brief instance, the thread starts, and goes back to the main thread's sequence of code. But, the module still doesn't load, or so it seems, given no error, or success message is printed to the screen. Also, within seconds of handing over processing time to the main's thread when launched in user mode, the psp still crashes.

Ignore the ugly appearance of the main function's formal parameter, it's just a supplement to the real function that calls the thread, but the actual function is no different, and resides within main with no other modules or threads launched prior this this procedure.

In addition, I almost forgot to mention, I'm using CSP pre packaged cygwin. I have to considering my circumstances, but this greatly affects the testing mehods I use. So far, I've had to use the snapshot prx 1.5 I believe, in hopes that it's not a pure export, simply because my package doesn't seem to include bin/sh. Without it, it appears cygwin will never allow me to compile the sample prx for testing. But, I'm not certain that's the issue, as I'm only looking to achieve the successful printouts of my own nested error handling and would've expected the printouts whether the prx used for testing was a pure export or not.

It fails right after the

Code: Select all

eprint("THREAD FUNCTION HAS STARTED!"); 
function prints. The "sceKernelLoadModule" is called not only in the main thread, but in a sub thread as well, a child of main's thread, already in kernel mode.

I made it through the module tutorial by "Anissian", and I've already searched the forums, but the prx issues I read seemed fairly different from mine. But, because it delayed for some time then crashed when loading the module in user mode, I figured this thread might've been helpful
http://forums.ps2dev.org/viewtopic.php?p=87021#87021

[/size]

Code: Select all

struct module_load
{
	Process *process;
	char	*fullfilename;
};

unsigned short Start_Module(void * arg, SceKernelLMOption *moduleprx);
signed short Load_Module(void *arg);
void Load_Module_In_Thread(void *argv);


int main(char *File)
{
struct module_load *load, set;
load=&set;//allocate some space for load;
load->process=process;//pointer to process to give control to the prx application.
load->fullfilename=File;//name and directrory path of file selected.
load->process->module->usermode=0;//false//0 as in NO to usermode. 1 is Yes to usermode.	
Load_Module_In_Thread( (void *) load );
while(1){eprint("SUCCESS");}
}

Code: Select all

void Load_Module_In_Thread(void *argv)
{

struct module_load * ml = (struct module_load *) argv;

	ml->process->thread->id = sceKernelCreateThread(ml->fullfilename, (void *)Load_Module, 111, 0xFA0, PSP_THREAD_ATTR_CLEAR_STACK, NULL);//0xFA0 is size of stack for thread//PSP_THREAD_ATTR_CLEAR_STACK=0x00200000

	if(ml->process->thread->id >= 0)
	{
	sceKernelStartThread(ml->process->thread->id, 1, (void *) ml );

	SceKernelThreadInfo tstatus;
	tstatus.size = sizeof(SceKernelThreadInfo);

	if(sceKernelReferThreadStatus(ml->process->thread->id, &tstatus)==0)
	{
		if(tstatus.status==1||tstatus.status==2||tstatus.status==4)
		{
			eprint("PERFECT! Everything seems fine, thread has started.");
		}
		else
		{
			eprint("ERROR: THREAD STARTING PROCESS, STATUS UNKNOWN");
	sceKernelTerminateDeleteThread(ml->process->thread->id);
		}
	}
	


	}else{eprint("ERROR: THREAD INSTANCE CREATION, STATUS UNKNOWN");}

}

Code: Select all

signed short Load_Module(void *arg)//returns true or false for success. true == successful loading of module
{
	eprint("THREAD FUNCTION HAS STARTED!");
	struct module_load * ml = (struct module_load *) arg;

	//ml->process;
	//mlprocess->filename;
	//ml->usermode;


                  SceKernelLMOption moduleprx;
                  moduleprx.mpidtext = (ml->process->module->usermode+1);// 2 is equivalent to usermode ;)
                  moduleprx.mpiddata = (ml->process->module->usermode+1);// 2 is equivalent to usermode ;)
                  moduleprx.position = 0;
                  moduleprx.access = 1;
                  moduleprx.size = sizeof(moduleprx);


	int PrxID = -1;
	PrxID = sceKernelLoadModule(ml->fullfilename,0,(ml->process->module->usermode > 0 ? &moduleprx : NULL));// use NULL if in kernel mode.

	
	ml->process->module->data = sceKernelFindModuleByUID(PrxID);
	if(ml->process->module->data == NULL)
	{
		//No need to clean load handed to thread, it's auto defined, and resides on stack. It will then, automatically deallocate.
	eprint("ERROR: MODULE COULD NOT BE LOADED");
	return 0;
	}
	else
	{
	eprint("PERFECT! Module Loaded.");
	ml->process->module->id=PrxID;
	if(Start_Module((void *) ml, &moduleprx )==1) { eprint("PERFECT! Module Started!");sceKernelSleepThreadCB(); }else{eprint("ERROR: MODULE UNABLE TO START");}
	return 1;
	}
sceKernelDelayThread(1000000);
return 0;
}

Code: Select all

unsigned short Start_Module(void * arg, SceKernelLMOption *moduleprx)
{
	struct module_load * ml = (struct module_load *) arg;
	
	if(ml->process->module->data == NULL) return 0;

	char argp[1][50];
	sprintf(argp[0],"%s",_OS_OS);

	int prxstatus=-1;

	if&#40;  sceKernelStartModule &#40;ml->process->module->id, 1, argp, &prxstatus,&#40;ml->process->module->usermode > 0 ? moduleprx &#58; NULL&#41; &#41; <0&#41;
	&#123;//I think this is an okay error check<-
	//DON'T PUT ERROR MESSAGE, THIS IS DONE IN CALLER
	    return &#40;prxstatus&#41;; //do nothing until necessary... &#58;&#41;, but this is on an errors existence
	&#125;
	return 1;
&#125;
Post Reply