interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / native / kernel / svc / continuity_commit.h

116 lines · 5685 bytes Raw Blame History
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
17/* continuity_commit.h -- C port, cut 4: provision, commit and resume of the
18 * continuity objects over the sealed Store (contract section 1.3-1.5, INV-4,
19 * INV-8..INV-11, K-1, K-2, P-1, P-2).
20 *
21 * Contract: native/kernel/CONTINUITY_RECOVERY_CONTRACT.md. Oracle: the Rust
22 * kernel at aienos 4a116e5: continuity.rs `provision` (:712-772), `commit_with_hook`
23 * (:786-855), `resume` (:859-868), nvme_read.rs `summary`/`stop` (:1118-1155).
24 *
25 * Writes go through cr_sink, one call = ONE Store transaction (INV-8): payload
26 * objects and the manifest together, in the order AgentState, WAL, Manifest.
27 * continuity_resolve_sealed.c binds it to ss_transact (<= SS_MAX_OBJECTS = 8,
28 * this layer writes <= 3). Cross references are logical ObjectIds (P-2).
29 *
30 * Nothing here is wired into the kernel. */
31#ifndef CK_CONTINUITY_COMMIT_H
32#define CK_CONTINUITY_COMMIT_H
33
34#include <stddef.h>
35#include <stdint.h>
36
37#include "continuity_resolve.h"
38#include "entropy.h"
39
40/* TEST-only mutants for the host mutation run (Makefile continuity-mutants).
41 * MC-11 (silent truncation) is CC_MUTANT_TRUNCATE_AT_CAP in continuity_codec.h. */
42#if defined(CK_HARDWARE_STAGING) && \
43 (defined(CM_MUTANT_RESUME_PROVISIONS) || defined(CM_MUTANT_RESUME_NO_COMMIT) || \
44 defined(CM_MUTANT_PROVISION_WITH_ROOT) || defined(CM_MUTANT_SPLIT_TXN) || \
45 defined(CM_MUTANT_NO_WRITABLE_CHECK) || defined(CM_MUTANT_FIXED_AGENT))
46#error "continuity commit mutants are TEST-only and refused under CK_HARDWARE_STAGING"
47#endif
48
49/* One object of a transaction (an application object, not an envelope). */
50struct cr_wobj {
51 uint16_t kind, version;
52 const uint8_t *bytes;
53 size_t len;
54};
55
56/* Write interface: all n objects commit atomically in one Store transaction
57 * or none do. Returns 0 or a store error (passed through as CR_STORE). */
58struct cr_sink {
59 void *ctx;
60 int (*transact)(void *ctx, const struct cr_wobj *objs, size_t n);
61};
62
63/* rs `Update` (continuity.rs:178-184): optional new branch table, optional new
64 * Cortex records (one WAL segment). Records are only read. */
65struct cr_update {
66 const struct cc_state *state; /* NULL = keep the current one */
67 const struct cc_record *rec; /* NULL / n_rec 0 = no WAL segment */
68 uint32_t n_rec;
69};
70
71/* Caller-owned scratch for the objects of one transaction (static storage). */
72struct cr_txwork {
73 uint8_t b[3][CC_MAX_OBJECT_BYTES];
74 struct cc_state state;
75 struct cc_manifest man;
76 struct cc_wal wal;
77 struct cr_view tmp;
78};
79
80/* rs `provision`. Order of refusals: not writable (CR_READ_ONLY, INV-11);
81 * a root exists (CR_ALREADY_PROVISIONED, also on Conflict); orphans or any
82 * other unreadable state (the resolve outcome: Corrupt, Limit, Store);
83 * no entropy (CR_NO_ENTROPY, nothing written, no fallback); zero agent
84 * (CR_CORRUPT). Writes AgentRoot + genesis AgentState + Manifest 1 in ONE
85 * transaction and returns the resolved view (CR_RESOLVED). `source` is
86 * CC_SOURCE_*. store_uuid is the Store's uuid. */
87int cr_provision(const struct cr_source *src, const struct cr_sink *snk, struct cr_work *w,
88 struct cr_txwork *tw, struct ck_rng *rng, const uint8_t store_uuid[16],
89 uint8_t source, struct cr_view *out, const char **why, int *store_rc);
90
91/* rs `commit`: one transaction for the optional state, the optional WAL
92 * segment and the new manifest; then re-resolve into out (must not alias cur).
93 * K-1: an object over 16384 bytes is CR_LIMIT and nothing is written. */
94int cr_commit(const struct cr_source *src, const struct cr_sink *snk, struct cr_work *w,
95 struct cr_txwork *tw, const struct cr_view *cur, const struct cr_update *up,
96 int new_incarnation, struct cr_view *out, const char **why, int *store_rc);
97
98/* rs `resume`: resolve; on a mount that is not Valid return the view with
99 * *committed = 0 (INV-11); else commit incarnation + 1 before returning
100 * (INV-10). Never mints an identity: Unprovisioned stays CR_UNPROVISIONED (INV-4). */
101int cr_resume(const struct cr_source *src, const struct cr_sink *snk, struct cr_work *w,
102 struct cr_txwork *tw, struct cr_view *out, int *committed, const char **why,
103 int *store_rc);
104
105/* ---- serial markers (contract section 3, nvme_read.rs:1118-1155; TEST-ONLY,
106 * absent from a CK_SERVICE image) ----
107 * Write the NUL-terminated line, without newline, into out[0..cap). Return the
108 * length, or 0 when cap is too small. word: "PROVISIONED", "RESUMED",
109 * "RESUMED_READONLY", "REMEMBERED", "COMMITTED". */
110size_t cr_marker_view(char *out, size_t cap, const char *word, const struct cr_view *v);
111/* UNPROVISIONED, CONFLICT, CORRUPT (why), NO_ENTROPY, else STOP (<Rust spelling>).
112 * For CR_STORE the text is `STOP (Store(<rc>))` (rc decimal; Rust prints the
113 * Debug of its own error, which differs). */
114size_t cr_marker_outcome(char *out, size_t cap, int outcome, const char *why, int store_rc);
115
116#endif /* CK_CONTINUITY_COMMIT_H */