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 

Prx loading issue

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



Joined: 17 Jun 2006
Posts: 15

PostPosted: Sat Jan 23, 2010 1:26 pm    Post subject: Prx loading issue Reply with quote

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:
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


Code:
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:
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:
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:
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(  sceKernelStartModule (ml->process->module->id, 1, argp, &prxstatus,(ml->process->module->usermode > 0 ? moduleprx : NULL) ) <0)
   {//I think this is an okay error check<-
   //DON'T PUT ERROR MESSAGE, THIS IS DONE IN CALLER
       return (prxstatus); //do nothing until necessary... :), but this is on an errors existence
   }
   return 1;
}
Back to top
View user's profile Send private message
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