SerenityOS / serenity

The Serenity Operating System 🐞
https://serenityos.org
BSD 2-Clause "Simplified" License
30.36k stars 3.17k forks source link

Userspace: Exception Handling #2216

Open ADKaster opened 4 years ago

ADKaster commented 4 years ago
bugaevc commented 4 years ago

But why?..

Let's maybe not have exceptions?

ADKaster commented 4 years ago

Why not?

Need to parse the frame information to get reasonable debugging backtraces and such, might as well go the extra mile to get exceptions in userspace.

On Thu, May 14, 2020, 1:17 AM Sergey Bugaev notifications@github.com wrote:

But why?..

Let's maybe not have exceptions?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/SerenityOS/serenity/issues/2216#issuecomment-628439714, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB777DTBY5GOT2BNGVGN5E3RROLIFANCNFSM4NAMOTNA .

awesomekling commented 4 years ago

Seems fine to support it if it's relatively non-invasive.

awesomekling commented 4 years ago

Just to be clear, the absence of exceptions in this project is a feature.

But we can still support it for ports :)

bugaevc commented 4 years ago

As long as we can make it not allocate a page upfront for bullshit reasons in each process, and as long as it doesn't cause all our methods to grow unwinding paths when built with exception support...

awesomekling commented 4 years ago

Indeed, this feature needs to have zero impact on the stock system. My understanding of LibUnwind is that everything necessary for exception support would go in there and unless you link against it, none of this affects you. :)

ADKaster commented 4 years ago

Growing non exceptional code when built with exceptions is a feature it setjump/longjump exceptions. The compiler has to set the jump buffer before calling a possibly throwing method.

There's a reason the two phase lookup ABI based on call frame information was developed, and it's specifically to give "zero overhead" exceptions. If you don't throw, nothing happens to your code.

That being said I'm looking into this mostly as an academic thing, because it looks like a cool technical challenge. Not looking to add try catch all over the place :).

On Thu, May 14, 2020, 3:00 AM Andreas Kling notifications@github.com wrote:

Indeed, this feature needs to have zero impact on the stock system. My understanding of LibUnwind is that everything necessary for exception support would go in there and unless you link against it, none of this affects you. :)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/SerenityOS/serenity/issues/2216#issuecomment-628498422, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB777DSN7CGPMDCFLBGYH5TRROXK5ANCNFSM4NAMOTNA .

bugaevc commented 4 years ago

There's a reason the two phase lookup ABI based on call frame information was developed, and it's specifically to give "zero overhead" exceptions. If you don't throw, nothing happens to your code.

It's true that no special setup is needed to call a potentially throwing method when the so-called zero cost exceptions are used. But you still pay by way of the exception handling code the C++ compiler inserts on your behalf (that runs object destructors) — if any call can potentially throw (as far as the compiler is concerned — we know we don't throw exceptions) that could a lot of additional code — so I'm concerned about executable size, cache friendliness and such.