So I know how to handle some of the common exceptions (page fault, double fault, general protection, etc). What I'm confused about handling are the other exceptions -- overflow, bounds range exceeded, division by zero, any SIMD exception, that sort of thing.
What is the proper way of handling these? The intel manual (and even aMD manual) is silent on these and doesn't explain how to handle them. I thought that I might need to go in and "patch" the process that triggered the exception via looking at the RIP and changing it to something else, but that seems both ridiculously invasive and far too complicated. Not to mention the number of conditions that can generate these exceptions. So how do you guys handle these?
Right way of handling various exceptions?
-
- Member
- Posts: 5567
- Joined: Mon Mar 25, 2013 7:01 pm
Re: Right way of handling various exceptions?
If something useful can be done in response to an exception, the program that causes the exception will know what needs to be done.
Give programs a way to register a callback. When the program causes an exception, call the callback. If no callback is registered, kill the program.
This also applies to page faults and general protection faults.
Give programs a way to register a callback. When the program causes an exception, call the callback. If no callback is registered, kill the program.
This also applies to page faults and general protection faults.
Re: Right way of handling various exceptions?
Most of these are simple exceptions. This means, if they are generated in user space, you just deliver a fault to the user process, and if they are generated in kernel space, you generate a kernel panic. On POSIX-like operating systems you deliver a fault in form of a signal. FPU and SIMD exceptions get SIGFPE, divide error also gets SIGFPE with a different reason code, bounds check gets a SIGSEGV, etc.
In kernel mode, these indicate programming errors on your part, so they have to be treated as such. Print all debugging information that you can, then halt the system.
In kernel mode, these indicate programming errors on your part, so they have to be treated as such. Print all debugging information that you can, then halt the system.
Carpe diem!
Re: Right way of handling various exceptions?
Thanks, that makes sense.