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 / ng / tests / ir / host-refusals.om

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