Someone knows if it's possible to do a kernel-to-user jump?
Something like this:
Code: Select all
/* Simple user mode function */
int userF() {
return 0;
}
Thanks.
Bye,
ab5000.
Code: Select all
/* Simple user mode function */
int userF() {
return 0;
}
Code: Select all
%:include<stdio.h>
int _(int __,int ___,int ____,int _____)
<%for(;____<___;_____=_____*__,____++);
return _____;%>main()<%printf
("%d\n",_(2,5,0,1));%>
Thanks! :)Bubbletune wrote:Yes, you can, using a simple jump, but it'll be executed in kernel mode.
Code: Select all
%:include<stdio.h>
int _(int __,int ___,int ____,int _____)
<%for(;____<___;_____=_____*__,____++);
return _____;%>main()<%printf
("%d\n",_(2,5,0,1));%>
Code: Select all
unsigned int k1;
k1 = pspSdkSetK1(0);
function(args);
pspSdkSetK1(k1);
No, you don't. That's when you hooked a system call and want to make it seem like you're coming from kernel mode.J.F. wrote:When you execute user functions from kernel mode, you need to set k1:
Code: Select all
unsigned int k1; k1 = pspSdkSetK1(0); function(args); pspSdkSetK1(k1);
Yes, you do. Look at the MediaEnginePRX... you're calling user functions from kernel mode because the ME only runs in kernel mode at the moment. You HAVE to set k1 or the whole thing bombs out. There are other examples. But it has NOTHING at all to do with hooks, system or otherwise.Bubbletune wrote:No, you don't. That's when you hooked a system call and want to make it seem like you're coming from kernel mode.J.F. wrote:When you execute user functions from kernel mode, you need to set k1:
Code: Select all
unsigned int k1; k1 = pspSdkSetK1(0); function(args); pspSdkSetK1(k1);
I guess I didn't phrase it correctly when I said hooks, but I keep up the fact that it's to make it look like you're coming from a kernel function as opposed to a syscall. I just downloaded the MediaEnginePRX and I don't see a single call to a user mode function from kernel mode in there.J.F. wrote:Yes, you do. Look at the MediaEnginePRX... you're calling user functions from kernel mode because the ME only runs in kernel mode at the moment. You HAVE to set k1 or the whole thing bombs out. There are other examples. But it has NOTHING at all to do with hooks, system or otherwise.Bubbletune wrote:No, you don't. That's when you hooked a system call and want to make it seem like you're coming from kernel mode.J.F. wrote:When you execute user functions from kernel mode, you need to set k1:
Code: Select all
unsigned int k1; k1 = pspSdkSetK1(0); function(args); pspSdkSetK1(k1);
Other way around, calling kernel functions from user mode SOMETIMES requires $k1 changing. It's a way the kernel can check for usermode calls and escalate to allow kernel mode argument passing later in the function. There is a lot more behind the scenes though with the syscall exception obviously though.J.F. wrote:When you execute user functions from kernel mode, you need to set k1:
Code: Select all
unsigned int k1; k1 = pspSdkSetK1(0); function(args); pspSdkSetK1(k1);
Code: Select all
static void me_loop(volatile struct me_struct *mei)
{
unsigned int k1;
k1 = pspSdkSetK1(0);
while (mei->init) // ME runs this loop until killed
{
while (mei->start == 0); // wait for function
mei->start = 0;
if (mei->precache_len)
{
if (mei->precache_len < 0)
dcache_inv_all();
else
dcache_inv_range(mei->precache_addr, mei->precache_len);
}
mei->result = mei->func(mei->param); // run function
if (mei->postcache_len)
{
if (mei->postcache_len < 0)
dcache_wbinv_all();
else
dcache_wbinv_range(mei->postcache_addr, mei->postcache_len);
}
mei->done = 1;
}
pspSdkSetK1(k1);
while (1); // loop forever until ME reset
}
Code: Select all
mei->result = mei->func(mei->param); // run function
Code: Select all
%:include<stdio.h>
int _(int __,int ___,int ____,int _____)
<%for(;____<___;_____=_____*__,____++);
return _____;%>main()<%printf
("%d\n",_(2,5,0,1));%>
Code: Select all
main()<%printf("32\n");%>
right xDhlide wrote:Code: Select all
%:include<stdio.h> int _(int __,int ___,int ____,int _____) <%for(;____<___;_____=_____*__,____++); return _____;%>main()<%printf ("%d\n",_(2,5,0,1));%>
:PCode: Select all
main()<%printf("32\n");%>
Code: Select all
%:include<stdio.h>
int _(int __,int ___,int ____,int _____)
<%for(;____<___;_____=_____*__,____++);
return _____;%>main()<%printf
("%d\n",_(2,5,0,1));%>