Another multitasking question
Posted: Thu Mar 16, 2017 8:27 am
I'm really sorry for asking very much questions about multitasking, but I'm out of ideas again, so I couldn't write even two lines of code.
I remove tasks with a queue. When I call remove_task(pid), it adds the task to remove queue, and when switching tasks, it removes all tasks in the queue, cleans the data and frees memory location used by task.
But, then I noticed that causes tasks to stroll out its address space.
For example:
User task calls exit(0);
Exit interrupt
System adds task to remove queue
Interrupt return
Task continues executing, strolls out its address space.
IRQ0 (task switch)
Task gets removed, system switches to next task.
Interrupt return
Next task's code...
Yes, the task gets removed after a while but it strolls out its address space until IRQ0, so it can do something bad.
My solution I thought is putting task in a kind of infinite loop, but it is an ugly solution as system call exit doesn't get the stack address (interrupt_registers_t*) as a parameter, that allows me to get / set eip.
(I *tried* to say int nn instruction pushes cs, eip and another data to stack, but I'm not a native speaker )
I'm out of ideas, what's the best way to do that?
Thanks in advance.
I remove tasks with a queue. When I call remove_task(pid), it adds the task to remove queue, and when switching tasks, it removes all tasks in the queue, cleans the data and frees memory location used by task.
But, then I noticed that causes tasks to stroll out its address space.
For example:
User task calls exit(0);
Exit interrupt
System adds task to remove queue
Interrupt return
Task continues executing, strolls out its address space.
IRQ0 (task switch)
Task gets removed, system switches to next task.
Interrupt return
Next task's code...
Yes, the task gets removed after a while but it strolls out its address space until IRQ0, so it can do something bad.
My solution I thought is putting task in a kind of infinite loop, but it is an ugly solution as system call exit doesn't get the stack address (interrupt_registers_t*) as a parameter, that allows me to get / set eip.
(I *tried* to say int nn instruction pushes cs, eip and another data to stack, but I'm not a native speaker )
I'm out of ideas, what's the best way to do that?
Thanks in advance.