I'm quite sure that linux does not use usermode exception handlers, and if you want to determine if the exception was caused by kernel or usermode, you should not check in which mode you are currently running (this was what you asked before, wasn't it?).
The fastest way I could think of by now is to check the code selector that the cpu pushed onto the stack when it entered the interrupt. Then, you just do a compare (when you only have one kernelmode and one usermode code segment), or you could use Brendan's hint (even better): check the lowest 2 bits, they indicate the PL. This way you know which PL caused the exception.
cheers Joe
Stack Swap
- Colonel Kernel
- Member
- Posts: 1437
- Joined: Tue Oct 17, 2006 6:06 pm
- Location: Vancouver, BC, Canada
- Contact:
Re:Stack Swap
Huh? I wasn't talking about user-mode exception handlers. You just look at the CS pushed on the stack... that's how you can tell in what mode you were running before the exception occurred. Same technique, different copy of CS.JoeKayzA wrote:I'm quite sure that linux does not use usermode exception handlers, and if you want to determine if the exception was caused by kernel or usermode, you should not check in which mode you are currently running
I wasn't asking anything before... Who were you replying to, anyway? ???JoeKayzA wrote:(this was what you asked before, wasn't it?).
Exactly what I meant. This is what my kernel (and Linux) do.JoeKayzA wrote:The fastest way I could think of by now is to check the code selector that the cpu pushed onto the stack when it entered the interrupt. Then, you just do a compare (when you only have one kernelmode and one usermode code segment), or you could use Brendan's hint (even better): check the lowest 2 bits, they indicate the PL. This way you know which PL caused the exception.
Top three reasons why my OS project died:
- Too much overtime at work
- Got married
- My brain got stuck in an infinite loop while trying to design the memory manager