Stack Swap

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.
JoeKayzA

Re:Stack Swap

Post 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
User avatar
Colonel Kernel
Member
Member
Posts: 1437
Joined: Tue Oct 17, 2006 6:06 pm
Location: Vancouver, BC, Canada
Contact:

Re:Stack Swap

Post 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.
Top three reasons why my OS project died:
  1. Too much overtime at work
  2. Got married
  3. My brain got stuck in an infinite loop while trying to design the memory manager
Don't let this happen to you!
JoeKayzA

Re:Stack Swap

Post by JoeKayzA »

:o

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

cheers
Joe
Post Reply