Thanks!pcmattman wrote:Slightly difficult concept to explain...eXeCuTeR wrote:Level of nesting? what do you mean?pcmattman wrote: (we actually have up to 16 kernel stacks per thread, one for each level of nesting, to avoid stack corruption).
Basically, when an event is sent to a thread, that thread is automatically interrupted. This is sort of like an IRQ firing, except local to a thread (events are, essentially, a form of IPC - this is not entirely true, but simplifies the explanation). Because the thread can be interrupted at any time, its context must be saved somewhere. We allow threads to be interrupted even while handling events - so we can't just have a dedicated "event stack".
When an event is dispatched to a thread, the thread's old context is saved onto its current stack. For this example, this is at nesting level 1. The nesting level is incremented to 2, and execution of the event begins. If another event is dispatched to the thread, the context is saved onto the current stack (which is now the second nesting level stack) and the nesting level is incremented to 3.
As each event finishes being handled, the nesting level is reduced by one and the previous context is restored.
The idea is that interrupts and further events (and even ring3/ring0 transitions) don't corrupt the kernel stack for a thread. This is our solution to one of our bigger stack corruption bugs.
So I have 2 questions:
1. How can you determine the maximum level of nesting? you just define a specific maximum level of nsting and create kernel stacks correspondingly for each process?
2. Why not define events as IPC? and BTW, you refer to events as signals?
p.s: Sorry for lousy English; If something isn't clear, let me know.