A lightweight C/assembly library for bridging exception handling between managed and native code using the DWARF unwinder.
A re-implementation of MonoMod's libexhelper, consolidated into a single cross-platform codebase. The original had separate implementations for each platform/architecture combination, which was difficult to maintain. This version uses unified C and assembly sources with platform-specific macros for Linux/macOS on x86_64/arm64.
libexhelper provides three exported functions for exception handling interoperability:
eh_get_exception_ptr()- Returns a pointer to the thread-local current exception pointereh_managed_to_native(target)- Calls native code from managed context, catching any C++ exceptionseh_native_to_managed(target)- Calls managed code from native context, rethrowing any pending exceptions
| Platform | Architecture |
|---|---|
| Linux | x86_64, arm64 |
| macOS | x86_64, arm64 |
./build.sh| Variable | Default | Description |
|---|---|---|
MODE |
debug |
Build mode: debug or release |
TEST |
0 |
Build and run test executable: 0 or 1 |
OS |
auto-detect | Target OS: Darwin or Linux |
PLATFORM |
auto-detect | Platform name: e.g. macos, linux, linux-gnu |
ARCH |
auto-detect | Target architecture: x86_64 or arm64 |
CC |
clang |
C compiler (for zig zig cc) |
CXX |
clang++ |
C++ compiler (for zig zig c++) |
# Release build
MODE=release ./build.sh
# Build and run tests
MODE=release TEST=1 ./build.sh
# Cross-compile for Linux arm64 on macOS
OS=Linux PLATFORM=linux ARCH=arm64 ./build.shOutputs to build/release/bin/ and build/debug/bin/.
# Native build
zig build -Doptimize=ReleaseFast
# Cross-compile for Linux x86_64
zig build -Doptimize=ReleaseFast -Dtarget=x86_64-linux-gnu
# Cross-compile for Linux arm64
zig build -Doptimize=ReleaseFast -Dtarget=aarch64-linux-gnuOutputs to zig-out/lib/.
# With build.sh
TEST=1 ./build.sh
# With zig
zig build testContributions are welcome! Feel free to open issues and pull requests.
MIT