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 

Cache invalidation in Kernel PRX not working?

 
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: Tue Feb 05, 2008 3:49 pm    Post subject: Cache invalidation in Kernel PRX not working? Reply with quote

Hi everyone :)

I got a problem again....


Lately I got a habit of patching syscalls :D
So far it always worked fine.... mostly....

Usually I have a usermode PRX that loads a pure kernel mode PRX, the kernel mode PRX does all the hooking/patching and everthing is fine, my own functions get called instead of the original ones.
The kernel mode PRX is also compiled against the kernel libs with those two line in the makefile:

Code:
USE_KERNEL_LIBC=1
USE_KERNEL_LIBS=1



So, NOW I have a PRX that is supposed to be a CFW plugin.
I also build it as kernel module, and here comes the thing....

With the above two lines in my makefile theese two lines of code seem to have no effect:

Code:
sceKernelDcacheWritebackInvalidateRange(addr, sizeof(addr));
sceKernelIcacheInvalidateRange(addr, sizeof(addr));


Instead of my hooked functions, the original ones are still called!

If I take out the KERNEL_LIB lines mentioned above from my makefile everything works perfectly and my hooked functions are called like they are supposed to.


What am I missing here? :)
Or could I just compile my PRX without those lines without risking mayor compatibility problems with games running?
Another advantage not to compile against those would be that I could use printf() again, couldn't I? :D
Back to top
View user's profile Send private message
Insert_witty_name



Joined: 10 May 2006
Posts: 376

PostPosted: Tue Feb 05, 2008 6:28 pm    Post subject: Reply with quote

There are only stubs for the user mode (UtilsForUser) versions of those functions in the SDK.

The kernel mode versions use the same NIDS, but are under the UtilsForKernel library.

Just create a stub file and link against that instead of -lpsputils.
Back to top
View user's profile Send private message
Hellcat



Joined: 24 Jan 2007
Posts: 84

PostPosted: Tue Feb 05, 2008 6:47 pm    Post subject: Reply with quote

Hey, cool! Will try :) Thanks!

I thought it might be something like that, but since the compiler didn't complain about missing references I didn't keep thinking of it....
Back to top
View user's profile Send private message
Insert_witty_name



Joined: 10 May 2006
Posts: 376

PostPosted: Tue Feb 05, 2008 7:02 pm    Post subject: Reply with quote

Actually, on looking there ARE stubs for those functions in the SDK.

They're part of -lpspkernel and the header is psputilsforkernel.h

You'll have to add the prototype for sceKernelDcacheWritebackInvalidateRange, but it will be the same as the user mode version.
Back to top
View user's profile Send private message
Hellcat



Joined: 24 Jan 2007
Posts: 84

PostPosted: Tue Feb 12, 2008 11:10 pm    Post subject: Reply with quote

Hmm, just got some time to try that.

No go :(

I already liked against lpspkernel and was using psputilsforkernel.h as header.
So, I tried making an own stub, importing from "UtilsForKernel".

But still no go, the cache doesn't get invalidated....


[EDIT]
ARGH!
By a second look at it, it seems the cache stuff works, my hooked functions are called - but my callbacks don't work!

sceKernelNotifyCallback() is the one that seems to ignore me now....
Back to top
View user's profile Send private message
hlide



Joined: 10 Sep 2006
Posts: 750

PostPosted: Wed Feb 13, 2008 6:14 am    Post subject: Reply with quote

Hellcat wrote:
Hmm, just got some time to try that.
sceKernelNotifyCallback() is the one that seems to ignore me now....


Be aware :

when you create a callback, it is callable only in the thread where it was created. To issue a callback, you just need to call sceKernelNotifyCallback(cbid) in any thread. But you need to call sceKernelCheckCallback() or sceKernelWaitThreadCB() or sceKernelSleepThreadCB() or whatever else ending with CB in the thread where the callback was created, otherwise you will never receive a callback notification.

If the thread of your callback uses sceKernelWaitThread() or sceKernelSleepThread() or whatever else not ending with CB, no callback won't be checked and executed.
Back to top
View user's profile Send private message
Hellcat



Joined: 24 Jan 2007
Posts: 84

PostPosted: Wed Feb 13, 2008 10:54 am    Post subject: Reply with quote

Yep, the thread creating the callbacks goes to sleep with sceKernelSleepThreadCB().

When NOT compiling against the kernel libs it works perfectly.
The callbacks get "called" and all is fine.
But when I compile against the kernel libs => no go, the callbacks don't get executed anymore.
Back to top
View user's profile Send private message
moonlight



Joined: 26 Oct 2005
Posts: 567

PostPosted: Wed Feb 13, 2008 5:58 pm    Post subject: Reply with quote

It is kernel code who created the callbacks?
Back to top
View user's profile Send private message
Hellcat



Joined: 24 Jan 2007
Posts: 84

PostPosted: Wed Feb 13, 2008 7:49 pm    Post subject: Reply with quote

Unfortunately yes.
It's a CFW plugin.

[EDIT]
When trying to start the thread creating the callbacks as userthread (PSP_THREAD_ATTR_USER) makes the PSP crash the moment the thread is started - even tho it didn't do anything (besides a sceKernelSleepThread()) at that point....
Back to top
View user's profile Send private message
moonlight



Joined: 26 Oct 2005
Posts: 567

PostPosted: Thu Feb 14, 2008 5:25 am    Post subject: Reply with quote

Maybe the system don't like callbacks created by kernel to be used by user mode. It happens something like that with file descriptors since some version (3.40 i think).
Try this code after creating the callback in kernel mode, just in case it works:
(this code did work at least with file descriptors)

Code:

u16 *block;

if (sceKernelGetUIDcontrolBlock(cbid, (void *)&block) == 0)
{
   block[0x16/2] |= 0x0015;
}
Back to top
View user's profile Send private message
Hellcat



Joined: 24 Jan 2007
Posts: 84

PostPosted: Tue Feb 19, 2008 2:14 pm    Post subject: Reply with quote

I tried it, but didn't work....

Well, it seems I managed to get it working anyway.
Rearranged some code and added a few SetK1's - now everthing seems OK.


But that snipped you gave me there might come in handy on another thing, where I'm indeed hooking IoOpen :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