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/seed/host/execenv/execenv.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 / seed / host / execenv / execenv.om` 296 lines ยท 6147 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note seed/host/execenv/execenv.om: fixture for execenv (keyword 233), program mode. Run by the OM-2 3 note conductor through seed/host/execenv/execenv.cases from the repository root, without arguments. 4 note Parent mode packs argv [argv0, "child"] and an environment of exactly three records, runs itself 5 note through execenv in a forked child and requires child exit 0: the child saw exactly those three 6 note entries, in packet order. The same child run through execprog must see an empty environment 7 note (child exit 30): the negative control. Malformed environment packets trap 3 (exit 103) in a forked 8 note child. The 64-record and 4096-byte boundaries are accepted: the child runs and reports 64 entries 9 note (exit 40) or the one 4092-byte entry (exit 41). A missing executable returns -2 (ENOENT) to the 10 note caller. Every boundary entry is NAME=VALUE with a distinct NAME: qemu-user, which runs the 11 note x86linux build of this fixture, drops entries without '=' and repeated names from a guest's 12 note environment. 13 note Child mode (argv[1] is "child"): exit 0 for exactly the three entries, 30 for an empty 14 note environment, 40 for 64 entries, 41 for one 4092-byte entry, 31 for another count, and 32/33/34 15 note for a wrong first/second/third entry. 16 note Parent exit: 0 when every check holds, otherwise the number of the first failed check. 17 om2 18 text tok "AIEN_COCKPIT_TOKEN=fixture-token-execenv" 19 text addr "AIEN_COCKPIT_ADDR=127.0.0.1:1" 20 text db "HIVE_DB_PATH=/nonexistent/hive.db" 21 text cmode "child" 22 text missing "/nonexistent/omega-execenv-missing" 23 global argv uchar 4096 24 global envp uchar 4096 25 global bad uchar 8192 26 global buf uchar 4096 27 global status uchar 4 28 29 fn erec pos ulong s view uchar * to ulong 30 put envp pos uchar and len s 255 31 put envp add pos 1 uchar shr len s 8 32 for i ulong len s 33 put envp add add pos 2 i get s i 34 end 35 ret add add pos 2 len s 36 end 37 38 fn same i ulong s view uchar * to ulong 39 n = envread i buf 0 len buf 40 if ne n long len s 41 ret 0 42 end 43 for j ulong len s 44 if ne get buf j get s j 45 ret 0 46 end 47 end 48 ret 1 49 end 50 51 fn child to int 52 c = ulong envcnt 53 if eq c 0 54 ret 30 55 end 56 if eq c 64 57 ret 40 58 end 59 if eq c 1 60 if eq envread 0 buf 0 len buf 4092 61 ret 41 62 end 63 end 64 if ne c 3 65 ret 31 66 end 67 if eq same 0 tok 0 68 ret 32 69 end 70 if eq same 1 addr 0 71 ret 33 72 end 73 if eq same 2 db 0 74 ret 34 75 end 76 ret 0 77 end 78 79 note argv packet: [argv0, "child"]; returns its length. 80 fn mkargv to ulong 81 n = argread 0 buf 0 len buf 82 if le n 0 83 exit 90 84 end 85 m = ulong n 86 put argv 0 2 87 put argv 1 0 88 put argv 2 uchar and m 255 89 put argv 3 uchar shr m 8 90 for i ulong m 91 put argv add i 4 get buf i 92 end 93 pos = add m 4 94 put argv pos uchar len cmode 95 put argv add pos 1 0 96 for k ulong len cmode 97 put argv add add pos 2 k get cmode k 98 end 99 ret add add pos 2 len cmode 100 end 101 102 note An environment of cnt records "XY=" (u16 length 3) with distinct names XY in AA..HH; returns 103 note its length. cnt is at most 64. 104 fn manya cnt ulong to ulong 105 put bad 0 uchar and cnt 255 106 put bad 1 0 107 pos = ulong 2 108 for i ulong cnt 109 put bad pos 3 110 put bad add pos 1 0 111 put bad add pos 2 uchar add 65 shr i 3 112 put bad add pos 3 uchar add 65 and i 7 113 put bad add pos 4 61 114 pos = add pos 5 115 end 116 ret pos 117 end 118 119 note One record "A=AAA..." of rn bytes (u16 length rn); returns the packet length 4 + rn. 120 fn onelong rn ulong to ulong 121 put bad 0 1 122 put bad 1 0 123 put bad 2 uchar and rn 255 124 put bad 3 uchar shr rn 8 125 for i ulong rn 126 put bad add i 4 65 127 end 128 put bad 5 61 129 ret add rn 4 130 end 131 132 fn reap pid long to ulong 133 r = waitpid int pid status 0 len status 0 134 if ne r pid 135 ret 1000 136 end 137 if ne get status 0 0 138 ret 2000 139 end 140 ret ulong get status 1 141 end 142 143 note execenv with the environment packet bad[0..bn) in a forked child; returns the child's exit. 144 fn trybad an ulong bn ulong to ulong 145 pid = fork 146 if lt pid 0 147 ret 1001 148 end 149 if eq pid 0 150 r = execenv argv 0 an bad 0 bn 151 exit 98 152 end 153 ret reap pid 154 end 155 156 note execenv with the argv packet bad[0..bn) and the valid environment envp[0..en) in a forked child. 157 fn tryargv bn ulong en ulong to ulong 158 pid = fork 159 if lt pid 0 160 ret 1001 161 end 162 if eq pid 0 163 r = execenv bad 0 bn envp 0 en 164 exit 98 165 end 166 ret reap pid 167 end 168 169 fn main to int 170 if eq argcnt 2 171 n = argread 1 buf 0 len buf 172 if ne n long len cmode 173 ret 35 174 end 175 for i ulong len cmode 176 if ne get buf i get cmode i 177 ret 35 178 end 179 end 180 ret child 181 end 182 if ne argcnt 1 183 ret 36 184 end 185 an = mkargv 186 put envp 0 3 187 put envp 1 0 188 en = erec 2 tok 189 en = erec en addr 190 en = erec en db 191 note 1: execenv delivers exactly the three entries. 192 pid = fork 193 if lt pid 0 194 ret 1 195 end 196 if eq pid 0 197 r = execenv argv 0 an envp 0 en 198 exit 98 199 end 200 if ne reap pid 0 201 ret 1 202 end 203 note 2: negative control, the same child through execprog sees no environment. 204 pid = fork 205 if lt pid 0 206 ret 2 207 end 208 if eq pid 0 209 r = execprog argv 0 an 210 exit 98 211 end 212 if ne reap pid 30 213 ret 2 214 end 215 note 3-9: malformed environment packets trap 3 before the kernel is asked. 216 put bad 0 0 217 put bad 1 0 218 if ne trybad an 2 103 219 ret 3 220 end 221 put bad 0 1 222 put bad 1 0 223 put bad 2 0 224 put bad 3 0 225 if ne trybad an 4 103 226 ret 4 227 end 228 put bad 2 3 229 put bad 3 0 230 put bad 4 65 231 put bad 5 61 232 put bad 6 49 233 put bad 7 120 234 if ne trybad an 8 103 235 ret 5 236 end 237 put bad 6 0 238 if ne trybad an 7 103 239 ret 6 240 end 241 put bad 2 5 242 if ne trybad an 5 103 243 ret 7 244 end 245 if ne trybad an 1 103 246 ret 8 247 end 248 if ne trybad an manya 65 103 249 ret 9 250 end 251 note 10: count 64 is accepted (count 65 trapped above). 252 if ne trybad an manya 64 40 253 ret 10 254 end 255 note 11-12: a 4096-byte environment packet is accepted; 4097 bytes trap 3. 256 if ne trybad an onelong 4092 41 257 ret 11 258 end 259 if ne trybad an onelong 4093 103 260 ret 12 261 end 262 note 13: every environment record must be nonempty, not only the first: [A=1, ""] traps 3. 263 put bad 0 2 264 put bad 1 0 265 put bad 2 3 266 put bad 3 0 267 put bad 4 65 268 put bad 5 61 269 put bad 6 49 270 put bad 7 0 271 put bad 8 0 272 if ne trybad an 9 103 273 ret 13 274 end 275 note 14: the argv packet keeps execprog's rules: an empty program path traps 3 with a valid environment. 276 put bad 0 1 277 put bad 1 0 278 put bad 2 0 279 put bad 3 0 280 if ne tryargv 4 en 103 281 ret 14 282 end 283 note 15: a valid argv packet whose program is missing: execenv returns -2 (ENOENT). 284 put bad 0 1 285 put bad 1 0 286 put bad 2 uchar len missing 287 put bad 3 0 288 for i ulong len missing 289 put bad add i 4 get missing i 290 end 291 r = execenv bad 0 add len missing 4 envp 0 en 292 if ne r neg long 2 293 ret 15 294 end 295 ret 0 296 end