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 / cortex_journal.h

87 lines · 4073 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/* cortex_journal.h -- the Omega Cortex journal over the AIENOS sealed Store
18 * (native v1 plan P06: "an AIENOS persistence adapter for canonical Omega
19 * CxStore"; CURRENT_EXECUTION_PLAN addendum conflict 3: the native
20 * continuity record of N2/N3 is the sealed C Store written and read through
21 * this adapter).
22 *
23 * The Cortex store (third_party/omega/rx_cortex.c, built by svc/cortex_store.c)
24 * reaches its journal only through CxJournalOps: a byte stream it appends
25 * records to and reads back whole at open. Here the stream is the ordered
26 * sequence of sealed Store objects of kind CK_CJ_KIND ('CJ'): one append is
27 * ONE sealed transaction of 1..SS_MAX_OBJECTS chunks of <= SS_MAX_PLAINTEXT
28 * bytes, so a record is on the disk entirely (generation G+1 durable, anchor
29 * advanced) or not at all. That is the durability-before-success rule and
30 * why a torn tail cannot exist: truncate accepts only the current length.
31 * One semantic writer: the kernel's single ck_cj context; a second writable
32 * open while one is held is CX_ERR_WRITER. Chain verification, digests and
33 * replay are Omega's, unchanged: the backend stores bytes and never
34 * interprets them. There is no second Cortex: the sealed Store on the disk
35 * IS the Cortex of this subject.
36 *
37 * Declared limits (v1): a journal of at most CK_CJ_MAX_CHUNKS chunks
38 * (CK_CJ_MAX_CHUNKS * 16 KiB), one record of at most SS_MAX_OBJECTS *
39 * SS_MAX_PLAINTEXT bytes (larger: CX_ERR_IO, nothing written), replay reads
40 * the whole journal into the Cortex heap, the heap is a bump allocator that
41 * frees nothing until ck_cx_heap_init is called again (sized by the caller;
42 * the kernel hands over CK_CX_HEAP_PAGES frames). Kernel use: the
43 * lifecycle's `remember` and `facts` verbs (core/lifecycle.c, P06 cut 4). */
44#ifndef AIENOS_CORTEX_JOURNAL_H
45#define AIENOS_CORTEX_JOURNAL_H
46
47#include <stddef.h>
48#include <stdint.h>
49
50#include "../third_party/omega/rx_cortex.h"
51#include "store_sealed.h"
52
53#define CK_CJ_KIND 0x434au /* 'CJ': one journal chunk, sealed */
54#define CK_CJ_MAX_CHUNKS 64u /* 1 MiB of journal */
55#define CK_CJ_MAX_RECORD (SS_MAX_OBJECTS * SS_MAX_PLAINTEXT) /* 128 KiB per append */
56#define CK_CX_HEAP_PAGES 1024u /* 4 MiB: the whole journal plus its replay */
57#define CK_CX_SUBJECTS 2u /* subject 0: the owner (facts); 1: reserved for ALLEN */
58#define CK_CX_FACT_SUBJECT 0u /* remembered facts: lifecycle `remember` and the Pi fact stage */
59
60typedef struct {
61 uint8_t sid[32];
62 uint64_t gen, seq;
63 uint32_t len;
64} ck_cj_chunk;
65
66typedef struct {
67 ss_store *s;
68 int writer; /* 1 while a writable handle is open */
69 int ro_handles;
70 size_t len; /* journal bytes = sum of chunk lengths */
71 uint32_t nchunks;
72 ck_cj_chunk chunks[CK_CJ_MAX_CHUNKS];
73 uint8_t buf[SS_MAX_PLAINTEXT];
74 uint32_t appends, reads, refused; /* evidence */
75} ck_cj;
76
77/* Bind the context to an open sealed Store (the index is rebuilt at every
78 * journal open from the Store's verified claims). */
79void ck_cj_init(ck_cj *j, ss_store *s);
80extern const CxJournalOps ck_cx_journal_store;
81
82/* The Cortex heap (CX_MALLOC of cortex_config.h): one region, bump
83 * allocation, realloc copies, free is a no-op. Re-init forgets everything. */
84void ck_cx_heap_init(void *base, size_t size);
85void ck_cx_heap_stats(size_t *used, size_t *peak, size_t *size);
86
87#endif /* AIENOS_CORTEX_JOURNAL_H */