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 / protocol / omnet / cmd / tkad / main.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | text ds_init "--init" |
| 3 | text ds_resum "--resume" |
| 4 | text ds_exe "/proc/self/exe" |
| 5 | fn dslistenercheck fd int to int |
| 6 | b = new uchar 65536 0 |
| 7 | if ne sockname fd b 0 128 add long len ds_sock 3 |
| 8 | ret 1 |
| 9 | end |
| 10 | if or ne get b 0 1 ne get b 1 0 |
| 11 | ret 1 |
| 12 | end |
| 13 | for i ulong len ds_sock |
| 14 | if ne get b add i 2 get ds_sock i |
| 15 | ret 1 |
| 16 | end |
| 17 | end |
| 18 | if ne get b add len ds_sock 2 0 |
| 19 | ret 1 |
| 20 | end |
| 21 | if ne fstat fd b 0 128 0 |
| 22 | ret 1 |
| 23 | end |
| 24 | if ne and dsleget b 16 61440 49152 |
| 25 | ret 1 |
| 26 | end |
| 27 | if ne lstat ds_sock 0 len ds_sock b 0 128 0 |
| 28 | ret 1 |
| 29 | end |
| 30 | if ne and dsleget b 16 4294967295 49536 |
| 31 | ret 1 |
| 32 | end |
| 33 | if ne and dsleget b 24 4294967295 ulong geteuid |
| 34 | ret 1 |
| 35 | end |
| 36 | if ne listen fd int 32 0 |
| 37 | ret 1 |
| 38 | end |
| 39 | ret 0 |
| 40 | end |
| 41 | fn dsroll fd int to void |
| 42 | b = new uchar 65536 0 |
| 43 | if ne fd 66 |
| 44 | if ne fstat int 66 b 0 128 -9 |
| 45 | exit 76 |
| 46 | end |
| 47 | if ne dupfd fd int 66 int 0 66 |
| 48 | exit 76 |
| 49 | end |
| 50 | if ne stpass int 64 int 65 0 |
| 51 | exit 76 |
| 52 | end |
| 53 | end |
| 54 | put b 0 2 |
| 55 | put b 1 0 |
| 56 | put b 2 uchar len ds_exe |
| 57 | put b 3 0 |
| 58 | for i ulong len ds_exe |
| 59 | put b add i 4 get ds_exe i |
| 60 | end |
| 61 | p = add len ds_exe 4 |
| 62 | put b p uchar len ds_resum |
| 63 | put b add p 1 0 |
| 64 | for i ulong len ds_resum |
| 65 | put b add add p 2 i get ds_resum i |
| 66 | end |
| 67 | z = execprog b 0 add add p 2 len ds_resum |
| 68 | exit 76 |
| 69 | end |
| 70 | fn dsstartup to int |
| 71 | b = new uchar 65536 0 |
| 72 | a = new uchar 65536 0 |
| 73 | args = argcnt |
| 74 | if and ne args 2 ne args 3 |
| 75 | ret -1 |
| 76 | end |
| 77 | n = argread 1 b 0 65536 |
| 78 | if or le n 0 gt n 4095 |
| 79 | ret -1 |
| 80 | end |
| 81 | resume = ulong 0 |
| 82 | if eq n long len ds_resum |
| 83 | resume = 1 |
| 84 | for i ulong len ds_resum |
| 85 | if ne get b i get ds_resum i |
| 86 | resume = 0 |
| 87 | end |
| 88 | end |
| 89 | end |
| 90 | if ne resume 0 |
| 91 | if ne args 2 |
| 92 | ret -1 |
| 93 | end |
| 94 | if ne stresume int 64 int 65 0 |
| 95 | ret -1 |
| 96 | end |
| 97 | if ne dslistenercheck int 66 0 |
| 98 | ret -1 |
| 99 | end |
| 100 | if ne dsload 0 |
| 101 | ret -1 |
| 102 | end |
| 103 | ret 66 |
| 104 | end |
| 105 | for i ulong ulong n |
| 106 | if eq get b i 0 |
| 107 | ret -1 |
| 108 | end |
| 109 | end |
| 110 | init = int 0 |
| 111 | if eq args 3 |
| 112 | m = argread 2 a 0 65536 |
| 113 | if ne m long len ds_init |
| 114 | ret -1 |
| 115 | end |
| 116 | for i ulong len ds_init |
| 117 | if ne get a i get ds_init i |
| 118 | ret -1 |
| 119 | end |
| 120 | end |
| 121 | init = 1 |
| 122 | end |
| 123 | if ne stopen b ulong n init 0 |
| 124 | ret -1 |
| 125 | end |
| 126 | if ne init 0 |
| 127 | dsselect 0 |
| 128 | if ne dsident 0 |
| 129 | ret -1 |
| 130 | end |
| 131 | s = dssave |
| 132 | if eq s 2 |
| 133 | exit 74 |
| 134 | end |
| 135 | if ne s 0 |
| 136 | ret -1 |
| 137 | end |
| 138 | else |
| 139 | if ne dsload 0 |
| 140 | ret -1 |
| 141 | end |
| 142 | end |
| 143 | ret dslisten |
| 144 | end |
| 145 | fn main to int |
| 146 | z = umask int 127 |
| 147 | fd = dsstartup |
| 148 | if lt fd 0 |
| 149 | ret 73 |
| 150 | end |
| 151 | dsbatch fd |
| 152 | dsroll fd |
| 153 | ret 76 |
| 154 | end |