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 / gate.om

863 lines · 15338 bytes Raw Blame History
1note Native host fixture gate. Run from the repository root.
2note An optional argv[1] names the candidate compiler (absolute, or relative to the root);
3note the default is seed/out/omc. That compiler builds every fixture and every generated
4note identity program, and the compiler-refusal fixture receives it as its argv[1].
5note Fixtures run in a fresh stage directory: any earlier stage is removed first, each child
6note exit status and timeout is checked, required leftovers are checked, and after a pass the
7note stage is removed. A failure prints the fixture and keeps the stage for inspection.
8note The environment fixture runs as /usr/bin/env OMTEST=hello ./environment because
9note execprog passes an empty environment. Identity fixtures are judged against the real
10note and effective ids that /proc/self/status reports, not against the words under test.
11om2
12
13text omcdef "seed/out/omc"
14text up4 "../../../../"
15text b1 "build"
16text b2 "build/seed"
17text b3 "build/seed/host"
18text stage "build/seed/host/run"
19text slash "/"
20text dotslash "./"
21text tests "seed/host/tests/"
22text dotom ".om"
23text argsbin "build/seed/host/run/args"
24text echild "build/seed/host/run/exec-child"
25text idom "build/seed/host/run/id.om"
26text idbin "build/seed/host/run/id.bin"
27text idname "id.bin"
28text pself "/proc/self/status"
29text kuid "\nUid:\t"
30text kgid "\nGid:\t"
31text envbin "/usr/bin/env"
32text omtest "OMTEST=hello"
33text envfx "./environment"
34text empty ""
35text twowords "two words"
36text pi "π"
37text tcp "tcp"
38text c1 "1"
39text c2 "2"
40text c3 "3"
41text nfiles "files"
42text nargs "args"
43text nnetwork "network"
44text nprocess "process"
45text ndirs "directories"
46text nerrors "errors"
47text nloc "location"
48text nsockopt "sockopt"
49text nnetdata "netdata"
50text nnetpeer "netpeer"
51text npeernm "peername"
52text ndevice "device"
53text ndevcall "devcall"
54text nuvmctl "uvmctl"
55text nvfio "vfio"
56text nvfcheck "vfiocheck"
57text nmapping "mapping"
58text nmapio "mapio"
59text nreserve "reserve"
60text nmemchk "memcheck"
61text nstruct "structfile"
62text nrandom "random"
63text nenv "environment"
64text nchdir "chdir"
65text ntrunc "trunc"
66text nstat "stat"
67text nstatsh "stat_short"
68text nlinks "links"
69text nlinksh "links_short"
70text nchmod "chmod"
71text nchown "chown"
72text nfaccess "faccess"
73text nfchdir "fchdir"
74text nfdsync "fdsync"
75text npio "pio"
76text npsync "psync"
77text nflock "flock"
78text npgroup "pgroup"
79text nlstat "lstat"
80text ntrnc "truncate"
81text nenvtrap "environment_trap"
82text srcuid "fn main to int\nret int getuid\nend\n"
83text srceuid "fn main to int\nret int geteuid\nend\n"
84text srcgid "fn main to int\nret int getgid\nend\n"
85text srcegid "fn main to int\nret int getegid\nend\n"
86text srcpp1 "fn main to int\nret int rem getppid long 256\nend\n"
87text srcpp2 "fn main to int\nret int rem getppid long 251\nend\n"
88text lprobe "probe.bin"
89text lsock "native.sock"
90text ladir "adir"
91text lbefore "before"
92text lafter "after"
93text lregular "regular-file"
94text lnetdata "netdata.sock"
95text lnetpeer "netpeer.sock"
96text lmapped "mapped.bin"
97text lreserve "reserve.bin"
98text lstruct "structfile.tmp"
99text lsubin "sub/inside"
100text lsubdir "subdir/inside"
101text lflock "flock.tmp"
102text lcase "case.om"
103text lcaseelf "case.elf"
104text lcaseerr "case.err"
105text fm "PASS native files, errno, exclusive creation, permissions, seek, sync and monotonic time\n"
106text am "PASS native argument access, empty arguments, UTF-8 bytes and short-buffer refusal\n"
107text nm "PASS native socket exchange, poll timeout, fork, accept and child reaping\n"
108text tm "PASS native TCP loopback exchange on an OS-assigned port\n"
109text pm "PASS native exec with exact arguments, exec failure, pipes, descriptor duplication, sleep, kill and wait\n"
110text dm "PASS native directory enumeration, file metadata and rename without overwriting\n"
111text em "PASS native syscall errors and nested expression register preservation\n"
112text lm "PASS native cwd and readlnk offsets, counts, truncation, errno and private path copy\n"
113text sm "PASS native socket options with independent bind behavior, readonly input and errno\n"
114text ndm "PASS native network slice bounds and poll record-size refusal\n"
115text dvm "PASS native checked device ioctl composed with host files and pipes\n"
116text sfm "PASS struct values and native file operations in one program\n"
117text rdm "PASS native random: exact count, non-zero, two calls differ, invalid flags refused\n"
118text evm "PASS native environment: count, entry bytes, short-buffer refusal\n"
119text cdm "PASS native chdir: relative file created in the new directory; missing path refused\n"
120text trm "PASS native ftrunc: write, shorten, rewind, read 4 then EOF; closed fd refused\n"
121text stm "PASS native stat: size field, missing path errno, 128-byte structure\n"
122text ssm "PASS native stat: short output traps 3 before the kernel\n"
123text lkm "PASS native link/symlnk: hard link nlink 2, symlink target, unlink\n"
124text lsm "PASS native link: one-record packed list traps 3\n"
125text chm "PASS native chmod: 0600 mode in st_mode; missing path errno\n"
126text com "PASS native chown: owner uid kept in st_uid; missing path errno\n"
127text fam "PASS native faccess: existing path accepted, missing path refused\n"
128text idm "PASS native identity: getuid/geteuid/getgid/getegid match /proc/self/status\n"
129text fcm "PASS native fchdir/umask/getppid: directory fd, 0777 under mask 0, parent id\n"
130text ppm "PASS native getppid: parent id equals the gate process pid (mod 256 and mod 251)\n"
131text fdm "PASS native fdsync/memfd: data sync, closed fd refused, anonymous file rw\n"
132text pim "PASS native pread/pwrite: positioned I/O, bytes intact, closed fd refused\n"
133text psm "PASS native getsid/syncfs/shutdown: session id, filesystem sync, non-socket refusal\n"
134text flm "PASS native flock: exclusive lock blocks a second open (EWOULDBLOCK), unlock, shared, EINVAL, EBADF\n"
135text pgm "PASS native process groups: getpgid/setpgid, setsid or EPERM\n"
136text lstm "PASS native lstat: stat follows the link, lstat reports S_IFLNK\n"
137text tcm "PASS native truncate: path length set to 4; missing path errno\n"
138text etm "PASS native environment: index at the count traps 3\n"
139text failp "GATE-HOST FAIL "
140text fails "; retained stage build/seed/host/run\n"
141text usage "usage: gate [compiler]\n"
142
143global omcp uchar 4096
144global omcn ulong 1
145global cur uchar 64
146global curn ulong 1
147global path uchar 4096
148global pathn ulong 1
149global wpath uchar 4096
150global argv uchar 8192
151global argc ulong 1
152global apos ulong 1
153global alast ulong 1
154global statbuf uchar 4
155global copybuf uchar 4096
156global pst uchar 8192
157global pstn ulong 1
158
159fn stop to void
160r = write 2 failp 0 len failp
161r = write 2 cur 0 get curn 0
162r = write 2 fails 0 len fails
163exit 99
164end
165
166fn setcur t view uchar * to void
167n = len t
168if gt n 64
169n = ulong 64
170end
171for i ulong n
172put cur i get t i
173end
174put curn 0 n
175end
176
177fn setomc to void
178c = argcnt
179if eq c 1
180for i ulong len omcdef
181put omcp i get omcdef i
182end
183put omcn 0 len omcdef
184ret
185end
186if ne c 2
187r = write 2 usage 0 len usage
188exit 2
189end
190n = argread 1 omcp 0 4096
191if le n 0
192r = write 2 usage 0 len usage
193exit 2
194end
195put omcn 0 ulong n
196end
197
198fn mkd t view uchar * to void
199r = makedir t 0 len t 448
200if or eq r 0 eq r -17
201else
202stop
203end
204end
205
206fn pclear to void
207put pathn 0 0
208end
209
210fn pcat t view uchar * to void
211p = get pathn 0
212n = len t
213if gt add p n 4096
214stop
215end
216for i ulong n
217put path add p i get t i
218end
219put pathn 0 add p n
220end
221
222fn spath t view uchar * to void
223pclear
224pcat stage
225pcat slash
226pcat t
227end
228
229fn gone t view uchar * to void
230spath t
231r = unlink path 0 get pathn 0
232if ne r -2
233stop
234end
235end
236
237fn goned t view uchar * to void
238spath t
239r = rmdir path 0 get pathn 0
240if ne r -2
241stop
242end
243end
244
245fn here t view uchar * to void
246spath t
247r = unlink path 0 get pathn 0
248if ne r 0
249stop
250end
251end
252
253fn wname d view uchar * o ulong base ulong to ulong
254k = add o 19
255if eq get d k 46
256if eq get d add k 1 0
257ret 0
258end
259if eq get d add k 1 46
260if eq get d add k 2 0
261ret 0
262end
263end
264end
265put wpath base 47
266p = add base 1
267while ne get d k 0
268if ge p 4095
269stop
270end
271put wpath p get d k
272p = add p 1
273k = add k 1
274end
275ret p
276end
277
278fn wone d view uchar * o ulong base ulong depth ulong to ulong
279rl = or ulong get d add o 16 shl ulong get d add o 17 8
280if eq rl 0
281stop
282end
283q = wname view d o base
284if eq q 0
285ret rl
286end
287r = unlink wpath 0 q
288if eq r -21
289if eq depth 0
290stop
291end
292wipe q sub depth 1
293r = rmdir wpath 0 q
294end
295if ne r 0
296stop
297end
298ret rl
299end
300
301fn wipe base ulong depth ulong to void
302d = new uchar 8192 0
303fd = fopen wpath 0 base 16384 0
304if lt fd 0
305stop
306end
307while true
308n = getdnts int fd d 0 len d
309if lt n 0
310stop
311end
312if eq n 0
313break
314end
315o = ulong 0
316while lt o ulong n
317o = add o wone view d o base depth
318end
319end
320if ne fclose int fd 0
321stop
322end
323end
324
325fn wstage to void
326setcur stage
327for i ulong len stage
328put wpath i get stage i
329end
330wipe len stage 2
331end
332
333fn areset to void
334put argc 0 0
335put apos 0 2
336put argv 0 0
337put argv 1 0
338end
339
340fn afix to void
341p = get apos 0
342q = get alast 0
343m = sub sub p q 2
344if gt m 65535
345stop
346end
347put argv q uchar and m 255
348put argv add q 1 uchar shr m 8
349end
350
351fn anew to void
352p = get apos 0
353if gt add p 2 8192
354stop
355end
356put alast 0 p
357put apos 0 add p 2
358afix
359c = add get argc 0 1
360put argc 0 c
361put argv 0 uchar and c 255
362put argv 1 uchar shr c 8
363end
364
365fn amore t view uchar * to void
366p = get apos 0
367n = len t
368if gt add p n 8192
369stop
370end
371for i ulong n
372put argv add p i get t i
373end
374put apos 0 add p n
375afix
376end
377
378fn aomc rel ulong to void
379anew
380if eq rel 1
381if ne get omcp 0 47
382amore up4
383end
384end
385p = get apos 0
386n = get omcn 0
387if gt add p n 8192
388stop
389end
390for i ulong n
391put argv add p i get omcp i
392end
393put apos 0 add p n
394afix
395end
396
397fn aadd t view uchar * to void
398anew
399amore t
400end
401
402fn astart t view uchar * to void
403areset
404anew
405amore dotslash
406amore t
407end
408
409fn araw t view uchar * to void
410areset
411aadd t
412end
413
414fn waitx pid int want ulong lim long to void
415start = monons
416if lt start 0
417stop
418end
419while true
420r = waitpid pid statbuf 0 4 1
421if eq r long pid
422if ne get statbuf 0 0
423stop
424end
425if ne ulong get statbuf 1 want
426stop
427end
428ret
429end
430if ne r 0
431stop
432end
433now = monons
434if gt sub now start lim
435r = killpid pid 9
436r = waitpid pid statbuf 0 4 0
437stop
438end
439r = sleepns 1000000
440if ne r 0
441stop
442end
443end
444end
445
446fn go want ulong lim long to void
447pid = fork
448if lt pid 0
449stop
450end
451if eq pid 0
452r = chdir stage 0 len stage
453if ne r 0
454stop
455end
456r = execprog argv 0 get apos 0
457exit 98
458end
459waitx int pid want lim
460end
461
462fn run t view uchar * to void
463astart t
464go 0 120000000000
465end
466
467fn runt t view uchar * to void
468astart t
469go 0 10000000000
470end
471
472fn trap3 t view uchar * to void
473astart t
474go 103 120000000000
475end
476
477fn compx sfd int ofd int to void
478areset
479aomc 0
480pid = fork
481if lt pid 0
482stop
483end
484if eq pid 0
485if ne dupfd sfd 0 0 long 0
486stop
487end
488if ne dupfd ofd 1 0 long 1
489stop
490end
491r = execprog argv 0 get apos 0
492exit 98
493end
494if ne fclose sfd 0
495stop
496end
497if ne fclose ofd 0
498stop
499end
500waitx int pid 0 120000000000
501end
502
503fn comp t view uchar * to void
504setcur t
505spath t
506ofd = fopen path 0 get pathn 0 577 448
507if lt ofd 0
508stop
509end
510if ne fchmod int ofd 448 0
511stop
512end
513pclear
514pcat tests
515pcat t
516pcat dotom
517sfd = fopen path 0 get pathn 0 0 0
518if lt sfd 0
519stop
520end
521compx int sfd int ofd
522end
523
524fn copyexec to void
525s = fopen argsbin 0 len argsbin 0 0
526if lt s 0
527stop
528end
529d = fopen echild 0 len echild 577 448
530if lt d 0
531stop
532end
533if ne fchmod int d 448 0
534stop
535end
536while true
537n = read int s copybuf 0 len copybuf
538if lt n 0
539stop
540end
541if eq n 0
542if ne fclose int d 0
543stop
544end
545if ne fclose int s 0
546stop
547end
548ret
549end
550r = write int d copybuf 0 ulong n
551if ne r n
552stop
553end
554end
555end
556
557fn loadst to void
558fd = fopen pself 0 len pself 0 0
559if lt fd 0
560stop
561end
562n = read int fd pst 0 8192
563if le n 0
564stop
565end
566if ge n 8192
567stop
568end
569put pstn 0 ulong n
570if ne fclose int fd 0
571stop
572end
573end
574
575fn idnum p ulong fld ulong to ulong
576q = p
577f = fld
578while gt f 0
579while ne get pst q 9
580q = add q 1
581end
582q = add q 1
583f = sub f 1
584end
585v = ulong 0
586d = ulong 0
587while true
588c = ulong get pst q
589if or lt c 48 gt c 57
590break
591end
592v = add mul v 10 sub c 48
593q = add q 1
594d = add d 1
595end
596if eq d 0
597stop
598end
599ret v
600end
601
602fn idval key view uchar * fld ulong to ulong
603n = get pstn 0
604k = len key
605i = ulong 0
606while le add i k n
607j = ulong 0
608while lt j k
609if ne get pst add i j get key j
610break
611end
612j = add j 1
613end
614if eq j k
615ret and idnum add i k fld 255
616end
617i = add i 1
618end
619stop
620ret 0
621end
622
623fn idcase src view uchar * want ulong to void
624fd = fopen idom 0 len idom 577 384
625if lt fd 0
626stop
627end
628r = write int fd src 0 len src
629if ne r long len src
630stop
631end
632if ne fclose int fd 0
633stop
634end
635sfd = fopen idom 0 len idom 0 0
636if lt sfd 0
637stop
638end
639ofd = fopen idbin 0 len idbin 577 448
640if lt ofd 0
641stop
642end
643if ne fchmod int ofd 448 0
644stop
645end
646compx int sfd int ofd
647astart idname
648go want 120000000000
649end
650
651fn say t view uchar * to void
652r = write 1 t 0 len t
653end
654
655fn part1 to void
656comp nfiles
657run nfiles
658gone lprobe
659say fm
660comp nargs
661astart nargs
662aadd empty
663aadd twowords
664aadd pi
665go 0 120000000000
666copyexec
667say am
668comp nnetwork
669runt nnetwork
670gone lsock
671say nm
672astart nnetwork
673aadd tcp
674go 0 10000000000
675say tm
676comp nprocess
677runt nprocess
678say pm
679comp ndirs
680run ndirs
681goned ladir
682gone lbefore
683gone lafter
684say dm
685comp nerrors
686run nerrors
687say em
688comp nloc
689run nloc
690gone lregular
691say lm
692comp nsockopt
693runt nsockopt
694say sm
695end
696
697fn part2 to void
698comp nnetdata
699runt nnetdata
700gone lnetdata
701astart nnetdata
702aadd c1
703go 103 10000000000
704astart nnetdata
705aadd c2
706go 103 10000000000
707astart nnetdata
708aadd c3
709go 103 10000000000
710say ndm
711comp nnetpeer
712runt nnetpeer
713gone lnetpeer
714comp npeernm
715runt npeernm
716astart npeernm
717aadd c1
718go 103 10000000000
719astart npeernm
720aadd c2
721go 103 10000000000
722astart npeernm
723aadd c3
724go 103 10000000000
725comp ndevice
726run ndevice
727say dvm
728comp ndevcall
729run ndevcall
730comp nuvmctl
731run nuvmctl
732comp nvfio
733run nvfio
734comp nvfcheck
735astart nvfcheck
736aomc 1
737go 0 120000000000
738gone lcase
739gone lcaseelf
740gone lcaseerr
741comp nmapping
742run nmapping
743gone lmapped
744comp nmapio
745run nmapio
746comp nreserve
747run nreserve
748gone lreserve
749comp nmemchk
750astart nmemchk
751aomc 1
752go 0 120000000000
753comp nstruct
754run nstruct
755gone lstruct
756say sfm
757comp nrandom
758run nrandom
759say rdm
760end
761
762fn part3 to void
763comp nenv
764araw envbin
765aadd omtest
766aadd envfx
767go 0 120000000000
768say evm
769comp nchdir
770run nchdir
771here lsubin
772say cdm
773comp ntrunc
774run ntrunc
775say trm
776comp nstat
777run nstat
778say stm
779comp nstatsh
780trap3 nstatsh
781say ssm
782comp nlinks
783run nlinks
784say lkm
785comp nlinksh
786trap3 nlinksh
787say lsm
788comp nchmod
789run nchmod
790say chm
791comp nchown
792run nchown
793say com
794comp nfaccess
795run nfaccess
796say fam
797end
798
799fn part4 to void
800setcur idname
801loadst
802idcase srcuid idval kuid 0
803idcase srceuid idval kuid 1
804idcase srcgid idval kgid 0
805idcase srcegid idval kgid 1
806say idm
807comp nfchdir
808run nfchdir
809here lsubdir
810say fcm
811note getppid must name this gate, the direct parent of the forked child that execs id.bin: compare
812note the parent id with getpid modulo 256 and modulo 251. They are coprime, so a wrong id passes only
813note if it is congruent to the gate pid modulo 64256; the child's own pid and constants fail.
814setcur idname
815me = getpid
816idcase srcpp1 ulong rem me long 256
817idcase srcpp2 ulong rem me long 251
818say ppm
819comp nfdsync
820run nfdsync
821say fdm
822comp npio
823run npio
824say pim
825comp npsync
826run npsync
827say psm
828comp nflock
829runt nflock
830gone lflock
831say flm
832comp npgroup
833run npgroup
834say pgm
835comp nlstat
836run nlstat
837say lstm
838comp ntrnc
839run ntrnc
840say tcm
841comp nenvtrap
842trap3 nenvtrap
843say etm
844end
845
846fn main to int
847setomc
848mkd b1
849mkd b2
850mkd b3
851mkd stage
852wstage
853part1
854part2
855part3
856part4
857wstage
858r = rmdir stage 0 len stage
859if ne r 0
860stop
861end
862ret 0
863end