0151: FFI
extern fn in the trusted tier
Status: Proposed — design default, pending the maintainer's confirmation
Context
Harness needs a constrained route to native libraries without allowing manifests to inject compiler arguments. This numbering starts at 0150, leaving 0122–0149 for the owner's in-progress M14 ADRs.
Decision
Permit top-level private extern "symbol" fn
declarations only in FFI packages. Both the package and root
capability ceilings must include ffi. Manifests may
list package-relative shim headers, probed system headers, library
names and optional pkg-config, but no free-form
flags. Reject invalid symbols, public declarations and unmappable
types; check C prototypes at compile time. Map fixed-width scalars
and bool directly, borrow str/bytes
arguments for the call, and copy shim-allocated return buffers
into the caller arena. Shims own opaque handles in
generation-checked i64 slots.
Search for headers/libraries in order:
HARNESS_FFI_PREFIX, pkg-config, then
system defaults. Probe system headers and fail with E0978 when
unavailable. Do not vendor C libraries. Use E0973–E0979 for FFI
diagnostics and ffi for the runtime trap.
Consequences
Plugins expose safe Harness wrappers; callers cannot directly invoke public extern declarations. Header, resolved flags and prefix participate in cache identity. FFI remains explicitly trusted and C failures may differ from interpreter helper-death traps.
Alternatives considered
Free-form compiler flags would permit argument injection. Exposing raw pointers or aggregates expands the ABI and lifetime surface; dynamically loaded native code is outside this design.