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/omtls/blob/main/tools/boot.om # omtls omtls: a TLS 1.3 client (RFC 8446) written fresh in seeded Omega, for mailhand. Not audited by a cryptographer. Free (Apache-2.0). Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omtls / tools / boot.om` 677 lines ยท 12719 bytes Raw Blame History 1 om2 2 note SPDX-License-Identifier: Apache-2.0 3 note boot.om: build one omtls unit with the pinned compiler. It is the only program built by hand: 4 note mkdir -p build && ./omc < tools/boot.om > build/boot && chmod 755 build/boot 5 note usage: build/boot UNIT [MUTANTS-FILE MUTANT-NAME] 6 note Reads units/UNIT.list (one source path per line, blank lines ignored) and writes build/UNIT.om: the line 7 note "om2", then every listed file with its own "om2" lines dropped and a leading "export fn " read as "fn ". 8 note Runs ./omc on it (stdin build/UNIT.om, stdout build/UNIT.new, stderr build/UNIT.err) and on success 9 note renames build/UNIT.new to build/UNIT (mode 755). With a mutant, the mutant line 10 note "NAME|FILE|ORIGINAL LINE|REPLACEMENT LINE" must match exactly one line of FILE in the unit; the output is 11 note build/UNIT.mut instead. 12 note Exit: 0 built, 1 the compiler refused (its stderr is copied to ours), 2 usage or I/O, 3 the mutant does not 13 note apply exactly once. 14 note Boundaries: the unit is at most `8388607` bytes, the compiler's own input boundary (OMEGESE 9.6); a larger 15 note unit is refused (exit 2) with that reason. The pin of ./omc is checked by the gate, not here. 16 const BT_MAX ulong `8388607` 17 global bt_out uchar `8388608` 18 global bt_in uchar `8388608` 19 global bt_list uchar `8388608` 20 global bt_mut uchar `8388608` 21 global bt_v ulong 32 22 global bt_unit uchar 4096 23 global bt_path uchar 8192 24 global bt_cur uchar 8192 25 global bt_mname uchar 8192 26 global bt_mfile uchar 8192 27 global bt_mold uchar `1048576` 28 global bt_mnew uchar `1048576` 29 global bt_pk uchar 20000 30 text bt_t_units "units/" 31 text bt_t_list ".list" 32 text bt_t_build "build/" 33 text bt_t_om ".om" 34 text bt_t_new ".new" 35 text bt_t_err ".err" 36 text bt_t_mut ".mut" 37 text bt_t_omc "./omc" 38 text bt_t_om2 "om2" 39 text bt_t_export "export fn " 40 text bt_t_fn "fn " 41 text bt_t_nl "\n" 42 text bt_t_usage "usage: build/boot UNIT [MUTANTS-FILE MUTANT-NAME]\n" 43 text bt_t_badname "boot: UNIT must be letters, digits, '_', '-' or '.'\n" 44 text bt_t_io "boot: cannot read or write " 45 text bt_t_big "boot: the unit is larger than `8388607` bytes, the compiler's input boundary\n" 46 text bt_t_refused "boot: omc refused build/" 47 text bt_t_exit ".om, exit " 48 text bt_t_mutapply "boot: the mutant does not match exactly one line, matches=" 49 text bt_t_mutnone "boot: no such mutant: " 50 text bt_t_mutbad "boot: malformed mutant line (want NAME|FILE|ORIGINAL|REPLACEMENT): " 51 text bt_t_built "boot: built build/" 52 text bt_t_bytes " bytes of source\n" 53 54 note ---- output to stderr ---- 55 fn bt_say t view uchar * to void 56 k = write 2 t 0 len t 57 end 58 fn bt_num n ulong to void 59 d = new uchar 24 0 60 i = ulong 24 61 v = n 62 while true bound 30 63 i = sub i 1 64 put d i uchar add 48 rem v 10 65 v = div v 10 66 if eq v 0 67 break 68 end 69 end 70 k = write 2 d i sub 24 i 71 end 72 fn bt_saypath to void 73 k = write 2 bt_path 0 get bt_v 6 74 k = write 2 bt_t_nl 0 1 75 end 76 77 note ---- path in bt_path, its length in bt_v[6] ---- 78 fn bt_pclear to void 79 put bt_v 6 0 80 end 81 fn bt_padd t view uchar * to void 82 p = get bt_v 6 83 for i ulong len t 84 put bt_path add p i get t i 85 end 86 put bt_v 6 add p len t 87 end 88 fn bt_paddunit to void 89 p = get bt_v 6 90 for i ulong get bt_v 7 91 put bt_path add p i get bt_unit i 92 end 93 put bt_v 6 add p get bt_v 7 94 end 95 96 note ---- read the file named by bt_path into bt_in (length bt_v[1]); false when it cannot be read whole ---- 97 fn bt_load to bool 98 fd = fopen bt_path 0 get bt_v 6 0 0 99 if lt fd 0 100 ret false 101 end 102 n = ulong 0 103 ok = true 104 while true bound `9223372036854775807` 105 if ge n BT_MAX 106 ok = false 107 break 108 end 109 k = read int fd bt_in n sub BT_MAX n 110 if eq k -4 111 continue 112 end 113 if lt k 0 114 ok = false 115 break 116 end 117 if eq k 0 118 break 119 end 120 n = add n ulong k 121 end 122 z = fclose int fd 123 put bt_v 1 n 124 ret ok 125 end 126 127 note ---- append to bt_out (length bt_v[0]); false when the unit would pass the compiler boundary ---- 128 fn bt_room n ulong to bool 129 if gt add get bt_v 0 n BT_MAX 130 put bt_v 9 1 131 ret false 132 end 133 ret true 134 end 135 fn bt_emitt t view uchar * to void 136 if not bt_room len t 137 ret 138 end 139 p = get bt_v 0 140 for i ulong len t 141 put bt_out add p i get t i 142 end 143 put bt_v 0 add p len t 144 end 145 fn bt_emitin s ulong e ulong to void 146 if not bt_room sub e s 147 ret 148 end 149 p = get bt_v 0 150 for i ulong sub e s 151 put bt_out add p i get bt_in add s i 152 end 153 put bt_v 0 add p sub e s 154 end 155 fn bt_emitnew to void 156 n = get bt_v 13 157 if not bt_room n 158 ret 159 end 160 p = get bt_v 0 161 for i ulong n 162 put bt_out add p i get bt_mnew i 163 end 164 put bt_v 0 add p n 165 end 166 167 note ---- comparisons against globals (globals cannot be passed, so each comparison names its arrays) ---- 168 fn bt_inist s ulong n ulong t view uchar * to bool 169 if ne n len t 170 ret false 171 end 172 for i ulong n 173 if ne get bt_in add s i get t i 174 ret false 175 end 176 end 177 ret true 178 end 179 fn bt_inprefix s ulong e ulong t view uchar * to bool 180 if lt sub e s len t 181 ret false 182 end 183 ret bt_inist s len t t 184 end 185 fn bt_inisold s ulong n ulong to bool 186 if ne n get bt_v 12 187 ret false 188 end 189 for i ulong n 190 if ne get bt_in add s i get bt_mold i 191 ret false 192 end 193 end 194 ret true 195 end 196 fn bt_curismfile to bool 197 if ne get bt_v 8 get bt_v 11 198 ret false 199 end 200 for i ulong get bt_v 8 201 if ne get bt_cur i get bt_mfile i 202 ret false 203 end 204 end 205 ret true 206 end 207 208 note ---- one source file (already in bt_in) into bt_out ---- 209 fn bt_source to void 210 n = get bt_v 1 211 mf = false 212 if eq get bt_v 4 1 213 mf = bt_curismfile 214 end 215 p = ulong 0 216 while lt p n bound `9223372036854775807` 217 q = p 218 while lt q n bound `9223372036854775807` 219 if eq get bt_in q 10 220 break 221 end 222 q = add q 1 223 end 224 if bt_inist p sub q p bt_t_om2 225 p = add q 1 226 continue 227 end 228 done = false 229 if mf 230 if bt_inisold p sub q p 231 put bt_v 5 add get bt_v 5 1 232 bt_emitnew 233 done = true 234 end 235 end 236 if not done 237 if bt_inprefix p q bt_t_export 238 bt_emitt bt_t_fn 239 bt_emitin add p len bt_t_export q 240 else 241 bt_emitin p q 242 end 243 end 244 bt_emitt bt_t_nl 245 p = add q 1 246 end 247 end 248 249 note ---- the mutant: find NAME in the mutants file (in bt_in) and split its fields into globals ---- 250 fn bt_mutfind to bool 251 n = get bt_v 1 252 p = ulong 0 253 while lt p n bound `9223372036854775807` 254 q = p 255 while lt q n bound `9223372036854775807` 256 if eq get bt_in q 10 257 break 258 end 259 q = add q 1 260 end 261 m = get bt_v 10 262 hit = false 263 if gt sub q p m 264 if eq get bt_in add p m 124 265 hit = true 266 for i ulong m 267 if ne get bt_in add p i get bt_mname i 268 hit = false 269 break 270 end 271 end 272 end 273 end 274 if hit 275 ret bt_mutsplit add add p m 1 q 276 end 277 p = add q 1 278 end 279 bt_say bt_t_mutnone 280 k = write 2 bt_mname 0 get bt_v 10 281 k = write 2 bt_t_nl 0 1 282 exit 3 283 end 284 fn bt_mutsplit s ulong e ulong to bool 285 note fields: FILE | ORIGINAL | REPLACEMENT (the replacement is the rest of the line) 286 a = s 287 while lt a e bound `9223372036854775807` 288 if eq get bt_in a 124 289 break 290 end 291 a = add a 1 292 end 293 b = add a 1 294 while lt b e bound `9223372036854775807` 295 if eq get bt_in b 124 296 break 297 end 298 b = add b 1 299 end 300 if or ge a e ge b e 301 ret false 302 end 303 if gt sub a s 8192 304 ret false 305 end 306 if gt sub b add a 1 `1048576` 307 ret false 308 end 309 if gt sub e add b 1 `1048576` 310 ret false 311 end 312 for i ulong sub a s 313 put bt_mfile i get bt_in add s i 314 end 315 put bt_v 11 sub a s 316 for i ulong sub b add a 1 317 put bt_mold i get bt_in add add a 1 i 318 end 319 put bt_v 12 sub b add a 1 320 for i ulong sub e add b 1 321 put bt_mnew i get bt_in add add b 1 i 322 end 323 put bt_v 13 sub e add b 1 324 ret true 325 end 326 327 note ---- write bt_out to the file named by bt_path ---- 328 fn bt_store to bool 329 fd = fopen bt_path 0 get bt_v 6 577 420 330 if lt fd 0 331 ret false 332 end 333 p = ulong 0 334 n = get bt_v 0 335 while lt p n bound `9223372036854775807` 336 k = write int fd bt_out p sub n p 337 if eq k -4 338 continue 339 end 340 if le k 0 341 z = fclose int fd 342 ret false 343 end 344 p = add p ulong k 345 end 346 z = fclose int fd 347 ret true 348 end 349 350 note ---- packed lists in bt_pk (length bt_v[14]) ---- 351 fn bt_pkstart count ulong to void 352 put bt_pk 0 uchar and count 255 353 put bt_pk 1 uchar shr count 8 354 put bt_v 14 2 355 end 356 fn bt_pkpath to void 357 note append the path in bt_path as one record 358 n = get bt_v 6 359 p = get bt_v 14 360 put bt_pk p uchar and n 255 361 put bt_pk add p 1 uchar shr n 8 362 for i ulong n 363 put bt_pk add add p 2 i get bt_path i 364 end 365 put bt_v 14 add add p 2 n 366 end 367 368 note ---- the output path: build/UNIT then the suffix ---- 369 fn bt_outpath sfx view uchar * to void 370 bt_pclear 371 bt_padd bt_t_build 372 bt_paddunit 373 bt_padd sfx 374 end 375 fn bt_outfinal to void 376 bt_pclear 377 bt_padd bt_t_build 378 bt_paddunit 379 note a mutant build already has ".mut" in its unit name 380 end 381 382 note ---- run ./omc with redirections; returns its exit status (or 300+ for a signal, 400 for I/O) ---- 383 fn bt_omc to ulong 384 bt_outpath bt_t_om 385 fi = fopen bt_path 0 get bt_v 6 0 0 386 bt_outpath bt_t_new 387 z = unlink bt_path 0 get bt_v 6 388 fo = fopen bt_path 0 get bt_v 6 577 493 389 bt_outpath bt_t_err 390 fe = fopen bt_path 0 get bt_v 6 577 420 391 if or or lt fi 0 lt fo 0 lt fe 0 392 ret 400 393 end 394 bt_pclear 395 bt_padd bt_t_omc 396 bt_pkstart 1 397 bt_pkpath 398 pid = fork 399 if lt pid 0 400 ret 400 401 end 402 if eq pid 0 403 if lt dupfd int fi 0 0 0 404 exit 126 405 end 406 if lt dupfd int fo 1 0 0 407 exit 126 408 end 409 if lt dupfd int fe 2 0 0 410 exit 126 411 end 412 r = execprog bt_pk 0 get bt_v 14 413 exit 127 414 end 415 z = fclose int fi 416 z = fclose int fo 417 z = fclose int fe 418 b = new uchar 4 0 419 while true bound `9223372036854775807` 420 w = waitpid int pid b 0 4 0 421 if eq w pid 422 break 423 end 424 if ne w -4 425 ret 400 426 end 427 end 428 st = or or ulong get b 0 shl ulong get b 1 8 or shl ulong get b 2 16 shl ulong get b 3 24 429 if eq and st 127 0 430 ret and shr st 8 255 431 end 432 ret add 300 and st 127 433 end 434 435 fn bt_copyerr to void 436 bt_outpath bt_t_err 437 if bt_load 438 k = write 2 bt_in 0 get bt_v 1 439 end 440 end 441 442 fn bt_ioerr to void 443 bt_say bt_t_io 444 bt_saypath 445 exit 2 446 end 447 448 note ---- the unit list into bt_list (length bt_v[2]); a line "@PATH" is replaced by the lines of list file PATH 449 note (one level: an included list does not include others) ---- 450 fn bt_expand to bool 451 n = get bt_v 1 452 for i ulong n 453 put bt_mut i get bt_in i 454 end 455 put bt_v 2 0 456 p = ulong 0 457 while lt p n bound `9223372036854775807` 458 q = p 459 while lt q n bound `9223372036854775807` 460 if eq get bt_mut q 10 461 break 462 end 463 q = add q 1 464 end 465 inc = false 466 if gt q p 467 inc = eq get bt_mut p 64 468 end 469 if inc 470 if not bt_include add p 1 q 471 ret false 472 end 473 else 474 bt_listadd p q 475 end 476 p = add q 1 477 end 478 ret true 479 end 480 fn bt_listadd s ulong e ulong to void 481 o = get bt_v 2 482 for i ulong sub e s 483 put bt_list add o i get bt_mut add s i 484 end 485 put bt_list add o sub e s 10 486 put bt_v 2 add add o sub e s 1 487 end 488 fn bt_include s ulong e ulong to bool 489 bt_pclear 490 m = e 491 while gt m s bound `9223372036854775807` 492 lc = get bt_mut sub m 1 493 if and ne lc 32 ne lc 13 494 break 495 end 496 m = sub m 1 497 end 498 for i ulong sub m s 499 put bt_path i get bt_mut add s i 500 end 501 put bt_v 6 sub m s 502 if not bt_load 503 ret false 504 end 505 o = get bt_v 2 506 k = get bt_v 1 507 for i ulong k 508 put bt_list add o i get bt_in i 509 end 510 put bt_list add o k 10 511 put bt_v 2 add add o k 1 512 ret true 513 end 514 515 fn bt_nameok to bool 516 for i ulong get bt_v 7 517 ch = get bt_unit i 518 lo = and ge ch 97 le ch 122 519 dg = and ge ch 48 le ch 57 520 pu = or eq ch 95 or eq ch 45 eq ch 46 521 if not or or lo dg pu 522 ret false 523 end 524 if and eq i 0 eq ch 46 525 ret false 526 end 527 end 528 ret true 529 end 530 531 fn main to int 532 c = ulong argcnt 533 if and ne c 2 ne c 4 534 bt_say bt_t_usage 535 ret 2 536 end 537 k = argread 1 bt_unit 0 4096 538 if or le k 0 gt k 200 539 bt_say bt_t_usage 540 ret 2 541 end 542 put bt_v 7 ulong k 543 if not bt_nameok 544 bt_say bt_t_badname 545 ret 2 546 end 547 if eq c 4 548 k = argread 3 bt_mname 0 8192 549 if le k 0 550 bt_say bt_t_usage 551 ret 2 552 end 553 put bt_v 10 ulong k 554 k = argread 2 bt_path 0 8192 555 if le k 0 556 bt_say bt_t_usage 557 ret 2 558 end 559 put bt_v 6 ulong k 560 if not bt_load 561 bt_ioerr 562 end 563 if not bt_mutfind 564 bt_say bt_t_mutbad 565 k = write 2 bt_mname 0 get bt_v 10 566 k = write 2 bt_t_nl 0 1 567 ret 3 568 end 569 put bt_v 4 1 570 end 571 note the unit list 572 bt_pclear 573 bt_padd bt_t_units 574 bt_paddunit 575 bt_padd bt_t_list 576 if not bt_load 577 bt_ioerr 578 end 579 if not bt_expand 580 bt_ioerr 581 end 582 ln = get bt_v 2 583 if eq get bt_v 4 1 584 u = get bt_v 7 585 for i ulong 4 586 put bt_unit add u i get bt_t_mut i 587 end 588 put bt_v 7 add u 4 589 end 590 put bt_v 0 0 591 bt_emitt bt_t_om2 592 bt_emitt bt_t_nl 593 p = ulong 0 594 while lt p ln bound `9223372036854775807` 595 q = p 596 while lt q ln bound `9223372036854775807` 597 if eq get bt_list q 10 598 break 599 end 600 q = add q 1 601 end 602 s = p 603 e = q 604 while lt s e bound `9223372036854775807` 605 if ne get bt_list s 32 606 break 607 end 608 s = add s 1 609 end 610 while gt e s bound `9223372036854775807` 611 lc = get bt_list sub e 1 612 if and ne lc 32 ne lc 13 613 break 614 end 615 e = sub e 1 616 end 617 if gt e s 618 if gt sub e s 8000 619 bt_say bt_t_usage 620 ret 2 621 end 622 bt_pclear 623 for i ulong sub e s 624 put bt_path i get bt_list add s i 625 put bt_cur i get bt_list add s i 626 end 627 put bt_v 6 sub e s 628 put bt_v 8 sub e s 629 if not bt_load 630 bt_ioerr 631 end 632 bt_source 633 end 634 p = add q 1 635 end 636 if eq get bt_v 9 1 637 bt_say bt_t_big 638 ret 2 639 end 640 if eq get bt_v 4 1 641 if ne get bt_v 5 1 642 bt_say bt_t_mutapply 643 bt_num get bt_v 5 644 bt_say bt_t_nl 645 ret 3 646 end 647 end 648 bt_outpath bt_t_om 649 if not bt_store 650 bt_ioerr 651 end 652 st = bt_omc 653 if ne st 0 654 bt_copyerr 655 bt_say bt_t_refused 656 k = write 2 bt_unit 0 get bt_v 7 657 bt_say bt_t_exit 658 bt_num st 659 bt_say bt_t_nl 660 ret 1 661 end 662 note rename build/UNIT.new to build/UNIT (or build/UNIT.mut) 663 bt_pkstart 2 664 bt_outpath bt_t_new 665 bt_pkpath 666 bt_outfinal 667 bt_pkpath 668 r = renames bt_pk 0 get bt_v 14 0 669 if lt r 0 670 bt_ioerr 671 end 672 bt_say bt_t_built 673 k = write 2 bt_unit 0 get bt_v 7 674 note (the unit name already ends in .mut for a mutant) 675 bt_say bt_t_nl 676 ret 0 677 end