How to catch unhandled exceptions ?
Björn Döbel
doebel at os.inf.tu-dresden.de
Sun Jun 2 21:05:50 CEST 2013
Hi,
[..]
> So far so good! This is exactly what I want to do, to have a way to be notified
> by the kernel about any exception of a thread. Now my problem is that I
> get no notification when something bad happens (e.g. division by 0 or a
> page fault), is there any example where I can look to see how to use
> thread control + exc_handler and co ? I don't think I really know what to
> pass to exc_handler method, I tried to pass a L4::Server_Object::obj_cap()
> object but nothing happened ...
The page fault handler and the exception handler are Fiasco.OC threads.
Hence, you pass thread capabilities to those calls. Page faults go to
the PF handler , all other exceptions end up in the exception handler
thread.
In the thread you would then do something like
while (1) {
msg = l4_ipc_receive();
inject_exception();
}
In inject_exception() you can use the Thread::ex_regs system call, which
allows you to modify the IP/SP of a thread.
[..]
>> 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.
>>
>
> Of course you need to add try/catch statements :) The beauty is that if
> you'll do it, you'll have a chance to survive to save your data, if not,
> then, as you said, std::terminate will be called and you get the same
> effect.
There may be libraries (e.g., libc_be_signal) that spawn their own
threads and where you do not have control over potential try/catch
statements in their code. But that might not be an issue for you.
>> 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.
>>
>
> AH, sorry , I think is a misunderstanding here, I don't want you to do it in
> Fiasco (even I think it will be very nice feature), I want to be able to do it
> in my apps (at user-level not kernel level)!
Sure, that's what I meant as well.
Cheers,
Bjoern
More information about the l4-hackers
mailing list