Calling a function in .PRX #1 from .PRX #2 via pointer.....?

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

Moderators: cheriff, TyRaNiD

Post Reply
Hellcat
Posts: 83
Joined: Wed Jan 24, 2007 2:52 pm

Calling a function in .PRX #1 from .PRX #2 via pointer.....?

Post by Hellcat »

Hi all :)

In one .PRX (kernel mode) I have something like this:

Code: Select all

void (*myCallback)(void* someparameter);

....

void SomeFunction(void* apointer)
{
  // some code here
  myCallback(apointer);
  // some code here
}

void SetCB(void* cbFunc)
{
  myCallback = cbFunc;
}
In another .PRX (usermode, this time) I have something like that:

Code: Select all

void BlahFunction(void* something)
{
  // do something here
}

int main(...)
{
  // some more code here
  SetCB(&BlahFunction);
  // some more code here
}
Now, everything looks fine up to the instant my kernel PRX calls myCallback() - there the PSP crashs and shuts off....

The pointer to the function has been set before the kernel PRX can try to call the usermode PRX the first time, that's for sure.
The usermode PRX also didn't get unloaded while sitting around....
Maybe I just can't call userland stuff from kernelland?

Anyone any idea what I missed?
Pleeeaaase? :)
KickinAezz
Posts: 328
Joined: Sun Jun 03, 2007 10:05 pm

Post by KickinAezz »

Back to basics,
Arent you using exports and imports?
Intrigued by PSP system Since December 2006.
Use it more for Development than for Gaming.
crazyc
Posts: 408
Joined: Fri Jun 17, 2005 10:13 am

Re: Calling a function in .PRX #1 from .PRX #2 via pointer..

Post by crazyc »

Hellcat wrote:Now, everything looks fine up to the instant my kernel PRX calls myCallback() - there the PSP crashs and shuts off....
What are you trying to do here?
Hellcat
Posts: 83
Joined: Wed Jan 24, 2007 2:52 pm

Re: Calling a function in .PRX #1 from .PRX #2 via pointer..

Post by Hellcat »

KickinAezz wrote:Back to basics,
Arent you using exports and imports?
No, I wanted to pass the address of a function in PRX #1 over to PXR #2, so that PRX #2 could then directly call it....

crazyc wrote:What are you trying to do here?
I wanted to have PRX #1 engage in some action when PRX #2 tells it to do so.
(PRX #2 had to do some things before PRX #1 could do it's job and I wanted to prevent a loop that constantly checks if there's something to do....)


However, I managed to get exactely what I need by the use of "real" callbacks/callbackthreads.
I set up a callbackthread just like it's done for the exit-callback of the home button.

I posted a sample here of how I did set it up :)
moonlight
Posts: 567
Joined: Wed Oct 26, 2005 7:46 pm

Post by moonlight »

You shouldn't call a user function from kernel mode. But if you do, make sure to "OR" the function address with 0x80000000, and be careful because that function would be still called in kernel mode, and depending of what user functions it calls, it could crash.
Hellcat
Posts: 83
Joined: Wed Jan 24, 2007 2:52 pm

Post by Hellcat »

Yep, that's exactely what I got, crash over crash....
Already thought it's a bad idea at all to jump into "usercode" from kernel.

That's the main reason I started digging into real callback threads like the exit_game one.
Turned out to be more easy than I thought :)
And it's working flawlessly, no crashs anymore, even with intense printf usage....

And that brought me right into my next problem *lol* savegame reading/writing....
Post Reply