Skip to main content

Module panic

Module panic 

Source
Expand description

catch_unwind helpers.

§Why it is needed, and why it cannot be the only line of defense

Plugins are code brought in by dlopen. One panic in a plugin takes the whole host process down. So the host wraps every cross-boundary call in catch_unwind.

But since Rust 1.81, letting a panic cross an extern "C" boundary aborts outright — meaning:

panic inside the plugin
   └─ if it escapes the plugin's extern "C" function → abort (a catch_unwind on
      the host side is useless)

So the correct setup has two layers:

LayerWhereWhat it does
InnerPlugin side (generated by the contract crate’s export! macro)Turns the panic into an error code, never letting it reach the extern "C" boundary
OuterHost side (here)Catches surprises such as a plugin built with panic=abort, or a plugin that forgot to wrap

The outer layer still works when the plugin does not wrap itself — provided the plugin was also built with panic=unwind. That is why the host’s Cargo.toml sets panic = "unwind".

Functions§

guard
Wraps one cross-boundary call in catch_unwind.