UnFFI
System libraries

System libraries

Focused, typed bindings for native OS libraries.

System library bindings are shipped as direct subpath imports. They use the same schema inference and lifecycle as dlopen, but the common library path, symbol schema, and open* helper are already defined.

import { openCoreFoundation } from 'unffi/macos/CoreFoundation'
import { openLibc } from 'unffi/linux/libc'
import { openKernel32 } from 'unffi/windows/kernel32'

await using cf = await openCoreFoundation()
const cfStringType = cf.symbols.CFStringGetTypeID()

await using libc = await openLibc()
const pid = libc.symbols.getpid()

await using kernel32 = await openKernel32()
const windowsPid = kernel32.symbols.GetCurrentProcessId()

What you get

  • One import per native library, for example unffi/macos/Security or unffi/windows/user32.
  • Typed open*() helpers that return an AsyncDisposable library handle.
  • Exported *Schema and *LibraryPaths constants for inspection or manual composition.
  • UNFFI_*_PATH environment overrides and open*(pathOverride) for custom library locations.

Shipped modules

PlatformImportSymbolsEnv override
macOSunffi/macos/libSystemgetpid, strlen, strcmp, atoiUNFFI_LIBSYSTEM_PATH
macOSunffi/macos/CoreFoundationCFAbsoluteTimeGetCurrent, CFStringGetTypeID, CFReleaseUNFFI_COREFOUNDATION_PATH
macOSunffi/macos/SecuritySecRandomCopyBytesUNFFI_SECURITY_PATH
macOSunffi/macos/SystemConfigurationSCDynamicStoreCopyProxiesUNFFI_SYSTEMCONFIGURATION_PATH
Linuxunffi/linux/libcgetpid, getppid, strlen, strcmpUNFFI_LIBC_PATH
Linuxunffi/linux/libmcos, sin, sqrt, fabsUNFFI_LIBM_PATH
Linuxunffi/linux/libdldlerrorUNFFI_LIBDL_PATH
Linuxunffi/linux/pthreadpthread_self, pthread_equalUNFFI_PTHREAD_PATH
Linuxunffi/linux/unistdgetuid, getgid, getppid, accessUNFFI_UNISTD_PATH
Windowsunffi/windows/kernel32GetCurrentProcessId, GetCurrentThreadId, GetTickCount64, lstrlenAUNFFI_KERNEL32_PATH
Windowsunffi/windows/advapi32GetUserNameAUNFFI_ADVAPI32_PATH
Windowsunffi/windows/user32GetSystemMetrics, GetDoubleClickTimeUNFFI_USER32_PATH

Conservative by design

The shipped surface is intentionally focused. APIs that need C++ classes, Objective-C messaging, COM vtables, variadic functions, bitfields, or ownership-heavy structs are skipped until UnFFI can model them safely.

The schema gives you a typed FFI boundary. It does not make arbitrary native pointers safe to own, inspect, or release.

Use the platform pages for runnable snippets, or see the repository examples/ folder for scripts grouped by OS.

On this page