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 / protocol / interplane / v03 / crossaxis.om

121 lines · 3458 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note protocol/interplane/v03/crossaxis.om: pure-Omega port of interplane-crossaxis (v0.3.0).
3note Explicit capability mapping table (data, not code) and deterministic domain selector.
4note Invariant: CrossAxis NEVER answers "may the model run it?".
5note Compose after si/directives/om2.om.
6
7const CA_OK ulong 0
8const CA_ERR_UNKNOWN_CAP ulong 1
9const CA_ERR_BAD_PASSTHROUGH ulong 2
10const CA_ERR_TABLE_FULL ulong 3
11const CA_ERR_BAD_NAME ulong 4
12
13const CA_RULE_ALIAS ulong 0
14const CA_RULE_PASSTHROUGH ulong 1
15
16const CA_MAX_RULES ulong 16
17
18note Rule table representation (fixed-slot scalar IDs for deterministic O(N) first-match lookup):
19note Each rule slot i (0..count-1) occupies 5 ulongs in rules[80]:
20note [i*5 + 0] = rule_id
21note [i*5 + 1] = kind (CA_RULE_ALIAS or CA_RULE_PASSTHROUGH)
22note [i*5 + 2] = from_ns (0 = null namespace, >0 = namespace id)
23note [i*5 + 3] = from_name_id
24note [i*5 + 4] = to_cap_id
25
26fn ca_validate_rule kind ulong from_ns ulong from_name ulong to_cap ulong to ulong
27if or eq from_name ulong 0 eq to_cap ulong 0
28ret CA_ERR_BAD_NAME
29end
30if eq kind CA_RULE_PASSTHROUGH
31if or ne from_ns ulong 0 ne from_name to_cap
32ret CA_ERR_BAD_PASSTHROUGH
33end
34ret CA_OK
35end
36if eq kind CA_RULE_ALIAS
37ret CA_OK
38end
39ret CA_ERR_BAD_PASSTHROUGH
40end
41
42note spec[0]=rule_id, spec[1]=kind, spec[2]=from_ns, spec[3]=from_name, spec[4]=to_cap
43fn ca_add_rule rules edit ulong 80 cnt edit ulong 1 spec view ulong 5 to ulong
44r_id = get spec 0
45kind = get spec 1
46from_ns = get spec 2
47from_name = get spec 3
48to_cap = get spec 4
49rc = ca_validate_rule kind from_ns from_name to_cap
50if ne rc CA_OK
51ret rc
52end
53n = get cnt 0
54if ge n CA_MAX_RULES
55ret CA_ERR_TABLE_FULL
56end
57base = mul n ulong 5
58put rules base r_id
59put rules add base ulong 1 kind
60put rules add base ulong 2 from_ns
61put rules add base ulong 3 from_name
62put rules add base ulong 4 to_cap
63put cnt 0 add n ulong 1
64ret CA_OK
65end
66
67note Exact lookup, first matching rule wins. No match -> CA_ERR_UNKNOWN_CAP.
68note On match: res[0] = to_cap_id, res[1] = rule_id, res[2] = passthrough (1/0).
69fn ca_map_tool rules view ulong 80 cnt ulong req_ns ulong req_name ulong res edit ulong 3 to ulong
70if gt cnt CA_MAX_RULES
71ret CA_ERR_UNKNOWN_CAP
72end
73i = ulong 0
74while lt i cnt bound 16
75base = mul i ulong 5
76r_ns = get rules add base ulong 2
77r_nm = get rules add base ulong 3
78if and eq r_ns req_ns eq r_nm req_name
79put res 0 get rules add base ulong 4
80put res 1 get rules base
81if eq get rules add base ulong 1 CA_RULE_PASSTHROUGH
82put res 2 ulong 1
83else
84put res 2 ulong 0
85end
86ret CA_OK
87end
88i = add i ulong 1
89end
90ret CA_ERR_UNKNOWN_CAP
91end
92
93note Deterministic domain selector: selects capabilities matching domain_mask within token budget.
94note caps_mask[i] = domain bitmask of cap i; caps_cost[i] = token cost of cap i.
95note Writes selected[i] = 1 (selected), 2 (excluded: domain), 3 (refused: budget).
96note Returns number of selected capabilities.
97fn ca_select_domain count ulong domain_mask ulong budget ulong caps_mask view ulong 16 caps_cost view ulong 16 selected edit ulong 16 to ulong
98if gt count CA_MAX_RULES
99ret ulong 0
100end
101used = ulong 0
102sel = ulong 0
103i = ulong 0
104while lt i count bound 16
105m = get caps_mask i
106c = get caps_cost i
107if eq and m domain_mask ulong 0
108put selected i ulong 2
109else
110if le add used c budget
111used = add used c
112put selected i ulong 1
113sel = add sel ulong 1
114else
115put selected i ulong 3
116end
117end
118i = add i ulong 1
119end
120ret sel
121end