Re: How to catch unhandled exceptions ?

Björn Döbel <[email protected]>
Newsgroups gmane.comp.micro-kernel.l4.devel
Message-ID <[email protected]>
Hi,

> Is there any way to catch all system unhandled exceptions (seg fault,
> fpu fault, etc.) and "transform" them into C++ exceptions ?

I'm afraid you're confusing two kinds of exceptions here.

Hardware exceptions (e.g., page faults) are raised by the CPU during
execution and are delivered to a kernel-level handler function, because
that's what the hardware specification says. Fiasco.OC being a
microkernel, we do not handle those exceptions in a kernel, but reflect
them to user-level handler threads - the page fault handler and the
exception handler. Each thread on top of Fiasco.OC has a PF handler and
an exception handler thread assigned. Whenever a CPU exception occurs
while a thread executes, the respective handler threads get a notification.

This is also what the functions you found (thread control + exc_handler)
do - they can be used to assign PF and exception handlers to a thread.

In contrast, C++ language-level exceptions are raised synchronously by
your code (or some library) using the C++ 'throw' keyword. These
language-level exceptions can be caught and handled using try/catch-blocks.

Transforming hardware exceptions into C++ exceptions appears to be
difficult: Suppose, your thread raises a page fault and you want to make
this a C++ exception - what happens if your exception handler raises
another page fault - leading to another exception that raises yet
another page fault ...

Also, C++ exceptions need to be caught in the thread that raised the
exception, otherwise the exceptions causes a call to std::terminate,
wich will abort your application. Hence, you'd need try/catch statements
for all potential hardware exceptions around all your threads' code.

I'm not saying it can't be done (I vaguely remember Choices OS [1] doing
this), it's just not what we are doing on Fiasco right now.

[1] http://choices.cs.uiuc.edu/

 Bjoern
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.