interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / seed / host / execenv / execenv.om

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