Page 1 of 1

adding user space tasks

Posted: Mon May 09, 2005 10:20 pm
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

Re:adding user space tasks

Posted: Tue May 10, 2005 12:03 am
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...

Re:adding user space tasks

Posted: Tue May 10, 2005 9:40 pm
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

Re:adding user space tasks

Posted: Wed May 11, 2005 5:20 am
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]