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 

How to manually call a callback function?

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



Joined: 28 May 2008
Posts: 842

PostPosted: Thu Nov 27, 2008 10:06 pm    Post subject: How to manually call a callback function? Reply with quote

From my kernel prx I want to invoke a callback function of another user prx. I have the function address and I'm trying to call it with the callback prototype but it crashes, because of kernel to user call I think. I also have its cbid in case its useful. How do I call it, and pass my own args?
Back to top
View user's profile Send private message
ne0h



Joined: 21 Feb 2008
Posts: 386

PostPosted: Fri Nov 28, 2008 12:12 am    Post subject: Reply with quote

You have to probably normalize the address...
Some days ago I've got the same thing but with a variable, maybe the solution is the same!
This is how to get a user address form a kernel addr:
Code:

char* data = "AbCd?";
return (char*)(((int)data)&~0x80000000);
Back to top
View user's profile Send private message
Torch



Joined: 28 May 2008
Posts: 842

PostPosted: Fri Nov 28, 2008 3:14 am    Post subject: Reply with quote

All that does is remove the leading 0x8.

The function address is in user memory, so its already in 0x0..... form.
Back to top
View user's profile Send private message
ne0h



Joined: 21 Feb 2008
Posts: 386

PostPosted: Fri Nov 28, 2008 3:53 am    Post subject: Reply with quote

Torch wrote:
All that does is remove the leading 0x8

Yes I know, is the same as
Code:
((int)data) - 0x80000000

Torch wrote:
The function address is in user memory, so its already in 0x0..... form.

I think that to call a user address from kernel mode you have to add 0x8...
_________________
Get Xplora!


Last edited by ne0h on Fri Nov 28, 2008 4:08 am; edited 1 time in total
Back to top
View user's profile Send private message
Torch



Joined: 28 May 2008
Posts: 842

PostPosted: Fri Nov 28, 2008 3:57 am    Post subject: Reply with quote

You can only read contents of user memory addresses. The code can't jump into user space instructions (normally).

There has to be a method for invoking callbacks, after all they are invoked by the kernel normally...
Back to top
View user's profile Send private message
ne0h



Joined: 21 Feb 2008
Posts: 386

PostPosted: Fri Nov 28, 2008 5:38 am    Post subject: Reply with quote

I think that sceKernelNotifyCallback go to resume a callback, but you can pass to the function only the 2nd arg...
_________________
Get Xplora!
Back to top
View user's profile Send private message
Torch



Joined: 28 May 2008
Posts: 842

PostPosted: Fri Nov 28, 2008 6:00 am    Post subject: Reply with quote

Yes I've seen that. But I need to forward all 3 args from the power callback.
Back to top
View user's profile Send private message
ne0h



Joined: 21 Feb 2008
Posts: 386

PostPosted: Fri Nov 28, 2008 6:37 am    Post subject: Reply with quote

How does the fw call a callback and send all the args?
Maybe a little reverse on this can help you!
But where I can find this call?
Torch wrote:
But I need to forward all 3 args from the power callback.

So you need to hook the power callback and replace it with another callback?
For this you can register your power callback!
Anyway I think that this is not what you want to do...
_________________
Get Xplora!
Back to top
View user's profile Send private message
TyRaNiD



Joined: 18 Jan 2004
Posts: 918

PostPosted: Fri Nov 28, 2008 8:19 am    Post subject: Reply with quote

You can't in any meaningful sense, just call Notify with arg2 of the callback (the actual unique value) and the other two will handle themselves.
Back to top
View user's profile Send private message
Torch



Joined: 28 May 2008
Posts: 842

PostPosted: Fri Nov 28, 2008 11:32 am    Post subject: Reply with quote

I want the power callbacks in the game to be invoked only when some conditions are met.

I've hooked scePowerRegisterCallback, and instead of calling the original function, my PRX maintains a table of all the callbacks the game tries to register and returns successful value to the game. The table is also updated on scePowerUnregist(its)erCallback.
My PRX registers itself in the power callback just once.

When the PSP is suspended, I want to forward the suspend power callbacks by manually calling it.
When the PSP is resumed (my app detects this by resume_complete), I freeze all the game threads (I will not forward the resuming or resume_complete callbacks).
My app asks for password, if the password is right it should forward the resume callbacks now and unfreeze the game.
The user should be able to suspend the PSP again without entering correct password also (without unfreezing threads).

The problem before was that the game would not suspend while the threads were frozen if the power switch was pressed. It would start suspending with a blank screen and the LED would just keep blinking until it crashed. I'm ASSUMING this was because the game received the resume callback and tried to resume its stuff, but couldn't because the threads were frozen. I'm ASSUMING that if it never receives the resume callbacks, then it will still be in a suspend-friendly state as it wouldn't have done anything since the last suspend and can be suspended again while the threads are frozen.

Time to try some experiments with NotifyCallback now..
Back to top
View user's profile Send private message
Torch



Joined: 28 May 2008
Posts: 842

PostPosted: Fri Nov 28, 2008 9:42 pm    Post subject: Reply with quote

I've succeeded :D using sceKernelNotifyCallback to send the resuming and resume_complete signals whenever I want after hooking the register callback functions so that the real ones aren't sent. The game can be frozen properly and even put into standby and resumed multiple times :D
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