adding user space tasks

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
proxy

adding user space tasks

Post by proxy »

ok i have kernel threads working pretty well and have been trying to move onto user space threads. Basically my problem boils down to this. I use the software context switching to switch tasks and I would like to simply be able to create a thread structure in memory with user space segments and such and just add it to my scheduler but obviously it isn't that simple. I tried to setup my equivalent to "longjmp" in a way that it would put the user space esp/ss on the fake iret stack but then i get a gpf on the iret as soon as i spin up any tasks (kernel or user mode).

I imagine the issue stems from the fact that ring0->ring0 irets aren't supposed to have ss3/esp3 pushed on the iret stack.

so...what do i do? should i have 2 "longjmp" functions one for changing ring level one for not? Is this even my problem in it's entirety?

any advice woudl be very much appreciated :)

proxy
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:adding user space tasks

Post by Pype.Clicker »

well, the common solution is to have a ring0 stack ready and waiting for each ring3 thread. Whatever happens, the switch will _always_ go from a ring0 stack to another ring0 stack. If there was some user process behind a ring0, then resuming the task will naturally go back to user mode...
proxy

Re:adding user space tasks

Post by proxy »

so would a good way to accomplish what i want be to set the entry point of the user space thread to a thunk which would do the "typcal trick" to switch it to user space code (it beleive it is the very first switch which is being a problem...)

or am i barking up the wrong tree?

proxy
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:adding user space tasks

Post by Pype.Clicker »

there are several way to setup 'thread running user code'. one of them indeed consist of filling the stack with what it would look like if the usercode was just interrupted, e.g.
[tt]
<state popped by stack_switch>
<eip pointing to some 'iretd'>
<cs, eip, ss, esp for your user code>
<arguments your user function will receive>
[/tt]
Post Reply