Files
aji/docs/spec/09-runtime-and-abi.md
T
dev 41b764ccfd spec: Phase 0 spec gate (P0-1, P0-2, P0-3)
- text AIR format 0: grammar (reference/air-text.ebnf) and module,
  block, SSA, type and canonical-form rules (spec 07 §8)
- instruction contracts for format 0 (new spec 07a)
- traps: stable T0xxx codes and trap records (spec 01 §6)
- integer edge cases and explicit casts (spec 02 §2.1)
- fixed verifier resource limits (spec 08 §7)
- target description with pointer_bits (spec 09 §9)
- new codes E0001-E0006, E1003, T0001-T0007
- resolves Q-001, Q-003..Q-008, Q-018; Q-002 resolved for format 0
2026-10-04 12:14:25 +03:00

85 lines
2.2 KiB
Markdown

# 09. Runtime, FFI and ABI
## 1. Runtime principle
The runtime should be small, explicit and auditable.
Core responsibilities may include:
- allocator adapters;
- task scheduler;
- synchronization primitives;
- I/O integration;
- capability materialization;
- platform intrinsics;
- deterministic/replay hooks.
## 2. System calls
Direct syscalls are runtime/unsafe-only by default.
A syscall wrapper must describe:
- argument types;
- memory read/write regions;
- created/consumed resources;
- effects;
- failure behavior;
- blocking behavior.
## 3. FFI
Foreign calls are explicit and unsafe unless wrapped in a verified safe abstraction.
Illustrative declaration:
```aji
extern "C"
unsafe fn read(
fd: i32,
buf: addr<u8>,
len: usize
) -> isize
effects [ffi];
```
Safe wrappers must state and uphold ownership, aliasing and thread-safety assumptions.
## 4. Volatile
`volatile.load` and `volatile.store` affect compiler access elimination/reordering as defined by the volatile contract.
Volatile does not itself imply atomicity or inter-thread synchronization.
## 5. MMIO
Device memory should use a distinct `Mmio<T>` abstraction obtained through `cap<device.mmio>`.
CPU-memory atomics and device-ordering barriers are separate concepts.
## 6. DMA
DMA buffers are explicitly pinned. A buffer cannot be freed, reset or physically relocated while a device operation owns it.
## 7. Signal/interrupt profiles
Signal and interrupt handlers use restricted capabilities/effects. Allocation, ordinary locking and blocking I/O are forbidden unless a profile explicitly defines a safe mechanism.
## 8. Backend
The initial native backend should lower AIR to LLVM IR.
A custom native backend is deferred until AIR and verifier semantics stabilize.
## 9. Target description
Every execution, interpreted or native, runs against an explicit target description. Target-dependent semantics come only from it.
Format version 0 defines one field:
| Field | Meaning |
|---|---|
| `pointer_bits` | width of `usize`/`isize` in bits: 32 or 64 |
The reference interpreter uses the target `air64` (`pointer_bits = 64`) unless a module declares target requirements (a later format version).