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 

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

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



Joined: 24 Jan 2007
Posts: 84

PostPosted: Wed Jan 16, 2008 3:46 pm    Post subject: Calling a function in .PRX #1 from .PRX #2 via pointer.....? Reply with quote

Hi all :)

In one .PRX (kernel mode) I have something like this:
Code:
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:
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? :)
Back to top
View user's profile Send private message
KickinAezz



Joined: 03 Jun 2007
Posts: 328

PostPosted: Fri Jan 18, 2008 8:11 am    Post subject: Reply with quote

Back to basics,
Arent you using exports and imports?
_________________
Intrigued by PSP system Since December 2006.
Use it more for Development than for Gaming.
Back to top
View user's profile Send private message
crazyc



Joined: 17 Jun 2005
Posts: 410

PostPosted: Fri Jan 18, 2008 1:18 pm    Post subject: Re: Calling a function in .PRX #1 from .PRX #2 via pointer.. Reply with quote

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?
Back to top
View user's profile Send private message
Hellcat



Joined: 24 Jan 2007
Posts: 84

PostPosted: Fri Jan 18, 2008 7:06 pm    Post subject: Re: Calling a function in .PRX #1 from .PRX #2 via pointer.. Reply with quote

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 :)
Back to top
View user's profile Send private message
moonlight



Joined: 26 Oct 2005
Posts: 567

PostPosted: Fri Jan 18, 2008 8:48 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Hellcat



Joined: 24 Jan 2007
Posts: 84

PostPosted: Fri Jan 18, 2008 9:36 pm    Post subject: Reply with quote

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