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/bench/inference_cost/handover.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 / bench / inference_cost / handover.om` 986 lines ยท 18343 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note bench/inference_cost/handover.om -- the handover rule: does a candidate model take over a job 3 note (language, arm) from the incumbent? Decided from scoreboard run records only, in integers, 4 note with no person involved. 5 note 6 note Usage: handover LANG ARM PERMFILE INCUMBENT_DIR CANDIDATE_DIR... 7 note LANG om|c|py|rs, ARM plain|feedback. PERMFILE lists task ids that must never fail again 8 note (whitespace separated; it may be empty). Each *_DIR is a driver.sh --run-model directory 9 note holding run.txt and attempts.txt (wire version 2). 10 note Output: line 1 is HANDOVER YES, HANDOVER NO or HANDOVER REFUSED; then one line per rule with 11 note the counts that decided it; then "sha256 " for every input file (PERMFILE, then 12 note run.txt and attempts.txt of each run in argument order) so the decision can be rechecked. 13 note Exit: 0 YES, 1 NO, 2 REFUSED, 3 usage. 14 note 15 note Rules (README section "Handover rule"): 16 note 1 comparable: every run's task_set_sha256 and omc_sha256 equal the incumbent's, every run has 17 note the job's group, and every candidate names one reported model and the same model_requested 18 note and models_reported as the first candidate. Otherwise REFUSED. 19 note 2 evidence: at least 3 candidate runs, no two in one directory (device and inode) or with one 20 note started time. Otherwise REFUSED. 21 note 3 every candidate run verifies at least as many tasks of the job as the incumbent run. 22 note 4 every candidate run verifies every permanent case in the job. 23 note 5 complete: a run with a NOT_RUN or interrupted line or a NOT_RUN file, without a finished 24 note line, with rows.txt left over (an interrupted driver), without run.txt or attempts.txt, or 25 note whose attempts.txt the scorer refuses (truncated or malformed) makes the answer REFUSED. 26 note REFUSED wins over NO; NO when rule 3 or 4 fails; YES otherwise. 27 note 28 note Build (tests/handover/run.sh): { printf 'om2\n'; cat om/tls/sha2.om; 29 note sed '/^fn main to int$/,$d' bench/inference_cost/scorer.om; cat bench/inference_cost/handover.om; } | omc 30 note The attempt wire is read by scorer.om's own functions and tables (read_all, read_task, lang_idx, 31 note arm_idx, parse_row, record_task, require_eof), unchanged. Only scorer.om's fn main is left out, 32 note because a unit has one main, and its version-2 header loop is repeated in hv_wire. scorer.om 33 note stops the process (fail, exit 2) on a malformed wire, so every wire is first read in a forked 34 note child and the parent reads it again only after the child exited 0. 35 note Files are read twice (decision, then digest); they must not change while the program runs. 36 37 note two run.txt images: base 0 and base 983040 (the scorer's input byte limit) 38 global hvrun uchar `1966080` 39 global hvrlen ulong 2 40 global hvperm uchar 983040 41 global hvpermn ulong 1 42 note one argument (Linux PATH_MAX 4096) plus the longest file suffix 43 global hvpath uchar 4112 44 global hvpathn ulong 1 45 global hvst uchar 128 46 global hvwst uchar 4 47 global hvvo ulong 1 48 global hvvl ulong 1 49 global hvjob ulong 2 50 global hvid ulong 2 51 global hvc ulong 32 52 53 const HV_NOTRUN ulong 0 54 const HV_INTR ulong 1 55 const HV_MISS ulong 2 56 const HV_WIRE ulong 3 57 const HV_TSMIS ulong 4 58 const HV_OMCMIS ulong 5 59 const HV_MODMIS ulong 6 60 const HV_FMISS ulong 7 61 const HV_JOBABS ulong 8 62 const HV_DUPDIR ulong 9 63 const HV_DUPSTART ulong 10 64 const HV_INCV ulong 11 65 const HV_ATLEAST ulong 12 66 const HV_PERMOK ulong 13 67 const HV_CMIN ulong 14 68 const HV_PCASES ulong 15 69 const HV_CPARSED ulong 16 70 71 text hv_usage "usage: handover LANG ARM PERMFILE INCUMBENT_DIR CANDIDATE_DIR...\n" 72 text hv_frun "/run.txt" 73 text hv_fatt "/attempts.txt" 74 text hv_frows "/rows.txt" 75 text hv_fnr "/NOT_RUN" 76 text hv_tnr "NOT_RUN" 77 text hv_tint "interrupted" 78 text hv_kfin "finished" 79 text hv_kts "task_set_sha256" 80 text hv_komc "omc_sha256" 81 text hv_kmreq "model_requested" 82 text hv_kmrep "models_reported" 83 text hv_kstart "started" 84 85 fn hv_inc i ulong to void 86 put hvc i add get hvc i 1 87 end 88 89 fn hv_die to void 90 w = write 2 hv_usage 0 len hv_usage 91 exit 3 92 end 93 94 note hv_arg: argument a into hvpath[0..n), trailing slashes dropped; usage when empty or too long 95 fn hv_arg a ulong to ulong 96 k = argread a hvpath 0 4096 97 if le k 0 98 hv_die 99 end 100 n = ulong k 101 while gt n 1 bound 4096 102 if ne get hvpath sub n 1 47 103 break 104 end 105 n = sub n 1 106 end 107 put hvpathn 0 n 108 ret n 109 end 110 111 fn hv_add t view uchar * to ulong 112 n = get hvpathn 0 113 for i ulong len t 114 put hvpath add n i get t i 115 end 116 m = add n len t 117 put hvpathn 0 m 118 ret m 119 end 120 121 fn hv_exists to bool 122 s = stat hvpath 0 get hvpathn 0 hvst 0 128 123 ret ge s 0 124 end 125 126 fn hv_argeq n ulong t view uchar * to bool 127 if ne n len t 128 ret false 129 end 130 for i ulong n 131 if ne get hvpath i get t i 132 ret false 133 end 134 end 135 ret true 136 end 137 138 fn hv_langarg n ulong to ulong 139 if hv_argeq n l_om 140 ret 0 141 end 142 if hv_argeq n l_c 143 ret 1 144 end 145 if hv_argeq n l_py 146 ret 2 147 end 148 if hv_argeq n l_rs 149 ret 3 150 end 151 hv_die 152 ret 0 153 end 154 155 fn hv_armarg n ulong to ulong 156 if hv_argeq n a_plain 157 ret 0 158 end 159 if hv_argeq n a_feed 160 ret 1 161 end 162 hv_die 163 ret 0 164 end 165 166 note hv_load: the file at hvpath into hvrun at base; its length, -1 cannot open or read, -2 too large 167 fn hv_load base ulong to long 168 fd = int fopen hvpath 0 get hvpathn 0 0 0 169 if lt fd 0 170 ret -1 171 end 172 p = ulong 0 173 bad = false 174 note every pass adds at least one byte or leaves the loop 175 while lt p 983040 bound 999999 176 k = read fd hvrun add base p sub 983040 p 177 if lt k 0 178 bad = true 179 end 180 if le k 0 181 break 182 end 183 p = add p ulong k 184 end 185 c = fclose fd 186 if bad 187 ret -1 188 end 189 if eq p 983040 190 ret -2 191 end 192 put hvrlen div base 983040 p 193 ret long p 194 end 195 196 fn hv_loadrun r ulong base ulong to long 197 n = hv_arg add 4 r 198 m = hv_add hv_frun 199 ret hv_load base 200 end 201 202 fn hv_nextline s ulong lim ulong to ulong 203 p = s 204 while lt p lim bound 999999 205 if eq get hvrun p 10 206 ret add p 1 207 end 208 p = add p 1 209 end 210 ret lim 211 end 212 213 fn hv_startswith s ulong lim ulong t view uchar * to bool 214 if gt add s len t lim 215 ret false 216 end 217 for i ulong len t 218 if ne get hvrun add s i get t i 219 ret false 220 end 221 end 222 ret true 223 end 224 225 note hv_keyat: the line at s starts with key and a space 226 fn hv_keyat s ulong lim ulong key view uchar * to bool 227 e = add s len key 228 if ge e lim 229 ret false 230 end 231 if ne get hvrun e 32 232 ret false 233 end 234 ret hv_startswith s lim key 235 end 236 237 note hv_value: the value after the key's space, to the end of the line, trailing blanks dropped 238 fn hv_value v ulong lim ulong to void 239 s = v 240 while lt s lim bound 999999 241 if ne get hvrun s 32 242 break 243 end 244 s = add s 1 245 end 246 e = s 247 while lt e lim bound 999999 248 if eq get hvrun e 10 249 break 250 end 251 e = add e 1 252 end 253 while gt e s bound 999999 254 c = get hvrun sub e 1 255 if and ne c 32 and ne c 9 ne c 13 256 break 257 end 258 e = sub e 1 259 end 260 put hvvo 0 s 261 put hvvl 0 sub e s 262 end 263 264 note hv_find: key appears on exactly one line of the run image at base; its value in hvvo, hvvl 265 fn hv_find base ulong key view uchar * to bool 266 lim = add base get hvrlen div base 983040 267 s = base 268 hits = ulong 0 269 while lt s lim bound 999999 270 if hv_keyat s lim key 271 hits = add hits 1 272 hv_value add s len key lim 273 end 274 s = hv_nextline s lim 275 end 276 ret eq hits 1 277 end 278 279 note hv_scan: bit 0 a line starts NOT_RUN, bit 1 a line starts interrupted (image at base 0) 280 fn hv_scan to ulong 281 lim = get hvrlen 0 282 f = ulong 0 283 s = ulong 0 284 while lt s lim bound 999999 285 if hv_startswith s lim hv_tnr 286 f = or f 1 287 end 288 if hv_startswith s lim hv_tint 289 f = or f 2 290 end 291 s = hv_nextline s lim 292 end 293 ret f 294 end 295 296 fn hv_eqv ao ulong al ulong bo ulong bl ulong to bool 297 if ne al bl 298 ret false 299 end 300 for i ulong al 301 if ne get hvrun add ao i get hvrun add bo i 302 ret false 303 end 304 end 305 ret true 306 end 307 308 note hv_same_key: key once in both run images, nonempty and equal; a difference counts in c 309 fn hv_same_key key view uchar * c ulong to void 310 if not (hv_find 0 key) 311 hv_inc HV_FMISS 312 ret 313 end 314 ao = get hvvo 0 315 al = get hvvl 0 316 if not (hv_find 983040 key) 317 hv_inc HV_FMISS 318 ret 319 end 320 if or eq al 0 not (hv_eqv ao al get hvvo 0 get hvvl 0) 321 hv_inc c 322 end 323 end 324 325 note ---- the attempt wire, read by scorer.om's functions (version 2 only: the job needs lang, arm) 326 fn hv_wire to int 327 n = read_all 328 if eq n 0 329 ret 1 330 end 331 put inlen 0 n 332 put pos 0 0 333 skip_token 334 v = read_uint 335 if ne v 2 336 ret 3 337 end 338 skip_token 339 att_cnt = read_uint 340 for i ulong att_cnt 341 read_task 342 lg = lang_idx 343 am = arm_idx 344 parse_row mul add mul lg 2 am 12 345 end 346 require_eof 347 ret 0 348 end 349 350 fn hv_stdin to bool 351 fd = int fopen hvpath 0 get hvpathn 0 0 0 352 if lt fd 0 353 ret false 354 end 355 if eq fd 0 356 ret true 357 end 358 r = dupfd fd 0 0 359 c = fclose fd 360 ret eq r 0 361 end 362 363 fn hv_child to void 364 hv_reset 365 if not (hv_stdin) 366 exit 5 367 end 368 rc = hv_wire 369 exit rc 370 end 371 372 note hv_wirechk: the wire at hvpath read in a child; its exit status (0 accepted, 5 cannot open) 373 fn hv_wirechk to int 374 pid = fork 375 if lt pid 0 376 ret 7 377 end 378 if eq pid 0 379 hv_child 380 exit 9 381 end 382 r = waitpid int pid hvwst 0 4 0 383 if ne r pid 384 ret 8 385 end 386 s0 = ulong get hvwst 0 387 if ne and s0 127 0 388 ret 9 389 end 390 ret int get hvwst 1 391 end 392 393 fn hv_reset to void 394 for i ulong 96 395 put stats i 0 396 end 397 for i ulong 65536 398 put taskbeg i 0 399 put tasklen i 0 400 put taskgrp i 0 401 put taskatt i 0 402 put taskver i 0 403 end 404 end 405 406 fn hv_grp to ulong 407 ret mul add mul get hvjob 0 2 get hvjob 1 12 408 end 409 410 fn hv_same h ulong s ulong n ulong to bool 411 st = get taskbeg h 412 for i ulong n 413 if ne get inbuf add st i get hvperm add s i 414 ret false 415 end 416 end 417 ret true 418 end 419 420 note hv_pver: the permanent case hvperm[s .. s+n) is verified in group b of the parsed wire 421 fn hv_pver b ulong s ulong n ulong to bool 422 for h ulong 65536 423 if and eq get tasklen h n eq get taskgrp h b 424 if hv_same h s n 425 ret eq get taskver h 1 426 end 427 end 428 end 429 ret false 430 end 431 432 fn hv_ptokend s ulong lim ulong to ulong 433 e = s 434 while lt e lim bound 999999 435 if is_space (get hvperm e) 436 ret e 437 end 438 e = add e 1 439 end 440 ret lim 441 end 442 443 note hv_perm: b < 65536 checks every permanent case in group b; b = 65536 only counts them 444 fn hv_perm b ulong to ulong 445 lim = get hvpermn 0 446 s = ulong 0 447 bad = ulong 0 448 while lt s lim bound 999999 449 if is_space (get hvperm s) 450 s = add s 1 451 else 452 e = hv_ptokend s lim 453 if eq b 65536 454 bad = add bad 1 455 else 456 if not (hv_pver b s (sub e s)) 457 bad = add bad 1 458 end 459 end 460 s = e 461 end 462 end 463 ret bad 464 end 465 466 fn hv_loadperm to void 467 fd = int fopen hvpath 0 get hvpathn 0 0 0 468 if lt fd 0 469 hv_die 470 end 471 p = ulong 0 472 note every pass adds at least one byte or leaves the loop 473 while lt p 983040 bound 999999 474 k = read fd hvperm p sub 983040 p 475 if lt k 0 476 hv_die 477 end 478 if eq k 0 479 break 480 end 481 p = add p ulong k 482 end 483 c = fclose fd 484 if eq p 983040 485 hv_die 486 end 487 put hvpermn 0 p 488 put hvc HV_PCASES hv_perm 65536 489 end 490 491 fn hv_args to ulong 492 c = ulong argcnt 493 if lt c 6 494 hv_die 495 end 496 n1 = hv_arg 1 497 put hvjob 0 hv_langarg n1 498 n2 = hv_arg 2 499 put hvjob 1 hv_armarg n2 500 n3 = hv_arg 3 501 hv_loadperm 502 for i ulong sub c 4 503 n4 = hv_arg add i 4 504 end 505 ret sub c 5 506 end 507 508 note ---- rule 3 and 4 counts of one parsed run (r 0 is the incumbent) 509 fn hv_atleast cv ulong to bool 510 iv = get hvc HV_INCV 511 note rule 3: at least the incumbent's verified count 512 if ge cv iv 513 ret true 514 end 515 ret false 516 end 517 518 fn hv_tally r ulong to void 519 b = hv_grp 520 if eq get stats add b 9 0 521 hv_inc HV_JOBABS 522 ret 523 end 524 v = get stats add b 2 525 if eq r 0 526 put hvc HV_INCV v 527 ret 528 end 529 hv_inc HV_CPARSED 530 if hv_atleast v 531 hv_inc HV_ATLEAST 532 end 533 if or (eq get hvc HV_CPARSED 1) (lt v get hvc HV_CMIN) 534 put hvc HV_CMIN v 535 end 536 if eq (hv_perm b) 0 537 hv_inc HV_PERMOK 538 end 539 end 540 541 fn hv_parse r ulong to void 542 hv_reset 543 if not (hv_stdin) 544 hv_inc HV_WIRE 545 ret 546 end 547 rc = hv_wire 548 if ne rc 0 549 hv_inc HV_WIRE 550 ret 551 end 552 hv_tally r 553 end 554 555 note ---- rule 5 for run r, then its wire and counts 556 fn hv_run r ulong to void 557 n = hv_loadrun r 0 558 if lt n 0 559 hv_inc HV_MISS 560 ret 561 end 562 f = hv_scan 563 fin = hv_find 0 hv_kfin 564 n1 = hv_arg add 4 r 565 m1 = hv_add hv_frows 566 rows = hv_exists 567 n2 = hv_arg add 4 r 568 m2 = hv_add hv_fnr 569 nrf = hv_exists 570 if or (ne (and f 1) 0) nrf 571 hv_inc HV_NOTRUN 572 end 573 if or (or (ne (and f 2) 0) (not fin)) rows 574 hv_inc HV_INTR 575 end 576 n3 = hv_arg add 4 r 577 m3 = hv_add hv_fatt 578 st = hv_wirechk 579 if eq st 5 580 hv_inc HV_MISS 581 ret 582 end 583 if ne st 0 584 hv_inc HV_WIRE 585 ret 586 end 587 hv_parse r 588 end 589 590 note ---- rule 1 591 fn hv_cmp1 r ulong to void 592 n = hv_loadrun r 983040 593 if lt n 0 594 hv_inc HV_FMISS 595 ret 596 end 597 hv_same_key hv_kts HV_TSMIS 598 hv_same_key hv_komc HV_OMCMIS 599 end 600 601 fn hv_onetok to bool 602 o = get hvvo 0 603 for i ulong get hvvl 0 604 if eq get hvrun add o i 32 605 ret false 606 end 607 end 608 ret true 609 end 610 611 fn hv_cmpm r ulong to void 612 n = hv_loadrun r 983040 613 if lt n 0 614 hv_inc HV_FMISS 615 ret 616 end 617 hv_same_key hv_kmreq HV_MODMIS 618 hv_same_key hv_kmrep HV_MODMIS 619 if hv_find 983040 hv_kmrep 620 if not (hv_onetok) 621 hv_inc HV_MODMIS 622 end 623 end 624 end 625 626 fn hv_rule1 nc ulong to void 627 n0 = hv_loadrun 0 0 628 if lt n0 0 629 hv_inc HV_FMISS 630 else 631 for r ulong nc 632 hv_cmp1 add r 1 633 end 634 end 635 n1 = hv_loadrun 1 0 636 if lt n1 0 637 hv_inc HV_FMISS 638 ret 639 end 640 for i ulong nc 641 hv_cmpm add i 1 642 end 643 end 644 645 fn hv_r1ok to bool 646 a = and eq get hvc HV_TSMIS 0 eq get hvc HV_OMCMIS 0 647 b = and eq get hvc HV_MODMIS 0 eq get hvc HV_FMISS 0 648 ret and and a b eq get hvc HV_JOBABS 0 649 end 650 651 note ---- rule 2 652 fn hv_le64 o ulong to ulong 653 v = ulong 0 654 for i ulong 8 655 v = or shl v 8 ulong get hvst sub add o 7 i 656 end 657 ret v 658 end 659 660 fn hv_dirid r ulong to bool 661 n = hv_arg add 4 r 662 s = stat hvpath 0 n hvst 0 128 663 if lt s 0 664 ret false 665 end 666 put hvid 0 hv_le64 0 667 put hvid 1 hv_le64 8 668 ret true 669 end 670 671 fn hv_samedir j ulong dev ulong ino ulong to bool 672 if not (hv_dirid j) 673 ret false 674 end 675 ret and eq get hvid 0 dev eq get hvid 1 ino 676 end 677 678 note hv_samestart: run j (into base 983040) has the started value of the image at base 0 679 fn hv_samestart j ulong ao ulong al ulong to bool 680 n = hv_loadrun j 983040 681 if lt n 0 682 ret false 683 end 684 if not (hv_find 983040 hv_kstart) 685 ret true 686 end 687 ret hv_eqv ao al get hvvo 0 get hvvl 0 688 end 689 690 note hv_dupof: candidate r shares its directory or its started time with an earlier candidate 691 fn hv_dupof r ulong to void 692 n = hv_loadrun r 0 693 if lt n 0 694 ret 695 end 696 ds = false 697 if not (hv_find 0 hv_kstart) 698 ds = true 699 end 700 ao = get hvvo 0 701 al = get hvvl 0 702 if eq al 0 703 ds = true 704 end 705 ok = hv_dirid r 706 dev = get hvid 0 707 ino = get hvid 1 708 dd = false 709 for j ulong sub r 1 710 if and ok (hv_samedir add j 1 dev ino) 711 dd = true 712 end 713 if hv_samestart add j 1 ao al 714 ds = true 715 end 716 end 717 if dd 718 hv_inc HV_DUPDIR 719 end 720 if ds 721 hv_inc HV_DUPSTART 722 end 723 end 724 725 fn hv_rule2 nc ulong to void 726 for i ulong nc 727 hv_dupof add i 1 728 end 729 end 730 731 fn hv_r5ok to bool 732 a = and eq get hvc HV_NOTRUN 0 eq get hvc HV_INTR 0 733 b = and eq get hvc HV_MISS 0 eq get hvc HV_WIRE 0 734 ret and a b 735 end 736 737 note ---- output 738 fn hv_num v ulong to void 739 p = ulong 32 740 x = v 741 for i ulong 20 742 p = sub p 1 743 put obuf p uchar add rem x 10 48 744 x = div x 10 745 if eq x 0 746 break 747 end 748 end 749 w = write 1 obuf p sub 32 p 750 end 751 752 fn hv_pair t view uchar * v ulong to void 753 wtext t 754 hv_num v 755 end 756 757 text hv_tpass "PASS" 758 text hv_tfailw "FAIL" 759 text hv_tnot "NOT_EVALUATED" 760 fn hv_status ok bool to void 761 if ok 762 wtext hv_tpass 763 else 764 wtext hv_tfailw 765 end 766 end 767 768 text hv_tr1 "rule1 comparable " 769 text hv_tr1a " runs " 770 text hv_tr1b " task_set_mismatch " 771 text hv_tr1c " omc_mismatch " 772 text hv_tr1d " model_mismatch " 773 text hv_tr1e " fields_missing " 774 text hv_tr1f " job_absent " 775 fn hv_line1 nc ulong ok bool to void 776 wtext hv_tr1 777 hv_status ok 778 hv_pair hv_tr1a add nc 1 779 hv_pair hv_tr1b get hvc HV_TSMIS 780 hv_pair hv_tr1c get hvc HV_OMCMIS 781 hv_pair hv_tr1d get hvc HV_MODMIS 782 hv_pair hv_tr1e get hvc HV_FMISS 783 hv_pair hv_tr1f get hvc HV_JOBABS 784 wtext t_nl 785 end 786 787 text hv_tr2 "rule2 evidence " 788 text hv_tr2a " candidate_runs " 789 text hv_tr2b " distinct_dirs " 790 text hv_tr2c " distinct_starts " 791 text hv_tr2d " need 3\n" 792 fn hv_line2 nc ulong ok bool to void 793 wtext hv_tr2 794 hv_status ok 795 hv_pair hv_tr2a nc 796 hv_pair hv_tr2b sub nc get hvc HV_DUPDIR 797 hv_pair hv_tr2c sub nc get hvc HV_DUPSTART 798 wtext hv_tr2d 799 end 800 801 fn hv_label to void 802 l = get hvjob 0 803 if eq l 0 804 wtext l_om 805 end 806 if eq l 1 807 wtext l_c 808 end 809 if eq l 2 810 wtext l_py 811 end 812 if eq l 3 813 wtext l_rs 814 end 815 wtext t_sp 816 if eq get hvjob 1 0 817 wtext a_plain 818 else 819 wtext a_feed 820 end 821 end 822 823 text hv_tr3 "rule3 verified " 824 text hv_tr3a " job " 825 text hv_tr3b " incumbent " 826 text hv_tr3c " candidate_min " 827 text hv_tr3d " at_least " 828 text hv_tr3e " of " 829 fn hv_line3 nc ulong ok bool refused bool to void 830 wtext hv_tr3 831 if refused 832 wtext hv_tnot 833 else 834 hv_status ok 835 end 836 wtext hv_tr3a 837 hv_label 838 hv_pair hv_tr3b get hvc HV_INCV 839 hv_pair hv_tr3c get hvc HV_CMIN 840 hv_pair hv_tr3d get hvc HV_ATLEAST 841 hv_pair hv_tr3e nc 842 wtext t_nl 843 end 844 845 text hv_tr4 "rule4 permanent " 846 text hv_tr4a " cases " 847 text hv_tr4b " all_verified_in " 848 fn hv_line4 nc ulong ok bool refused bool to void 849 wtext hv_tr4 850 if refused 851 wtext hv_tnot 852 else 853 hv_status ok 854 end 855 hv_pair hv_tr4a get hvc HV_PCASES 856 hv_pair hv_tr4b get hvc HV_PERMOK 857 hv_pair hv_tr3e nc 858 wtext t_nl 859 end 860 861 text hv_tr5 "rule5 complete " 862 text hv_tr5a " not_run " 863 text hv_tr5b " interrupted " 864 text hv_tr5c " missing_files " 865 text hv_tr5d " wire_refused " 866 fn hv_line5 nc ulong ok bool to void 867 wtext hv_tr5 868 hv_status ok 869 hv_pair hv_tr1a add nc 1 870 hv_pair hv_tr5a get hvc HV_NOTRUN 871 hv_pair hv_tr5b get hvc HV_INTR 872 hv_pair hv_tr5c get hvc HV_MISS 873 hv_pair hv_tr5d get hvc HV_WIRE 874 wtext t_nl 875 end 876 877 text hv_hexd "`0123456789abcdef`" 878 text hv_tsha "sha256 " 879 text hv_tmiss "MISSING " 880 text hv_tunr "UNREADABLE " 881 fn hv_pathln to void 882 w = write 1 hvpath 0 get hvpathn 0 883 wtext t_nl 884 end 885 886 fn hv_hexout dig view uchar 32 to void 887 hx = new uchar 65 32 888 for i ulong 32 889 d = get dig i 890 put hx mul i 2 get hv_hexd ulong shr d 4 891 put hx add mul i 2 1 get hv_hexd ulong and d 15 892 end 893 w = write 1 hx 0 65 894 end 895 896 note hv_sha: "sha256 " for the file at hvpath 897 fn hv_sha to void 898 ctx = new ulong 40 0 899 buf = new uchar 65536 0 900 dig = new uchar 32 0 901 wtext hv_tsha 902 fd = int fopen hvpath 0 get hvpathn 0 0 0 903 if lt fd 0 904 wtext hv_tmiss 905 hv_pathln 906 ret 907 end 908 sha256_init ctx 909 more = true 910 bad = false 911 note every pass reads at least one byte or leaves the loop (files below 999999 * 64 KiB) 912 while more bound 999999 913 k = read fd buf 0 65536 914 if gt k 0 915 sha256_update ctx part buf 0 ulong k 916 else 917 more = false 918 if lt k 0 919 bad = true 920 end 921 end 922 end 923 c = fclose fd 924 if bad 925 wtext hv_tunr 926 else 927 sha256_final ctx dig 928 hv_hexout dig 929 end 930 hv_pathln 931 end 932 933 fn hv_digests nc ulong to void 934 n = hv_arg 3 935 hv_sha 936 for r ulong add nc 1 937 a1 = hv_arg add 4 r 938 b1 = hv_add hv_frun 939 hv_sha 940 a2 = hv_arg add 4 r 941 b2 = hv_add hv_fatt 942 hv_sha 943 end 944 end 945 946 text hv_tyes "HANDOVER YES\n" 947 text hv_tno "HANDOVER NO\n" 948 text hv_tref "HANDOVER REFUSED\n" 949 fn hv_report nc ulong to int 950 r5 = hv_r5ok 951 r1 = hv_r1ok 952 r2n = ge nc 3 953 r2 = and r2n and eq get hvc HV_DUPDIR 0 eq get hvc HV_DUPSTART 0 954 refused = not (and r1 and r2 r5) 955 r3ok = eq get hvc HV_ATLEAST nc 956 r4ok = eq get hvc HV_PERMOK nc 957 rc = int 0 958 if refused 959 wtext hv_tref 960 rc = 2 961 else 962 if and r3ok r4ok 963 wtext hv_tyes 964 else 965 wtext hv_tno 966 rc = 1 967 end 968 end 969 hv_line1 nc r1 970 hv_line2 nc r2 971 hv_line3 nc r3ok refused 972 hv_line4 nc r4ok refused 973 hv_line5 nc r5 974 hv_digests nc 975 ret rc 976 end 977 978 fn main to int 979 nc = hv_args 980 for r ulong add nc 1 981 hv_run r 982 end 983 hv_rule1 nc 984 hv_rule2 nc 985 ret hv_report nc 986 end