code wiki / _hdl_build / nx_gateorder.nx

nx_gateorder.nx source

↩ module page · 254 lines · 9860 B

1// nx_gateorder.nx -- sweeps a source tree asking ONE question it can actually answer: 2// DOES THIS GATE LEAVE A DURABLE VERDICT RECORD AT ALL? 3// 4// The standing form of a one-off /tmp shell sweep. A finding not wired into a standing instrument 5// decays, so the check lives here: repeatable by any seat, on any tree, with no shell. 6// 7// ⚠⚠ORDERING IS DELIBERATELY NOT JUDGED. An earlier version of this organ also reported EMIT-EARLY by 8// comparing the first emit-token offset against the last tooth offset. It was WRONG ON ALL SEVEN gates 9// it flagged, and I filed a sev7 debt against other lanes before checking: the token's first textual 10// occurrence lands on HELPER DEFINITIONS (`func g_log`), on TEST FIXTURES, and on /tmp scratch writes -- 11// and this organ's own gate self-flagged, because the pattern appears in its test-data string literals. 12// ★★★★★TEXTUAL POSITION CANNOT DECIDE EXECUTION ORDER. The one genuine ordering defect in this arc was 13// caught by READING THE LOG (gate printed 41/41 while its log said 23/23), which grep could never do. 14// 15// nx_gateorder [root] default root = runtime exit 0 always (a report, not a verdict) 16// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0 17import "nx_gateorder_lib.nx" 18 19const GOW_FCAP: i64 = 262144 20const GOW_DBUF: i64 = 65536 21const GOW_PATH: i64 = 1024 22const GOW_MAXDEPTH: i64 = 12 23const GOW_MAXLIVE: i64 = 512 24const GOW_NAMEW: i64 = 64 25 26static gow_fbuf: *u8 27static gow_noemit: i64 28static gow_present: i64 29static gow_total: i64 30static gow_noemit_live: i64 31static gow_noemit_srconly: i64 32static gow_elfpath: *u8 33static gow_livenames: *u8 34static gow_nlive: i64 35static gow_listmode: i64 36 37func gow_init() { 38 gow_fbuf = sys_mmap(GOW_FCAP + 64) as *u8 39 gow_elfpath = sys_mmap(GOW_PATH + 64) as *u8 40 gow_noemit = 0 41 gow_present = 0 42 gow_total = 0 43 gow_noemit_live = 0 44 gow_noemit_srconly = 0 45 gow_livenames = sys_mmap(GOW_MAXLIVE * GOW_NAMEW + 64) as *u8 46 gow_nlive = 0 47 gow_listmode = 0 48} 49 50// A bare COUNT of no-emit gates is too blunt to act on: 2239 reads as hopeless and hides the part that 51// matters. A gate with a PROMOTED BINARY runs and records nothing -- a real, live gap. A source-only 52// gate has never run at all, so its silence is expected. Splitting them turns one scary number into a 53// prioritised one. Existence check only: open the promoted elf beside the organ's cwd and close it. 54func gow_has_binary(srcname: *u8) -> i64 { 55 var w: i64 = 0 56 var i: i64 = 0 57 while srcname[i] != (0 as u8) { 58 if w < GOW_PATH - 5 { 59 gow_elfpath[w] = srcname[i] 60 w = w + 1 61 } 62 i = i + 1 63 } 64 if w < 3 { return 0 } 65 w = w - 3 66 gow_elfpath[w] = 46 as u8 67 gow_elfpath[w + 1] = 101 as u8 68 gow_elfpath[w + 2] = 108 as u8 69 gow_elfpath[w + 3] = 102 as u8 70 gow_elfpath[w + 4] = 0 as u8 71 let fd: i64 = sys_openat_rd(gow_elfpath) 72 if fd < 0 { return 0 } 73 sys_close(fd) 74 return 1 75} 76 77func gow_join(dir: *u8, name: *u8, out: *u8) { 78 var w: i64 = 0 79 var i: i64 = 0 80 while dir[i] != (0 as u8) { 81 if w < GOW_PATH - 2 { 82 out[w] = dir[i] 83 w = w + 1 84 } 85 i = i + 1 86 } 87 if w > 0 { 88 if out[w - 1] != (47 as u8) { 89 out[w] = 47 as u8 90 w = w + 1 91 } 92 } 93 var j: i64 = 0 94 while name[j] != (0 as u8) { 95 if w < GOW_PATH - 1 { 96 out[w] = name[j] 97 w = w + 1 98 } 99 j = j + 1 100 } 101 out[w] = 0 as u8 102} 103 104func gow_is_dot(name: *u8) -> i64 { 105 if name[0] != (46 as u8) { return 0 } 106 if name[1] == (0 as u8) { return 1 } 107 if name[1] == (46 as u8) { 108 if name[2] == (0 as u8) { return 1 } 109 } 110 return 0 111} 112 113func gow_read_file(path: *u8) -> i64 { 114 let fd: i64 = sys_openat_rd(path) 115 if fd < 0 { return 0 - 1 } 116 var total: i64 = 0 117 var done: i64 = 0 118 while done == 0 { 119 let want: i64 = GOW_FCAP - total 120 if want <= 0 { done = 1 } 121 else { 122 let got: i64 = sys_read(fd, ((gow_fbuf as i64) + total) as *u8, want) 123 if got <= 0 { done = 1 } 124 else { total = total + got } 125 } 126 } 127 sys_close(fd) 128 return total 129} 130 131func gow_record(cls: i64, srcname: *u8) { 132 gow_total = gow_total + 1 133 if cls == GO_NOEMIT { 134 gow_noemit = gow_noemit + 1 135 if gow_has_binary(srcname) == 1 { 136 gow_noemit_live = gow_noemit_live + 1 137 // NAME THEM. A count without its members cannot be acted on or disproved -- my own lesson, 138 // and this very number (317) was the last place in my work still violating it. 139 if gow_nlive < GOW_MAXLIVE { 140 var w: i64 = 0 141 let slot: i64 = (gow_livenames as i64) + gow_nlive * GOW_NAMEW 142 while srcname[w] != (0 as u8) { 143 if w < GOW_NAMEW - 1 { 144 let d: *u8 = (slot + w) as *u8 145 d[0] = srcname[w] 146 } 147 w = w + 1 148 } 149 if w > GOW_NAMEW - 1 { w = GOW_NAMEW - 1 } 150 let term: *u8 = (slot + w) as *u8 151 term[0] = 0 as u8 152 gow_nlive = gow_nlive + 1 153 } 154 } 155 else { gow_noemit_srconly = gow_noemit_srconly + 1 } 156 } 157 else { gow_present = gow_present + 1 } 158} 159 160func gow_scan_dir(dir: *u8, depth: i64) { 161 if depth > GOW_MAXDEPTH { return } 162 let dfd: i64 = sys_openat_rd(dir) 163 if dfd < 0 { return } 164 let dbuf: *u8 = sys_mmap(GOW_DBUF + 64) as *u8 165 let cpath: *u8 = sys_mmap(GOW_PATH + 64) as *u8 166 var looping: i64 = 1 167 while looping == 1 { 168 let nread: i64 = sys_getdents64(dfd, dbuf, GOW_DBUF) 169 if nread <= 0 { looping = 0 } 170 else { 171 var off: i64 = 0 172 while off < nread { 173 let lo: i64 = dbuf[off + 16] as i64 174 let hi: i64 = dbuf[off + 17] as i64 175 let reclen: i64 = lo + hi * 256 176 let dtype: i64 = dbuf[off + 18] as i64 177 let nm: *u8 = ((dbuf as i64) + off + 19) as *u8 178 if gow_is_dot(nm) == 0 { 179 gow_join(dir, nm, cpath) 180 if dtype == 4 { gow_scan_dir(cpath, depth + 1) } 181 if dtype == 8 { 182 if go_ends_gate_nx(nm) == 1 { 183 let n: i64 = gow_read_file(cpath) 184 if n > 0 { gow_record(go_classify(gow_fbuf, n), nm) } 185 } 186 } 187 } 188 if reclen <= 0 { off = nread } 189 else { off = off + reclen } 190 } 191 } 192 } 193 sys_close(dfd) 194} 195 196func main(argc: i64, argv: *i64) -> i64 { 197 gow_init() 198 var root: *u8 = "runtime" as *u8 199 var ai: i64 = 1 200 while ai < argc { 201 let a: *u8 = argv[ai] as *u8 202 if go_match_at(a, 0, go_strlen(a), "--list" as *u8) == 1 { gow_listmode = 1 } 203 else { root = a } 204 ai = ai + 1 205 } 206 go_puts("=== NX-GATEORDER: do gates leave a DURABLE VERDICT RECORD? ===\n" as *u8) 207 go_puts("root=" as *u8) 208 go_puts(root) 209 go_puts("\n\n" as *u8) 210 gow_scan_dir(root, 0) 211 212 go_kv("gates_scanned" as *u8, gow_total) 213 go_kv("NO_EMIT_no_durable_verdict" as *u8, gow_noemit) 214 go_puts("\n" as *u8) 215 go_kv(" of_those_LIVE_have_a_promoted_binary" as *u8, gow_noemit_live) 216 go_kv(" source_only_never_promoted" as *u8, gow_noemit_srconly) 217 go_puts("\n" as *u8) 218 go_kv("emit_present" as *u8, gow_present) 219 var permil: i64 = 0 220 if gow_total > 0 { permil = gow_present * 1000 / gow_total } 221 go_kv("emit_coverage_permil" as *u8, permil) 222 if gow_listmode == 1 { 223 go_puts("\n\n-- THE ACTIONABLE SET: gates that RUN (promoted binary) and record NOTHING --\n" as *u8) 224 go_puts(" these are the ones a ruler cannot see. Source-only gates are excluded on purpose.\n\n" as *u8) 225 var li: i64 = 0 226 while li < gow_nlive { 227 go_puts(" " as *u8) 228 go_puts(((gow_livenames as i64) + li * GOW_NAMEW) as *u8) 229 go_puts("\n" as *u8) 230 li = li + 1 231 } 232 // A SILENT CAP READS AS "THAT IS ALL". Declare what was withheld. 233 if gow_noemit_live > gow_nlive { 234 go_puts("\n ⚠LIST CAPPED at " as *u8) 235 go_puti(gow_nlive) 236 go_puts(" -- " as *u8) 237 go_puti(gow_noemit_live - gow_nlive) 238 go_puts(" MORE not shown. A silent cap would read as 'that is all'.\n" as *u8) 239 } 240 } 241 go_puts("\n\n-- WHAT THIS DOES AND DOES NOT SAY --\n" as *u8) 242 go_puts(" NO-EMIT: the source carries no verdict-emit token, so it leaves no durable record in\n" as *u8) 243 go_puts(" knowledge/status. A ruler reading that channel cannot see these gates at all.\n" as *u8) 244 go_puts(" It does NOT mean unevidenced: /api/gate_run and nx_swcompare_evidence run a gate and read\n" as *u8) 245 go_puts(" its EXIT CODE live. The gap is the PERSISTENT channel, consulted when nobody is watching.\n" as *u8) 246 go_puts(" It also cannot see an emit reaching a gate through an IMPORTED helper -- so NO-EMIT is an\n" as *u8) 247 go_puts(" UPPER BOUND on the gap, never a proven count.\n\n" as *u8) 248 go_puts(" ORDERING IS NOT JUDGED, ON PURPOSE. Deriving it from textual position flagged SEVEN\n" as *u8) 249 go_puts(" innocent gates (helper definitions, test fixtures, /tmp writes) and this organ's own gate.\n" as *u8) 250 go_puts(" A WRONG ANSWER IS WORSE THAN AN ABSENT ONE, and a sev7 built on a bad detector sends other\n" as *u8) 251 go_puts(" seats to edit correct code. Catch ordering by READING THE LOG against the gate output.\n" as *u8) 252 go_puts(" classifier gate: nx_gateorder_gate (carries a revert-detector for the ordering verdict).\n" as *u8) 253 return 0 254}