Implementing SEH in Rust and why you shouldn't do it
a day ago
- SEH is Windows' exception handling model; x64/ARM64 use a table-based version.
- SEH is needed in Rust for safely accessing usermode memory in drivers and for continuable exceptions.
- Implementing SEH via LLVM is not feasible because Rust lacks inline LLVM support.
- Assembly approach using gas macros and __C_specific_handler works but requires careful label range management.
- Rust inline assembly can replicate SEH, but resource cleanup (Drop) is not automatically called on SEH exceptions.
- C++ with /EHa properly destructs objects during SEH; Rust's lack of this leads to resource leaks.
- Best practice: implement SEH wrappers in C++ with /EHa and call them from Rust.