Page 1 of 1
Exception Handler
Posted: Sun Mar 28, 2004 7:13 am
by ich_will
What should I do if an exception occurs?
For Example the Div by Zero exception, at the moment my function prints out a message and holds, but I think thats a really bad solution.
Re:Exception Handler
Posted: Sun Mar 28, 2004 8:27 am
by Tim
Depends on the exception. Some exceptions (e.g. page fault) can be corrected and the app can continue. Others (e.g. divide by zero) indicate and error, and the app should exit.
Re:Exception Handler
Posted: Sun Mar 28, 2004 9:00 am
by ich_will
But I can't close the Kernel if there's an div by zero exception, or should i.
Re:Exception Handler
Posted: Sun Mar 28, 2004 9:42 am
by Tim
How can the kernel handle a fatal error in its own code? If the kernel has a fatal error (i.e. a bug), the only thing to do is print as much information about the exception as is available, and halt the system.
Re:Exception Handler
Posted: Sun Mar 28, 2004 10:31 am
by Candy
Tim Robinson wrote:
How can the kernel handle a fatal error in its own code?
For some cases you might be able to code something
For instance, when you call INVLPG on a 386 you get an invalid opcode exception. If you define the invlpg instruction to take an X number of bytes (possibly some more, maybe with a zero operand with it?) and you can runtime replace it with a different code sequence (the cr3 reload sequence) you could use the same code for both computers without slowing them down, by using (not even abusing) the invalid opcode mechanism.
Re:Exception Handler
Posted: Sun Mar 28, 2004 2:19 pm
by Pype.Clicker
iirc, the Intel Manual (section about exceptions) gives hints on how exceptions should be handled. In the case of a kernel, as the same piece of code generated an exception and tries to handle it, things may sometimes be a little different.
For instance, you might try to have "resume points" where the execution should be transferred in case of an "expected" exception, but just entering a "panic mode" on unrecoverable errors (that is, errors that come from kernel itself rather than from some user-level call) would probably a more realistic target.