OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 10:36 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Right way of handling various exceptions?
PostPosted: Fri Jun 25, 2021 11:08 pm 
Offline
Member
Member

Joined: Sun Jun 23, 2019 5:36 pm
Posts: 618
Location: North Dakota, United States
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?


Top
 Profile  
 
 Post subject: Re: Right way of handling various exceptions?
PostPosted: Sat Jun 26, 2021 1:13 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5101
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.


Top
 Profile  
 
 Post subject: Re: Right way of handling various exceptions?
PostPosted: Sat Jun 26, 2021 1:14 am 
Offline
Member
Member

Joined: Wed Aug 30, 2017 8:24 am
Posts: 1593
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.

_________________
Carpe diem!


Top
 Profile  
 
 Post subject: Re: Right way of handling various exceptions?
PostPosted: Sat Jun 26, 2021 2:25 am 
Offline
Member
Member

Joined: Sun Jun 23, 2019 5:36 pm
Posts: 618
Location: North Dakota, United States
Thanks, that makes sense.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 40 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group