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