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/src/osh/osh_core.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 / src / osh / osh_core.om` 165 lines ยท 3139 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note Pure seeded OM-2 core logic backing src/osh/host/osh_req.c: 3 note POSIX identifier validator, OSH request header validator (magic/version/ 4 note reserved/bounds), and command reserved-cell zero validator. 5 om2 6 7 fn osh_is_start c ulong to ulong 8 if eq c 95 9 ret 1 10 end 11 if and ge c 65 le c 90 12 ret 1 13 end 14 if and ge c 97 le c 122 15 ret 1 16 end 17 ret 0 18 end 19 20 export fn osh_om_name_valid s view uchar * n ulong to ulong 21 if eq n 0 22 ret 0 23 end 24 if eq osh_is_start ulong get s 0 0 25 ret 0 26 end 27 i = ulong 1 28 while lt i n 29 c = ulong get s i 30 ok = osh_is_start c 31 if and ge c 48 le c 57 32 ok = 1 33 end 34 if eq ok 0 35 ret 0 36 end 37 i = add i 1 38 end 39 ret 1 40 end 41 42 export fn osh_om_check_req_hdr rec view ulong * nrec ulong nout ulong has_out ulong to ulong 43 if lt nrec 8 44 ret 216 45 end 46 if ne get rec 0 0x4f524551 47 ret 214 48 end 49 if ne get rec 5 1 50 ret 215 51 end 52 if or ne get rec 6 0 ne get rec 7 0 53 ret 217 54 end 55 if ne and get rec 3 0xfffffffffffffffe 0 56 ret 217 57 end 58 ncmds = get rec 1 59 conn = get rec 2 60 used = get rec 4 61 if or lt ncmds 1 or gt ncmds 8 gt conn 3 62 ret 218 63 end 64 if lt nrec add 8 mul ncmds 164 65 ret 216 66 end 67 if gt used 8192 68 ret 218 69 end 70 if gt used 0 71 if or eq has_out 0 lt nout used 72 ret 216 73 end 74 end 75 ret 0 76 end 77 78 fn osh_zero_cells b view ulong * start ulong stop ulong to ulong 79 i = start 80 while lt i stop 81 if ne get b i 0 82 ret 217 83 end 84 i = add i 1 85 end 86 ret 0 87 end 88 89 export fn osh_om_check_cmd_reserved b view ulong * na ulong ns ulong nr ulong to ulong 90 if ne osh_zero_cells b add mul na 2 4 68 0 91 ret 217 92 end 93 if ne osh_zero_cells b add mul ns 4 68 132 0 94 ret 217 95 end 96 ret osh_zero_cells b add mul nr 4 132 164 97 end 98 99 note Map OSH_OP_* (1=SPAWN, 2=CHDIR, 3=OPEN_WRITE, 4=OPEN_READ) to RX_RIGHT_*. 100 export fn osh_om_op_right op ulong to ulong 101 if eq op 1 102 ret 4 103 end 104 if eq op 3 105 ret 2 106 end 107 ret 1 108 end 109 110 note Map RX_CAP_ERR_* to OSH_E_*. 111 export fn osh_om_map_cap_rc rc long to long 112 if eq rc 0 113 ret 0 114 end 115 if eq rc -2 116 ret 3 117 end 118 if or eq rc -3 or eq rc -4 or eq rc -8 eq rc -9 119 ret 2 120 end 121 ret 1 122 end 123 124 note Check whether canonical path is under canonical prefix. 125 export fn osh_om_path_under pref view uchar * np ulong path view uchar * npath ulong to ulong 126 if eq np 0 127 ret 0 128 end 129 if and eq np 1 eq get pref 0 uchar 47 130 ret 1 131 end 132 if lt npath np 133 ret 0 134 end 135 for i ulong np bound 4096 136 if ne get pref i get path i 137 ret 0 138 end 139 end 140 if eq npath np 141 ret 1 142 end 143 if eq get path np uchar 47 144 ret 1 145 end 146 ret 0 147 end 148 149 note Validate OshBinding domain (must be 2) and principal_id[4..31] == 0. 150 note Returns >= 0 (u32 subject) on ok, or negative (-OSH_E_*) on refusal. 151 export fn osh_om_check_binding domain ulong pid view uchar 32 to long 152 if ne domain 2 153 ret -12 154 end 155 for i ulong 28 156 if ne get pid add i 4 uchar 0 157 ret -1 158 end 159 end 160 s = ulong get pid 0 161 s = or s shl ulong get pid 1 8 162 s = or s shl ulong get pid 2 16 163 s = or s shl ulong get pid 3 24 164 ret long s 165 end