How to release a stack with the context switch?
Posted: Thu Dec 24, 2015 11:07 am
I now found out why my OS corrupts the stack in SMP mode:
The task_save_state() function stores context and then clears the task->is_running flag, which allows the use of the stack after a context switch in a parallel task_schedule().
BUT: The scheduler/interrupt handler is still running on top of the old context, which results in the same stack being used by two tasks. (only ring0->ring0 CS'es for now)
What strategy do you use to avoid this problem?
I cannot clear the task->is_running flag until the scheduler has finished execution: An idea would be to construct an artificial second context which switches to some function like context_switch(task* prev_task, context* real_ctx) using a stack on top of the new stack, which would clear the flag and then continue to the context of the task selected by the scheduler.
Are there other, possibly more simple ways to handle this?
Cheers cmpxchg64
The task_save_state() function stores context and then clears the task->is_running flag, which allows the use of the stack after a context switch in a parallel task_schedule().
BUT: The scheduler/interrupt handler is still running on top of the old context, which results in the same stack being used by two tasks. (only ring0->ring0 CS'es for now)
What strategy do you use to avoid this problem?
I cannot clear the task->is_running flag until the scheduler has finished execution: An idea would be to construct an artificial second context which switches to some function like context_switch(task* prev_task, context* real_ctx) using a stack on top of the new stack, which would clear the flag and then continue to the context of the task selected by the scheduler.
Are there other, possibly more simple ways to handle this?
Cheers cmpxchg64