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