aien-sovereign-core-mv
AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.
Brought by drakestapleton
aien-sovereign-core-mv / crates / aien-omega-compose / src / ffi.rs
| 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 3 | // |
| 4 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | // you may not use this file except in compliance with the License. |
| 6 | // You may obtain a copy of the License at |
| 7 | // |
| 8 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | // |
| 10 | // Unless required by applicable law or agreed to in writing, software |
| 11 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | // See the License for the specific language governing permissions and |
| 14 | // limitations under the License. |
| 15 | |
| 16 | //! Raw declarations of omega `src/runtime/rxc_host_abi.h` (ABI version 2). |
| 17 | //! |
| 18 | //! Every mirrored constant, callback type, struct and function is declared through the |
| 19 | //! `aien-abi-conformance` macros, which record what they declare. The contract they must |
| 20 | //! match is `abi/rxc_host_abi.manifest`: the crate's `abi_manifest` test checks these Rust |
| 21 | //! declarations against it (every build, stub included) and `build.rs` checks the pinned C |
| 22 | //! header, a compiled layout probe and the archive's symbols against it before linking. |
| 23 | //! At run time `Compose::open` still compares the four struct sizes with |
| 24 | //! `rxc_host_abi_layout` before any other call. |
| 25 | |
| 26 | #![allow(non_camel_case_types)] |
| 27 | |
| 28 | use aien_abi_conformance::{abi_consts, abi_externs, abi_fnptr, abi_struct}; |
| 29 | #[cfg(has_omega_compose)] |
| 30 | use std::os::raw::c_char; |
| 31 | use std::os::raw::{c_int, c_void}; |
| 32 | |
| 33 | abi_consts! { CONSTS; |
| 34 | pub const RXC_HOST_ABI_VERSION: u32 = 2; |
| 35 | pub const RXC_HOST_MAX_HANDLES: u32 = 4; |
| 36 | pub const RXC_HOST_MAX_SKILLS: u32 = 2; |
| 37 | pub const RXC_HOST_NAME_MAX: u32 = 64; |
| 38 | pub const RXC_HOST_NONE: u32 = 0xFFFF_FFFF; |
| 39 | pub const RXC_HOST_SUBJECT_GOAL: u64 = 1; |
| 40 | pub const RXC_HOST_SUBJECT_STATE: u64 = 5; |
| 41 | /// Host records (notes, repair records): no World object. |
| 42 | pub const RXC_HOST_SUBJECT_HOST: u64 = 0; |
| 43 | pub const RXC_HOST_TAG_REPAIR_TAIL: u64 = 1; |
| 44 | pub const RXC_HOST_NOTE_CONSTRAINT: u32 = 2; |
| 45 | pub const RXC_HOST_NOTE_AUTHORIZATION: u32 = 3; |
| 46 | pub const RXC_HOST_NOTE_EFFECT: u32 = 4; |
| 47 | pub const RXC_HOST_NOTE_MAX: usize = 16384; |
| 48 | pub const RXC_HOST_NP_LEN: usize = 0; |
| 49 | pub const RXC_HOST_NP_SHA: usize = 1; |
| 50 | pub const RXC_HOST_NP_BYTES: usize = 5; |
| 51 | pub const RXC_HOST_RP_CUT_LO: usize = 0; |
| 52 | pub const RXC_HOST_RP_CUT_HI: usize = 1; |
| 53 | pub const RXC_HOST_RP_DROPPED: usize = 5; |
| 54 | pub const RXC_HOST_RP_CAUSE: usize = 6; |
| 55 | pub const RXC_HOST_OK: c_int = 0; |
| 56 | pub const RXC_HOST_E_ARG: c_int = -1; |
| 57 | pub const RXC_HOST_E_IDENTITY: c_int = -2; |
| 58 | pub const RXC_HOST_E_TORN: c_int = -3; |
| 59 | pub const RXC_HOST_E_OPEN: c_int = -4; |
| 60 | pub const RXC_HOST_E_FULL: c_int = -5; |
| 61 | pub const RXC_HOST_E_STATE: c_int = -6; |
| 62 | pub const RXC_HOST_E_RUN: c_int = -7; |
| 63 | pub const RXC_HOST_E_NOMEM: c_int = -8; |
| 64 | pub const RXC_HOST_E_NOT_FOUND: c_int = -9; |
| 65 | pub const RXC_HOST_E_DIGEST: c_int = -10; |
| 66 | pub const RXC_HOST_E_REPLAY: c_int = -11; |
| 67 | } |
| 68 | |
| 69 | #[repr(C)] |
| 70 | pub struct RxcHost { |
| 71 | _private: [u8; 0], |
| 72 | } |
| 73 | |
| 74 | abi_fnptr! { FNPTRS; |
| 75 | pub type RxcHostSkillFn = |
| 76 | unsafe extern "C" fn(ctx: *mut c_void, task: u64, result: *mut u64) -> c_int; |
| 77 | pub type RxcHostVerifyFn = |
| 78 | unsafe extern "C" fn(ctx: *mut c_void, task: u64, result: u64) -> c_int; |
| 79 | } |
| 80 | |
| 81 | abi_struct! { |
| 82 | #[repr(C)] |
| 83 | #[derive(Debug, Clone, Copy, Default)] |
| 84 | pub struct RxcHostInfo { |
| 85 | pub abi_version: u32, |
| 86 | pub machine_root: u8, |
| 87 | pub machine_id: [u8; 32], |
| 88 | pub machine_id_was_stored: u32, |
| 89 | pub tail_torn: u32, |
| 90 | pub opened: u32, |
| 91 | pub open_rc: i32, |
| 92 | pub records: u64, |
| 93 | pub recovered_record: u64, |
| 94 | pub rolled_back: u32, |
| 95 | pub recovered_completed: u32, |
| 96 | pub anchor_unknown: u32, |
| 97 | pub n_skills: u32, |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | abi_struct! { |
| 102 | #[repr(C)] |
| 103 | #[derive(Debug, Clone, Copy, Default)] |
| 104 | pub struct RxcHostResult { |
| 105 | pub run_rc: i32, |
| 106 | pub outcome: i32, |
| 107 | pub committed: u32, |
| 108 | pub n_branches: u32, |
| 109 | pub branches_reclaimed: u32, |
| 110 | pub winner: u32, |
| 111 | pub winner_skill: u32, |
| 112 | pub aegis_pass_mask: u32, |
| 113 | pub task: u64, |
| 114 | pub result: u64, |
| 115 | pub cx_goal: u64, |
| 116 | pub cx_candidate: [u64; 2], |
| 117 | pub cx_evidence: u64, |
| 118 | pub cx_promotion: u64, |
| 119 | pub cx_admission: [u64; 2], |
| 120 | pub winner_digest: [u8; 32], |
| 121 | pub record_digest: [u8; 32], |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | abi_struct! { |
| 126 | #[repr(C)] |
| 127 | #[derive(Debug, Clone, Copy, Default)] |
| 128 | pub struct RxcHostRecord { |
| 129 | pub id: u64, |
| 130 | pub cls: u32, |
| 131 | pub kind: u32, |
| 132 | pub subject: u64, |
| 133 | pub t: u64, |
| 134 | pub generation: u64, |
| 135 | pub tag: u64, |
| 136 | pub links: [u64; 4], |
| 137 | pub n_payload: u32, |
| 138 | pub verified: u32, |
| 139 | pub digest: [u8; 32], |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | abi_struct! { |
| 144 | #[repr(C)] |
| 145 | #[derive(Debug, Clone, Copy, Default)] |
| 146 | pub struct RxcHostRepair { |
| 147 | pub repaired: u32, |
| 148 | pub tail_torn: u32, |
| 149 | pub anchor_present: u32, |
| 150 | pub cause: i32, |
| 151 | pub opens: u32, |
| 152 | pub open_rc: i32, |
| 153 | pub rolled_back: u32, |
| 154 | pub recovered_completed: u32, |
| 155 | pub cut_lo: u64, |
| 156 | pub cut_hi: u64, |
| 157 | pub partial_records: u64, |
| 158 | pub anchor_records: u64, |
| 159 | pub records_kept: u64, |
| 160 | pub dropped_records: u64, |
| 161 | pub event_id: u64, |
| 162 | pub cut_bytes_kept: u64, |
| 163 | pub cut_sha256: [u8; 32], |
| 164 | pub anchor_head: [u8; 32], |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | abi_externs! { FNS; |
| 169 | #[cfg(has_omega_compose)] |
| 170 | extern "C" { |
| 171 | pub fn rxc_host_abi_layout(out: *mut u32) -> u32; |
| 172 | pub fn rxc_host_open( |
| 173 | dir: *const c_char, |
| 174 | root_kind: u32, |
| 175 | root: *const u8, |
| 176 | root_len: usize, |
| 177 | session: u64, |
| 178 | flags: u32, |
| 179 | out: *mut *mut RxcHost, |
| 180 | info: *mut RxcHostInfo, |
| 181 | ) -> c_int; |
| 182 | pub fn rxc_host_register_skill( |
| 183 | h: *mut RxcHost, |
| 184 | name: *const c_char, |
| 185 | digest32: *const u8, |
| 186 | cost: u64, |
| 187 | f: RxcHostSkillFn, |
| 188 | ctx: *mut c_void, |
| 189 | ) -> c_int; |
| 190 | pub fn rxc_host_set_verify( |
| 191 | h: *mut RxcHost, |
| 192 | f: Option<RxcHostVerifyFn>, |
| 193 | ctx: *mut c_void, |
| 194 | ) -> c_int; |
| 195 | pub fn rxc_host_run(h: *mut RxcHost, task: u64, now_us: u64, out: *mut RxcHostResult) -> c_int; |
| 196 | pub fn rxc_host_recall( |
| 197 | h: *mut RxcHost, |
| 198 | subject: u64, |
| 199 | out: *mut RxcHostRecord, |
| 200 | max: u32, |
| 201 | n_filled: *mut u32, |
| 202 | n_total: *mut u64, |
| 203 | ) -> c_int; |
| 204 | pub fn rxc_host_record(h: *mut RxcHost, id: u64, out: *mut RxcHostRecord) -> c_int; |
| 205 | pub fn rxc_host_payload(h: *mut RxcHost, id: u64, out: *mut u64, max: u32) -> c_int; |
| 206 | pub fn rxc_host_info(h: *mut RxcHost, info: *mut RxcHostInfo) -> c_int; |
| 207 | pub fn rxc_host_note( |
| 208 | h: *mut RxcHost, |
| 209 | note: u32, |
| 210 | links: *const u64, |
| 211 | bytes: *const u8, |
| 212 | len: usize, |
| 213 | out_id: *mut u64, |
| 214 | ) -> c_int; |
| 215 | pub fn rxc_host_recover( |
| 216 | dir: *const c_char, |
| 217 | root_kind: u32, |
| 218 | root: *const u8, |
| 219 | root_len: usize, |
| 220 | out: *mut RxcHostRepair, |
| 221 | ) -> c_int; |
| 222 | pub fn rxc_host_close(h: *mut RxcHost); |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | // Present only when the archive defines it (build.rs sets `has_omega_wait_ms` after finding |
| 227 | // the declaration in rxc_host_abi.h and the symbol in the archive). |
| 228 | abi_externs! { WAIT_FNS; |
| 229 | #[cfg(has_omega_wait_ms)] |
| 230 | extern "C" { |
| 231 | /// Wraps omega `rx_compose_set_wait_ms` on the handle's composition. |
| 232 | pub fn rxc_host_set_wait_ms(h: *mut RxcHost, wait_ms: u32) -> c_int; |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | /// omega settle wait when `rxc_host_set_wait_ms` is never called. |
| 237 | pub const WAIT_MS_DEFAULT: u32 = 30_000; |
| 238 | |
| 239 | /// The Rust side of the `rxc_host` contract, for the manifest check. |
| 240 | pub fn rust_abi() -> aien_abi_conformance::RustAbi { |
| 241 | aien_abi_conformance::RustAbi::default() |
| 242 | .with_struct::<RxcHostInfo>() |
| 243 | .with_struct::<RxcHostResult>() |
| 244 | .with_struct::<RxcHostRecord>() |
| 245 | .with_struct::<RxcHostRepair>() |
| 246 | .with_consts(CONSTS) |
| 247 | .with_fnptrs(FNPTRS) |
| 248 | .with_fns(FNS) |
| 249 | .with_fns(WAIT_FNS) |
| 250 | } |