IT lexicon › Programming › libffi

libffi

Programming På svenska → Updated: 2026-11-07
More info
Creator
Anthony Green
Type
Library
License
MIT
Website
sourceware.org/libffi
Source
github.com/libffi/libffi

The C library that lets a program call a function whose signature it only learns at run time, by following the platform's calling convention on its behalf.

A C compiler knows at compile time which arguments go in which registers and how much goes on the stack. An interpreter asked to call printf on behalf of a Python script doesn't know until the script runs. libffi bridges the gap: the program describes the types in an ffi_cif, and ffi_call lays out the arguments exactly as the ABI demands — for x86-64, ARM64, RISC-V and some thirty other architecture and OS combinations.

Anthony Green wrote it at Cygnus in the 1990s. Today it sits underneath CPython's ctypes, Ruby's FFI, GHC and several JVM ports. It works in reverse too: closures produce a genuine C function pointer that jumps back into the interpreter. That has traditionally required memory that is both writable and executable, which collides with hardening rules such as W^X.

← Back to the lexicon