Page 2 of 2

Re:Stack Swap

Posted: Sun Sep 25, 2005 12:00 pm
by JoeKayzA
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

Re:Stack Swap

Posted: Sun Sep 25, 2005 12:39 pm
by Colonel Kernel
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
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:(this was what you asked before, wasn't it?).
I wasn't asking anything before... Who were you replying to, anyway? ???
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.
Exactly what I meant. This is what my kernel (and Linux) do.

Re:Stack Swap

Posted: Tue Sep 27, 2005 8:19 am
by JoeKayzA
:o

Man, sorry, it seems I confused some things here ::)

cheers
Joe