Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/aienux/crates/aienos-capability-ffi/cap_ffi_test.om # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / aienux / crates / aienos-capability-ffi / cap_ffi_test.om` 137 lines ยท 2861 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note aienux/crates/aienos-capability-ffi/cap_ffi_test.om: Behavioral self-test for aienos-capability-ffi. 3 note Compose with: si/directives/om2.om aienux/crates/aienos-capability-ffi/cap_ffi.om aienux/crates/aienos-capability-ffi/cap_ffi_test.om 4 5 fn t_ref_id r view Cap32Ref to uint 6 ret get r cap_id 7 end 8 9 fn t_ref_gen r view Cap32Ref to uint 10 ret get r gen 11 end 12 13 fn t_ent_subj e view Cap32Ent to uint 14 ret get e subject 15 end 16 17 fn t_fill_mnt req edit Cap32Mnt office view Cap32Ref to void 18 put req issuer 1 19 put req subject 42 20 put req res 0x1000 21 put req rights CAP32_RIGHT_READ 22 put req lease 100 23 put req par_id 0 24 put req par_gen 0 25 put req auth_id get office cap_id 26 put req auth_gen get office gen 27 end 28 29 fn main to int 30 note 1. ABI layout contract matches 32-bit cap32 ABI [8, 4, 4, 64] and version 1 31 words = new uint 4 0 32 ver = cap32_abi_layout words 33 if ne ver CAP32_ABI_VERSION 34 ret 1 35 end 36 if ne get words 0 8 37 ret 2 38 end 39 if ne get words 1 4 40 ret 3 41 end 42 if ne get words 2 4 43 ret 4 44 end 45 if ne get words 3 64 46 ret 5 47 end 48 49 note 2. Start authority and fetch office ref 50 if ne cap32_start CAP32_OK 51 ret 9 52 end 53 office = new uchar 8 0 54 if ne cap32_office office CAP32_OK 55 ret 10 56 end 57 58 note 3. Mint a capability and validate it 59 req = new uchar 48 0 60 t_fill_mnt req office 61 cap = new uchar 8 0 62 if ne cap32_mint req cap CAP32_OK 63 ret 11 64 end 65 66 ent = new uchar 64 0 67 if ne cap32_validate cap 42 0x1000 CAP32_RIGHT_READ ent CAP32_OK 68 ret 12 69 end 70 if ne t_ent_subj ent 42 71 ret 13 72 end 73 74 note 4. Wrong subject and wrong rights refused 75 if ne cap32_validate cap 99 0x1000 CAP32_RIGHT_READ ent CAP32_ERR_SUBJECT 76 ret 14 77 end 78 if ne cap32_validate cap 42 0x1000 CAP32_RIGHT_WRITE ent CAP32_ERR_RIGHTS 79 ret 15 80 end 81 82 note 5. Cognition mint/admin unconditionally unauthorized 83 if ne cap32_cognition_mint req CAP32_ERR_UNAUTH 84 ret 16 85 end 86 if ne cap32_cognition_admin 1 office cap CAP32_ERR_UNAUTH 87 ret 17 88 end 89 90 note 6. Clock advance expires lease 91 if ne cap32_advance_clock office 100 CAP32_OK 92 ret 18 93 end 94 if ne cap32_clock 100 95 ret 19 96 end 97 if ne cap32_validate cap 42 0x1000 CAP32_RIGHT_READ ent CAP32_ERR_EXPIRED 98 ret 20 99 end 100 101 note 7. Revoke, reclaim bumps generation, old ref becomes STALE_GEN 102 if ne cap32_revoke office cap CAP32_OK 103 ret 21 104 end 105 if ne cap32_reclaim office t_ref_id cap CAP32_OK 106 ret 22 107 end 108 if ne cap32_validate cap 42 0x1000 CAP32_RIGHT_READ ent CAP32_ERR_STALE_GEN 109 ret 23 110 end 111 112 note 8. Generation exhaustion at 0xffffffff 113 nxt = new uint 1 0 114 if ne cap32_gen_advance 0xffffffff nxt CAP32_ERR_EXHAUSTED 115 ret 24 116 end 117 118 note 9. Restart advances boot generation above floor, invalidating old office ref 119 if ne cap32_restart CAP32_OK 120 ret 25 121 end 122 new_off = new uchar 8 0 123 if ne cap32_office new_off CAP32_OK 124 ret 26 125 end 126 if le t_ref_gen new_off t_ref_gen office 127 ret 27 128 end 129 if ne cap32_bump_epoch office CAP32_ERR_STALE_GEN 130 ret 28 131 end 132 if ne cap32_bump_epoch new_off CAP32_OK 133 ret 29 134 end 135 136 ret 0 137 end