Files
aji/docs/spec/09-runtime-and-abi.md
dev 2bbbd2135c rfc: 0015 scalar atomics and the Aji memory model accepted (revision 2) and integrated into the spec
The Aji RC11 profile (RC11 with NO-THIN-AIR; stronger than ISO C11/C++20) as
normative axioms in spec 04 §20; DRF-SC; linear atomic<T> for AtomicScalar
with atomic.new/atomic.take; ref<atomic<T>> operands; ordering tables incl.
cmpxchg failure table and two results; effects [atomic] / [atomic, atomic.weak];
target atomic_widths and E4203; E4202; enumerator as oracle (observed ⊆ allowed,
exact equality on the normative litmus corpus). Feature atomics stays reserved
until P5-2a. Q-015 resolved; record/replay and Q-017 moved to Phase 8.
RFC 0003 superseded. AIR bundle +1.9 %.
2026-10-06 00:30:35 +03:00

88 lines
2.5 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 |
| `atomic_widths` | the AtomicScalar widths, in bits, that the target implements natively and lock-free (feature `atomics`, spec 04 §23) |
A module that uses `atomic<T>` for a width the target does not list is rejected for that target at build time (`E4203`, `atomic.unsupported_width`). An implementation MUST NOT emulate an atomic with a lock.
The reference interpreter uses the target `air64` (`pointer_bits = 64`, `atomic_widths = {8, 16, 32, 64}`) unless a module declares target requirements (a later format version).