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/seed/ng/memo/gate_memo.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 / seed / ng / memo / gate_memo.om` 1831 lines · 35928 bytes Raw Blame History 1 note SPDX-License-Identifier: Apache-2.0 2 note seed/ng/memo/gate_memo.om: Standalone Pure-OM-2 Verification Gate for Stage 1 OMEGA-MEMO 3 note (Sovereign Intelligence 2.0 Pillar 2: Universal Content-Addressed Memoization). 4 note 5 note Link order (program mode; ir.om provides om2 at line 1): 6 note cat seed/ng/src/ir.om seed/ng/sha256.om seed/ng/target/target_desc.om \ 7 note seed/ng/pack/sem_pack.om seed/ng/memo/memo_policy.om \ 8 note seed/ng/memo/memo_store.om seed/ng/memo/gate_memo.om | seed/out/omc > gate_memo 9 note 10 note Usage: 11 note ./gate_memo [SCRATCH_DIR [NG_BIN NGCHECK_BIN]] 12 note 13 note Stages verified: 14 note Stage 1: Default root resolution (OMEGA_MEMO_DIR, $HOME/.local/share/omega-memo, empty-env refusal) 15 note Stage 2: ΩIR v2 SEMANTIC_ID + OMPK v2 purity admission & fail-closed impure/contract refusals 16 note Stage 3: Cross-process persistence via fork + execprog (/proc/self/exe): Process A stores, 17 note fresh Process B hits with 0 recompute & exact output bytes + cross-PID provenance 18 note Stage 4: One-way precision dominance (@exact->@tol PASS, @tol(100)->@tol(1000) PASS, 19 note @tol->@exact REFUSED in-proc & cross-proc, looser->tighter REFUSED, monotonic upgrade, 20 note downgrade refusal, conflicting @exact nondeterminism refusal) 21 note Stage 5: Fail-closed tamper & corruption controls (1-bit output flip, 1-bit header/tier forge, 22 note truncated body, truncated header, trailing byte, bad magic/version, key substitution) 23 note Stage 6: Profitability policy (monons-timed trivial op skip, precheck skip, heavy op admit, 24 note explicit MP_OVR_FORCE test override) 25 note Stage 7: Uncapped scaling (128+ entries > 32-slot cap), loud disk-floor alarm without silent 26 note truncation (both store_bytes and free_bytes thresholds), and explicit oldest-first mm_prune 27 note Stage 8 (optional with NG_BIN NGCHECK_BIN): live ng @ng front-ir / @ng sem-id + ngcheck ck_pure 28 29 global gm_dig uchar 24 30 global gm_chk ulong 1 31 global gm_neg ulong 1 32 global gm_xproc ulong 1 33 global gm_ent ulong 1 34 global gm_cli_chk ulong 1 35 global gm_cli_neg ulong 1 36 37 global gm_scp uchar 1024 38 global gm_scl ulong 1 39 global gm_ngp uchar 1024 40 global gm_ngl ulong 1 41 global gm_ckp uchar 1024 42 global gm_ckl ulong 1 43 44 global gm_root_a uchar 1024 45 global gm_root_al ulong 1 46 global gm_pa uchar 2048 47 global gm_pl ulong 1 48 global gm_pb uchar 2048 49 global gm_pbl ulong 1 50 51 global gm_fid_ex uchar 32 52 global gm_fid_t1 uchar 32 53 global gm_fid_trv uchar 32 54 global gm_fid_hvy uchar 32 55 global gm_fid_cli uchar 32 56 57 global gm_av uchar 4096 58 global gm_an ulong 1 59 global gm_ev uchar 4096 60 global gm_en ulong 1 61 global gm_st uchar 4 62 global gm_arg uchar 1024 63 global gm_io uchar 65536 64 global gm_io2 uchar 65536 65 global gm_bkp uchar 4096 66 global gm_bkpl ulong 1 67 68 text gm_m_hdr "=== OMEGA NG STAGE 1 (OMEGA-MEMO) VERIFICATION GATE ===\n" 69 text gm_m_pass "GATE-MEMO PASS checks=" 70 text gm_m_neg " neg_controls=" 71 text gm_m_xp " xproc=" 72 text gm_m_ent " entries=" 73 text gm_m_cli " cli_checks=" 74 text gm_m_cneg " cli_neg=" 75 text gm_m_nl "\n" 76 text gm_m_fail "GATE-MEMO FAIL check=" 77 78 text gm_self "/proc/self/exe" 79 text gm_def_pfx "/tmp/omega-memo-gate-" 80 text gm_w_store "--worker-store" 81 text gm_w_look "--worker-lookup" 82 text gm_w_ref "--worker-refuse" 83 text gm_w_env "--worker-env" 84 85 text gm_s_env1 "/env-explicit" 86 text gm_s_env2 "/env-home" 87 text gm_s_home_suf "/.local/share/omega-memo" 88 text gm_s_main "/cas-main" 89 text gm_s_scale "/cas-scale" 90 text gm_s_cli "/cas-cli" 91 text gm_e_dir "OMEGA_MEMO_DIR=" 92 text gm_e_home "HOME=" 93 text gm_e_other "UNRELATED_VAR=1" 94 95 text gm_al_want "OMEGA-MEMO ALARM disk_floor " 96 text gm_f_in "/in.bin" 97 text gm_f_out "/out.bin" 98 text gm_f_err "/err.bin" 99 text gm_h_fi "@ng front-ir\n" 100 text gm_h_sd "@ng sem-id\n" 101 text gm_pfx_acc "ACCEPT " 102 text gm_pfx_fn0 "fn 0 " 103 104 text gm_src_pure "om2\n@pure\n@exact\nfn calc x ulong to ulong\nret add mul x 7 13\nend\nfn main to int\nret int and calc 5 255\nend\n" 105 text gm_src_imp "om2\nglobal g_bad ulong 4\n@pure\nfn bad x ulong to ulong\nput g_bad 0 x\nret x\nend\nfn main to int\nret int and bad 5 255\nend\n" 106 107 note ---- Output & Counting Helpers ---- 108 109 fn gm_wrt s view uchar * to void 110 r = write 1 s 0 len s 111 end 112 113 fn gm_num v ulong to void 114 x = v 115 p = ulong 24 116 for i ulong 21 117 p = sub p 1 118 put gm_dig p uchar add 48 rem x 10 119 x = div x 10 120 if eq x 0 121 r = write 1 gm_dig p sub 24 p 122 ret 123 end 124 end 125 end 126 127 fn gm_fail code ulong to int 128 gm_wrt gm_m_fail 129 gm_num code 130 gm_wrt gm_m_nl 131 ret int add 1 rem code 95 132 end 133 134 fn gm_add_chk n ulong to void 135 put gm_chk 0 add get gm_chk 0 n 136 end 137 138 fn gm_add_neg to void 139 put gm_neg 0 add get gm_neg 0 1 140 end 141 142 fn gm_put_u64_val v ulong to void 143 for j ulong 8 144 put mm_val_buf j uchar and shr v mul j 8 255 145 end 146 put mm_val_len 0 8 147 end 148 149 fn gm_get_u64_val to ulong 150 v = ulong 0 151 for j ulong 8 152 b = ulong get mm_val_buf j 153 v = or v shl b mul j 8 154 end 155 ret v 156 end 157 158 note Heavy deterministic pure computation for real monons & cross-process persistence 159 fn gm_heavy_compute x ulong iters ulong to ulong 160 acc = xor x `11400714819323198485` 161 for i ulong iters bound 200000 162 acc = xor mul acc `6364136223846793005` add i `1442695040888963407` 163 acc = xor acc shr acc 29 164 end 165 ret acc 166 end 167 168 note Trivial pure computation (sub-threshold for profitability filter) 169 fn gm_trivial_compute x ulong to ulong 170 ret add x 1 171 end 172 173 note ---- Path, Decimal, and Subprocess Argv/Env Packet Builders ---- 174 175 fn gm_parse_u64 n ulong to ulong 176 v = ulong 0 177 for i ulong n bound 32 178 ch = get gm_arg i 179 if or lt ch 48 gt ch 57 180 break 181 end 182 v = add mul v 10 ulong sub ch 48 183 end 184 ret v 185 end 186 187 fn gm_arg_eq idx ulong want view uchar * to bool 188 rn = argread idx gm_arg 0 1023 189 if ne rn long len want 190 ret false 191 end 192 for i ulong len want bound 64 193 if ne get gm_arg i get want i 194 ret false 195 end 196 end 197 ret true 198 end 199 200 fn gm_spath suf view uchar * to void 201 n = get gm_scl 0 202 for i ulong n bound 1024 203 put gm_pa i get gm_scp i 204 end 205 m = len suf 206 for j ulong m bound 128 207 put gm_pa add n j get suf j 208 end 209 put gm_pl 0 add n m 210 end 211 212 fn gm_set_root_pa to ulong 213 n = get gm_pl 0 214 for i ulong n bound 2048 215 put mm_env_buf i get gm_pa i 216 end 217 ret mm_set_root_from_envbuf n 218 end 219 220 fn gm_av_reset to void 221 put gm_av 0 0 222 put gm_av 1 0 223 put gm_an 0 2 224 end 225 226 fn gm_av_inc_cnt to void 227 c = or ulong get gm_av 0 shl ulong get gm_av 1 8 228 c = add c 1 229 put gm_av 0 uchar and c 255 230 put gm_av 1 uchar and shr c 8 255 231 end 232 233 fn gm_av_push_txt s view uchar * to void 234 p = get gm_an 0 235 m = len s 236 put gm_av p uchar and m 255 237 put gm_av add p 1 uchar and shr m 8 255 238 p = add p 2 239 for i ulong m bound 256 240 put gm_av add p i get s i 241 end 242 put gm_an 0 add p m 243 gm_av_inc_cnt 244 end 245 246 fn gm_av_push_pa to void 247 p = get gm_an 0 248 m = get gm_pl 0 249 put gm_av p uchar and m 255 250 put gm_av add p 1 uchar and shr m 8 255 251 p = add p 2 252 for i ulong m bound 2048 253 put gm_av add p i get gm_pa i 254 end 255 put gm_an 0 add p m 256 gm_av_inc_cnt 257 end 258 259 fn gm_av_push_u64 v ulong to void 260 x = v 261 q = ulong 24 262 for i ulong 21 263 q = sub q 1 264 put gm_dig q uchar add 48 rem x 10 265 x = div x 10 266 if eq x 0 267 break 268 end 269 end 270 m = sub 24 q 271 p = get gm_an 0 272 put gm_av p uchar and m 255 273 put gm_av add p 1 uchar and shr m 8 255 274 p = add p 2 275 for j ulong m bound 24 276 put gm_av add p j get gm_dig add q j 277 end 278 put gm_an 0 add p m 279 gm_av_inc_cnt 280 end 281 282 fn gm_ev_reset to void 283 put gm_ev 0 0 284 put gm_ev 1 0 285 put gm_en 0 2 286 end 287 288 fn gm_ev_inc_cnt to void 289 c = or ulong get gm_ev 0 shl ulong get gm_ev 1 8 290 c = add c 1 291 put gm_ev 0 uchar and c 255 292 put gm_ev 1 uchar and shr c 8 255 293 end 294 295 fn gm_ev_push_kv pfx view uchar * use_pa bool to void 296 p = get gm_en 0 297 m1 = len pfx 298 m2 = ulong 0 299 if use_pa 300 m2 = get gm_pl 0 301 end 302 m = add m1 m2 303 put gm_ev p uchar and m 255 304 put gm_ev add p 1 uchar and shr m 8 255 305 p = add p 2 306 for i ulong m1 bound 128 307 put gm_ev add p i get pfx i 308 end 309 p = add p m1 310 if use_pa 311 for j ulong m2 bound 2048 312 put gm_ev add p j get gm_pa j 313 end 314 p = add p m2 315 end 316 put gm_en 0 p 317 gm_ev_inc_cnt 318 end 319 320 fn gm_spawn_self use_env bool to ulong 321 pid = fork 322 if lt pid 0 323 ret 254 324 end 325 if eq pid 0 326 if use_env 327 r = execenv gm_av 0 get gm_an 0 gm_ev 0 get gm_en 0 328 else 329 r = execprog gm_av 0 get gm_an 0 330 end 331 exit 127 332 end 333 w = waitpid int pid gm_st 0 4 0 334 if ne w pid 335 ret 253 336 end 337 if ne get gm_st 0 0 338 ret add 256 ulong get gm_st 0 339 end 340 ret ulong get gm_st 1 341 end 342 343 note ---- Real ΩIR v2 Module Builder for Canonical Per-Function SEMANTIC_IDs ---- 344 345 fn gm_hash_fn_to_fid f uint which ulong to void 346 m = ir_wfn_sem f 347 for i ulong m bound 65536 348 put sh_dat i ar_bg 1 i 349 end 350 sh_all m 351 for i ulong 32 352 b = get sh_dig i 353 if eq which 0 354 put gm_fid_ex i b 355 else 356 if eq which 1 357 put gm_fid_t1 i b 358 else 359 if eq which 2 360 put gm_fid_trv i b 361 else 362 put gm_fid_hvy i b 363 end 364 end 365 end 366 end 367 end 368 369 fn gm_build_f1 to uint 370 f = ir_fnew 0 0 5 371 ir_fset_mode f 1 1 0 372 ir_fset_phys f 0 1000 10000 373 p = ir_fpar f 5 374 b = ir_blk f 375 c = ir_res ir_op b 1 5 17 0 376 om = ir_op b 12 5 0 2 377 ir_set om 0 p 378 ir_set om 1 p 379 oa = ir_op b 10 5 0 2 380 ir_set oa 0 ir_res om 381 ir_set oa 1 c 382 r = ir_op b 63 0 0 2 383 ir_set r 0 ir_ftok f 384 ir_set r 1 ir_res oa 385 ret f 386 end 387 388 fn gm_build_f2 to uint 389 f = ir_fnew 0 0 5 390 ir_fset_mode f 1 2 0 391 ir_fset_phys f 100 500 5000 392 p = ir_fpar f 5 393 b = ir_blk f 394 c3 = ir_res ir_op b 1 5 3 0 395 c5 = ir_res ir_op b 1 5 5 0 396 om = ir_op b 12 5 0 2 397 ir_set om 0 p 398 ir_set om 1 c3 399 oa = ir_op b 10 5 0 2 400 ir_set oa 0 ir_res om 401 ir_set oa 1 c5 402 r = ir_op b 63 0 0 2 403 ir_set r 0 ir_ftok f 404 ir_set r 1 ir_res oa 405 ret f 406 end 407 408 fn gm_build_f3 to uint 409 f = ir_fnew 0 0 5 410 ir_fset_mode f 1 1 0 411 ir_fset_phys f 0 0 0 412 p = ir_fpar f 5 413 b = ir_blk f 414 c1 = ir_res ir_op b 1 5 1 0 415 oa = ir_op b 10 5 0 2 416 ir_set oa 0 p 417 ir_set oa 1 c1 418 r = ir_op b 63 0 0 2 419 ir_set r 0 ir_ftok f 420 ir_set r 1 ir_res oa 421 ret f 422 end 423 424 fn gm_build_f4 to uint 425 f = ir_fnew 0 0 5 426 ir_fset_mode f 1 1 0 427 ir_fset_phys f 0 0 0 428 p = ir_fpar f 5 429 b = ir_blk f 430 c99 = ir_res ir_op b 1 5 99 0 431 ox = ir_op b 18 5 0 2 432 ir_set ox 0 p 433 ir_set ox 1 c99 434 r = ir_op b 63 0 0 2 435 ir_set r 0 ir_ftok f 436 ir_set r 1 ir_res ox 437 ret f 438 end 439 440 fn gm_build_fm to void 441 fm = ir_fnew 2 0 8 442 bm = ir_blk fm 443 cz = ir_res ir_op bm 1 8 0 0 444 rm = ir_op bm 63 0 0 2 445 ir_set rm 0 ir_ftok fm 446 ir_set rm 1 cz 447 end 448 449 fn gm_build_ir_fids to bool 450 ir_init 451 f1 = gm_build_f1 452 f2 = gm_build_f2 453 f3 = gm_build_f3 454 f4 = gm_build_f4 455 gm_build_fm 456 gm_hash_fn_to_fid f1 0 457 gm_hash_fn_to_fid f2 1 458 gm_hash_fn_to_fid f3 2 459 gm_hash_fn_to_fid f4 3 460 ret true 461 end 462 463 fn gm_load_fid which ulong to void 464 for i ulong 32 465 if eq which 0 466 put mm_req_fid i get gm_fid_ex i 467 else 468 if eq which 1 469 put mm_req_fid i get gm_fid_t1 i 470 else 471 if eq which 2 472 put mm_req_fid i get gm_fid_trv i 473 else 474 if eq which 3 475 put mm_req_fid i get gm_fid_hvy i 476 else 477 put mm_req_fid i get gm_fid_cli i 478 end 479 end 480 end 481 end 482 end 483 end 484 485 note ---- Cross-Process Child Worker Entrypoints ---- 486 487 fn gm_worker_store to int 488 if lt argcnt 6 489 ret 2 490 end 491 rl = argread 2 mm_env_buf 0 1900 492 if lt rl 1 493 ret 3 494 end 495 if ne mm_set_root_from_envbuf ulong rl MM_OK 496 ret 4 497 end 498 an = argread 3 gm_arg 0 64 499 inp = gm_parse_u64 ulong an 500 an = argread 4 gm_arg 0 64 501 tier = gm_parse_u64 ulong an 502 an = argread 5 gm_arg 0 64 503 err_b = gm_parse_u64 ulong an 504 ok = gm_build_ir_fids 505 mp_init 506 mp_set_override MP_OVR_FORCE 507 mm_reset_req 508 gm_load_fid 0 509 mm_hash_input_u64 inp 510 mm_set_contract 1 1 tier err_b 511 mm_set_provenance 1 0 512 t0 = monons 513 val = gm_heavy_compute inp 50000 514 t1 = monons 515 cns = ulong 10000 516 if gt t1 t0 517 cns = ulong sub t1 t0 518 end 519 gm_put_u64_val val 520 src = mm_store cns 500 521 if ne src MM_OK 522 ret int add 30 src 523 end 524 ret 0 525 end 526 527 fn gm_worker_lookup to int 528 if lt argcnt 7 529 ret 2 530 end 531 rl = argread 2 mm_env_buf 0 1900 532 if lt rl 1 533 ret 3 534 end 535 if ne mm_set_root_from_envbuf ulong rl MM_OK 536 ret 4 537 end 538 an = argread 3 gm_arg 0 64 539 inp = gm_parse_u64 ulong an 540 an = argread 4 gm_arg 0 64 541 tier = gm_parse_u64 ulong an 542 an = argread 5 gm_arg 0 64 543 err_b = gm_parse_u64 ulong an 544 an = argread 6 gm_arg 0 64 545 want_val = gm_parse_u64 ulong an 546 ok = gm_build_ir_fids 547 mp_init 548 mp_set_override MP_OVR_FORCE 549 mm_reset_req 550 gm_load_fid 0 551 mm_hash_input_u64 inp 552 mm_set_contract 1 1 tier err_b 553 note Zero recompute: MUST hit directly from disk written by Process A! 554 lrc = mm_lookup 555 if ne lrc MM_OK 556 ret int add 40 lrc 557 end 558 if ne get mm_val_len 0 8 559 ret 41 560 end 561 got = gm_get_u64_val 562 if ne got want_val 563 ret 42 564 end 565 note Verify cross-process provenance: creator_pid != my own pid! 566 mypid = ulong getpid 567 if eq get mm_hit_meta 6 mypid 568 ret 43 569 end 570 ret 0 571 end 572 573 fn gm_worker_refuse to int 574 if lt argcnt 7 575 ret 2 576 end 577 rl = argread 2 mm_env_buf 0 1900 578 if lt rl 1 579 ret 3 580 end 581 if ne mm_set_root_from_envbuf ulong rl MM_OK 582 ret 4 583 end 584 an = argread 3 gm_arg 0 64 585 inp = gm_parse_u64 ulong an 586 an = argread 4 gm_arg 0 64 587 tier = gm_parse_u64 ulong an 588 an = argread 5 gm_arg 0 64 589 err_b = gm_parse_u64 ulong an 590 an = argread 6 gm_arg 0 64 591 want_rc = gm_parse_u64 ulong an 592 ok = gm_build_ir_fids 593 mp_init 594 mp_set_override MP_OVR_FORCE 595 mm_reset_req 596 gm_load_fid 0 597 mm_hash_input_u64 inp 598 mm_set_contract 1 1 tier err_b 599 lrc = mm_lookup 600 if ne lrc want_rc 601 ret int add 50 lrc 602 end 603 if ne get mm_val_len 0 0 604 ret 59 605 end 606 ret 0 607 end 608 609 fn gm_worker_env to int 610 if lt argcnt 3 611 ret 2 612 end 613 want_n = argread 2 gm_arg 0 1023 614 if lt want_n 0 615 ret 3 616 end 617 rc = mm_init_default_root 618 if eq want_n 0 619 if ne rc MM_ERR_NO_ROOT 620 ret 60 621 end 622 ret 0 623 end 624 if ne rc MM_OK 625 ret int add 61 rc 626 end 627 if ne get mm_root_len 0 ulong want_n 628 ret 68 629 end 630 for i ulong ulong want_n bound 1024 631 if ne get mm_root i get gm_arg i 632 ret 69 633 end 634 end 635 ret 0 636 end 637 638 note ---- Stage 1: Default Root Resolution (OMEGA_MEMO_DIR, $HOME, Empty-Env Refusal) ---- 639 640 fn gm_stage1_env_root to int 641 note 1a. OMEGA_MEMO_DIR env variable takes precedence 642 gm_spath gm_s_env1 643 gm_av_reset 644 gm_av_push_txt gm_self 645 gm_av_push_txt gm_w_env 646 gm_av_push_pa 647 gm_ev_reset 648 gm_ev_push_kv gm_e_dir true 649 if ne gm_spawn_self true 0 650 ret gm_fail 10 651 end 652 653 note 1b. HOME fallback resolves to /.local/share/omega-memo 654 gm_spath gm_s_env2 655 gm_ev_reset 656 gm_ev_push_kv gm_e_home true 657 n0 = get gm_pl 0 658 sl = len gm_s_home_suf 659 for j ulong sl bound 64 660 put gm_pa add n0 j get gm_s_home_suf j 661 end 662 put gm_pl 0 add n0 sl 663 gm_av_reset 664 gm_av_push_txt gm_self 665 gm_av_push_txt gm_w_env 666 gm_av_push_pa 667 if ne gm_spawn_self true 0 668 ret gm_fail 11 669 end 670 671 note 1c. Neither OMEGA_MEMO_DIR nor HOME set -> fail-closed MM_ERR_NO_ROOT 672 put gm_pl 0 0 673 gm_av_reset 674 gm_av_push_txt gm_self 675 gm_av_push_txt gm_w_env 676 gm_av_push_pa 677 gm_ev_reset 678 gm_ev_push_kv gm_e_other false 679 if ne gm_spawn_self true 0 680 ret gm_fail 12 681 end 682 gm_add_neg 683 gm_add_chk 3 684 ret 0 685 end 686 687 note ---- Stage 2: ΩIR v2 SEMANTIC_ID & OMPK v2 Purity Admission + Negative Controls ---- 688 689 fn gm_stage2_purity to int 690 gm_spath gm_s_main 691 if ne gm_set_root_pa MM_OK 692 ret gm_fail 20 693 end 694 mp_init 695 mp_set_override MP_OVR_FORCE 696 mm_reset_stats 697 698 note 2a. Build OMPK v2 package for @pure @exact function -> mm_admit_ompk_v2 MUST succeed 699 tdInitAll 700 tdCacheInit 701 pk_reset_all 702 n2 = ir_wr 703 if lt n2 64 704 ret gm_fail 21 705 end 706 pk_reset_builder 707 pk_set_req EXEC_SCALAR_SIMD 0 8 0 0 0 708 for i ulong 32 709 put pk_fid_in i get gm_fid_ex i 710 end 711 pk_set_contract 1 1 0 0 1000 10000 712 for i ulong n2 bound 4096 713 rc = pk_ir_push ar_bg 1 i 714 if ne rc PK_OK 715 ret gm_fail 22 716 end 717 end 718 if ne pk_pack PK_OK 719 ret gm_fail 23 720 end 721 if ne pk_verify PK_OK 722 ret gm_fail 24 723 end 724 plen = get pk_len 0 725 for i ulong plen bound 8192 726 put mm_val_buf i get pk_buf i 727 end 728 if ne mm_admit_ompk_v2 plen 1 MM_OK 729 ret gm_fail 25 730 end 731 for i ulong 32 732 if ne get mm_req_fid i get gm_fid_ex i 733 ret gm_fail 26 734 end 735 end 736 737 note 2b. NEG: OMPK v2 with purity_flag == 0 -> mm_admit_ompk_v2 REFUSED (MM_ERR_IMPURE) 738 pk_reset_builder 739 pk_set_req EXEC_SCALAR_SIMD 0 8 0 0 0 740 pk_set_contract 0 1 0 0 1000 10000 741 rc = pk_ir_push 97 742 if ne pk_pack PK_OK 743 ret gm_fail 27 744 end 745 plen2 = get pk_len 0 746 for i ulong plen2 bound 8192 747 put mm_val_buf i get pk_buf i 748 end 749 if ne mm_admit_ompk_v2 plen2 1 MM_ERR_IMPURE 750 ret gm_fail 28 751 end 752 gm_add_neg 753 754 note 2c. NEG: OMPK v1 (no v2 purity contract) -> mm_admit_ompk_v2 REFUSED (MM_ERR_IMPURE) 755 pk_reset_builder 756 pk_set_req EXEC_SCALAR_SIMD 0 8 0 0 0 757 rc = pk_ir_push 98 758 if ne pk_pack PK_OK 759 ret gm_fail 29 760 end 761 plen1 = get pk_len 0 762 for i ulong plen1 bound 8192 763 put mm_val_buf i get pk_buf i 764 end 765 if ne mm_admit_ompk_v2 plen1 1 MM_ERR_IMPURE 766 ret gm_fail 30 767 end 768 gm_add_neg 769 770 note 2d. NEG: Direct mm_store & mm_lookup with purity_flag == 0 -> MM_ERR_IMPURE 771 mm_reset_req 772 gm_load_fid 0 773 mm_hash_input_u64 777 774 gm_put_u64_val 9999 775 mm_set_contract 0 1 1 0 776 if ne mm_store 50000 500 MM_ERR_IMPURE 777 ret gm_fail 31 778 end 779 if ne mm_lookup MM_ERR_IMPURE 780 ret gm_fail 32 781 end 782 gm_add_neg 783 784 note 2e. NEG: purity_flag == 1 WITHOUT ck_pure structural verification (ck_pure_ok == 0) -> MM_ERR_IMPURE 785 mm_set_contract 1 0 1 0 786 if ne mm_store 50000 500 MM_ERR_IMPURE 787 ret gm_fail 33 788 end 789 if ne mm_lookup MM_ERR_IMPURE 790 ret gm_fail 34 791 end 792 gm_add_neg 793 794 note 2f. NEG: Malformed precision contracts (tier=0, tier=3, @exact with err=5) -> MM_ERR_CONTRACT 795 mm_set_contract 1 1 0 0 796 if ne mm_store 50000 500 MM_ERR_CONTRACT 797 ret gm_fail 35 798 end 799 mm_set_contract 1 1 3 0 800 if ne mm_store 50000 500 MM_ERR_CONTRACT 801 ret gm_fail 36 802 end 803 mm_set_contract 1 1 1 5 804 if ne mm_store 50000 500 MM_ERR_CONTRACT 805 ret gm_fail 37 806 end 807 gm_add_neg 808 809 gm_add_chk 10 810 ret 0 811 end 812 813 note ---- Stage 3: True Cross-Process Persistence (Process A -> Disk -> Fresh Process B) ---- 814 815 fn gm_stage3_xproc to int 816 gm_spath gm_s_main 817 if ne gm_set_root_pa MM_OK 818 ret gm_fail 40 819 end 820 inp = ulong `123456789` 821 expect_val = gm_heavy_compute inp 50000 822 823 note Spawn fresh Process A to compute & store @exact entry to disk 824 gm_av_reset 825 gm_av_push_txt gm_self 826 gm_av_push_txt gm_w_store 827 gm_av_push_pa 828 gm_av_push_u64 inp 829 gm_av_push_u64 1 830 gm_av_push_u64 0 831 if ne gm_spawn_self false 0 832 ret gm_fail 41 833 end 834 835 note Confirm exact sharded path /<2hex>/<64hex>.ome exists with size 232 (224 hdr + 8 val) 836 mm_reset_req 837 gm_load_fid 0 838 mm_hash_input_u64 inp 839 if ne mm_derive_paths MM_OK 840 ret gm_fail 42 841 end 842 sr = stat mm_file_path 0 get mm_file_plen 0 mp_stbuf 0 128 843 if ne sr 0 844 ret gm_fail 43 845 end 846 if ne mp_st_u64 48 232 847 ret gm_fail 44 848 end 849 850 note Spawn fresh Process B to hit @exact with 0 recompute & verify exact bytes + cross-PID provenance 851 gm_av_reset 852 gm_av_push_txt gm_self 853 gm_av_push_txt gm_w_look 854 gm_av_push_pa 855 gm_av_push_u64 inp 856 gm_av_push_u64 1 857 gm_av_push_u64 0 858 gm_av_push_u64 expect_val 859 if ne gm_spawn_self false 0 860 ret gm_fail 45 861 end 862 put gm_xproc 0 add get gm_xproc 0 1 863 864 note Spawn fresh Process C to hit @tol(1000) from Process A's @exact entry (cross-process dominance!) 865 gm_av_reset 866 gm_av_push_txt gm_self 867 gm_av_push_txt gm_w_look 868 gm_av_push_pa 869 gm_av_push_u64 inp 870 gm_av_push_u64 2 871 gm_av_push_u64 1000 872 gm_av_push_u64 expect_val 873 if ne gm_spawn_self false 0 874 ret gm_fail 46 875 end 876 put gm_xproc 0 add get gm_xproc 0 1 877 878 gm_add_chk 6 879 ret 0 880 end 881 882 note ---- Stage 4: One-Way Precision Dominance, Refusals, Upgrades, No-Downgrade, Exact Nondet ---- 883 884 fn gm_stage4_dominance to int 885 gm_spath gm_s_main 886 if ne gm_set_root_pa MM_OK 887 ret gm_fail 50 888 end 889 mp_init 890 mp_set_override MP_OVR_FORCE 891 mm_reset_stats 892 893 note 4a. @exact -> @tol(1000) and @exact -> @tol(0) PASS (using Stage 3 entry inp=`123456789`) 894 inp_ex = ulong `123456789` 895 want_ex = gm_heavy_compute inp_ex 50000 896 mm_reset_req 897 gm_load_fid 0 898 mm_hash_input_u64 inp_ex 899 mm_set_contract 1 1 2 1000 900 if ne mm_lookup MM_OK 901 ret gm_fail 51 902 end 903 if ne gm_get_u64_val want_ex 904 ret gm_fail 52 905 end 906 if ne get mm_stats 2 1 907 ret gm_fail 53 908 end 909 mm_set_contract 1 1 2 0 910 if ne mm_lookup MM_OK 911 ret gm_fail 54 912 end 913 if ne gm_get_u64_val want_ex 914 ret gm_fail 55 915 end 916 917 note 4b. Store @tol(100) via fresh Process A on inp=2002; test @tol(100)->@tol(1000) PASS 918 inp_t1 = ulong 2002 919 want_t1 = gm_heavy_compute inp_t1 50000 920 gm_av_reset 921 gm_av_push_txt gm_self 922 gm_av_push_txt gm_w_store 923 gm_av_push_pa 924 gm_av_push_u64 inp_t1 925 gm_av_push_u64 2 926 gm_av_push_u64 100 927 if ne gm_spawn_self false 0 928 ret gm_fail 56 929 end 930 931 mm_reset_req 932 gm_load_fid 0 933 mm_hash_input_u64 inp_t1 934 mm_set_contract 1 1 2 1000 935 if ne mm_lookup MM_OK 936 ret gm_fail 57 937 end 938 if ne gm_get_u64_val want_t1 939 ret gm_fail 58 940 end 941 mm_set_contract 1 1 2 100 942 if ne mm_lookup MM_OK 943 ret gm_fail 59 944 end 945 946 note 4c. NEG: @tol(100) -> @exact poisoning REFUSED (in-process AND fresh cross-process!) 947 mm_set_contract 1 1 1 0 948 if ne mm_lookup MM_ERR_PRECISION_MISS 949 ret gm_fail 60 950 end 951 if ne get mm_val_len 0 0 952 ret gm_fail 61 953 end 954 gm_av_reset 955 gm_av_push_txt gm_self 956 gm_av_push_txt gm_w_ref 957 gm_av_push_pa 958 gm_av_push_u64 inp_t1 959 gm_av_push_u64 1 960 gm_av_push_u64 0 961 gm_av_push_u64 MM_ERR_PRECISION_MISS 962 if ne gm_spawn_self false 0 963 ret gm_fail 62 964 end 965 put gm_xproc 0 add get gm_xproc 0 1 966 gm_add_neg 967 968 note 4d. NEG: @tol(0) -> @exact poisoning STILL REFUSED (tier 2 NEVER satisfies tier 1!) 969 mm_reset_req 970 gm_load_fid 0 971 mm_hash_input_u64 2003 972 gm_put_u64_val 55555 973 mm_set_contract 1 1 2 0 974 if ne mm_store 50000 500 MM_OK 975 ret gm_fail 63 976 end 977 mm_set_contract 1 1 1 0 978 if ne mm_lookup MM_ERR_PRECISION_MISS 979 ret gm_fail 64 980 end 981 gm_add_neg 982 983 note 4e. NEG: looser @tol(1000) -> tighter @tol(100) REFUSED! 984 mm_reset_req 985 gm_load_fid 0 986 mm_hash_input_u64 2004 987 gm_put_u64_val 10040 988 mm_set_contract 1 1 2 1000 989 if ne mm_store 50000 500 MM_OK 990 ret gm_fail 65 991 end 992 mm_set_contract 1 1 2 100 993 if ne mm_lookup MM_ERR_PRECISION_MISS 994 ret gm_fail 66 995 end 996 gm_add_neg 997 998 note 4f. Monotonic upgrade: @tol(1000) -> @tol(100) -> @exact; then downgrade attempt REFUSED! 999 gm_put_u64_val 10010 1000 mm_set_contract 1 1 2 100 1001 if ne mm_store 50000 500 MM_OK 1002 ret gm_fail 67 1003 end 1004 if ne get mm_stats 8 1 1005 ret gm_fail 68 1006 end 1007 if ne mm_lookup MM_OK 1008 ret gm_fail 69 1009 end 1010 if ne gm_get_u64_val 10010 1011 ret gm_fail 70 1012 end 1013 gm_put_u64_val 10000 1014 mm_set_contract 1 1 1 0 1015 if ne mm_store 50000 500 MM_OK 1016 ret gm_fail 71 1017 end 1018 if ne get mm_stats 8 2 1019 ret gm_fail 72 1020 end 1021 note Attempt downgrade @exact -> @tol(500) MUST return MM_OK_DOMINATED and keep @exact=10000! 1022 gm_put_u64_val 99999 1023 mm_set_contract 1 1 2 500 1024 if ne mm_store 50000 500 MM_OK_DOMINATED 1025 ret gm_fail 73 1026 end 1027 mm_set_contract 1 1 1 0 1028 if ne mm_lookup MM_OK 1029 ret gm_fail 74 1030 end 1031 if ne gm_get_u64_val 10000 1032 ret gm_fail 75 1033 end 1034 1035 note 4g. NEG: Conflicting @exact output for identical (func_sem_id, inputs_sha256) -> MM_ERR_NONDET! 1036 gm_put_u64_val 10001 1037 mm_set_contract 1 1 1 0 1038 if ne mm_store 50000 500 MM_ERR_NONDET 1039 ret gm_fail 76 1040 end 1041 gm_add_neg 1042 1043 gm_add_chk 16 1044 ret 0 1045 end 1046 1047 note ---- Stage 5: Fail-Closed Tamper & Corruption Negative Controls ---- 1048 1049 fn gm_backup_cur_ome to bool 1050 fd = fopen mm_file_path 0 get mm_file_plen 0 0 0 1051 if lt fd 0 1052 ret false 1053 end 1054 n = read int fd gm_bkp 0 4096 1055 cf = fclose int fd 1056 if lt n 224 1057 ret false 1058 end 1059 put gm_bkpl 0 ulong n 1060 ret true 1061 end 1062 1063 fn gm_write_raw_ome n ulong to bool 1064 fd = fopen mm_file_path 0 get mm_file_plen 0 577 420 1065 if lt fd 0 1066 ret false 1067 end 1068 w = write int fd gm_io 0 n 1069 cf = fclose int fd 1070 ret eq w long n 1071 end 1072 1073 fn gm_copy_bkp_to_io to ulong 1074 n = get gm_bkpl 0 1075 for i ulong n bound 4096 1076 put gm_io i get gm_bkp i 1077 end 1078 ret n 1079 end 1080 1081 fn gm_stage5_tamper to int 1082 gm_spath gm_s_main 1083 if ne gm_set_root_pa MM_OK 1084 ret gm_fail 80 1085 end 1086 mp_init 1087 mp_set_override MP_OVR_FORCE 1088 mm_reset_req 1089 gm_load_fid 0 1090 mm_hash_input_u64 3001 1091 gm_put_u64_val `31415926535` 1092 mm_set_contract 1 1 2 100 1093 if ne mm_store 50000 500 MM_OK 1094 ret gm_fail 81 1095 end 1096 if ne mm_derive_paths MM_OK 1097 ret gm_fail 82 1098 end 1099 if not gm_backup_cur_ome 1100 ret gm_fail 83 1101 end 1102 1103 note 5a. NEG: 1-bit tamper in output_bytes[0] (offset 224) -> MM_ERR_TAMPER (14) 1104 n = gm_copy_bkp_to_io 1105 put gm_io 224 xor get gm_io 224 uchar 1 1106 if not gm_write_raw_ome n 1107 ret gm_fail 84 1108 end 1109 if ne mm_lookup MM_ERR_TAMPER 1110 ret gm_fail 85 1111 end 1112 if ne get mm_val_len 0 0 1113 ret gm_fail 86 1114 end 1115 gm_add_neg 1116 1117 note 5b. NEG: 1-bit header tamper trying to forge @tol(100) into @exact (tier 2->1, err->0) -> MM_ERR_TAMPER (14) 1118 n = gm_copy_bkp_to_io 1119 put gm_io 9 uchar 1 1120 for j ulong 8 1121 put gm_io add 16 j uchar 0 1122 end 1123 if not gm_write_raw_ome n 1124 ret gm_fail 87 1125 end 1126 mm_set_contract 1 1 1 0 1127 if ne mm_lookup MM_ERR_TAMPER 1128 ret gm_fail 88 1129 end 1130 gm_add_neg 1131 mm_set_contract 1 1 2 100 1132 1133 note 5c. NEG: Truncated .ome output (minus 1 byte) AND truncated header (100 bytes) -> MM_ERR_TRUNCATED (12) 1134 n = gm_copy_bkp_to_io 1135 if not gm_write_raw_ome sub n 1 1136 ret gm_fail 89 1137 end 1138 if ne mm_lookup MM_ERR_TRUNCATED 1139 ret gm_fail 90 1140 end 1141 if not gm_write_raw_ome 100 1142 ret gm_fail 91 1143 end 1144 if ne mm_lookup MM_ERR_TRUNCATED 1145 ret gm_fail 92 1146 end 1147 gm_add_neg 1148 1149 note 5d. NEG: Trailing garbage byte appended -> MM_ERR_TRAILING (13) 1150 n = gm_copy_bkp_to_io 1151 put gm_io n uchar 65 1152 if not gm_write_raw_ome add n 1 1153 ret gm_fail 93 1154 end 1155 if ne mm_lookup MM_ERR_TRAILING 1156 ret gm_fail 94 1157 end 1158 gm_add_neg 1159 1160 note 5e. NEG: Corrupt magic byte -> MM_ERR_MAGIC (10); corrupt version -> MM_ERR_VERSION (11) 1161 n = gm_copy_bkp_to_io 1162 put gm_io 0 uchar 88 1163 if not gm_write_raw_ome n 1164 ret gm_fail 95 1165 end 1166 if ne mm_lookup MM_ERR_MAGIC 1167 ret gm_fail 96 1168 end 1169 n = gm_copy_bkp_to_io 1170 put gm_io 4 uchar 9 1171 if not gm_write_raw_ome n 1172 ret gm_fail 97 1173 end 1174 if ne mm_lookup MM_ERR_VERSION 1175 ret gm_fail 98 1176 end 1177 gm_add_neg 1178 1179 note 5f. Restore valid file for inp=3001, then copy it onto path of inp=3002 (key-substitution attack -> MM_ERR_KEY_MISMATCH) 1180 n = gm_copy_bkp_to_io 1181 if not gm_write_raw_ome n 1182 ret gm_fail 99 1183 end 1184 mm_hash_input_u64 3002 1185 if ne mm_derive_paths MM_OK 1186 ret gm_fail 100 1187 end 1188 sr = makedir mm_shard_path 0 get mm_shard_plen 0 493 1189 if not gm_write_raw_ome n 1190 ret gm_fail 101 1191 end 1192 if ne mm_lookup MM_ERR_KEY_MISMATCH 1193 ret gm_fail 102 1194 end 1195 u = unlink mm_file_path 0 get mm_file_plen 0 1196 gm_add_neg 1197 1198 gm_add_chk 12 1199 ret 0 1200 end 1201 1202 note ---- Stage 6: Profitability Policy (Trivial Skip, Precheck Skip, Heavy Admit, Test Override) ---- 1203 1204 fn gm_stage6_profitability to int 1205 gm_spath gm_s_main 1206 if ne gm_set_root_pa MM_OK 1207 ret gm_fail 110 1208 end 1209 mp_init 1210 mp_set_override MP_OVR_AUTO 1211 mp_set_thresholds 5000 2 1 1212 mm_reset_stats 1213 1214 note 6a. Trivial sub-threshold op (real monons timing + explicit 150ns vs 4000ns) -> SKIPPED, no file created! 1215 mm_reset_req 1216 gm_load_fid 2 1217 mm_hash_input_u64 4001 1218 mm_set_contract 1 1 1 0 1219 t0 = monons 1220 tv = gm_trivial_compute 4001 1221 t1 = monons 1222 cns_trv = ulong 150 1223 if and gt t1 t0 lt sub t1 t0 4000 1224 cns_trv = ulong sub t1 t0 1225 end 1226 gm_put_u64_val tv 1227 if ne mm_store cns_trv 4000 MM_SKIP_UNPROFITABLE 1228 ret gm_fail 111 1229 end 1230 if ne mm_derive_paths MM_OK 1231 ret gm_fail 112 1232 end 1233 if eq stat mm_file_path 0 get mm_file_plen 0 mp_stbuf 0 128 0 1234 ret gm_fail 113 1235 end 1236 gm_add_neg 1237 1238 note 6b. Subsequent mm_lookup on already-profiled trivial SEMANTIC_ID fast-skips via mp_precheck! 1239 if ne mm_lookup MM_SKIP_UNPROFITABLE 1240 ret gm_fail 114 1241 end 1242 1243 note 6c. Heavy pure op (real monons timing >= 5000ns and >= 2x overhead) -> ADMITTED & HIT! 1244 mm_reset_req 1245 gm_load_fid 3 1246 mm_hash_input_u64 4002 1247 mm_set_contract 1 1 1 0 1248 h0 = monons 1249 hv = gm_heavy_compute 4002 60000 1250 h1 = monons 1251 cns_hvy = ulong 100000 1252 if gt h1 h0 1253 cns_hvy = ulong sub h1 h0 1254 end 1255 if lt cns_hvy 10000 1256 cns_hvy = ulong 100000 1257 end 1258 gm_put_u64_val hv 1259 if ne mm_store cns_hvy 2000 MM_OK 1260 ret gm_fail 115 1261 end 1262 if ne mm_lookup MM_OK 1263 ret gm_fail 116 1264 end 1265 if ne gm_get_u64_val hv 1266 ret gm_fail 117 1267 end 1268 1269 note 6d. Explicit override MP_OVR_FORCE admits even trivial sub-threshold op for tests! 1270 mp_set_override MP_OVR_FORCE 1271 mm_reset_req 1272 gm_load_fid 2 1273 mm_hash_input_u64 4001 1274 mm_set_contract 1 1 1 0 1275 gm_put_u64_val tv 1276 if ne mm_store 100 4000 MM_OK 1277 ret gm_fail 118 1278 end 1279 if ne mm_lookup MM_OK 1280 ret gm_fail 119 1281 end 1282 if ne gm_get_u64_val tv 1283 ret gm_fail 120 1284 end 1285 1286 gm_add_chk 9 1287 ret 0 1288 end 1289 1290 note ---- Stage 7: Uncapped 128+ Entry Scaling (No 32-Slot Cap) + Disk-Floor Alarm + memo_prune ---- 1291 1292 fn gm_stage7_scale_alarm_prune to int 1293 gm_spath gm_s_scale 1294 if ne gm_set_root_pa MM_OK 1295 ret gm_fail 130 1296 end 1297 mp_init 1298 mp_set_override MP_OVR_FORCE 1299 mp_set_disk_limits `1048576` 4096 `2097152` 1300 mm_reset_stats 1301 1302 note 7a. Store 128 distinct content-addressed entries (4x past 32-slot cap!) 1303 for i ulong 128 1304 mm_reset_req 1305 gm_load_fid 0 1306 mm_hash_input_u64 add 50000 i 1307 mm_set_contract 1 1 1 0 1308 gm_put_u64_val add mul i 1000 7 1309 rc = mm_store 50000 500 1310 if ne rc MM_OK 1311 ret gm_fail 131 1312 end 1313 end 1314 if ne mp_scan_store MP_DISK_OK 1315 ret gm_fail 132 1316 end 1317 if ne get mp_stat 0 128 1318 ret gm_fail 133 1319 end 1320 if ne get mp_stat 1 29696 1321 ret gm_fail 134 1322 end 1323 put gm_ent 0 get mp_stat 0 1324 1325 note Verify sample entries spanning well beyond slot 32 (0, 31, 32, 63, 64, 99, 127) 1326 for k ulong 7 1327 idx = ulong 0 1328 if eq k 1 1329 idx = ulong 31 1330 end 1331 if eq k 2 1332 idx = ulong 32 1333 end 1334 if eq k 3 1335 idx = ulong 63 1336 end 1337 if eq k 4 1338 idx = ulong 64 1339 end 1340 if eq k 5 1341 idx = ulong 99 1342 end 1343 if eq k 6 1344 idx = ulong 127 1345 end 1346 mm_reset_req 1347 gm_load_fid 0 1348 mm_hash_input_u64 add 50000 idx 1349 mm_set_contract 1 1 1 0 1350 if ne mm_lookup MM_OK 1351 ret gm_fail 135 1352 end 1353 if ne gm_get_u64_val add mul idx 1000 7 1354 ret gm_fail 136 1355 end 1356 end 1357 1358 note 7b. Disk-floor alarm: set max_store_bytes = 20000 (< 29696), store entry #128 -> MUST fire loud ALARM without truncating ANY existing entry! 1359 mp_set_disk_limits 20000 4096 `2097152` 1360 mm_reset_req 1361 gm_load_fid 0 1362 mm_hash_input_u64 50128 1363 mm_set_contract 1 1 1 0 1364 gm_put_u64_val 128007 1365 if ne mm_store 50000 500 MM_OK_ALARM 1366 ret gm_fail 137 1367 end 1368 if or ne get mp_stat 3 1 lt get mp_stat 4 1 1369 ret gm_fail 138 1370 end 1371 note Confirm structured alarm message begins with "OMEGA-MEMO ALARM disk_floor " 1372 if lt get mp_alarm_len 0 len gm_al_want 1373 ret gm_fail 139 1374 end 1375 for i ulong len gm_al_want bound 64 1376 if ne get mp_alarm_buf i get gm_al_want i 1377 ret gm_fail 140 1378 end 1379 end 1380 note Confirm ZERO silent truncation: ALL 129 entries remain intact and verifiable on disk! 1381 if ne mp_scan_store MP_DISK_OK 1382 ret gm_fail 141 1383 end 1384 if ne get mp_stat 0 129 1385 ret gm_fail 142 1386 end 1387 put gm_ent 0 get mp_stat 0 1388 mm_reset_req 1389 gm_load_fid 0 1390 mm_hash_input_u64 50000 1391 mm_set_contract 1 1 1 0 1392 if ne mm_lookup MM_OK 1393 ret gm_fail 143 1394 end 1395 if ne gm_get_u64_val 7 1396 ret gm_fail 144 1397 end 1398 mm_hash_input_u64 50128 1399 if ne mm_lookup MM_OK 1400 ret gm_fail 145 1401 end 1402 if ne gm_get_u64_val 128007 1403 ret gm_fail 146 1404 end 1405 gm_add_neg 1406 1407 note 7c. Also verify free_bytes < free_floor_bytes alarm triggers loudly 1408 mp_set_disk_limits `1048576` 8192 `2097152` 1409 mp_set_ext_free 1 1024 1410 if ne mp_check_disk_floor MP_ALARM_DISK_FLOOR 1411 ret gm_fail 147 1412 end 1413 mp_set_ext_free 0 0 1414 gm_add_neg 1415 1416 note 7d. Explicit oldest-first mm_prune down to 11600 bytes (50 entries x 232B) clears alarm cleanly! 1417 mp_set_disk_limits 12000 4096 `2097152` 1418 if ne mm_prune 11600 MM_OK 1419 ret gm_fail 148 1420 end 1421 if ne get mp_stat 5 79 1422 ret gm_fail 149 1423 end 1424 if ne get mp_stat 6 18328 1425 ret gm_fail 150 1426 end 1427 if ne get mp_stat 0 50 1428 ret gm_fail 151 1429 end 1430 if gt get mp_stat 1 11600 1431 ret gm_fail 152 1432 end 1433 if ne get mp_stat 3 0 1434 ret gm_fail 153 1435 end 1436 1437 gm_add_chk 16 1438 ret 0 1439 end 1440 1441 note ---- Stage 8 (Optional): Live ng + ngcheck ck_pure End-to-End Integration ---- 1442 1443 fn gm_cli_write_txt hdr view uchar * body view uchar * to bool 1444 gm_spath gm_f_in 1445 fd = fopen gm_pa 0 get gm_pl 0 577 420 1446 if lt fd 0 1447 ret false 1448 end 1449 if gt len hdr 0 1450 w1 = write int fd hdr 0 len hdr 1451 if ne w1 long len hdr 1452 cf = fclose int fd 1453 ret false 1454 end 1455 end 1456 w2 = write int fd body 0 len body 1457 cf2 = fclose int fd 1458 ret eq w2 long len body 1459 end 1460 1461 fn gm_cli_write_bin hdr view uchar * n ulong to bool 1462 gm_spath gm_f_in 1463 fd = fopen gm_pa 0 get gm_pl 0 577 420 1464 if lt fd 0 1465 ret false 1466 end 1467 if gt len hdr 0 1468 w1 = write int fd hdr 0 len hdr 1469 if ne w1 long len hdr 1470 cf = fclose int fd 1471 ret false 1472 end 1473 end 1474 w2 = write int fd gm_io2 0 n 1475 cf2 = fclose int fd 1476 ret eq w2 long n 1477 end 1478 1479 fn gm_cli_read_out to long 1480 gm_spath gm_f_out 1481 fd = fopen gm_pa 0 get gm_pl 0 0 0 1482 if lt fd 0 1483 ret neg long 1 1484 end 1485 n = ulong 0 1486 while lt n 65536 bound 1024 1487 k = read int fd gm_io n sub 65536 n 1488 if lt k 0 1489 cf = fclose int fd 1490 ret neg long 1 1491 end 1492 if eq k 0 1493 cf = fclose int fd 1494 ret long n 1495 end 1496 n = add n ulong k 1497 end 1498 cf = fclose int fd 1499 ret long n 1500 end 1501 1502 fn gm_cli_exec use_ng bool to ulong 1503 put gm_av 0 1 1504 put gm_av 1 0 1505 n = ulong 0 1506 if use_ng 1507 n = get gm_ngl 0 1508 put gm_av 2 uchar and n 255 1509 put gm_av 3 uchar and shr n 8 255 1510 for i ulong n bound 1024 1511 put gm_av add 4 i get gm_ngp i 1512 end 1513 else 1514 n = get gm_ckl 0 1515 put gm_av 2 uchar and n 255 1516 put gm_av 3 uchar and shr n 8 255 1517 for i ulong n bound 1024 1518 put gm_av add 4 i get gm_ckp i 1519 end 1520 end 1521 put gm_an 0 add 4 n 1522 gm_spath gm_f_in 1523 fi = fopen gm_pa 0 get gm_pl 0 0 0 1524 gm_spath gm_f_out 1525 fo = fopen gm_pa 0 get gm_pl 0 577 420 1526 gm_spath gm_f_err 1527 fe = fopen gm_pa 0 get gm_pl 0 577 420 1528 if or lt fi 0 or lt fo 0 lt fe 0 1529 ret 255 1530 end 1531 pid = fork 1532 if lt pid 0 1533 ret 254 1534 end 1535 if eq pid 0 1536 r = dupfd int fi 0 0 1537 r = dupfd int fo 1 0 1538 r = dupfd int fe 2 0 1539 r = execprog gm_av 0 get gm_an 0 1540 exit 127 1541 end 1542 r = fclose int fi 1543 r = fclose int fo 1544 r = fclose int fe 1545 w = waitpid int pid gm_st 0 4 0 1546 if ne w pid 1547 ret 253 1548 end 1549 if ne get gm_st 0 0 1550 ret add 256 ulong get gm_st 0 1551 end 1552 ret ulong get gm_st 1 1553 end 1554 1555 fn gm_hex_nib ch uchar to ulong 1556 if and ge ch 48 le ch 57 1557 ret ulong sub ch 48 1558 end 1559 if and ge ch 97 le ch 102 1560 ret add 10 ulong sub ch 97 1561 end 1562 ret 255 1563 end 1564 1565 fn gm_parse_semid_hex to bool 1566 for i ulong 32 1567 hi = gm_hex_nib get gm_io add 5 mul i 2 1568 lo = gm_hex_nib get gm_io add 6 mul i 2 1569 if or gt hi 15 gt lo 15 1570 ret false 1571 end 1572 put gm_fid_cli i uchar or shl hi 4 lo 1573 end 1574 ret true 1575 end 1576 1577 fn gm_stage8_pure to int 1578 if not gm_cli_write_txt gm_h_fi gm_src_pure 1579 ret gm_fail 161 1580 end 1581 if ne gm_cli_exec true 0 1582 ret gm_fail 162 1583 end 1584 irn = gm_cli_read_out 1585 if lt irn 64 1586 ret gm_fail 163 1587 end 1588 for i ulong ulong irn bound 65536 1589 put gm_io2 i get gm_io i 1590 end 1591 gm_spath gm_f_in 1592 fd = fopen gm_pa 0 get gm_pl 0 577 420 1593 if lt fd 0 1594 ret gm_fail 164 1595 end 1596 kw = write int fd gm_io2 0 ulong irn 1597 cf = fclose int fd 1598 if ne kw irn 1599 ret gm_fail 164 1600 end 1601 if ne gm_cli_exec false 0 1602 ret gm_fail 165 1603 end 1604 acn = gm_cli_read_out 1605 if lt acn long len gm_pfx_acc 1606 ret gm_fail 166 1607 end 1608 for i ulong len gm_pfx_acc bound 16 1609 if ne get gm_io i get gm_pfx_acc i 1610 ret gm_fail 167 1611 end 1612 end 1613 if not gm_cli_write_bin gm_h_sd ulong irn 1614 ret gm_fail 168 1615 end 1616 if ne gm_cli_exec true 0 1617 ret gm_fail 169 1618 end 1619 sdn = gm_cli_read_out 1620 if lt sdn 70 1621 ret gm_fail 170 1622 end 1623 for i ulong len gm_pfx_fn0 bound 16 1624 if ne get gm_io i get gm_pfx_fn0 i 1625 ret gm_fail 171 1626 end 1627 end 1628 if not gm_parse_semid_hex 1629 ret gm_fail 172 1630 end 1631 gm_spath gm_s_cli 1632 if ne gm_set_root_pa MM_OK 1633 ret gm_fail 173 1634 end 1635 mp_init 1636 mp_set_override MP_OVR_FORCE 1637 mm_reset_req 1638 gm_load_fid 4 1639 mm_hash_input_u64 5 1640 mm_set_contract 1 1 1 0 1641 gm_put_u64_val 48 1642 if ne mm_store 50000 500 MM_OK 1643 ret gm_fail 174 1644 end 1645 if ne mm_lookup MM_OK 1646 ret gm_fail 175 1647 end 1648 if ne gm_get_u64_val 48 1649 ret gm_fail 176 1650 end 1651 put gm_cli_chk 0 add get gm_cli_chk 0 5 1652 ret 0 1653 end 1654 1655 fn gm_stage8_impure to int 1656 if not gm_cli_write_txt gm_h_fi gm_src_imp 1657 ret gm_fail 177 1658 end 1659 if ne gm_cli_exec true 0 1660 ret gm_fail 178 1661 end 1662 irn = gm_cli_read_out 1663 if lt irn 64 1664 ret gm_fail 179 1665 end 1666 for i ulong ulong irn bound 65536 1667 put gm_io2 i get gm_io i 1668 end 1669 gm_spath gm_f_in 1670 fd = fopen gm_pa 0 get gm_pl 0 577 420 1671 if lt fd 0 1672 ret gm_fail 180 1673 end 1674 kw = write int fd gm_io2 0 ulong irn 1675 cf = fclose int fd 1676 ckrc = gm_cli_exec false 1677 if ne ckrc 22 1678 ret gm_fail 181 1679 end 1680 ckp = ulong 0 1681 if eq ckrc 0 1682 ckp = ulong 1 1683 end 1684 mm_reset_req 1685 gm_load_fid 4 1686 mm_hash_input_u64 99 1687 mm_set_contract 1 ckp 1 0 1688 gm_put_u64_val 99 1689 if ne mm_store 50000 500 MM_ERR_IMPURE 1690 ret gm_fail 182 1691 end 1692 put gm_cli_neg 0 add get gm_cli_neg 0 1 1693 ret 0 1694 end 1695 1696 fn gm_stage8_live_ng to int 1697 nl = argread 2 gm_ngp 0 1023 1698 cl = argread 3 gm_ckp 0 1023 1699 if or lt nl 1 lt cl 1 1700 ret gm_fail 160 1701 end 1702 put gm_ngl 0 ulong nl 1703 put gm_ckl 0 ulong cl 1704 rc = gm_stage8_pure 1705 if ne rc 0 1706 ret rc 1707 end 1708 ret gm_stage8_impure 1709 end 1710 1711 note ---- Setup Scratch Root & Main ---- 1712 1713 fn gm_init_scratch to bool 1714 if ge argcnt 2 1715 sl = argread 1 gm_scp 0 1023 1716 if lt sl 1 1717 ret false 1718 end 1719 put gm_scl 0 ulong sl 1720 else 1721 pl = len gm_def_pfx 1722 for i ulong pl bound 64 1723 put gm_scp i get gm_def_pfx i 1724 end 1725 pid = ulong getpid 1726 x = pid 1727 q = ulong 24 1728 for i ulong 21 1729 q = sub q 1 1730 put gm_dig q uchar add 48 rem x 10 1731 x = div x 10 1732 if eq x 0 1733 break 1734 end 1735 end 1736 dc = sub 24 q 1737 for j ulong dc bound 24 1738 put gm_scp add pl j get gm_dig add q j 1739 end 1740 put gm_scl 0 add pl dc 1741 end 1742 r = makedir gm_scp 0 get gm_scl 0 493 1743 if and ne r 0 ne r neg long 17 1744 ret false 1745 end 1746 ret true 1747 end 1748 1749 fn main to int 1750 z = ar_need 0 65536 1751 ar_init 1752 note Check internal cross-process worker subcommands first 1753 if ge argcnt 2 1754 if gm_arg_eq 1 gm_w_store 1755 ret gm_worker_store 1756 end 1757 if gm_arg_eq 1 gm_w_look 1758 ret gm_worker_lookup 1759 end 1760 if gm_arg_eq 1 gm_w_ref 1761 ret gm_worker_refuse 1762 end 1763 if gm_arg_eq 1 gm_w_env 1764 ret gm_worker_env 1765 end 1766 end 1767 1768 put gm_chk 0 0 1769 put gm_neg 0 0 1770 put gm_xproc 0 0 1771 put gm_ent 0 0 1772 put gm_cli_chk 0 0 1773 put gm_cli_neg 0 0 1774 1775 gm_wrt gm_m_hdr 1776 if not gm_init_scratch 1777 ret gm_fail 1 1778 end 1779 ok = gm_build_ir_fids 1780 1781 rc = gm_stage1_env_root 1782 if ne rc 0 1783 ret rc 1784 end 1785 rc = gm_stage2_purity 1786 if ne rc 0 1787 ret rc 1788 end 1789 rc = gm_stage3_xproc 1790 if ne rc 0 1791 ret rc 1792 end 1793 rc = gm_stage4_dominance 1794 if ne rc 0 1795 ret rc 1796 end 1797 rc = gm_stage5_tamper 1798 if ne rc 0 1799 ret rc 1800 end 1801 rc = gm_stage6_profitability 1802 if ne rc 0 1803 ret rc 1804 end 1805 rc = gm_stage7_scale_alarm_prune 1806 if ne rc 0 1807 ret rc 1808 end 1809 1810 if ge argcnt 4 1811 rc = gm_stage8_live_ng 1812 if ne rc 0 1813 ret rc 1814 end 1815 end 1816 1817 gm_wrt gm_m_pass 1818 gm_num get gm_chk 0 1819 gm_wrt gm_m_neg 1820 gm_num get gm_neg 0 1821 gm_wrt gm_m_xp 1822 gm_num get gm_xproc 0 1823 gm_wrt gm_m_ent 1824 gm_num get gm_ent 0 1825 gm_wrt gm_m_cli 1826 gm_num get gm_cli_chk 0 1827 gm_wrt gm_m_cneg 1828 gm_num get gm_cli_neg 0 1829 gm_wrt gm_m_nl 1830 ret 0 1831 end