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
omega-mv / seed / qualification / security673 / game / roundtrip.om
| 1 | note Fixed two-child lifecycle measurement using gate669 fork/exec/wait pattern. |
| 2 | note Not a general runner. Existing compiled solver/checker required; no model code here. |
| 3 | text solver "build/security760-v3/solve0" |
| 4 | text checker "build/security760-v3/check0" |
| 5 | text spool "build/security760-v3/roundtrip.bin" |
| 6 | text nullpath "/dev/null" |
| 7 | global argv uchar 256 |
| 8 | global status uchar 4 |
| 9 | fn command c uint to ulong |
| 10 | put argv 0 1 |
| 11 | put argv 1 0 |
| 12 | n = len solver |
| 13 | if eq c 1 |
| 14 | n = len checker |
| 15 | end |
| 16 | put argv 2 uchar n |
| 17 | put argv 3 0 |
| 18 | for i ulong n |
| 19 | if eq c 0 |
| 20 | put argv add i 4 get solver i |
| 21 | else |
| 22 | put argv add i 4 get checker i |
| 23 | end |
| 24 | end |
| 25 | ret add n 4 |
| 26 | end |
| 27 | fn redir fd int dst int to void |
| 28 | if ne fd dst |
| 29 | if ne dupfd fd dst 0 long dst |
| 30 | exit 90 |
| 31 | end |
| 32 | end |
| 33 | end |
| 34 | fn reap pid long to void |
| 35 | start = monons |
| 36 | while true bound 60000 |
| 37 | r = waitpid int pid status 0 len status 1 |
| 38 | if eq r pid |
| 39 | if or ne get status 0 0 ne get status 1 0 |
| 40 | exit 90 |
| 41 | end |
| 42 | ret |
| 43 | end |
| 44 | if or lt r 0 gt sub monons start 30000000000 |
| 45 | r = killpid int pid 9 |
| 46 | r = waitpid int pid status 0 len status 0 |
| 47 | exit 90 |
| 48 | end |
| 49 | if ne sleepns 1000000 0 |
| 50 | exit 90 |
| 51 | end |
| 52 | end |
| 53 | exit 90 |
| 54 | end |
| 55 | fn child c uint fd int nullfd int to void |
| 56 | n = command c |
| 57 | pid = fork |
| 58 | if lt pid 0 |
| 59 | exit 90 |
| 60 | end |
| 61 | if eq pid 0 |
| 62 | redir nullfd 2 |
| 63 | if eq c 0 |
| 64 | redir nullfd 0 |
| 65 | redir fd 1 |
| 66 | else |
| 67 | redir fd 0 |
| 68 | redir nullfd 1 |
| 69 | end |
| 70 | r = execprog argv 0 n |
| 71 | exit 90 |
| 72 | end |
| 73 | reap pid |
| 74 | end |
| 75 | fn main to int |
| 76 | fd = fopen spool 0 len spool 194 384 |
| 77 | if lt fd 0 |
| 78 | ret 90 |
| 79 | end |
| 80 | nullfd = fopen nullpath 0 len nullpath 2 0 |
| 81 | if lt nullfd 0 |
| 82 | ret 90 |
| 83 | end |
| 84 | for i ulong 101 |
| 85 | start = monons |
| 86 | if ne fseek int fd 0 0 0 |
| 87 | ret 90 |
| 88 | end |
| 89 | child 0 int fd int nullfd |
| 90 | if ne fseek int fd 0 0 0 |
| 91 | ret 90 |
| 92 | end |
| 93 | child 1 int fd int nullfd |
| 94 | put samples i ulong sub monons start |
| 95 | end |
| 96 | percentiles |
| 97 | if ne fclose int fd 0 |
| 98 | ret 90 |
| 99 | end |
| 100 | if ne fclose int nullfd 0 |
| 101 | ret 90 |
| 102 | end |
| 103 | label 8 |
| 104 | ret 0 |
| 105 | end |