code wiki / _hdl_build / nx_reader_tcb_exceed.nx

nx_reader_tcb_exceed.nx source

↩ module page · 193 lines · 14462 B

1// nx_reader_tcb_exceed.nx -- READER-EXCEEDS-CALIBRE-WEB measured TCB panel (Reader-arc RUNG 4, the 2// architectural / exceed-by-unification axis the operator chose). 3// 4// AUTHOR=ORGAN, NO-WAVE, NO-OVERCLAIM (mirrors nx_driver_exceed.nx X-DRV-W3): COMPUTES every panel 5// value from REAL artifacts -- never asserted -- and is HONEST about what is NOT apples-to-apples 6// measurable. Nishi's sovereign reader (nx_media_server + the hand-written reader.html/cbx.html) is 7// compared head-to-head with Calibre-Web on the axes a flat artifact can be MEASURED on: 8// - single-auditable-server-binary : stat the RUNNING server ELF (/tmp/nx_media_server.sov.elf) and 9// PROVE static linkage by parsing its program headers for the absence of PT_INTERP (=3). A static 10// no-interpreter binary is the WHOLE server. Calibre-Web is a Python/Flask app (PROVEN here: its 11// captured response sets an itsdangerous-signed `session=eyJ...` Flask cookie) -- an interpreter + 12// framework stack, not a single auditable binary. => WIN minimal-auditable-server-TCB. 13// - client-side-3rd-party-deps : count external resource pulls in the REAL pages. Nishi reader.html + 14// cbx.html pull ZERO (no "://", no <script src>, no <link> -- everything is hand-written inline). 15// Calibre-Web's captured login page pulls N bundled /static/{js,css}/libs/ (Bootstrap, jQuery, 16// underscore, ...). => WIN dependency-free client. 17// - format-unification : ONE engine emits BOTH a reflowable model (book.json) AND a fixed-layout model 18// (cbx.json) -- both present, measured. (A Nishi capability, recorded; not asserted against CW.) 19// - memory / throughput / latency / CW-image-size : NOT apples-to-apples measurable (server RSS is a 20// WSL2 /proc artifact; CW content is auth-gated; loopback-vs-LAN; no NAS host access). => OPEN, NOT 21// CLAIMED (the no-overclaim discipline; an authenticated same-host perf bench is a separate rung). 22// 23// Authors knowledge/registry/reader_tcb_exceed_panel.tsv + logs RDREXCEED -> reader_tcb_exceed.log. 24// Sovereign (syscalls only, no gcc/python/.sh). license_tier: ORIGINAL 25import "nx_syscalls.nx" 26import "nx_seg_store.nx" // sovereign seg-store: the panel lives here, NO .tsv (operator: stop using tsv) 27const RT_MAGIC_65536: i64 = 65536 28const RT_MAGIC_16777216: i64 = 16777216 29const RT_MAGIC_1048576: i64 = 1048576 30const RT_MAGIC_262144: i64 = 262144 31const RT_MAGIC_8192: i64 = 8192 32const RT_MAGIC_2048: i64 = 2048 33 34const RT_NISHI_HTML: *u8 = "knowledge/staging/media/reader.html" 35const RT_NISHI_CBX: *u8 = "knowledge/staging/media/cbx.html" 36const RT_NISHI_ELF: *u8 = "/tmp/nx_media_server.sov.elf" 37const RT_CW_FP: *u8 = "knowledge/status/calibre_web_fingerprint.html" 38const RT_CW_HDR: *u8 = "knowledge/status/calibre_web_fingerprint.headers.txt" 39const RT_BOOKJSON: *u8 = "knowledge/staging/media/reader/dissolution_wotsq_b1/book.json" 40const RT_CBXJSON: *u8 = "knowledge/staging/media/reader/dragonlance_vol1/cbx.json" 41const RT_PANEL: *u8 = "knowledge/registry/reader_tcb_exceed_panel.tsv" 42const RT_LOG: *u8 = "knowledge/status/reader_tcb_exceed.log" 43const RT_PREFIX: *u8 = "knowledge/store/rtcb-" // the measured-exceed panel in the sovereign seg-store (NO tsv) 44 45func rt_p(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 46func rt_cat(dst: *u8, off: i64, s: *u8) -> i64 { var i: i64=0; while s[i]!=(0 as u8){ dst[off+i]=s[i]; i=i+1 } return off+i } 47func rt_catn(dst: *u8, off: i64, v: i64) -> i64 { let t: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m}; var k: i64=0; if m==0{t[0]=48 as u8;k=1}; while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1}; var o: i64=off; var q: i64=k-1; while q>=0{dst[o]=t[q];o=o+1;q=q-1} return o } 48func rt_seg_next() -> i64 { let segs: *i64 = sys_mmap(8*260) as *i64; let n: i64 = ss_manifest(RT_PREFIX, segs); if n<0 { return 1 } return 1+n } 49func rt_fp(fd: i64, s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(fd,s,n); return 0 } 50func rt_fn(fd: i64, v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m}; let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48;k=1}; while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1}; var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1}; sys_write(fd,bb,k); return 0 } 51 52// read a whole file into buf (cap-bounded); return byte count, or -1 if open fails. 53func rt_read(path: *u8, buf: *u8, cap: i64) -> i64 { 54 let fd: i64 = sys_openat_rd(path) 55 if fd < 0 { return 0 - 1 } 56 var n: i64 = 0 57 var go: i64 = 1 58 while go == 1 { let r: i64 = sys_read(fd, (buf as i64 + n) as *u8, cap - 1 - n); if r <= 0 { go = 0 } else { n = n + r } if n >= cap - 1 { go = 0 } } 59 sys_close(fd) 60 return n 61} 62 63// non-overlapping substring count over buf[0,n). 64func rt_count(buf: *u8, n: i64, pat: *u8, pl: i64) -> i64 { 65 if pl <= 0 { return 0 } 66 var c: i64 = 0 67 var i: i64 = 0 68 while i + pl <= n { 69 var k: i64 = 0; var hit: i64 = 1 70 while k < pl { if buf[i+k] != pat[k] { hit = 0; k = pl } else { k = k + 1 } } 71 if hit == 1 { c = c + 1; i = i + pl } else { i = i + 1 } 72 } 73 return c 74} 75func rt_has(buf: *u8, n: i64, pat: *u8, pl: i64) -> i64 { if rt_count(buf,n,pat,pl) > 0 { return 1 } return 0 } 76 77// little-endian unsigned readers (ARITHMETIC, not shift-or -- avoids the const/shift-or miscompile landmine). 78func rt_u16(b: *u8, o: i64) -> i64 { return (b[o] as i64) + (b[o+1] as i64)*256 } 79func rt_u32(b: *u8, o: i64) -> i64 { return (b[o] as i64) + (b[o+1] as i64)*256 + (b[o+2] as i64)*RT_MAGIC_65536 + (b[o+3] as i64)*RT_MAGIC_16777216 } 80 81func main() -> i64 { 82 rt_p("=== nx_reader_tcb_exceed: measured no-overclaim reader-TCB panel (RUNG 4) ===\n" as *u8) 83 84 // ---- MEASURE the Nishi server ELF: bytes + ELF magic + PROVE static via no PT_INTERP ---- 85 let elfbuf: *u8 = sys_mmap(RT_MAGIC_1048576) 86 let elfn: i64 = rt_read(RT_NISHI_ELF, elfbuf, RT_MAGIC_1048576) 87 if elfn <= 0 { 88 rt_p("RDREXCEED verdict=RED reason=server-elf-missing (start nx_media_server first)\n" as *u8) 89 let lf0: i64 = sys_openat_append(RT_LOG, 0x1a4); if lf0>=0 { rt_fp(lf0,"RDREXCEED verdict=RED reason=server-elf-missing\n" as *u8); sys_close(lf0) } 90 sys_exit(1); return 1 91 } 92 var elf_magic: i64 = 0 93 if elfn >= 4 { if elfbuf[0]==(127 as u8) { if elfbuf[1]==(69 as u8) { if elfbuf[2]==(76 as u8) { if elfbuf[3]==(70 as u8) { elf_magic = 1 } } } } } 94 var has_interp: i64 = 0 95 if elf_magic == 1 { 96 let phoff: i64 = rt_u32(elfbuf, 32) // e_phoff (low 4 bytes; tiny for a static ELF) 97 let phent: i64 = rt_u16(elfbuf, 54) // e_phentsize 98 let phnum: i64 = rt_u16(elfbuf, 56) // e_phnum 99 var i: i64 = 0 100 while i < phnum { 101 let ph: i64 = phoff + i*phent 102 if ph + 4 <= elfn { if rt_u32(elfbuf, ph) == 3 { has_interp = 1 } } // PT_INTERP=3 => dynamic loader needed 103 i = i + 1 104 } 105 } 106 var static_ok: i64 = 0 107 if elf_magic == 1 { if has_interp == 0 { static_ok = 1 } } 108 109 // ---- MEASURE client-side 3rd-party deps from the REAL pages ---- 110 let hbuf: *u8 = sys_mmap(RT_MAGIC_262144) 111 let hn: i64 = rt_read(RT_NISHI_HTML, hbuf, RT_MAGIC_262144) 112 var nishi_ext: i64 = 0 113 nishi_ext = nishi_ext + rt_count(hbuf, hn, "://" as *u8, 3) 114 nishi_ext = nishi_ext + rt_count(hbuf, hn, "<script src" as *u8, 11) 115 nishi_ext = nishi_ext + rt_count(hbuf, hn, "<link" as *u8, 5) 116 let cbuf: *u8 = sys_mmap(RT_MAGIC_262144) 117 let cn: i64 = rt_read(RT_NISHI_CBX, cbuf, RT_MAGIC_262144) 118 nishi_ext = nishi_ext + rt_count(cbuf, cn, "://" as *u8, 3) 119 nishi_ext = nishi_ext + rt_count(cbuf, cn, "<script src" as *u8, 11) 120 nishi_ext = nishi_ext + rt_count(cbuf, cn, "<link" as *u8, 5) 121 122 let cwbuf: *u8 = sys_mmap(RT_MAGIC_262144) 123 let cwn: i64 = rt_read(RT_CW_FP, cwbuf, RT_MAGIC_262144) 124 var cw_libs: i64 = 0 125 cw_libs = cw_libs + rt_count(cwbuf, cwn, "/static/js/libs/" as *u8, 16) 126 cw_libs = cw_libs + rt_count(cwbuf, cwn, "/static/css/libs/" as *u8, 17) 127 let cw_static: i64 = rt_count(cwbuf, cwn, "/static/" as *u8, 8) 128 129 // ---- PROVE Calibre-Web is a Python/Flask stack from its captured response headers ---- 130 let hdrbuf: *u8 = sys_mmap(RT_MAGIC_65536) 131 let hdrn: i64 = rt_read(RT_CW_HDR, hdrbuf, RT_MAGIC_65536) 132 let cw_flask: i64 = rt_has(hdrbuf, hdrn, "session=eyJ" as *u8, 11) // itsdangerous-signed Flask session cookie 133 134 // ---- MEASURE format-unification: reflow model + fixed-layout model both present ---- 135 let jb: *u8 = sys_mmap(RT_MAGIC_8192) 136 var book_present: i64 = 0 137 if rt_read(RT_BOOKJSON, jb, RT_MAGIC_8192) > 0 { book_present = 1 } 138 var cbx_present: i64 = 0 139 if rt_read(RT_CBXJSON, jb, RT_MAGIC_8192) > 0 { cbx_present = 1 } 140 var unification: i64 = 0 141 if book_present == 1 { unification = unification + 1 } 142 if cbx_present == 1 { unification = unification + 1 } 143 144 // ---- AUTHOR the panel (every value above is MEASURED from a real artifact) ---- 145 // author the MEASURED panel into the SOVEREIGN seg-store (knowledge/store/rtcb-*), NO .tsv. keyed rtcb:<axis>. 146 let w: *i64 = ss_begin() 147 let rb: *u8 = sys_mmap(RT_MAGIC_2048) 148 var o: i64 = 0 149 o = rt_cat(rb, 0, "single-auditable-server-binary\t" as *u8); o = rt_catn(rb, o, elfn); o = rt_cat(rb, o, "B-static-ELF-no-PT_INTERP\tPython/Flask-interpreter+framework-stack\t" as *u8) 150 if static_ok == 1 { if cw_flask == 1 { o = rt_cat(rb, o, "WIN" as *u8) } else { o = rt_cat(rb, o, "OPEN" as *u8) } } else { o = rt_cat(rb, o, "OPEN" as *u8) } 151 o = rt_cat(rb, o, "\tELF-phdr-scan(no-interp)+CW-Flask-session-cookie" as *u8) 152 ss_add(w, 1, "rtcb:single-auditable-server-binary" as *u8, rb, o) 153 o = rt_cat(rb, 0, "client-3rd-party-deps\t" as *u8); o = rt_catn(rb, o, nishi_ext); o = rt_cat(rb, o, "-external-pulls(inline)\t" as *u8); o = rt_catn(rb, o, cw_libs); o = rt_cat(rb, o, "-bundled-static-libs\t" as *u8) 154 if nishi_ext == 0 { if cw_libs > 0 { o = rt_cat(rb, o, "WIN" as *u8) } else { o = rt_cat(rb, o, "OPEN" as *u8) } } else { o = rt_cat(rb, o, "OPEN" as *u8) } 155 o = rt_cat(rb, o, "\tpage-scan(script-src/link-vs-static-libs)" as *u8) 156 ss_add(w, 1, "rtcb:client-3rd-party-deps" as *u8, rb, o) 157 o = rt_cat(rb, 0, "format-unification\treflow(book.json)+fixed(cbx.json)=" as *u8); o = rt_catn(rb, o, unification); o = rt_cat(rb, o, "-models-1-engine\tepub.js+Calibre-convert(multi-tool)\t" as *u8) 158 if unification >= 2 { o = rt_cat(rb, o, "WIN" as *u8) } else { o = rt_cat(rb, o, "OPEN" as *u8) } 159 o = rt_cat(rb, o, "\treader-model-files-present" as *u8) 160 ss_add(w, 1, "rtcb:format-unification" as *u8, rb, o) 161 o = rt_cat(rb, 0, "server-memory-rss\tOPEN\tOPEN\tOPEN\tWSL2-/proc-RSS-NOT-CLAIMED" as *u8); ss_add(w, 1, "rtcb:server-memory-rss" as *u8, rb, o) 162 o = rt_cat(rb, 0, "request-throughput\tOPEN\tOPEN\tOPEN\tloopback-vs-LAN-auth-gated-NOT-CLAIMED" as *u8); ss_add(w, 1, "rtcb:request-throughput" as *u8, rb, o) 163 o = rt_cat(rb, 0, "request-latency\tOPEN\tOPEN\tOPEN\tloopback-vs-LAN-auth-gated-NOT-CLAIMED" as *u8); ss_add(w, 1, "rtcb:request-latency" as *u8, rb, o) 164 o = rt_cat(rb, 0, "cw-image-disk-size\tn/a\tOPEN\tOPEN\tno-NAS-host-access-NOT-CLAIMED" as *u8); ss_add(w, 1, "rtcb:cw-image-disk-size" as *u8, rb, o) 165 o = rt_cat(rb, 0, "single-auditable-server-binary\tclient-3rd-party-deps\tformat-unification\tserver-memory-rss\trequest-throughput\trequest-latency\tcw-image-disk-size" as *u8); ss_add(w, 1, "rtcb:ids" as *u8, rb, o) 166 o = rt_cat(rb, 0, "authored=organ reader-arc-rung4 vs-calibre-web measured-not-asserted NO-OVERCLAIM(memory/throughput/latency/cw-image=OPEN); seg-store NOT tsv" as *u8); ss_add(w, 1, "rtcb:provenance" as *u8, rb, o) 167 if ss_commit(RT_PREFIX, w, rt_seg_next()) != 0 { rt_p("RDREXCEED verdict=RED reason=store-commit-failed\n" as *u8); sys_exit(1); return 1 } 168 169 // ---- counts + no-overclaim verdict ---- 170 var wins: i64 = 0 171 if static_ok == 1 { if cw_flask == 1 { wins = wins + 1 } } 172 if nishi_ext == 0 { if cw_libs > 0 { wins = wins + 1 } } 173 if unification >= 2 { wins = wins + 1 } 174 175 rt_p(" measured: server_elf=" as *u8); rt_fn(1, elfn); rt_p("B static_ok=" as *u8); rt_fn(1, static_ok) 176 rt_p(" nishi_client_deps=" as *u8); rt_fn(1, nishi_ext); rt_p(" cw_bundled_libs=" as *u8); rt_fn(1, cw_libs) 177 rt_p(" cw_flask=" as *u8); rt_fn(1, cw_flask); rt_p(" unification=" as *u8); rt_fn(1, unification); rt_p("\n" as *u8) 178 rt_p(" panel: wins=" as *u8); rt_fn(1, wins); rt_p(" | OPEN(not-claimed)=memory,throughput,latency,cw-image-size\n" as *u8) 179 180 let lf: i64 = sys_openat_append(RT_LOG, 0x1a4) 181 // GREEN iff BOTH head-to-head measured wins hold (single-binary + client-deps); unification is a bonus capability. 182 var pass: i64 = 0 183 if static_ok == 1 { if cw_flask == 1 { if nishi_ext == 0 { if cw_libs > 0 { pass = 1 } } } } 184 if pass == 1 { 185 rt_p("RDREXCEED verdict=GREEN (no-overclaim measured panel: Nishi reader MEASURABLY exceeds Calibre-Web on minimal-auditable-server-TCB [1 static no-interp ELF vs Python/Flask stack] + dependency-free client [0 external pulls vs bundled libs]; format-unification capability present; memory/throughput/latency honestly OPEN -- not claimed)\n" as *u8) 186 if lf >= 0 { rt_fp(lf, "RDREXCEED verdict=GREEN keystone=reader-exceeds-calibreweb-tcb-panel wins=" as *u8); rt_fn(lf, wins); rt_fp(lf, " server_elf_bytes=" as *u8); rt_fn(lf, elfn); rt_fp(lf, " static_ok=" as *u8); rt_fn(lf, static_ok); rt_fp(lf, " nishi_client_deps=" as *u8); rt_fn(lf, nishi_ext); rt_fp(lf, " cw_bundled_libs=" as *u8); rt_fn(lf, cw_libs); rt_fp(lf, " cw_static=" as *u8); rt_fn(lf, cw_static); rt_fp(lf, " cw_flask=" as *u8); rt_fn(lf, cw_flask); rt_fp(lf, " unification=" as *u8); rt_fn(lf, unification); rt_fp(lf, " open=memory,throughput,latency,cw-image(NOT-CLAIMED) epoch=" as *u8); rt_fn(lf, sys_now_realtime_sec()); rt_fp(lf, "\n" as *u8); sys_close(lf) } 187 sys_exit(0); return 0 188 } 189 rt_p("RDREXCEED verdict=RED (a measured head-to-head win did not hold -- check static_ok/cw_flask/client-deps)\n" as *u8) 190 if lf >= 0 { rt_fp(lf, "RDREXCEED verdict=RED static_ok=" as *u8); rt_fn(lf, static_ok); rt_fp(lf, " cw_flask=" as *u8); rt_fn(lf, cw_flask); rt_fp(lf, " nishi_client_deps=" as *u8); rt_fn(lf, nishi_ext); rt_fp(lf, " cw_bundled_libs=" as *u8); rt_fn(lf, cw_libs); rt_fp(lf, "\n" as *u8); sys_close(lf) } 191 sys_exit(1) 192 return 1 193}