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-bridge/blob/main/tests/native/x86/check_physical_receipt.om # omega-bridge Omega-first language interoperability: checked conversion backends and native language bindings 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 `omega-bridge / tests / native / x86 / check_physical_receipt.om` 2233 lines ยท 36297 bytes Raw Blame History 1 om2 2 note check_physical_receipt.om: check a physical x86-64 receipt against docs/NATIVE-X86-PHYSICAL.md (DRA-104). 3 note usage: check_physical_receipt RECEIPT.json [LOGDIR], run from the repository root (it reads tools/native). 4 note LOGDIR defaults to the receipt path without its suffix (evidence/native-x86-physical-PIN8/). 5 note It reads only the receipt, its four logs and tools/native; it runs no compiler, caller or emulator. 6 note It refuses any receipt that is not a PHYSICAL NATIVE_PASS at the current x86 pin, including every 7 note EMULATED or VIRTUAL receipt, and any receipt whose logs do not show the suite's own NATIVE PASS line 8 note with virtualization=none and the hypervisor flag clear. Passing is a format and consistency check; 9 note it is not itself a run. Output: one PASS or FAIL line per check, then PHYSICAL-RECEIPT ACCEPTED (exit 0) 10 note or PHYSICAL-RECEIPT REJECTED (exit 1); a wrong argument count prints the usage line and exits 2. 11 note This program replaces check_physical_receipt.py (removed); the differences are listed in 12 note evidence/native-x86-physical-checker/README.md. 13 const PO ulong 0 14 const RL ulong 1 15 const NN ulong 2 16 const PU ulong 3 17 const SO ulong 4 18 const SL ulong 5 19 const NF ulong 6 20 const LN ulong 7 21 const FL ulong 8 22 const PL ulong 9 23 const DL ulong 10 24 const ABN ulong 11 25 const NBN ulong 12 26 const E1 ulong 13 27 const E2 ulong 14 28 const HX ulong 15 29 const HB ulong 16 30 const LS ulong 17 31 const LE ulong 18 32 const TL ulong 19 33 const FLAST ulong 20 34 const FEMU ulong 21 35 const FVIRT ulong 22 36 const FHYP ulong 23 37 const FFAIL ulong 24 38 const FCPU ulong 25 39 const FKERN ulong 26 40 const FCTRL ulong 27 41 const FWRONG ulong 28 42 const FMUT ulong 29 43 const OPN ulong 30 44 const BIGN ulong 31 45 const NODES ulong 524288 46 const RCAP ulong 900000 47 const FCAP ulong `16777215` 48 const KNONE ulong `4294967295` 49 global gv ulong 64 50 global rcp uchar `1048576` 51 global pool uchar `1048576` 52 global nty uchar 524288 53 global npa long 524288 54 global nko ulong 524288 55 global nkl ulong 524288 56 global nvo ulong 524288 57 global nvl ulong 524288 58 global nix ulong 524288 59 global fch long 524288 60 global nxs long 524288 61 global lch long 524288 62 global hfst ulong 524288 63 global hlst ulong 524288 64 global liv uchar 524288 65 global htab ulong `1048576` 66 global fbuf uchar `16777216` 67 global hexo uchar 64 68 global ln uchar `8388608` 69 global fl uchar `8388608` 70 global pth uchar 4096 71 global ldr uchar 4096 72 global ab uchar 4096 73 global nb uchar 4096 74 global opn uchar 8192 75 global xp uchar `2097152` 76 global pinb uchar 128 77 note SHA-256 (FIPS 180-4) of fbuf[0..n), digest as 64 lowercase hex bytes in hexo[0..64). 78 note The schedule, round and padding code is copied from omega-mv `e5b32567` om/sha256/sha256-om2.om 79 note (Apache-2.0), changed only to read the message from the global fbuf instead of an unsized view. 80 fn kinit k edit uint 64 to void 81 put k 0 0x428a2f98 82 put k 1 0x71374491 83 put k 2 0xb5c0fbcf 84 put k 3 0xe9b5dba5 85 put k 4 0x3956c25b 86 put k 5 0x59f111f1 87 put k 6 0x923f82a4 88 put k 7 0xab1c5ed5 89 put k 8 0xd807aa98 90 put k 9 0x12835b01 91 put k 10 0x243185be 92 put k 11 0x550c7dc3 93 put k 12 0x72be5d74 94 put k 13 0x80deb1fe 95 put k 14 0x9bdc06a7 96 put k 15 0xc19bf174 97 put k 16 0xe49b69c1 98 put k 17 0xefbe4786 99 put k 18 0x0fc19dc6 100 put k 19 0x240ca1cc 101 put k 20 0x2de92c6f 102 put k 21 0x4a7484aa 103 put k 22 0x5cb0a9dc 104 put k 23 0x76f988da 105 put k 24 0x983e5152 106 put k 25 0xa831c66d 107 put k 26 0xb00327c8 108 put k 27 0xbf597fc7 109 put k 28 0xc6e00bf3 110 put k 29 0xd5a79147 111 put k 30 0x06ca6351 112 put k 31 0x14292967 113 put k 32 0x27b70a85 114 put k 33 0x2e1b2138 115 put k 34 0x4d2c6dfc 116 put k 35 0x53380d13 117 put k 36 0x650a7354 118 put k 37 0x766a0abb 119 put k 38 0x81c2c92e 120 put k 39 0x92722c85 121 put k 40 0xa2bfe8a1 122 put k 41 0xa81a664b 123 put k 42 0xc24b8b70 124 put k 43 0xc76c51a3 125 put k 44 0xd192e819 126 put k 45 0xd6990624 127 put k 46 0xf40e3585 128 put k 47 0x106aa070 129 put k 48 0x19a4c116 130 put k 49 0x1e376c08 131 put k 50 0x2748774c 132 put k 51 0x34b0bcb5 133 put k 52 0x391c0cb3 134 put k 53 0x4ed8aa4a 135 put k 54 0x5b9cca4f 136 put k 55 0x682e6ff3 137 put k 56 0x748f82ee 138 put k 57 0x78a5636f 139 put k 58 0x84c87814 140 put k 59 0x8cc70208 141 put k 60 0x90befffa 142 put k 61 0xa4506ceb 143 put k 62 0xbef9a3f7 144 put k 63 0xc67178f2 145 end 146 fn iv s edit uint 8 to void 147 put s 0 0x6a09e667 148 put s 1 0xbb67ae85 149 put s 2 0x3c6ef372 150 put s 3 0xa54ff53a 151 put s 4 0x510e527f 152 put s 5 0x9b05688c 153 put s 6 0x1f83d9ab 154 put s 7 0x5be0cd19 155 end 156 fn sched w edit uint 64 o ulong to void 157 q = ulong 0 158 x = uint 0 159 y = uint 0 160 for i ulong 16 unroll 161 q = add o mul i 4 162 x = uint get fbuf q 163 x = or shl x 8 uint get fbuf add q 1 164 x = or shl x 8 uint get fbuf add q 2 165 put w i or shl x 8 uint get fbuf add q 3 166 end 167 for i ulong 48 unroll 168 x = get w add i 1 169 y = get w add i 14 170 x = add add get w i get w add i 9 xor xor rotr x 7 rotr x 18 shr x 3 171 put w add i 16 add x xor xor rotr y 17 rotr y 19 shr y 10 172 end 173 end 174 fn schedp w edit uint 64 p view uchar 128 o ulong to void 175 q = ulong 0 176 x = uint 0 177 y = uint 0 178 for i ulong 16 unroll 179 q = add o mul i 4 180 x = uint get p q 181 x = or shl x 8 uint get p add q 1 182 x = or shl x 8 uint get p add q 2 183 put w i or shl x 8 uint get p add q 3 184 end 185 for i ulong 48 unroll 186 x = get w add i 1 187 y = get w add i 14 188 x = add add get w i get w add i 9 xor xor rotr x 7 rotr x 18 shr x 3 189 put w add i 16 add x xor xor rotr y 17 rotr y 19 shr y 10 190 end 191 end 192 fn rounds s edit uint 8 w view uint 64 kt view uint 64 to void 193 a = get s 0 194 b = get s 1 195 c = get s 2 196 d = get s 3 197 e = get s 4 198 f = get s 5 199 g = get s 6 200 h = get s 7 201 t = uint 0 202 for i ulong 64 unroll 203 h = add h get kt i 204 h = add h get w i 205 t = xor rotr e 6 rotr e 11 206 t = xor t rotr e 25 207 h = add h t 208 h = add h xor g and e xor f g 209 d = add d h 210 t = xor rotr a 2 rotr a 13 211 t = xor t rotr a 22 212 h = add h t 213 t = and c or a b 214 h = add h or and a b t 215 t = h 216 h = g 217 g = f 218 f = e 219 e = d 220 d = c 221 c = b 222 b = a 223 a = t 224 end 225 put s 0 add get s 0 a 226 put s 1 add get s 1 b 227 put s 2 add get s 2 c 228 put s 3 add get s 3 d 229 put s 4 add get s 4 e 230 put s 5 add get s 5 f 231 put s 6 add get s 6 g 232 put s 7 add get s 7 h 233 end 234 text hexd "`0123456789abcdef`" 235 fn hexout s view uint 8 to void 236 for i ulong 8 237 v = get s i 238 for j2 ulong 8 239 sh = sub uint 28 mul uint j2 4 240 d = ulong and shr v sh 15 241 q = add mul i 8 j2 242 put hexo q get hexd d 243 end 244 end 245 end 246 fn tailblk s edit uint 8 w edit uint 64 kt view uint 64 n ulong to void 247 p = new uchar 128 0 248 off = shl shr n 6 6 249 k = sub n off 250 for i ulong k 251 put p i get fbuf add off i 252 end 253 put p k 0x80 254 e = ulong 64 255 if ge k 56 256 e = 128 257 end 258 bits = shl n 3 259 for i ulong 8 unroll 260 put p sub e add i 1 uchar and shr bits mul i 8 0xff 261 end 262 schedp w view p 0 263 rounds s view w kt 264 if eq e 128 265 schedp w view p 64 266 rounds s view w kt 267 end 268 end 269 fn shafbuf n ulong to void 270 s = new uint 8 0 271 w = new uint 64 0 272 kt = new uint 64 0 273 kinit kt 274 iv s 275 nbl = shr n 6 276 j = ulong 0 277 while lt j nbl bound 999999 278 sched w shl j 6 279 rounds s view w view kt 280 j = add j 1 281 end 282 tailblk s w view kt n 283 hexout view s 284 end 285 286 note ---- output: one check line is built in ln, then written as PASS/FAIL ---- 287 text tpass "PASS " 288 text tfail "FAIL " 289 note a line longer than ln (only from a pathological receipt value) is cut there 290 fn lnb b uchar to void 291 n = get gv LN 292 if ge n `8388608` 293 ret 294 end 295 put ln n b 296 put gv LN add n 1 297 end 298 fn lnt t view uchar * to void 299 for i ulong len t 300 lnb get t i 301 end 302 end 303 fn lnpool o ulong n ulong to void 304 for i ulong n 305 lnb get pool add o i 306 end 307 end 308 fn lndec v ulong to void 309 d = new uchar 24 0 310 k = ulong 0 311 x = v 312 go = true 313 while go bound 30 314 put d k uchar add 48 rem x 10 315 k = add k 1 316 x = div x 10 317 go = gt x 0 318 end 319 while gt k 0 bound 30 320 k = sub k 1 321 lnb get d k 322 end 323 end 324 fn lnhex v ulong nd ulong to void 325 k = nd 326 while gt k 0 bound 16 327 k = sub k 1 328 d = ulong and shr v mul k 4 15 329 lnb get hexd d 330 end 331 end 332 fn wln to void 333 n = get gv LN 334 o = ulong 0 335 while lt o n bound 999999 336 w = write 1 ln o sub n o 337 if le w 0 338 exit 3 339 end 340 o = add o ulong w 341 end 342 put gv LN 0 343 end 344 fn flkeep to void 345 f = get gv FL 346 if ge f `8388606` 347 ret 348 end 349 if gt f 0 350 put fl f 59 351 put fl add f 1 32 352 f = add f 2 353 end 354 n = get gv LN 355 if gt n sub `8388608` f 356 n = sub `8388608` f 357 end 358 for i ulong n 359 put fl add f i get ln i 360 end 361 put gv FL add f n 362 end 363 fn emit ok bool to void 364 if ok 365 w = write 1 tpass 0 5 366 else 367 w2 = write 1 tfail 0 5 368 nf = get gv NF 369 if lt nf 4 370 flkeep 371 end 372 put gv NF add nf 1 373 end 374 lnb 10 375 wln 376 end 377 fn chk t view uchar * ok bool to void 378 lnt t 379 emit ok 380 end 381 text trej "PHYSICAL-RECEIPT REJECTED (" 382 text tfailed " failed: " 383 text tacc "PHYSICAL-RECEIPT ACCEPTED (format and log consistency only; not a run)\n" 384 fn finish to int 385 nf = get gv NF 386 if eq nf 0 387 w = write 1 tacc 0 len tacc 388 ret 0 389 end 390 put gv LN 0 391 lnt trej 392 lndec nf 393 lnt tfailed 394 f = get gv FL 395 for i ulong f 396 lnb get fl i 397 end 398 lnb 41 399 lnb 10 400 wln 401 ret 1 402 end 403 404 note ---- JSON (RFC 8259 as Python json.loads accepts it, without NaN/Infinity) into a node table ---- 405 note node j: nty 1 object, 2 array, 3 string, 4 integer, 8 number with a fraction, 9 number with an 406 note exponent, 5 true, 6 false, 7 null; npa parent (-1 for the top value); nko/nkl the member key in pool 407 note (nkl KNONE for array elements, which carry their index in nix); nvo/nvl the decoded string or the 408 note number's text in pool. Every pass of each loop consumes at least one receipt byte (at most RCAP). 409 fn pk to long 410 p = get gv PO 411 if lt p get gv RL 412 ret long get rcp p 413 end 414 ret -1 415 end 416 fn adv to void 417 put gv PO add get gv PO 1 418 end 419 fn skipws to void 420 go = true 421 while go bound 999999 422 c = pk 423 go = or or eq c 32 eq c 9 or eq c 10 eq c 13 424 if go 425 adv 426 end 427 end 428 end 429 fn isdig c long to bool 430 ret and ge c 48 le c 57 431 end 432 fn hexv c long to long 433 if isdig c 434 ret sub c 48 435 end 436 if and ge c 97 le c 102 437 ret sub c 87 438 end 439 if and ge c 65 le c 70 440 ret sub c 55 441 end 442 ret -1 443 end 444 fn hex4 to long 445 v = long 0 446 for i ulong 4 447 h = hexv pk 448 if lt h 0 449 ret -1 450 end 451 v = add mul v 16 h 452 adv 453 end 454 ret v 455 end 456 fn pput b ulong to void 457 u = get gv PU 458 put pool u uchar b 459 put gv PU add u 1 460 end 461 fn putcp cp ulong to void 462 if lt cp 128 463 pput cp 464 ret 465 end 466 if lt cp 2048 467 pput or 192 shr cp 6 468 pput or 128 and cp 63 469 ret 470 end 471 if lt cp 65536 472 pput or 224 shr cp 12 473 pput or 128 and shr cp 6 63 474 pput or 128 and cp 63 475 ret 476 end 477 pput or 240 shr cp 18 478 pput or 128 and shr cp 12 63 479 pput or 128 and shr cp 6 63 480 pput or 128 and cp 63 481 end 482 fn lowsur v long to long 483 if or lt v 0xd800 ge v 0xdc00 484 ret v 485 end 486 p = get gv PO 487 if ne pk 92 488 ret v 489 end 490 adv 491 if ne pk 117 492 put gv PO p 493 ret v 494 end 495 adv 496 w = hex4 497 if and ge w 0xdc00 lt w 0xe000 498 ret add 0x10000 add shl sub v 0xd800 10 sub w 0xdc00 499 end 500 put gv PO p 501 ret v 502 end 503 fn pesc to bool 504 c = pk 505 if lt c 0 506 ret false 507 end 508 adv 509 if eq c 117 510 v = hex4 511 if lt v 0 512 ret false 513 end 514 v2 = lowsur v 515 putcp ulong v2 516 ret true 517 end 518 m = long -1 519 if or eq c 34 or eq c 92 eq c 47 520 m = c 521 end 522 if eq c 98 523 m = 8 524 end 525 if eq c 102 526 m = 12 527 end 528 if eq c 110 529 m = 10 530 end 531 if eq c 114 532 m = 13 533 end 534 if eq c 116 535 m = 9 536 end 537 if lt m 0 538 ret false 539 end 540 pput ulong m 541 ret true 542 end 543 fn pstr to bool 544 if ne pk 34 545 ret false 546 end 547 adv 548 put gv SO get gv PU 549 go = true 550 while go bound 999999 551 c = pk 552 if lt c 32 553 ret false 554 end 555 adv 556 if eq c 34 557 go = false 558 else 559 if eq c 92 560 ok = pesc 561 if not ok 562 ret false 563 end 564 else 565 pput ulong c 566 end 567 end 568 end 569 put gv SL sub get gv PU get gv SO 570 ret true 571 end 572 fn digs to ulong 573 k = ulong 0 574 while isdig pk bound 999999 575 adv 576 k = add k 1 577 end 578 ret k 579 end 580 fn pnum to long 581 s = get gv PO 582 if eq pk 45 583 adv 584 end 585 c = pk 586 if eq c 48 587 adv 588 else 589 if not isdig c 590 ret -1 591 end 592 d = digs 593 end 594 ty = long 4 595 if eq pk 46 596 adv 597 if eq digs 0 598 ret -1 599 end 600 ty = 8 601 end 602 c = pk 603 if or eq c 101 eq c 69 604 adv 605 c = pk 606 if or eq c 43 eq c 45 607 adv 608 end 609 if eq digs 0 610 ret -1 611 end 612 ty = 9 613 end 614 put gv SO get gv PU 615 e = get gv PO 616 while lt s e bound 999999 617 pput ulong get rcp s 618 s = add s 1 619 end 620 put gv SL sub get gv PU get gv SO 621 ret ty 622 end 623 fn plit t view uchar * to bool 624 for i ulong len t 625 if ne pk long get t i 626 ret false 627 end 628 adv 629 end 630 ret true 631 end 632 note ---- object members: a hash of (parent, key) finds the first member with that key (hfst) and the 633 note last one (hlst of the first), so lookups and Python dict order cost one probe, not a scan ---- 634 fn hpool p long o ulong k ulong to ulong 635 h = ulong 0xcbf29ce484222325 636 h = xor h ulong add p 1 637 h = mul h 0x100000001b3 638 for i ulong k 639 h = xor h ulong get pool add o i 640 h = mul h 0x100000001b3 641 end 642 r = and h `1048575` 643 ret r 644 end 645 fn htext p long t view uchar * to ulong 646 h = ulong 0xcbf29ce484222325 647 h = xor h ulong add p 1 648 h = mul h 0x100000001b3 649 for i ulong len t 650 h = xor h ulong get t i 651 h = mul h 0x100000001b3 652 end 653 r = and h `1048575` 654 ret r 655 end 656 fn sibeq a ulong b ulong to bool 657 if ne get nkl a get nkl b 658 ret false 659 end 660 oa = get nko a 661 ob = get nko b 662 k = get nkl a 663 for i ulong k 664 x = get pool add oa i 665 if ne x get pool add ob i 666 ret false 667 end 668 end 669 ret true 670 end 671 note at most NODES entries in `1048576` slots, so a probe always reaches an empty slot 672 fn hput n ulong to void 673 p = get npa n 674 s = hpool p get nko n get nkl n 675 go = true 676 while go bound 999999 677 v = get htab s 678 if eq v 0 679 put htab s add n 1 680 put hfst n n 681 put hlst n n 682 ret 683 end 684 m = sub v 1 685 if eq get npa m p 686 if sibeq m n 687 put hfst n m 688 put hlst m n 689 ret 690 end 691 end 692 s = and add s 1 `1048575` 693 end 694 end 695 fn keyeq j ulong t view uchar * to bool 696 if ne get nkl j len t 697 ret false 698 end 699 o = get nko j 700 for i ulong len t 701 if ne get pool add o i get t i 702 ret false 703 end 704 end 705 ret true 706 end 707 fn dget par long t view uchar * to long 708 if lt par 0 709 ret -1 710 end 711 if ne get nty par 1 712 ret -1 713 end 714 s = htext par t 715 go = true 716 while go bound 999999 717 v = get htab s 718 if eq v 0 719 ret -1 720 end 721 m = sub v 1 722 if eq get npa m par 723 if keyeq m t 724 ret long get hlst m 725 end 726 end 727 s = and add s 1 `1048575` 728 end 729 ret -1 730 end 731 fn newnd ty uchar par long ko ulong kl ulong ix ulong to long 732 n = get gv NN 733 if ge n NODES 734 ret -1 735 end 736 put nty n ty 737 put npa n par 738 put nko n ko 739 put nkl n kl 740 put nix n ix 741 put nvo n get gv SO 742 put nvl n get gv SL 743 put fch n -1 744 put nxs n -1 745 put lch n -1 746 if ge par 0 747 l = get lch par 748 if lt l 0 749 put fch par long n 750 else 751 put nxs l long n 752 end 753 put lch par long n 754 end 755 if ne kl KNONE 756 hput n 757 end 758 put gv NN add n 1 759 ret long n 760 end 761 text ttrue "true" 762 text tfalse "false" 763 text tnull "null" 764 fn pobj par long ko ulong kl ulong ix ulong dep ulong to bool 765 n = newnd 1 par ko kl ix 766 if lt n 0 767 ret false 768 end 769 adv 770 skipws 771 if eq pk 125 772 adv 773 ret true 774 end 775 go = true 776 while go bound 999999 777 skipws 778 ok = pstr 779 if not ok 780 ret false 781 end 782 k0 = get gv SO 783 k1 = get gv SL 784 skipws 785 if ne pk 58 786 ret false 787 end 788 adv 789 ok2 = pval n k0 k1 0 add dep 1 790 if not ok2 791 ret false 792 end 793 skipws 794 c = pk 795 adv 796 if eq c 125 797 go = false 798 else 799 if ne c 44 800 ret false 801 end 802 end 803 end 804 ret true 805 end 806 fn parr par long ko ulong kl ulong ix ulong dep ulong to bool 807 n = newnd 2 par ko kl ix 808 if lt n 0 809 ret false 810 end 811 adv 812 skipws 813 if eq pk 93 814 adv 815 ret true 816 end 817 i = ulong 0 818 go = true 819 while go bound 999999 820 ok = pval n 0 KNONE i add dep 1 821 if not ok 822 ret false 823 end 824 i = add i 1 825 skipws 826 c = pk 827 adv 828 if eq c 93 829 go = false 830 else 831 if ne c 44 832 ret false 833 end 834 end 835 end 836 ret true 837 end 838 fn pscal par long ko ulong kl ulong ix ulong to bool 839 c = pk 840 ty = long 0 841 if eq c 34 842 ok = pstr 843 if not ok 844 ret false 845 end 846 ty = 3 847 end 848 if eq c 116 849 if not plit ttrue 850 ret false 851 end 852 ty = 5 853 end 854 if eq c 102 855 if not plit tfalse 856 ret false 857 end 858 ty = 6 859 end 860 if eq c 110 861 if not plit tnull 862 ret false 863 end 864 ty = 7 865 end 866 if or eq c 45 isdig c 867 ty = pnum 868 end 869 if le ty 0 870 ret false 871 end 872 n = newnd uchar ty par ko kl ix 873 ret ge n 0 874 end 875 fn pval par long ko ulong kl ulong ix ulong dep ulong to bool 876 if gt dep 900 877 ret false 878 end 879 skipws 880 c = pk 881 if eq c 123 882 ret pobj par ko kl ix dep 883 end 884 if eq c 91 885 ret parr par ko kl ix dep 886 end 887 ret pscal par ko kl ix 888 end 889 890 note ---- receipt bytes must be UTF-8 (Python read_text then json.loads) ---- 891 fn cont p ulong lo ulong hi ulong to bool 892 if ge p get gv RL 893 ret false 894 end 895 b = ulong get rcp p 896 ret and ge b lo le b hi 897 end 898 fn u8len p ulong to ulong 899 b = ulong get rcp p 900 if lt b 0x80 901 ret 1 902 end 903 if and ge b 0xc2 le b 0xdf 904 if cont add p 1 0x80 0xbf 905 ret 2 906 end 907 ret 0 908 end 909 lo = ulong 0x80 910 hi = ulong 0xbf 911 if eq b 0xe0 912 lo = 0xa0 913 end 914 if eq b 0xed 915 hi = 0x9f 916 end 917 if and ge b 0xe0 le b 0xef 918 if and cont add p 1 lo hi cont add p 2 0x80 0xbf 919 ret 3 920 end 921 ret 0 922 end 923 if eq b 0xf0 924 lo = 0x90 925 end 926 if eq b 0xf4 927 hi = 0x8f 928 end 929 if and ge b 0xf0 le b 0xf4 930 if and cont add p 1 lo hi and cont add p 2 0x80 0xbf cont add p 3 0x80 0xbf 931 ret 4 932 end 933 end 934 ret 0 935 end 936 fn utf8ok to long 937 p = ulong 0 938 n = get gv RL 939 while lt p n bound 999999 940 k = u8len p 941 if eq k 0 942 ret long p 943 end 944 p = add p k 945 end 946 ret -1 947 end 948 note ---- node lookups (a repeated key: the last one wins, as in a Python dict) ---- 949 fn isobj n long to bool 950 if lt n 0 951 ret false 952 end 953 ret eq get nty n 1 954 end 955 fn nch par long to ulong 956 if lt par 0 957 ret 0 958 end 959 if ne get nty par 2 960 ret 0 961 end 962 c = ulong 0 963 j = get fch par 964 while ge j 0 bound 999999 965 c = add c 1 966 j = get nxs j 967 end 968 ret c 969 end 970 fn aget par long i ulong to long 971 if lt par 0 972 ret -1 973 end 974 if ne get nty par 2 975 ret -1 976 end 977 j = get fch par 978 while ge j 0 bound 999999 979 if eq get nix j i 980 ret j 981 end 982 j = get nxs j 983 end 984 ret -1 985 end 986 note ---- value tests ---- 987 fn peq o ulong n ulong t view uchar * to bool 988 if ne n len t 989 ret false 990 end 991 for i ulong n 992 if ne get pool add o i get t i 993 ret false 994 end 995 end 996 ret true 997 end 998 fn vstr n long t view uchar * to bool 999 if lt n 0 1000 ret false 1001 end 1002 if ne get nty n 3 1003 ret false 1004 end 1005 ret peq get nvo n get nvl n t 1006 end 1007 fn psub o ulong n ulong t view uchar * to bool 1008 m = len t 1009 if lt n m 1010 ret false 1011 end 1012 s = ulong 0 1013 while le s sub n m bound 999999 1014 if peq add o s m t 1015 ret true 1016 end 1017 s = add s 1 1018 end 1019 ret false 1020 end 1021 fn vsub n long t view uchar * to bool 1022 if lt n 0 1023 ret false 1024 end 1025 if ne get nty n 3 1026 ret false 1027 end 1028 ret psub get nvo n get nvl n t 1029 end 1030 note value == d for d 0 or 1 with exact decimal arithmetic: true is 1, false is 0, and a number is 1031 note compared by its digits and exponent (-0, 1.0, 10e-1, 0e5 all count). Python compares the binary64 1032 note rounding instead, so a number like 1.`00000000000000001` that only rounds to 1 is refused here. 1033 fn numcls n long to ulong 1034 o = get nvo n 1035 e = add o get nvl n 1036 if eq get pool o 45 1037 o = add o 1 1038 end 1039 ipe = e 1040 st = ulong 0 1041 nz = ulong 0 1042 dig = ulong 0 1043 pz = ulong 0 1044 ex = long 0 1045 while lt o e bound 999999 1046 c = ulong get pool o 1047 if or eq c 46 or eq c 101 eq c 69 1048 if eq st 0 1049 ipe = o 1050 end 1051 st = 1 1052 if ne c 46 1053 st = 2 1054 end 1055 else 1056 if eq c 45 1057 st = 3 1058 else 1059 if lt st 2 1060 if and ne c 43 ne c 48 1061 nz = add nz 1 1062 dig = c 1063 pz = o 1064 end 1065 else 1066 if and ne c 43 lt ex `100000000` 1067 ex = add mul ex 10 long sub c 48 1068 end 1069 end 1070 end 1071 end 1072 o = add o 1 1073 end 1074 if eq nz 0 1075 ret 0 1076 end 1077 s0 = get nvo n 1078 if eq get pool s0 45 1079 ret 2 1080 end 1081 if or ne nz 1 ne dig 49 1082 ret 2 1083 end 1084 if eq st 3 1085 ex = neg ex 1086 end 1087 r = add long ipe ex 1088 if lt pz ipe 1089 r = sub r 1 1090 end 1091 if eq long pz r 1092 ret 1 1093 end 1094 ret 2 1095 end 1096 fn numis n long d ulong to bool 1097 if lt n 0 1098 ret false 1099 end 1100 t = get nty n 1101 if eq t 5 1102 ret eq d 1 1103 end 1104 if eq t 6 1105 ret eq d 0 1106 end 1107 if and and ne t 4 ne t 8 ne t 9 1108 ret false 1109 end 1110 ret eq numcls n d 1111 end 1112 fn cplen o ulong to ulong 1113 b = get pool o 1114 if lt b 0x80 1115 ret 1 1116 end 1117 if lt b 0xe0 1118 ret 2 1119 end 1120 if lt b 0xf0 1121 ret 3 1122 end 1123 ret 4 1124 end 1125 fn cpat o ulong to ulong 1126 b = ulong get pool o 1127 k = cplen o 1128 if eq k 1 1129 ret b 1130 end 1131 v = ulong and b 0x1f 1132 if eq k 3 1133 v = and b 0x0f 1134 end 1135 if eq k 4 1136 v = and b 0x07 1137 end 1138 for i ulong sub k 1 1139 v = or shl v 6 and ulong get pool add o add i 1 0x3f 1140 end 1141 ret v 1142 end 1143 fn isspc cp ulong to bool 1144 if or and ge cp 9 le cp 13 and ge cp 28 le cp 32 1145 ret true 1146 end 1147 if or or eq cp 0x85 eq cp 0xa0 or eq cp 0x1680 and ge cp 0x2000 le cp 0x200a 1148 ret true 1149 end 1150 ret or or eq cp 0x2028 eq cp 0x2029 or or eq cp 0x202f eq cp 0x205f eq cp 0x3000 1151 end 1152 note text(v): a string that is not empty after Python str.strip() 1153 fn vtext n long to bool 1154 if lt n 0 1155 ret false 1156 end 1157 if ne get nty n 3 1158 ret false 1159 end 1160 o = get nvo n 1161 e = add o get nvl n 1162 while lt o e bound 999999 1163 if not isspc cpat o 1164 ret true 1165 end 1166 o = add o cplen o 1167 end 1168 ret false 1169 end 1170 fn ishexs n long k ulong to bool 1171 if lt n 0 1172 ret false 1173 end 1174 if ne get nty n 3 1175 ret false 1176 end 1177 if ne get nvl n k 1178 ret false 1179 end 1180 o = get nvo n 1181 for i ulong k 1182 c = long get pool add o i 1183 if not or isdig c and ge c 97 le c 102 1184 ret false 1185 end 1186 end 1187 ret true 1188 end 1189 1190 note ---- Python repr() and str() of a JSON value, appended to the check line ---- 1191 text tnone "None" 1192 text ttru "True" 1193 text tfls "False" 1194 fn npr cp ulong to bool 1195 if or le cp 0xa0 eq cp 0xad 1196 ret true 1197 end 1198 if or and ge cp 0xd800 le cp 0xf8ff or eq cp 0x1680 and ge cp 0x2000 le cp 0x200f 1199 ret true 1200 end 1201 if or and ge cp 0x2028 le cp 0x202f or eq cp 0x205f and ge cp 0x2060 le cp 0x206f 1202 ret true 1203 end 1204 ret or or eq cp 0x3000 eq cp 0xfeff and ge cp 0xfff9 le cp 0xfffb 1205 end 1206 fn rpcp cp ulong q ulong o ulong k ulong to void 1207 if or eq cp q eq cp 92 1208 lnb 92 1209 lnb uchar cp 1210 ret 1211 end 1212 if eq cp 9 1213 lnb 92 1214 lnb 116 1215 ret 1216 end 1217 if eq cp 10 1218 lnb 92 1219 lnb 110 1220 ret 1221 end 1222 if eq cp 13 1223 lnb 92 1224 lnb 114 1225 ret 1226 end 1227 if and ge cp 32 lt cp 127 1228 lnb uchar cp 1229 ret 1230 end 1231 if and lt cp 128 or lt cp 32 eq cp 127 1232 lnb 92 1233 lnb 120 1234 lnhex cp 2 1235 ret 1236 end 1237 if npr cp 1238 lnb 92 1239 if le cp 0xff 1240 lnb 120 1241 lnhex cp 2 1242 else 1243 lnb 117 1244 lnhex cp 4 1245 end 1246 ret 1247 end 1248 lnpool o k 1249 end 1250 fn rpstr o ulong n ulong to void 1251 sq = false 1252 dq = false 1253 for i ulong n 1254 b = get pool add o i 1255 if eq b 39 1256 sq = true 1257 end 1258 if eq b 34 1259 dq = true 1260 end 1261 end 1262 q = ulong 39 1263 if and sq not dq 1264 q = 34 1265 end 1266 lnb uchar q 1267 i = ulong 0 1268 while lt i n bound 999999 1269 p = add o i 1270 k = cplen p 1271 rpcp cpat p q p k 1272 i = add i k 1273 end 1274 lnb uchar q 1275 end 1276 fn rpnum n long to void 1277 o = get nvo n 1278 k = get nvl n 1279 if eq get nty n 4 1280 if eq k 2 1281 if and eq get pool o 45 eq get pool add o 1 48 1282 lnb 48 1283 ret 1284 end 1285 end 1286 end 1287 lnpool o k 1288 end 1289 fn rpobj n long to void 1290 lnb 123 1291 c = ulong 0 1292 j = get fch n 1293 while ge j 0 bound 999999 1294 u = ulong j 1295 if eq get hfst u u 1296 if gt c 0 1297 lnb 44 1298 lnb 32 1299 end 1300 rpstr get nko u get nkl u 1301 lnb 58 1302 lnb 32 1303 prep long get hlst u 1304 c = add c 1 1305 end 1306 j = get nxs u 1307 end 1308 lnb 125 1309 end 1310 fn rparr n long to void 1311 lnb 91 1312 j = get fch n 1313 while ge j 0 bound 999999 1314 if ne j get fch n 1315 lnb 44 1316 lnb 32 1317 end 1318 prep j 1319 j = get nxs j 1320 end 1321 lnb 93 1322 end 1323 fn prep n long to void 1324 if lt n 0 1325 lnt tnone 1326 ret 1327 end 1328 t = get nty n 1329 if eq t 3 1330 rpstr get nvo n get nvl n 1331 ret 1332 end 1333 if eq t 5 1334 lnt ttru 1335 ret 1336 end 1337 if eq t 6 1338 lnt tfls 1339 ret 1340 end 1341 if eq t 7 1342 lnt tnone 1343 ret 1344 end 1345 if eq t 1 1346 rpobj n 1347 ret 1348 end 1349 if eq t 2 1350 rparr n 1351 ret 1352 end 1353 rpnum n 1354 end 1355 fn pstrv n long to void 1356 if ge n 0 1357 if eq get nty n 3 1358 lnpool get nvo n get nvl n 1359 ret 1360 end 1361 end 1362 prep n 1363 end 1364 note the receipt (its live members only, as json.dumps sees the dict) names EMULATED anywhere 1365 text temu "EMULATED" 1366 note live: the member json.dumps would see, i.e. no later sibling has its key and its parent is live; 1367 note parents come before children in the node table, so one forward pass fills liv 1368 fn sayemu to bool 1369 k = get gv NN 1370 for j ulong k 1371 p = get npa j 1372 ok = true 1373 if ge p 0 1374 ok = eq get liv p 1 1375 end 1376 if ne get nkl j KNONE 1377 if ne get hlst get hfst j j 1378 ok = false 1379 end 1380 end 1381 put liv j 0 1382 if ok 1383 put liv j 1 1384 if ne get nkl j KNONE 1385 if psub get nko j get nkl j temu 1386 ret true 1387 end 1388 end 1389 if eq get nty j 3 1390 if psub get nvo j get nvl j temu 1391 ret true 1392 end 1393 end 1394 end 1395 end 1396 ret false 1397 end 1398 1399 note ---- paths: Python pathlib display (str(Path(arg))) and Path.with_suffix("") ---- 1400 fn nbb b uchar to void 1401 k = get gv NBN 1402 put nb k b 1403 put gv NBN add k 1 1404 end 1405 note normalise ab[0..ABN) into nb: repeated slashes and "." parts dropped, "//" kept at the start 1406 fn normp to void 1407 n = get gv ABN 1408 put gv NBN 0 1409 pre = ulong 0 1410 if gt n 0 1411 if eq get ab 0 47 1412 nbb 47 1413 pre = 1 1414 if gt n 1 1415 if eq get ab 1 47 1416 if or eq n 2 ne get ab 2 47 1417 nbb 47 1418 pre = 2 1419 end 1420 end 1421 end 1422 end 1423 end 1424 i = ulong 0 1425 while lt i n bound 4097 1426 if eq get ab i 47 1427 i = add i 1 1428 continue 1429 end 1430 j = i 1431 while lt j n bound 4097 1432 if eq get ab j 47 1433 break 1434 end 1435 j = add j 1 1436 end 1437 dot = and eq sub j i 1 eq get ab i 46 1438 if not dot 1439 if gt get gv NBN pre 1440 nbb 47 1441 end 1442 for k ulong sub j i 1443 nbb get ab add i k 1444 end 1445 end 1446 i = j 1447 end 1448 if eq get gv NBN 0 1449 nbb 46 1450 end 1451 end 1452 fn rdarg i ulong to void 1453 r = argread i ab 0 4096 1454 if lt r 0 1455 exit 2 1456 end 1457 put gv ABN ulong r 1458 normp 1459 end 1460 note start of the last path part of nb (the name); equal to NBN when the name is empty 1461 fn namest to ulong 1462 k = get gv NBN 1463 if and eq k 1 eq get nb 0 46 1464 ret 1 1465 end 1466 i = k 1467 while gt i 0 bound 4097 1468 if eq get nb sub i 1 47 1469 ret i 1470 end 1471 i = sub i 1 1472 end 1473 ret 0 1474 end 1475 fn topth to void 1476 k = get gv NBN 1477 for i ulong k 1478 put pth i get nb i 1479 end 1480 put gv PL k 1481 end 1482 fn toldr k ulong to void 1483 for i ulong k 1484 put ldr i get nb i 1485 end 1486 put gv DL k 1487 end 1488 note logdir default: the receipt path without its suffix (Python Path.suffix: 0 < rfind(".") < len-1) 1489 fn dfltdir to void 1490 k = get gv NBN 1491 s = namest 1492 c = k 1493 i = k 1494 while gt i s bound 4097 1495 i = sub i 1 1496 if eq get nb i 46 1497 c = i 1498 break 1499 end 1500 end 1501 if or eq c k or eq c s eq c sub k 1 1502 c = k 1503 end 1504 toldr c 1505 end 1506 note ---- tools/native pins: the first line exactly KEY= plus 64 lowercase hex ---- 1507 text tpin "PIN=" 1508 text tx86 "X86_PIN=" 1509 fn fhex p ulong to bool 1510 c = long get fbuf p 1511 ret or isdig c and ge c 97 le c 102 1512 end 1513 fn pinln s ulong e ulong t view uchar * to bool 1514 k = len t 1515 if ne sub e s add k 64 1516 ret false 1517 end 1518 for i ulong k 1519 if ne get fbuf add s i get t i 1520 ret false 1521 end 1522 end 1523 for i ulong 64 1524 if not fhex add s add k i 1525 ret false 1526 end 1527 end 1528 ret true 1529 end 1530 text tnat "tools/native" 1531 fn rdfile fd int to long 1532 n = ulong 0 1533 go = true 1534 while go bound 999999 1535 r = read fd fbuf n sub FCAP n 1536 if lt r 0 1537 ret r 1538 end 1539 if eq r 0 1540 go = false 1541 else 1542 n = add n ulong r 1543 if eq n FCAP 1544 r2 = read fd fbuf n 1 1545 if ne r2 0 1546 ret -27 1547 end 1548 go = false 1549 end 1550 end 1551 end 1552 ret long n 1553 end 1554 fn natpins to void 1555 put gv HX 0 1556 put gv HB 0 1557 fd = fopen tnat 0 len tnat 0 0 1558 if lt fd 0 1559 ret 1560 end 1561 n = rdfile int fd 1562 c = fclose int fd 1563 if lt n 0 1564 ret 1565 end 1566 s = ulong 0 1567 while lt s ulong n bound 999999 1568 e = s 1569 while lt e ulong n bound 999999 1570 if eq get fbuf e 10 1571 break 1572 end 1573 e = add e 1 1574 end 1575 if and eq get gv HX 0 pinln s e tx86 1576 put gv HX 1 1577 for i ulong 64 1578 put pinb i get fbuf add s add 8 i 1579 end 1580 end 1581 if and eq get gv HB 0 pinln s e tpin 1582 put gv HB 1 1583 for i ulong 64 1584 put pinb add 64 i get fbuf add s add 4 i 1585 end 1586 end 1587 s = add e 1 1588 end 1589 end 1590 fn pineq n long base ulong to bool 1591 if lt n 0 1592 ret false 1593 end 1594 if ne get nty n 3 1595 ret false 1596 end 1597 if ne get nvl n 64 1598 ret false 1599 end 1600 o = get nvo n 1601 for i ulong 64 1602 if ne get pool add o i get pinb add base i 1603 ret false 1604 end 1605 end 1606 ret true 1607 end 1608 text tfpre "native-x86-physical-" 1609 text tjson ".json" 1610 fn fnameok to bool 1611 k = get gv PL 1612 s = k 1613 while gt s 0 bound 4097 1614 if eq get pth sub s 1 47 1615 break 1616 end 1617 s = sub s 1 1618 end 1619 if eq k 1 1620 if eq get pth 0 46 1621 s = 1 1622 end 1623 end 1624 if ne sub k s 33 1625 ret false 1626 end 1627 for i ulong 20 1628 if ne get pth add s i get tfpre i 1629 ret false 1630 end 1631 end 1632 for i ulong 8 1633 if ne get pth add s add 20 i get pinb i 1634 ret false 1635 end 1636 end 1637 for i ulong 5 1638 if ne get pth add s add 28 i get tjson i 1639 ret false 1640 end 1641 end 1642 ret true 1643 end 1644 1645 note ---- logs: open LOGDIR/NAME, require a regular file (Path.is_file), read it into fbuf ---- 1646 text tlog0 "x86-native.log" 1647 text tlog1 "x86-native-controls.log" 1648 text tlog2 "x86-native-wrongpin.log" 1649 text tlog3 "x86-native-mut.log" 1650 fn opb b uchar to void 1651 k = get gv OPN 1652 put opn k b 1653 put gv OPN add k 1 1654 end 1655 fn opnam t view uchar * to void 1656 put gv OPN 0 1657 k = get gv DL 1658 for i ulong k 1659 opb get ldr i 1660 end 1661 opb 47 1662 for i ulong len t 1663 opb get t i 1664 end 1665 end 1666 note returns the byte count, -1 when the path is not a regular file, -2 when larger than FCAP 1667 fn rdlog t view uchar * to long 1668 opnam t 1669 fd = fopen opn 0 get gv OPN 2048 0 1670 if lt fd 0 1671 ret -1 1672 end 1673 st = new uchar 128 0 1674 r = fstat int fd st 0 128 1675 m = or uint get st 16 shl uint get st 17 8 1676 if or lt r 0 ne and m 0xf000 0x8000 1677 c = fclose int fd 1678 ret -1 1679 end 1680 n = rdfile int fd 1681 c2 = fclose int fd 1682 if lt n 0 1683 ret -2 1684 end 1685 ret n 1686 end 1687 note ---- line scan with Python str.splitlines() terminators ---- 1688 fn lend s ulong n ulong to ulong 1689 e = s 1690 while lt e n bound 999999 1691 b = get fbuf e 1692 put gv TL 1 1693 if or eq b 10 eq b 13 1694 if eq b 13 1695 if lt add e 1 n 1696 if eq get fbuf add e 1 10 1697 put gv TL 2 1698 end 1699 end 1700 end 1701 ret e 1702 end 1703 if or or eq b 11 eq b 12 and ge b 28 le b 30 1704 ret e 1705 end 1706 if and eq b 0xc2 lt add e 1 n 1707 if eq get fbuf add e 1 0x85 1708 put gv TL 2 1709 ret e 1710 end 1711 end 1712 if and eq b 0xe2 lt add e 2 n 1713 if eq get fbuf add e 1 0x80 1714 c = get fbuf add e 2 1715 if or eq c 0xa8 eq c 0xa9 1716 put gv TL 3 1717 ret e 1718 end 1719 end 1720 end 1721 e = add e 1 1722 end 1723 put gv TL 0 1724 ret n 1725 end 1726 fn fpre s ulong e ulong t view uchar * to bool 1727 k = len t 1728 if lt sub e s k 1729 ret false 1730 end 1731 for i ulong k 1732 if ne get fbuf add s i get t i 1733 ret false 1734 end 1735 end 1736 ret true 1737 end 1738 fn feq s ulong e ulong t view uchar * to bool 1739 if ne sub e s len t 1740 ret false 1741 end 1742 ret fpre s e t 1743 end 1744 fn xeq s ulong e ulong o ulong k ulong to bool 1745 if ne sub e s k 1746 ret false 1747 end 1748 for i ulong k 1749 if ne get fbuf add s i get xp add o i 1750 ret false 1751 end 1752 end 1753 ret true 1754 end 1755 note substring search of t in fbuf[s..e) 1756 fn fsubc a ulong b ulong e ulong t view uchar * to bool 1757 p = a 1758 while lt p b bound 999999 1759 if fpre p e t 1760 ret true 1761 end 1762 p = add p 1 1763 end 1764 ret false 1765 end 1766 fn fsub s ulong e ulong t view uchar * to bool 1767 m = len t 1768 if lt sub e s m 1769 ret false 1770 end 1771 lst = add sub e m 1 1772 a = s 1773 while lt a lst bound 999999 1774 b = add a 900000 1775 if gt b lst 1776 b = lst 1777 end 1778 if fsubc a b e t 1779 ret true 1780 end 1781 a = b 1782 end 1783 ret false 1784 end 1785 text tvirt "INFO virtualization=none" 1786 text thyp "INFO cpu hypervisor flag=no" 1787 text tfln "FAIL " 1788 text tctl "NATIVE-X86 CONTROLS PASS (NATIVE" 1789 text tnpass "NATIVE-X86 NATIVE PASS " 1790 text tvnone "virtualization=none" 1791 fn sline s ulong e ulong to void 1792 put gv LS s 1793 put gv LE e 1794 if feq s e tvirt 1795 put gv FVIRT 1 1796 end 1797 if feq s e thyp 1798 put gv FHYP 1 1799 end 1800 if fpre s e tfln 1801 put gv FFAIL 1 1802 end 1803 if xeq s e 0 get gv E1 1804 put gv FCPU 1 1805 end 1806 if xeq s e `1048576` get gv E2 1807 put gv FKERN 1 1808 end 1809 end 1810 fn kline s ulong e ulong kind ulong to void 1811 if eq kind 0 1812 sline s e 1813 else 1814 if fpre s e tctl 1815 put gv FCTRL 1 1816 end 1817 end 1818 end 1819 note one pass over at most 900000 lines from s; returns where it stopped 1820 fn lchunk s ulong n ulong kind ulong to ulong 1821 p = s 1822 c = ulong 0 1823 while and lt p n lt c 900000 bound 999999 1824 e = lend p n 1825 kline p e kind 1826 p = add e get gv TL 1827 if eq get gv TL 0 1828 p = n 1829 end 1830 c = add c 1 1831 end 1832 ret p 1833 end 1834 fn lscan n ulong kind ulong to void 1835 p = ulong 0 1836 while lt p n bound 999999 1837 p = lchunk p n kind 1838 end 1839 end 1840 1841 note ---- the checks, in the order and wording of the replaced Python checker ---- 1842 text tusage "usage: check_physical_receipt RECEIPT.json [LOGDIR] (run from the repository root)\n" 1843 text trdj "receipt is readable JSON (" 1844 text terrno "open or read failed: errno " 1845 text tbig "larger than 900000 bytes" 1846 text tutf "not UTF-8 at byte " 1847 text tbad "invalid JSON near byte " 1848 text tobj "receipt is a JSON object" 1849 fn rdfail t view uchar * v ulong hasv bool to int 1850 put gv LN 0 1851 lnt trdj 1852 lnt t 1853 if hasv 1854 lndec v 1855 end 1856 lnb 41 1857 emit false 1858 ret finish 1859 end 1860 note returns -1 when the receipt parsed (node 0 is the top value), else the finish status 1861 fn rdrcp to int 1862 fd = fopen pth 0 get gv PL 0 0 1863 if lt fd 0 1864 ret rdfail terrno ulong neg fd true 1865 end 1866 n = ulong 0 1867 go = true 1868 while go bound 999999 1869 r = read int fd rcp n sub `1048576` n 1870 if lt r 0 1871 c = fclose int fd 1872 ret rdfail terrno ulong neg r true 1873 end 1874 if eq r 0 1875 go = false 1876 end 1877 n = add n ulong r 1878 if gt n RCAP 1879 c2 = fclose int fd 1880 ret rdfail tbig 0 false 1881 end 1882 end 1883 c3 = fclose int fd 1884 put gv RL n 1885 u = utf8ok 1886 if ge u 0 1887 ret rdfail tutf ulong u true 1888 end 1889 put gv PO 0 1890 ok = pval -1 0 KNONE 0 0 1891 skipws 1892 if or not ok ne get gv PO n 1893 ret rdfail tbad get gv PO true 1894 end 1895 ret -1 1896 end 1897 text tsch "schema is 1" 1898 text tsch2 "schema" 1899 text tlab "label is PHYSICAL (got " 1900 text tlabk "label" 1901 text tphys "PHYSICAL" 1902 text tsta "status is NATIVE_PASS (got " 1903 text tstak "status" 1904 text tnp "NATIVE_PASS" 1905 text tnx "native_x86 is PASS (got " 1906 text tnxk "native_x86" 1907 text tpassv "PASS" 1908 text tnoemu "receipt nowhere says EMULATED" 1909 text tbc "bridge_commit is a full sha" 1910 text tbck "bridge_commit" 1911 text txo "x86_omc_sha256 is the tools/native X86_PIN" 1912 text txok "x86_omc_sha256" 1913 text tbo "baseline_omc_sha256 is the tools/native PIN" 1914 text tbok "baseline_omc_sha256" 1915 text tfn "file name carries the x86 pin prefix" 1916 text tgotc ")" 1917 fn gotchk t view uchar * v long want view uchar * to void 1918 put gv LN 0 1919 lnt t 1920 prep v 1921 lnb 41 1922 emit vstr v want 1923 end 1924 fn chktop to void 1925 r = long 0 1926 put gv LN 0 1927 chk tsch numis dget r tsch2 1 1928 gotchk tlab dget r tlabk tphys 1929 gotchk tsta dget r tstak tnp 1930 gotchk tnx dget r tnxk tpassv 1931 chk tnoemu not sayemu 1932 chk tbc ishexs dget r tbck 40 1933 hx = eq get gv HX 1 1934 chk txo and hx pineq dget r txok 0 1935 chk tbo and eq get gv HB 1 pineq dget r tbok 64 1936 chk tfn and hx fnameok 1937 end 1938 text thost "host" 1939 text tvirtk "virtualization" 1940 text thv "host.virtualization is none (got " 1941 text tnone2 "none" 1942 text thf "host.hypervisor_flag is no (got " 1943 text thfk "hypervisor_flag" 1944 text tno "no" 1945 text tcpu "host.cpu_model is recorded" 1946 text tcpuk "cpu_model" 1947 text tker "host.kernel is recorded" 1948 text tkerk "kernel" 1949 text tos "host.os is recorded" 1950 text tosk "os" 1951 text tbin "binfmt_qemu_aarch64" 1952 text tbiv "host.binfmt_qemu_aarch64 interpreter and version recorded" 1953 text tbis "host.binfmt_qemu_aarch64 sha256 recorded" 1954 text tinter "interpreter" 1955 text tver "version" 1956 text tsha "sha256" 1957 fn objor n long to long 1958 if isobj n 1959 ret n 1960 end 1961 ret -1 1962 end 1963 fn chkhost to long 1964 h = objor dget long 0 thost 1965 gotchk thv dget h tvirtk tnone2 1966 gotchk thf dget h thfk tno 1967 chk tcpu vtext dget h tcpuk 1968 chk tker vtext dget h tkerk 1969 chk tos vtext dget h tosk 1970 b = objor dget h tbin 1971 chk tbiv and vtext dget b tinter vtext dget b tver 1972 chk tbis ishexs dget b tsha 64 1973 ret h 1974 end 1975 text ttools "toolchains" 1976 text ttc "toolchains." 1977 text tvrec " version recorded" 1978 text tgcc "gcc" 1979 text tgpp "g++" 1980 text trustc "rustc" 1981 text tzig "zig" 1982 text tgo "go" 1983 text tpy "python" 1984 fn chktc t long name view uchar * to void 1985 put gv LN 0 1986 lnt ttc 1987 lnt name 1988 lnt tvrec 1989 emit vtext dget t name 1990 end 1991 fn chktools to void 1992 t = objor dget long 0 ttools 1993 chktc t tgcc 1994 chktc t tgpp 1995 chktc t trustc 1996 chktc t tzig 1997 chktc t tgo 1998 chktc t tpy 1999 end 2000 text tcmds "commands" 2001 text tfour "four runbook commands recorded (got " 2002 text tcmd "command " 2003 text tisrb " is the runbook command (" 2004 text texit " exit is " 2005 text tgot " (got " 2006 text tresn " result names " 2007 text tcmdk "command" 2008 text texitk "exit" 2009 text tresk "result" 2010 text tn1 "OMEGA_NATIVE_X86_EXEC=native sh tests/native/x86/run.sh" 2011 text tn2 "OMEGA_NATIVE_X86_EXEC=native python3 tests/native/x86/test_build_failures.py" 2012 text tn3 "OMEGA_NATIVE_X86_OMC=" 2013 text tn4 "tools/native --target x86linux" 2014 text tr1 "NATIVE-X86 NATIVE PASS" 2015 text tr2 "NATIVE-X86 CONTROLS PASS" 2016 text tr3 "FAIL x86 compiler pin" 2017 text tr4 "refused" 2018 fn chkcmd c long i ulong nd view uchar * res view uchar * to void 2019 code = ulong 0 2020 if ge i 2 2021 code = 1 2022 end 2023 e = objor aget c i 2024 put gv LN 0 2025 lnt tcmd 2026 lndec add i 1 2027 lnt tisrb 2028 lnt nd 2029 lnb 41 2030 emit vsub dget e tcmdk nd 2031 put gv LN 0 2032 lnt tcmd 2033 lndec add i 1 2034 lnt texit 2035 lndec code 2036 lnt tgot 2037 x = dget e texitk 2038 prep x 2039 lnb 41 2040 emit numis x code 2041 put gv LN 0 2042 lnt tcmd 2043 lndec add i 1 2044 lnt tresn 2045 lnt res 2046 emit vsub dget e tresk res 2047 end 2048 fn chkcmds to void 2049 c = dget long 0 tcmds 2050 if lt c 0 2051 c = -1 2052 else 2053 if ne get nty c 2 2054 c = -1 2055 end 2056 end 2057 k = nch c 2058 put gv LN 0 2059 lnt tfour 2060 lndec k 2061 lnb 41 2062 emit eq k 4 2063 chkcmd c 0 tn1 tr1 2064 chkcmd c 1 tn2 tr2 2065 chkcmd c 2 tn3 tr3 2066 chkcmd c 3 tn4 tr4 2067 end 2068 text tlg "log " 2069 text tpres " present in " 2070 text tsham " sha256 matches receipt" 2071 text tlogs "logs_sha256" 2072 fn chklog h long t view uchar * to long 2073 put gv LN 0 2074 lnt tlg 2075 lnt t 2076 lnt tpres 2077 k = get gv DL 2078 for i ulong k 2079 lnb get ldr i 2080 end 2081 n = rdlog t 2082 emit ne n -1 2083 if eq n -1 2084 ret -1 2085 end 2086 ok = false 2087 if ge n 0 2088 shafbuf ulong n 2089 x = dget h t 2090 if ge x 0 2091 if eq get nty x 3 2092 if eq get nvl x 64 2093 ok = true 2094 o = get nvo x 2095 for i ulong 64 2096 if ne get pool add o i get hexo i 2097 ok = false 2098 end 2099 end 2100 end 2101 end 2102 end 2103 end 2104 put gv LN 0 2105 lnt tlg 2106 lnt t 2107 lnt tsham 2108 emit ok 2109 if lt n 0 2110 ret 0 2111 end 2112 ret n 2113 end 2114 note expected suite lines "INFO cpu model=" + str(host.cpu_model) and "INFO kernel=" + str(host.kernel) 2115 text tem1 "INFO cpu model=" 2116 text tem2 "INFO kernel=" 2117 fn mkexp h long to void 2118 put gv LN 0 2119 lnt tem1 2120 pstrv dget h tcpuk 2121 k = get gv LN 2122 for i ulong k 2123 put xp i get ln i 2124 end 2125 put gv E1 k 2126 put gv LN 0 2127 lnt tem2 2128 pstrv dget h tkerk 2129 k2 = get gv LN 2130 for i ulong k2 2131 put xp add `1048576` i get ln i 2132 end 2133 put gv E2 k2 2134 put gv LN 0 2135 end 2136 text tsl1 "suite log ends with the NATIVE PASS line" 2137 text tsl2 "suite log never ran EMULATED" 2138 text tsl3 "suite log shows virtualization=none" 2139 text tsl4 "suite log shows hypervisor flag clear" 2140 text tsl5 "suite log has no FAIL line" 2141 text tsl6 "suite log cpu model matches receipt" 2142 text tsl7 "suite log kernel matches receipt" 2143 text tcl "controls log reports NATIVE CONTROLS PASS" 2144 text twp "wrong-pin log refuses the x86 compiler pin" 2145 text tmu "mutated-compiler log is refused by tools/native" 2146 text twpn "NATIVE-X86 FAIL x86 compiler pin" 2147 text tmun "tools/native: x86 omc sha256" 2148 fn fg i ulong to bool 2149 ret eq get gv i 1 2150 end 2151 fn suitefx n long to void 2152 if le n 0 2153 ret 2154 end 2155 k = ulong n 2156 if fsub 0 k temu 2157 put gv FEMU 1 2158 end 2159 put gv LS 0 2160 put gv LE 0 2161 put gv FLAST 2 2162 lscan k 0 2163 s = get gv LS 2164 e = get gv LE 2165 if and fpre s e tnpass fsub s e tvnone 2166 put gv FLAST 1 2167 end 2168 end 2169 fn chklogs h long to void 2170 l = objor dget long 0 tlogs 2171 n0 = chklog l tlog0 2172 suitefx n0 2173 n1 = chklog l tlog1 2174 if gt n1 0 2175 lscan ulong n1 1 2176 end 2177 n2 = chklog l tlog2 2178 if gt n2 0 2179 if fsub 0 ulong n2 twpn 2180 put gv FWRONG 1 2181 end 2182 end 2183 n3 = chklog l tlog3 2184 if gt n3 0 2185 if fsub 0 ulong n3 tmun 2186 put gv FMUT 1 2187 end 2188 end 2189 chk tsl1 fg FLAST 2190 chk tsl2 not fg FEMU 2191 chk tsl3 fg FVIRT 2192 chk tsl4 fg FHYP 2193 chk tsl5 not fg FFAIL 2194 chk tsl6 fg FCPU 2195 chk tsl7 fg FKERN 2196 chk tcl fg FCTRL 2197 chk twp fg FWRONG 2198 chk tmu fg FMUT 2199 end 2200 fn main to int 2201 c = argcnt 2202 if or lt c 2 gt c 3 2203 w = write 2 tusage 0 len tusage 2204 ret 2 2205 end 2206 rdarg 1 2207 topth 2208 if eq c 3 2209 rdarg 2 2210 toldr get gv NBN 2211 else 2212 rdarg 1 2213 dfltdir 2214 end 2215 r = rdrcp 2216 if ge r 0 2217 ret r 2218 end 2219 put gv LN 0 2220 ob = isobj 0 2221 chk tobj ob 2222 if not ob 2223 ret finish 2224 end 2225 natpins 2226 chktop 2227 h = chkhost 2228 chktools 2229 chkcmds 2230 mkexp h 2231 chklogs h 2232 ret finish 2233 end