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 / seed / ng / tests / ir / host-refusals.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note Build with src/ir.om. host-refusals MODE emits one accepted host op and a return if it were executed. |
| 3 | note Modes 115..121 select process, limits, device, network, path, nondeterminism, unsafe-fs. |
| 4 | note 215 checks execenv's process class, 219 checks a parent traversal, 319 checks pwrite on inherited stdout. |
| 5 | note 324 and 325 check execprog's process class on argv packets that omc 564c5835 accepts and the older |
| 6 | note 64-record / 4096-byte rule refused: 1024 records (2051 bytes) and one 4095-byte record (4099 bytes). |
| 7 | note 236..240 check the scheduler words: cpuset, cpuget, setprio and getprio process (115), cpunow |
| 8 | note nondeterministic (120). |
| 9 | global hd_s uint 3 |
| 10 | global hd_a uint 8 |
| 11 | global hd_arg uchar 8 |
| 12 | text hd_abs "/ngrun-outside-control" |
| 13 | text hd_rel "../ngrun-outside-control" |
| 14 | fn hd_c t uint v ulong to uint |
| 15 | ret ir_res ir_op get hd_s 0 1 t v 0 |
| 16 | end |
| 17 | fn hd_text word view uchar * to uint |
| 18 | t = ir_tarr 2 uint len word |
| 19 | r = ir_tref t 0 0 |
| 20 | g = ir_glob t 1 |
| 21 | for j ulong len word bound 8192 |
| 22 | ir_gbyt g uint get word j |
| 23 | end |
| 24 | ret ir_res ir_op get hd_s 0 52 r ulong g 0 |
| 25 | end |
| 26 | fn hd_slice slot ulong ref uint n ulong to void |
| 27 | z = hd_c 5 0 |
| 28 | sz = hd_c 5 n |
| 29 | o = ir_op get hd_s 0 80 0 3 4 |
| 30 | ir_set o 0 get hd_s 1 |
| 31 | ir_set o 1 ref |
| 32 | ir_set o 2 z |
| 33 | ir_set o 3 sz |
| 34 | put hd_s 1 ir_otok o |
| 35 | put hd_a slot ref |
| 36 | put hd_a add slot 1 z |
| 37 | put hd_a add slot 2 sz |
| 38 | end |
| 39 | fn hd_op word ulong n uint to void |
| 40 | o = ir_op get hd_s 0 110 9 word add n 1 |
| 41 | ir_set o 0 get hd_s 1 |
| 42 | for j uint n bound 8 |
| 43 | ir_set o add j 1 get hd_a j |
| 44 | end |
| 45 | put hd_s 1 ir_otok o |
| 46 | end |
| 47 | fn hd_emit mode uint to void |
| 48 | note Well-formed packets (count, u16-length records) for execenv and symlnk: a malformed one traps 3 natively |
| 49 | note before any kernel call, and ngrun gives that trap first, so a refusal control must not hold one. |
| 50 | pg = new uchar 5 0 |
| 51 | put pg 0 1 |
| 52 | put pg 2 1 |
| 53 | put pg 4 120 |
| 54 | ev = new uchar 7 0 |
| 55 | put ev 0 1 |
| 56 | put ev 2 3 |
| 57 | put ev 4 88 |
| 58 | put ev 5 61 |
| 59 | put ev 6 49 |
| 60 | pr = new uchar 8 0 |
| 61 | put pr 0 2 |
| 62 | put pr 2 1 |
| 63 | put pr 4 97 |
| 64 | put pr 5 1 |
| 65 | put pr 7 98 |
| 66 | pc = new uchar 2051 0 |
| 67 | pb = new uchar 4099 0 |
| 68 | if eq mode 115 |
| 69 | hd_op 107 0 |
| 70 | ret |
| 71 | end |
| 72 | if eq mode 324 |
| 73 | put pc 1 4 |
| 74 | put pc 2 1 |
| 75 | put pc 4 120 |
| 76 | hd_slice 0 hd_text pc 2051 |
| 77 | hd_op 124 3 |
| 78 | ret |
| 79 | end |
| 80 | if eq mode 325 |
| 81 | put pb 0 1 |
| 82 | put pb 2 255 |
| 83 | put pb 3 15 |
| 84 | for j ulong 4095 |
| 85 | put pb add j 4 120 |
| 86 | end |
| 87 | hd_slice 0 hd_text pb 4099 |
| 88 | hd_op 124 3 |
| 89 | ret |
| 90 | end |
| 91 | if eq mode 215 |
| 92 | hd_slice 0 hd_text pg 5 |
| 93 | hd_slice 3 hd_text ev 7 |
| 94 | hd_op 233 6 |
| 95 | ret |
| 96 | end |
| 97 | if eq mode 116 |
| 98 | put hd_a 0 hd_c 8 0 |
| 99 | put hd_a 1 hd_c 8 0 |
| 100 | hd_slice 2 get hd_s 2 16 |
| 101 | hd_op 235 5 |
| 102 | ret |
| 103 | end |
| 104 | if eq mode 117 |
| 105 | put hd_a 0 hd_c 9 0 |
| 106 | hd_op 168 1 |
| 107 | ret |
| 108 | end |
| 109 | if eq mode 118 |
| 110 | put hd_a 0 hd_c 8 2 |
| 111 | put hd_a 1 hd_c 8 1 |
| 112 | put hd_a 2 hd_c 8 0 |
| 113 | hd_op 104 3 |
| 114 | ret |
| 115 | end |
| 116 | if or eq mode 119 eq mode 219 |
| 117 | r = hd_text hd_abs |
| 118 | n = len hd_abs |
| 119 | if eq mode 219 |
| 120 | r = hd_text hd_rel |
| 121 | n = len hd_rel |
| 122 | end |
| 123 | hd_slice 0 r n |
| 124 | put hd_a 3 hd_c 8 577 |
| 125 | put hd_a 4 hd_c 8 384 |
| 126 | hd_op 110 5 |
| 127 | ret |
| 128 | end |
| 129 | if eq mode 120 |
| 130 | hd_slice 0 get hd_s 2 1 |
| 131 | put hd_a 3 hd_c 8 0 |
| 132 | hd_op 135 4 |
| 133 | ret |
| 134 | end |
| 135 | if eq mode 121 |
| 136 | hd_slice 0 hd_text pr 8 |
| 137 | hd_op 142 3 |
| 138 | ret |
| 139 | end |
| 140 | if eq mode 319 |
| 141 | put hd_a 0 hd_c 8 1 |
| 142 | hd_slice 1 get hd_s 2 1 |
| 143 | put hd_a 4 hd_c 9 0 |
| 144 | hd_op 162 5 |
| 145 | ret |
| 146 | end |
| 147 | if or eq mode 236 eq mode 237 |
| 148 | put hd_a 0 hd_c 8 0 |
| 149 | hd_slice 1 get hd_s 2 8 |
| 150 | hd_op ulong mode 4 |
| 151 | ret |
| 152 | end |
| 153 | if eq mode 238 |
| 154 | hd_op 238 0 |
| 155 | ret |
| 156 | end |
| 157 | if eq mode 239 |
| 158 | put hd_a 0 hd_c 8 0 |
| 159 | put hd_a 1 hd_c 8 0 |
| 160 | put hd_a 2 hd_c 8 0 |
| 161 | hd_op 239 3 |
| 162 | ret |
| 163 | end |
| 164 | if eq mode 240 |
| 165 | put hd_a 0 hd_c 8 0 |
| 166 | put hd_a 1 hd_c 8 0 |
| 167 | hd_op 240 2 |
| 168 | ret |
| 169 | end |
| 170 | exit 2 |
| 171 | end |
| 172 | fn main to int |
| 173 | if ne argcnt 2 |
| 174 | ret 2 |
| 175 | end |
| 176 | n = argread 1 hd_arg 0 len hd_arg |
| 177 | if or le n 0 gt n 3 |
| 178 | ret 2 |
| 179 | end |
| 180 | mode = uint 0 |
| 181 | for j ulong ulong n bound 3 |
| 182 | c = uint get hd_arg j |
| 183 | if or lt c 48 gt c 57 |
| 184 | ret 2 |
| 185 | end |
| 186 | mode = add mul mode 10 sub c 48 |
| 187 | end |
| 188 | ir_init |
| 189 | f = ir_fnew 2 0 8 |
| 190 | put hd_s 0 ir_blk f |
| 191 | put hd_s 1 ir_ftok f |
| 192 | t = ir_tarr 2 64 |
| 193 | r = ir_tref t 1 0 |
| 194 | g = ir_glob t 0 |
| 195 | put hd_s 2 ir_res ir_op get hd_s 0 52 r ulong g 0 |
| 196 | hd_emit mode |
| 197 | v = hd_c 8 0 |
| 198 | o = ir_op get hd_s 0 63 0 0 2 |
| 199 | ir_set o 0 get hd_s 1 |
| 200 | ir_set o 1 v |
| 201 | lenout = ir_wr |
| 202 | if eq ar_out 1 1 0 lenout 0 |
| 203 | ret 2 |
| 204 | end |
| 205 | ret 0 |
| 206 | end |