Detecting exception error code

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

Re:Detecting exception error code

Post by Ryu »

JAAman wrote: dont tell me im assuming something that i didnt even think about -- you obviously didnt get what i meant

what i meant is in my OS, there is only 2 possible CS values (say 0x10 (kernel CS) and 0x1B (user CS --entry 0x18+ring3) -- it would be easy to change this -- or add more CS values for rings 1&2)
then you try:

if (esp+8) == 0x10
call withErrorCode
if (esp+8) == 0x1B
call withErrorCode
call withoutErrorCode // if you get here, then it cannot be CS
Your just not getting the points mentioned throughout this thread. Above all, with the points you've agreed that is correct, the pseudo code doesn't make sense.

What you've given us here assumes when theres no error code, [esp+8h] should be the return segment. This is based on your default procedure: call withoutErrorCode and that your checking [esp+8h] is corresponding to a specific segment to determin when theres an error code, which is logically all wrong. We know that when theres no error code [esp+8h] should be EFLAGS, so this conflicts with your pseudo's logic to detect error/no error code. The pseudo before hand, also checks if that corresponds with a specific ring0 segment to determin if theres an error code (for the ring3, hold your horses, I will say something about this after), really what is the differnts to what I stated which I think your assuming?

As for the pseudo: if (esp+8) == 0x1B that checks if its a specific ring3 segment, now why would do this and call withErrorCode when we know that only ring0 can software interrupt and that rings 1, 2, and 3 can only generate exceptions ?, while for exception cases whether it has an error code or not depends on the which exception where when theres none I can just push a fake error code, because even in a software generated case theres none.
JAAman

Re:Detecting exception error code

Post by JAAman »

would you please read what i post before replying to it?
what you've given us here assumes when theres no error code, [esp+8h] should be the return segment.
you obviously did not read anything that i have posted
my psudocode does NOT assume that no error code esp+8 is the return segment -- quite the opposite, it assumes that when there is no error code esp+8 is eflags
This is based on your default procedure: call withoutErrorCode and that your checking [esp+8h] is corresponding to a specific segment to determin when theres an error code
the default procedure is called when esp+8 is eflags (which should be withoutErrorCode) -- not when it is segment
We know that when theres no error code [esp+8h] should be EFLAGS, so this conflicts with your pseudo's logic to detect error/no error code.
no it doesnt -- that is in fact exactly what it does
The pseudo before hand, also checks if that corresponds with a specific ring0 segment to determin if theres an error code (for the ring3, hold your horses, I will say something about this after), really what is the differnts to what I stated which I think your assuming?
the pseudo code only checks for CS -- i dont ever check for eflags -- the only assumption is that if it is not a valid CS, then it must be eflags

it is very different, i cannot even see any similarity to what you stated (i didnt even realize that all ring0 CS values are invalid in eflags -- actually, i didnt even understand that when you posted it earlier)
As for the pseudo: if (esp+8) == 0x1B that checks if its a specific ring3 segment, now why would do this and call withErrorCode when we know that only ring0 can software interrupt and that rings 1, 2, and 3 can only generate exceptions ?
because your assumptions are wrong -- unless you specifically block them, exceptions can be called from any ring (of course you can block them by setting the permisions flag in the IDT, but i mentioned this earlier, and your reply seemed to indicate that you didnt want to do this)
Post Reply