Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
If you're only using syscall/sysret for system calls, user mode programs have no valid reason to trigger a software interrupt. This got me thinking: is there any way to disable software interrupts, so that if a user mode program reaches an int instruction, it throws #UD or some other exception?
I realise that there's not much point to this - your OS needs to be able to distinguish between interrupt source anyway. But it would be interesting to know
madanra wrote:your OS needs to be able to distinguish between interrupt source anyway.
That's the answer to your question. The int instruction in user code typically results in a #GP (if we're talking about protected mode and if we don't set up IDT entries in special ways (you could configure ISRs to be callable from user code (read up on CPL, DPL and conforming segments))) and so you have the distinction already. And whatever interrupt it is, you have to handle it somehow in the kernel. You can't just magically turn all int instructions into nops.
The DPL field in the IDT entry determines what level is required to invoke that interrupt via 'INT', by setting it to 0, the user cannot invoke 'INT' (they'll probably get a GPF if they try)
thepowersgang wrote:The DPL field in the IDT entry determines what level is required to invoke that interrupt via 'INT', by setting it to 0, the user cannot invoke 'INT' (they'll probably get a GPF if they try)
Thank you - that was exactly what I was thinking of.