Exception tables

Rust compiler produced gcc_except_table section. How do I tell the compiler to create the appropriate tables for handling exceptions in this section?

Can you be a little more specific about what you’re trying to achieve and what isn’t working right now?

I’m writing my own kernel, which will have a modular architecture. And I want to catch the exceptions that occur in the modules. For example, rust does not allow the usual methods to catch an “index out of bounds” exception. I need to catch this exception, but not crash the kernel

Take a look at https://os.phil-opp.com/handling-exceptions/

It is a processor interrupts (https://os.phil-opp.com/handling-exceptions/), but I need handling rust exceptions. It’s different things

Since Rust does not support exceptions, possibly you’re referring to being able to respond to Rust panics which also unwind the stack?

Panic macros are calling _rust_begin_unwind. In this function I need work with exception, processing eh_frame and gcc_except_table sections. But this tables does not have information about catching panic, only for unwinding stack. But I don’t would like stop kernel at any errors in submodules

But rust is a system programming language. Why is there panics in it, but there is no correct way to catch of panics?

Panics indicate a programming error that can’t be recovered from. For error handling, you can use the Result type. This is all described in the Error handling chapter of the Rust book.

For more information about catching and handling panics, see the std::panic module.

I find std::intrinsics::try in libstd. I think, it helps me

I can’t use std module on bare metal

Unwinding is not supported without using std, you’ll have to write all the glue code yourself (or copy it from std). More info in https://github.com/rust-lang/rust/issues/44489

2 Likes

Okay, so in order to have unwinding panics instead of aborting panics, you need some sort of code that does stack unwinding. On most platforms this is left to libunwind or libgcc, both of which are C libraries. There is a pure Rust unwinder in the works at https://github.com/gimli-rs/unwind-rs, but it might or might not be mature enough for your purposes.

Thank you for link, it’s helps me