interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / src / runtime / aienos_cap.h

112 lines · 4693 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/*
18 * aienos_cap.h -- C view of the native AIENOS capability authority.
19 *
20 * The view can check a reference. The admin can change the table. The
21 * reaction world is given the view. Cognition has no path to the admin.
22 * The Linux mint process is a separate oracle and is not started here.
23 * Layout matches aienos native/capability/aienos_capability.h: generations
24 * are 64 bits. make test-aienos-cap-abi checks this copy against the pinned header.
25 */
26#ifndef AIENOS_CAP_H
27#define AIENOS_CAP_H
28
29#include <stdint.h>
30
31typedef struct AienosCapAdmin AienosCapAdmin;
32typedef struct AienosCapView AienosCapView;
33
34typedef struct {
35 uint32_t cap_id;
36 uint64_t generation;
37} AienosCapRef;
38
39typedef struct {
40 uint32_t cap_id;
41 uint64_t generation;
42 uint32_t state;
43 uint32_t issuer;
44 uint32_t subject;
45 uint32_t rights;
46 uint64_t resource;
47 uint64_t epoch;
48 uint64_t lease_expiry;
49 uint32_t parent_id;
50 uint64_t parent_generation;
51 uint32_t minted_by_id;
52 uint64_t minted_by_generation;
53} AienosCapEntry;
54
55typedef struct {
56 uint32_t issuer;
57 uint32_t subject;
58 uint64_t resource;
59 uint32_t rights;
60 uint64_t lease_ticks;
61 AienosCapRef parent;
62 AienosCapRef authority;
63} AienosCapMint;
64
65int aienos_cap_start(AienosCapAdmin **admin, AienosCapView **view);
66void aienos_cap_stop(AienosCapAdmin *admin, AienosCapView *view);
67int aienos_cap_office(const AienosCapAdmin *admin, AienosCapRef *out);
68int aienos_cap_mint(AienosCapAdmin *admin, const AienosCapMint *request, AienosCapRef *out);
69int aienos_cap_revoke(AienosCapAdmin *admin, AienosCapRef authority, AienosCapRef target);
70int aienos_cap_reclaim(AienosCapAdmin *admin, AienosCapRef authority, uint32_t cap_id);
71int aienos_cap_advance_clock(AienosCapAdmin *admin, AienosCapRef authority, uint64_t ticks);
72int aienos_cap_bump_epoch(AienosCapAdmin *admin, AienosCapRef authority);
73int aienos_cap_kill(AienosCapAdmin *admin);
74int aienos_cap_restart(AienosCapAdmin *admin);
75int aienos_cap_validate(const AienosCapView *view, AienosCapRef cap, uint32_t subject,
76 uint64_t resource, uint32_t rights, AienosCapEntry *out);
77int aienos_cap_inspect(const AienosCapView *view, AienosCapRef cap, AienosCapEntry *out);
78uint64_t aienos_cap_clock(const AienosCapView *view);
79int aienos_cap_cognition_mint(const AienosCapView *view, const AienosCapMint *request,
80 const uint8_t *token);
81int aienos_cap_cognition_admin(const AienosCapView *view, uint32_t op, AienosCapRef authority,
82 AienosCapRef target);
83int aienos_cap_force_generation(AienosCapAdmin *admin, uint32_t cap_id, uint64_t generation);
84int aienos_cap_generation_advance(uint64_t generation, uint64_t *out);
85
86/* Authority observer (aienos native/capability, 12add16, on aienos main from
87 * d39dd5b). Set on the admin handle; the view has no path to it and
88 * aienos_cap_validate never calls it. One call per state change, with a copy
89 * of the entry after the change, made after the table lock is released:
90 * MINT new entry (refused: entry NULL + code); REVOKE target, then each
91 * descendant, ancestors first; RECLAIM freed slot; EPOCH/CLOCK the acting
92 * authority's entry; KILL entry NULL; RESTART the new office entry.
93 * VALIDATE_DENIED is reserved and never sent. With no observer set, each admin
94 * operation pays one NULL check. */
95#define AIENOS_CAP_OBS_MINT 1u
96#define AIENOS_CAP_OBS_REVOKE 2u
97#define AIENOS_CAP_OBS_RECLAIM 3u
98#define AIENOS_CAP_OBS_EPOCH 4u
99#define AIENOS_CAP_OBS_CLOCK 5u
100#define AIENOS_CAP_OBS_KILL 6u
101#define AIENOS_CAP_OBS_RESTART 7u
102#define AIENOS_CAP_OBS_VALIDATE_DENIED 8u
103
104typedef void (*AienosCapObserver)(void *ctx, uint32_t op, const AienosCapEntry *entry,
105 int result);
106
107int aienos_cap_set_observer(AienosCapAdmin *admin, AienosCapObserver fn, void *ctx);
108
109/* Office token check, constant time (not called by the library itself). */
110int aienos_cap_authorize(const AienosCapAdmin *admin, const uint8_t *presented);
111
112#endif