ffi
lib/ffi.vklib/ffi.vk
Opt-in .ffi foreign shared library boundary and deterministic C-struct packing helpers.
- Denied by default at compile time and runtime unless allow-caps = [.ffi] in veko.vk or --allow-ffi
- Strictly forbidden on Wasm 3.0 zero-trust targets (--wasm)
- Zero-W^X static AOT C-ABI trampolines (Win64, Linux x86_64 dynamic ELF64, macOS arm64 libSystem)
- Enforces .secret firewall: .secret values can never cross ffi/open, ffi/sym, or ffi/call
Library = struct { handle i64, path str }
Handle to a dynamically loaded foreign shared library.
candidate-paths = fn [name str, veko_lib_env str, is_win bool] block[str]
Splits VEKO_LIB on ; (Windows) or : (POSIX) and returns candidate shared-library paths
before falling back to name for standard OS dynamic loader resolution.
use [ffi]
cands = ffi/candidate-paths 'custom_ext' '/opt/veko/lib:/usr/local/lib' false
resolve-lib-path = fn [name str] str
Resolves name against VEKO_LIB directories on disk when present, otherwise returns name.
open-lib = fn [path str] Library
Opens a foreign shared library (LoadLibraryA on Windows, dlopen on Linux/macOS),
searching VEKO_LIB directories first when configured. Requires opt-in .ffi capability.
resolve = fn [lib Library, name str] Symbol
Resolves a C symbol inside lib (GetProcAddress on Windows, dlsym on Linux/macOS).
call-c = fn [s Symbol, args block] i64
Invokes a foreign C function s with up to 6 integer/string/bytes/bool arguments
using the platform's static AOT C-ABI trampoline and returns its i64 result register.
pack-u32 = fn [mut buf bytes, v i64]
Appends an unsigned 32-bit little-endian integer into buf.
pad-align = fn [mut buf bytes, align i64]
Appends pad zero bytes to align a C struct field to align bytes.
unpack-u32 = fn [buf bytes, off i64] i64
Reads an unsigned 32-bit little-endian integer at byte offset off.
unpack-i32 = fn [buf bytes, off i64] i64
Reads a signed 32-bit little-endian integer at byte offset off.
unpack-i64 = fn [buf bytes, off i64] i64
Reads a 64-bit little-endian integer at byte offset off.
unpack-cstr = fn [buf bytes, off i64] str
Reads a NUL-terminated C string starting at off.