Hi,
In my OS, every programs run in ring 0. So when an interrupt or exception is raised, the CPU will not change stack if I use Interrupt gate in IDT. This leads to some problems like:
Stack is near full -> Page fault -> Push current state to stack (in order to call handler) -> Stack overflow -> Double fault -> Push -> Triple fault -> die
or
Stack overflow -> Push current state -> Stack overflow -> Double fault -> ... -> die
Therefore, I am considering using Task gate to handle exceptions and IRQs, and this will remove stack pressure from interrupt for normal programs. But TSS switching has considerable overhead. Are there any other solutions?
Using Task gate for exceptions and IRQs handling
Re: Using Task gate for exceptions and IRQs handling
I'd say that you have discovered one of the drawbacks of not using the x86 security model. So why does evey program run in ring 0? Are you, perhaps, addressing the wrong problem?
Re: Using Task gate for exceptions and IRQs handling
Hi,
You could simply use the task gate for your double fault handler but no other exceptions, or you could run your user-mode code in ring 3. Presumably you are running in protected mode so do not have the IST mechanism available?
Cheers,
Adam
[Edit: ...and +1 to iansjack]
You could simply use the task gate for your double fault handler but no other exceptions, or you could run your user-mode code in ring 3. Presumably you are running in protected mode so do not have the IST mechanism available?
Cheers,
Adam
[Edit: ...and +1 to iansjack]
Re: Using Task gate for exceptions and IRQs handling
Thanks, this is much more efficient and simple than my solution. And yes, I am running in protected mode.AJ wrote:You could simply use the task gate for your double fault handler but no other exceptions, or you could run your user-mode code in ring 3. Presumably you are running in protected mode so do not have the IST mechanism available?
Yes, I understand the drawbacks of not using other rings but I am experimenting with running all programs in ring 0.iansjack wrote:I'd say that you have discovered one of the drawbacks of not using the x86 security model. So why does evey program run in ring 0? Are you, perhaps, addressing the wrong problem?
Re: Using Task gate for exceptions and IRQs handling
Hi,
One word of warning if you go down this route - some Virtual Machines (MS VPC, I think, and possibly VirtualBox) did not handle task gates well the last time I tried (admittedly this was 5+ years ago). In the case of VPC, I was told that it was a known bug and there was no intention to fix, because mainstream OSes did not use this feature. Having said that, Bochs and Qemu worked fine IIRC.
Ultimately, though, you are very likely to want to run things in ring 3. I'm just curious - are you running managed code?
Cheers,
Adam
One word of warning if you go down this route - some Virtual Machines (MS VPC, I think, and possibly VirtualBox) did not handle task gates well the last time I tried (admittedly this was 5+ years ago). In the case of VPC, I was told that it was a known bug and there was no intention to fix, because mainstream OSes did not use this feature. Having said that, Bochs and Qemu worked fine IIRC.
Ultimately, though, you are very likely to want to run things in ring 3. I'm just curious - are you running managed code?
Cheers,
Adam