| View previous topic :: View next topic |
| Author |
Message |
Hellcat
Joined: 24 Jan 2007 Posts: 84
|
Posted: Tue Feb 05, 2008 3:49 pm Post subject: Cache invalidation in Kernel PRX not working? |
|
|
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 |
|
 |
Insert_witty_name
Joined: 10 May 2006 Posts: 376
|
Posted: Tue Feb 05, 2008 6:28 pm Post subject: |
|
|
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 |
|
 |
Hellcat
Joined: 24 Jan 2007 Posts: 84
|
Posted: Tue Feb 05, 2008 6:47 pm Post subject: |
|
|
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 |
|
 |
Insert_witty_name
Joined: 10 May 2006 Posts: 376
|
Posted: Tue Feb 05, 2008 7:02 pm Post subject: |
|
|
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 |
|
 |
Hellcat
Joined: 24 Jan 2007 Posts: 84
|
Posted: Tue Feb 12, 2008 11:10 pm Post subject: |
|
|
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 |
|
 |
hlide
Joined: 10 Sep 2006 Posts: 750
|
Posted: Wed Feb 13, 2008 6:14 am Post subject: |
|
|
| 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 |
|
 |
Hellcat
Joined: 24 Jan 2007 Posts: 84
|
Posted: Wed Feb 13, 2008 10:54 am Post subject: |
|
|
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 |
|
 |
moonlight
Joined: 26 Oct 2005 Posts: 567
|
Posted: Wed Feb 13, 2008 5:58 pm Post subject: |
|
|
| It is kernel code who created the callbacks? |
|
| Back to top |
|
 |
Hellcat
Joined: 24 Jan 2007 Posts: 84
|
Posted: Wed Feb 13, 2008 7:49 pm Post subject: |
|
|
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 |
|
 |
moonlight
Joined: 26 Oct 2005 Posts: 567
|
Posted: Thu Feb 14, 2008 5:25 am Post subject: |
|
|
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 |
|
 |
Hellcat
Joined: 24 Jan 2007 Posts: 84
|
Posted: Tue Feb 19, 2008 2:14 pm Post subject: |
|
|
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 |
|
 |
|