Rust FFI unwinding: choose an explicit panic and exception boundary

이 문서는 아직 한국어로 제공되지 않습니다. 원문을 표시합니다.

article · en · 지식 기준일 2026-09-22 · 변경일 , 리비전 1 · unreviewed

주제: coding · exceptions · ffi · rust

적용 대상: Rust foreign-function boundaries

증상: A panic or foreign exception unexpectedly crosses a language boundary.

Separate ordinary error returns, Rust panics and foreign exceptions before selecting the boundary ABI.

목차
  1. What it is
  2. Why it matters
  3. How to apply
  4. Pitfalls
  5. 범위와 근거
  6. 출처
  7. 저작자 표시와 라이선스
  8. 기계 접근

What it is

The Rustonomicon distinguishes ABI strings that permit unwinding from those that do not. A Rust panic reaching a non-unwinding boundary aborts; a foreign exception entering Rust through such a boundary causes undefined behavior. It also states that panic=abort still aborts regardless of the selected ABI and that catch_unwind is not a general foreign-exception catcher. Rustonomicon: FFI

Why it matters

An agent wrapping a C++ library may add catch_unwind around a call and assume all failures become error values. Before writing recovery code, specify which language owns each failure mechanism. The proposed boundary review makes error representation an explicit interface decision.

How to apply

  • Inventory every exported function and callback. For each, record its ABI, panic strategy, foreign exception behavior and ordinary error return contract.
  • Prefer translating expected failures into the interface's documented status or result representation at the side that understands them. Define how an error message is stored and how long it remains valid.
  • If unwinding is intentionally permitted, review all intervening frames and cleanup assumptions against the appropriate ABI contract. Do not make the change solely to stop an observed abort.
  • Propose separate fixtures for an ordinary error, a Rust panic and a foreign exception. Run any potentially terminating fixture in an isolated child process and classify its exit without treating termination as a recoverable return.
  • Check resource cleanup and callback behavior for each supported failure path. Keep unsupported combinations explicit in the public binding documentation.

Pitfalls

Do not infer compatibility from a single compiler and optimization level. A catch mechanism from one language is not automatically valid for another language's exception. The correct boundary also depends on the foreign library and build configuration, so a generic wrapper cannot promise universal recovery. This article describes a review plan and claims no executed cross-language exception experiment.

범위와 근거

Original synthesis from the cited primary documentation, with proposed diagnostic and verification steps. No benchmark, experiment or field result is claimed; unreviewed AI-assisted contribution.

지식 기준일: 2026-09-22. 상태: unreviewed (기록된 검토 없음) — 편집하면 검토 상태가 초기화됩니다. 본문은 검증되지 않은 참고 자료로 다루고 출처를 확인하세요.

출처

  1. Rustonomicon: FFI — 2026-09-22 확인: 접근 가능, 인용문 있음

저작자 표시와 라이선스

  • Account External coding curation authors (57eb56c9)
  • Written with Codex, an AI coding agent, at the site operator's request; original synthesis, sources credited separately.

마지막 변경: New English original; AI-assisted and unreviewed. Proposed checks have not been executed for this article.

원본 기여: CC BY 4.0. 링크된 출처 자료는 각자의 권리를 유지합니다.

기계 접근