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 

Passing arguments to a Kernel module. How?

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



Joined: 03 Apr 2008
Posts: 39

PostPosted: Tue Apr 06, 2010 8:02 am    Post subject: Passing arguments to a Kernel module. How? Reply with quote

First of all, sorry for my poor English... :P
I made a User-Mode homebrew which, at a certain point, loads a kernel module (PRX). This kernel module has the only purpose to start a EBOOT.PBP (thing that does not work in usermode).
Now, my problem is that I have to give to kernel module the path of the EBOOT.PBP to start. So, essentially, in (usermode) homebrew I have to pass to (kernelmode) PRX an argument.

This is the code of my (Kernel-mode) PRX:
Code:
int threadMain(SceSize args, void *argp)
{
   exec(...);
   return 0;
}

int module_start(SceSize args, void *argp)
{
   main_thid = sceKernelCreateThread("hbb_main", threadMain, 6, 0x800, 0, NULL);
   if(main_thid >= 0) sceKernelStartThread(main_thid, args, argp);
   return 0;
   sceKernelExitDeleteThread(0);
}

int module_stop(SceSize args, void *argp)
{
   return 0;
}


And, in the (usermode) homebrew I load the module with:
Code:
int build_args(char *args, const char *execfile, int argc, char **argv)
{
   int loc = 0;
   int i;

   strcpy(args, execfile);
   loc += strlen(execfile) + 1;
   for(i = 0; i < argc; i++)
   {
      strcpy(&args[loc], argv[i]);
      loc += strlen(argv[i]) + 1;
   }

   return loc;
}

int loadStartModule(const char *name, int argc, char **argv)
{
   SceUID modid;
   int status;
   char args[128];
   int len;

   modid = sceKernelLoadModule(name, 0, NULL);
   if(modid >= 0)
   {
      len = build_args(args, name, argc, argv);
      modid = sceKernelStartModule(modid, len, (void *) args, &status, NULL);
   }
   return modid;
}


So I have to give to exec(...) function the path of the EBOOT.PBP to start.
I tried to use char *argv[] like main functions, but sceKernelStartModule() use void* and don't accept any type of my arguments :S

In what way i could give my path to exec(...) from the hombrew? Thx
Back to top
View user's profile Send private message
willow :--)



Joined: 13 Jan 2007
Posts: 126

PostPosted: Tue Apr 06, 2010 8:14 am    Post subject: Reply with quote

just cast your arguments as void *
if you pass a string, args is the size of the string afaik

http://psp.jim.sh/pspsdk-doc/group__ModuleMgr.html#g69c3f128b68a8b0ec89fb1f17a5bd5b5
_________________
Wagic. Play that card game against an AI on your PSP
Back to top
View user's profile Send private message
psPea



Joined: 01 Sep 2007
Posts: 64

PostPosted: Tue Apr 06, 2010 8:14 am    Post subject: Reply with quote

how about exporting exec(...) from your kernel module and calling it from your app
_________________
Click ME!
Back to top
View user's profile Send private message Yahoo Messenger MSN Messenger
carl0sgs



Joined: 10 Dec 2009
Posts: 41

PostPosted: Tue Apr 06, 2010 8:24 am    Post subject: Reply with quote

I did it like this:

Sending the string to the module:
int runPRX(char *path, SceSize args, void *argp) {//Load and start module
SceUID mod = sceKernelLoadModule(path, 0, NULL);
if (mod > 0) {
return sceKernelStartModule(mod, args, argp, NULL, NULL);
}
return 0;
}

And in your code:
char path[500];
sprintf(path, "ms0:/eboot.pbp");
runPRX("ms0:/yourmodule.prx",strlen(path)+1,path);//+1 is important (\0 character).


Receiving the string in the module:
int threadMain(SceSize args, void *argp)
{
if(args > 0) {
char path[args];
sprintf(path,argp);
//The path you want is in "path"
exec(path);
return 0;
}

Hope it helped :-P
Back to top
View user's profile Send private message Visit poster's website
carl0sgs



Joined: 10 Dec 2009
Posts: 41

PostPosted: Tue Apr 06, 2010 8:25 am    Post subject: Reply with quote

double post sorry ><
Back to top
View user's profile Send private message Visit poster's website
Stewie87



Joined: 03 Apr 2008
Posts: 39

PostPosted: Tue Apr 06, 2010 8:43 am    Post subject: Reply with quote

carl0sgs wrote:
I did it like this:

Sending the string to the module:
int runPRX(char *path, SceSize args, void *argp) {//Load and start module
SceUID mod = sceKernelLoadModule(path, 0, NULL);
if (mod > 0) {
return sceKernelStartModule(mod, args, argp, NULL, NULL);
}
return 0;
}

And in your code:
char path[500];
sprintf(path, "ms0:/eboot.pbp");
runPRX("ms0:/yourmodule.prx",strlen(path)+1,path);//+1 is important (\0 character).


Receiving the string in the module:
int threadMain(SceSize args, void *argp)
{
if(args > 0) {
char path[args];
sprintf(path,argp);
//The path you want is in "path"
exec(path);
return 0;
}

Hope it helped :-P


Wow, it worked and on first attempt! Thank you very much :)
Back to top
View user's profile Send private message
carl0sgs



Joined: 10 Dec 2009
Posts: 41

PostPosted: Tue Apr 06, 2010 3:27 pm    Post subject: Reply with quote

You are welcome ;-)
Back to top
View user's profile Send private message Visit poster's website
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