 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
ab5000
Joined: 06 May 2008 Posts: 74
|
Posted: Fri Aug 07, 2009 5:46 am Post subject: Kernel to user jump? |
|
|
Hi.
Someone knows if it's possible to do a kernel-to-user jump?
Something like this:
| Code: | /* Simple user mode function */
int userF() {
return 0;
} |
can i jump to userF from a kernel module? If yes, it's just a simple jump or a more complicated thing? userF gets executed as user or kernel? (i'll aspect it to be executed as kernel, because when userF returns the context cannot be switched from user to kernel with a jump like "jump to $ra", only with syscalls)
Thanks.
Bye,
ab5000. _________________
| Code: | %:include<stdio.h>
int _(int __,int ___,int ____,int _____)
<%for(;____<___;_____=_____*__,____++);
return _____;%>main()<%printf
("%d\n",_(2,5,0,1));%> |
|
|
| Back to top |
|
 |
Bubbletune
Joined: 03 Jan 2009 Posts: 28
|
Posted: Fri Aug 07, 2009 5:15 pm Post subject: |
|
|
| Yes, you can, using a simple jump, but it'll be executed in kernel mode. |
|
| Back to top |
|
 |
ab5000
Joined: 06 May 2008 Posts: 74
|
Posted: Fri Aug 07, 2009 7:50 pm Post subject: |
|
|
| Bubbletune wrote: | | Yes, you can, using a simple jump, but it'll be executed in kernel mode. |
Thanks! :) _________________
| Code: | %:include<stdio.h>
int _(int __,int ___,int ____,int _____)
<%for(;____<___;_____=_____*__,____++);
return _____;%>main()<%printf
("%d\n",_(2,5,0,1));%> |
|
|
| Back to top |
|
 |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Sat Aug 08, 2009 1:36 am Post subject: |
|
|
When you execute user functions from kernel mode, you need to set k1:
| Code: | unsigned int k1;
k1 = pspSdkSetK1(0);
function(args);
pspSdkSetK1(k1);
|
|
|
| Back to top |
|
 |
Bubbletune
Joined: 03 Jan 2009 Posts: 28
|
Posted: Sat Aug 08, 2009 2:58 am Post subject: |
|
|
| J.F. wrote: | When you execute user functions from kernel mode, you need to set k1:
| Code: | 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. |
|
| Back to top |
|
 |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Sat Aug 08, 2009 3:06 am Post subject: |
|
|
| Bubbletune wrote: | | J.F. wrote: | When you execute user functions from kernel mode, you need to set k1:
| Code: | 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. |
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. |
|
| Back to top |
|
 |
Bubbletune
Joined: 03 Jan 2009 Posts: 28
|
Posted: Sat Aug 08, 2009 3:11 am Post subject: |
|
|
| J.F. wrote: | | Bubbletune wrote: | | J.F. wrote: | When you execute user functions from kernel mode, you need to set k1:
| Code: | 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. |
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. |
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. |
|
| Back to top |
|
 |
Davee
Joined: 22 Jun 2009 Posts: 59
|
Posted: Sat Aug 08, 2009 4:29 am Post subject: |
|
|
| J.F. wrote: | When you execute user functions from kernel mode, you need to set k1:
| Code: | 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.
In kernel mode $k1 is 0, so setting it to 0 is pointless.
Looks like you got the two mixed around =/
To call from kernel to user you either OR the address with 0x80000000 or you create a user mode thread. Depending on the circumstances, a usermode thread may be more suitable. |
|
| Back to top |
|
 |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Sat Aug 08, 2009 7:09 am Post subject: |
|
|
Look at the kernel mode PRX example thread for details, but when you call a user function from kernel mode, you set k1. It's in every example of kernel mode prx's there are... it's in every kernel mode prx you'll find. Look at cooleye's kernel prx to set the sample rate... or the kernel prx to get the HOME button... or the MediaEnginePRX. We didn't just make this up to laugh at people - if you don't set k1, it DOESN'T WORK.
@Bubbletune: The call is in the loop.
| Code: | 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
} |
Specifically
| Code: | | mei->result = mei->func(mei->param); // run function |
Those functions passed in are to user functions in the program. |
|
| Back to top |
|
 |
hlide
Joined: 10 Sep 2006 Posts: 750
|
Posted: Sat Aug 08, 2009 8:02 am Post subject: |
|
|
| Code: | %:include<stdio.h>
int _(int __,int ___,int ____,int _____)
<%for(;____<___;_____=_____*__,____++);
return _____;%>main()<%printf
("%d\n",_(2,5,0,1));%> |
| Code: | | main()<%printf("32\n");%> |
:P |
|
| Back to top |
|
 |
ab5000
Joined: 06 May 2008 Posts: 74
|
Posted: Sat Aug 08, 2009 6:45 pm Post subject: |
|
|
| hlide wrote: | | Code: | %:include<stdio.h>
int _(int __,int ___,int ____,int _____)
<%for(;____<___;_____=_____*__,____++);
return _____;%>main()<%printf
("%d\n",_(2,5,0,1));%> |
| Code: | | main()<%printf("32\n");%> |
:P |
right xD _________________
| Code: | %:include<stdio.h>
int _(int __,int ___,int ____,int _____)
<%for(;____<___;_____=_____*__,____++);
return _____;%>main()<%printf
("%d\n",_(2,5,0,1));%> |
|
|
| Back to top |
|
 |
|
|
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
|