code wiki / (root) / nx_execsurface.nx

nx_execsurface.nx source

↩ module page · 813 lines · 45298 B

1// nx_execsurface.nx -- WHICH SURFACE RUNS THIS PROGRAM? The execution-surface census for PROMOTED organs 2// (2026-08-23, compare CE2, operator: no false ceilings). 3// 4// THE FALSE CEILING THIS CLOSES: the adoption ladder's INVOKED axis reads knowledge/status/actlog.jrnl, 5// which records MCP-surface invocations ONLY. A program the clock plane fires nightly, a cron row, a daemon 6// supervisor, the gate roster, or a ./x.elf fork from another organ therefore read REGISTERED-DARK ("no MCP 7// invocation on record") while executing every day -- measured on the live graphics board: 12 of 19 8// PARTIAL rows, among them organs gates fork on every beat. nx_gateadjudicate solved exactly this for 9// GATES by joining the gate population to the surfaces that CAUSE EXECUTION; nobody did it for programs. 10// THE MCP REGISTRY IS NOT THE ONLY DOOR, AND A LADDER THAT ONLY WATCHES ONE DOOR CALLS EVERY OTHER 11// ENTRANT DARK. 12// 13// THE EDGE DEFINITION IS THE QUESTION (gateadjudicate's law, measured 08-07: four definitions gave 14// 75 / 0 / 2,043 / 30). A program counts as ON A SURFACE only through something that CAUSES execution: 15// CLOCK the live clocksched- plane names its .elf in the organ column, split at spaces so an organ 16// named in another row's ARGUMENTS (nx_sov_build_run.elf <gate>) counts too 17// CRON a cron.reg row names <n>.elf, <n>.sh or <n>.cron.sh (shell wrappers spawn the organ) 18// PLAN a clock row runs nx_plan_run.elf <id>: every tool the rows of knowledge/store/plan-<id>- name is 19// credited (2026-09-17; the clock row is the cause, the plan the route -- workflows-as-data are a 20// surface, and before this every plan-run organ read REGISTERED-DARK, measured on nx_search_ship) 21// DAEMON a daemons.reg row's argv names <n>.elf (the supervisor keeps it alive) 22// ROSTER a row of a ROSTER CONF names it (a beat of nx_gate_roster_run forks it): the runner's default 23// knowledge/gateroster.conf and every conf a live clock row runs through nx_gate_roster_run beat, whatever 24// journal that beat writes, derived from the plane by nx_rosterconf_lib and read with the beat's own row grammar 25// (2026-09-18: the heavy roster's gates read roster=0 while its beat ran them daily; a later roster is read by 26// declaring its clock row, with no edit here). A slow beat writing its own journal is credited like any other: 27// the close ruler reads each roster's evidence from that roster's journal; the stamp still counts those beats 28// (roster_beats_other_journal) 29// ACTLOG the MCP tail window mentions it (the one door the ladder already watched) 30// FORK another organ's SOURCE carries the string literal "./<n>.elf", "../<n>.elf" or "_offc/<n>.elf" AND that 31// caller is itself on a surface -- 2-hop, iterated to a fixed point, so a beat-run organ that 32// forks a helper that forks a third credits the third. A literal in a caller that is NOT on any 33// surface is a REF: something wants it, nothing runs it. A MERE MENTION IS NOT INVOCATION. 34// The literal must open a string ("./x.elf), so prose in a comment cannot credit a fork. 35// ROWS name<TAB>clock<TAB>cron<TAB>daemon<TAB>fork<TAB>roster<TAB>actlog<TAB>first_surface 36// clock/cron/daemon/roster/actlog are 0|1; fork is "-" or the first crediting caller's basename; 37// first_surface is clock|cron|daemon|roster|actlog|plan|fork:<caller>|ref:<caller>|- (the token a board prints) 38// LAST LINE (the canonical stamp, anchored BY POSITION; consumers never grep the rows for it): 39// # asof=<epoch> organs=N on_surface=A ref_only=B dark=C sources=clock:<rows>,cron:<rows>,daemon:<rows>, 40// roster:<rows>,roster_confs:<read>,roster_beats:<n>,roster_beats_other_journal:<n>,actlog:<bytes>,fork_files:<n>, 41// fork_edges:<n>,hops:<n> 42// blind=laptop-hooks,offhost-rosters 43// A + B + C == organs is the partition, printed and checked by the gate. 44// DECLARED BLIND SPOTS: laptop-side hooks and off-host rosters are not on this host; the actlog is a tail 45// window; a fork literal assembled at runtime from pieces is invisible to a literal scan. 46// usage: nx_execsurface [out-path] default knowledge/status/execsurface.tsv (run from the estate root) 47// nx_execsurface who <organ> READ the last census: which surface launches <organ> (exit 0 ON-SURFACE, 1 NO-SURFACE, 2 NOT-IN-CENSUS, 3 UNOBSERVABLE) 48// exit 0 written | 3 UNOBSERVABLE (no organs enumerated: wrong CWD -- writes NOTHING) | 4 write failed 49// license_tier: ORIGINAL Read-only over the estate except its one artifact. No hw writes (Rule 26). 50import "nx_syscalls.nx" 51import "nx_tool_run.nx" 52import "nx_rosterconf_lib.nx" 53 54const ES_DEC_MAX: i64 = 20 55const ES_NAME_CAP: i64 = 128 // one organ basename; a longer name is refused and counted 56const ES_DIRBUF: i64 = 131072 // one getdents64 window (looped until 0, so no listing is a prefix) 57const ES_PATHCAP: i64 = 4096 // Linux PATH_MAX 58const ES_ROW_FIXED: i64 = 16 + 2 * ES_NAME_CAP // tabs, five flags, "fork:" + caller, newline 59const ES_TAIL_FIXED: i64 = 512 60const ES_ACT_TAIL: i64 = 4194304 // the same tail window nx_catalog reads (declared in the stamp) 61const ES_PLANE_CAP: i64 = 1048576 // captured stdout of nx_store_put load: a pipe has no knowable size; ANNOUNCED if it fills 62const ES_MIN_LIT: i64 = 9 // the shortest fork literal: "./x.elf" plus its opening quote 63 64func es_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 65func es_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 66func es_cat(d: *u8, o: i64, s: *u8) -> i64 { var i: i64 = 0; var p: i64 = o; while s[i] != (0 as u8) { d[p] = s[i]; p = p + 1; i = i + 1 } d[p] = 0 as u8; return p } 67func es_catn(d: *u8, o: i64, v: i64) -> i64 { 68 var p: i64 = o 69 var m: i64 = v 70 if m < 0 { d[p] = 45 as u8; p = p + 1; m = 0 - m } 71 let t: *u8 = sys_mmap(ES_DEC_MAX + 4) 72 var k: i64 = 0 73 if m == 0 { t[0] = 48 as u8; k = 1 } 74 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 75 var j: i64 = 0 76 while j < k { d[p] = t[k - 1 - j]; p = p + 1; j = j + 1 } 77 d[p] = 0 as u8 78 sys_munmap(t, ES_DEC_MAX + 4) 79 return p 80} 81func es_putn(v: i64) -> i64 { let b: *u8 = sys_mmap(ES_DEC_MAX + 4); let n: i64 = es_catn(b, 0, v); sys_write(1, b, n); sys_munmap(b, ES_DEC_MAX + 4); return 0 } 82func es_eq(a: *u8, b: *u8) -> i64 { var i: i64 = 0; while a[i] != (0 as u8) { if a[i] != b[i] { return 0 } i = i + 1 } if b[i] != (0 as u8) { return 0 } return 1 } 83func es_ends(s: *u8, sfx: *u8) -> i64 { 84 let n: i64 = es_slen(s) 85 let m: i64 = es_slen(sfx) 86 if n < m { return 0 } 87 var k: i64 = 0 88 while k < m { if s[n - m + k] != sfx[k] { return 0 } k = k + 1 } 89 return 1 90} 91func es_isdotdot(nm: *u8) -> i64 { 92 if nm[0] == (46 as u8) { if nm[1] == (0 as u8) { return 1 } if nm[1] == (46 as u8) { if nm[2] == (0 as u8) { return 1 } } } 93 return 0 94} 95// read a whole file, estate-relative to the CWD; length into lp[0]; 0 when absent 96func es_read(path: *u8, lp: *i64) -> *u8 { 97 lp[0] = 0 98 let fd: i64 = sys_openat_rd(path) 99 if fd < 0 { return 0 as *u8 } 100 let sz: i64 = sys_lseek(fd, 0, 2) 101 if sz < 0 { sys_close(fd); return 0 as *u8 } 102 sys_lseek(fd, 0, 0) 103 let buf: *u8 = sys_mmap(sz + 8) 104 var n: i64 = 0 105 var go: i64 = 1 106 while go == 1 { 107 if n >= sz { go = 0 } else { 108 let r: i64 = sys_read(fd, ((buf as i64) + n) as *u8, sz - n) 109 if r <= 0 { go = 0 } else { n = n + r } 110 } 111 } 112 sys_close(fd) 113 buf[n] = 0 as u8 114 lp[0] = n 115 return buf 116} 117// tail window of an append-only ledger (nx_catalog's rule: the NEWEST bytes are the evidence) 118func es_read_tail(path: *u8, cap: i64, lp: *i64) -> *u8 { 119 lp[0] = 0 120 let fd: i64 = sys_openat_rd(path) 121 if fd < 0 { return 0 as *u8 } 122 let sz: i64 = sys_lseek(fd, 0, 2) 123 if sz > cap { sys_lseek(fd, sz - cap, 0) } else { sys_lseek(fd, 0, 0) } 124 let buf: *u8 = sys_mmap(cap + 8) 125 var n: i64 = 0 126 var go: i64 = 1 127 while go == 1 { 128 let r: i64 = sys_read(fd, ((buf as i64) + n) as *u8, cap - n) 129 if r <= 0 { go = 0 } else { n = n + r } 130 if n >= cap { go = 0 } 131 } 132 sys_close(fd) 133 buf[n] = 0 as u8 134 lp[0] = n 135 return buf 136} 137 138// ---- THE ORGAN TABLE: names in an arena, flags per organ ---- 139// st[] layout per organ i: ES_F_* slots; names at name_off[i] in arena 140const ES_F_CLOCK: i64 = 0 141const ES_F_CRON: i64 = 1 142const ES_F_DAEMON: i64 = 2 143const ES_F_ROSTER: i64 = 3 144const ES_F_ACTLOG: i64 = 4 145const ES_F_FORK: i64 = 5 // index of the crediting caller organ, -1 none 146const ES_F_REF: i64 = 6 // index of the first caller organ that merely names it, -1 none 147const ES_F_PLAN: i64 = 7 // 1 = a clock row runs nx_plan_run <id> and that plan's rows name this organ 148const ES_F_N: i64 = 8 149 150func es_name(arena: *u8, off: *i64, i: i64) -> *u8 { return ((arena as i64) + off[i]) as *u8 } 151// index of name in the table, -1 absent (linear: the table is ~2k names, the queries ~5k tokens) 152func es_find(arena: *u8, off: *i64, n: i64, name: *u8) -> i64 { 153 var i: i64 = 0 154 while i < n { if es_eq(es_name(arena, off, i), name) == 1 { return i } i = i + 1 } 155 return 0 - 1 156} 157// strip a leading "./" and a trailing ".elf" from tok into out; returns 1 when it looked like an organ ref 158func es_organ_token(tok: *u8, out: *u8) -> i64 { 159 var s: i64 = 0 160 if tok[0] == (46 as u8) { if tok[1] == (47 as u8) { s = 2 } } 161 // any path prefix: keep the basename 162 var i: i64 = s 163 while tok[i] != (0 as u8) { if tok[i] == (47 as u8) { s = i + 1 } i = i + 1 } 164 let base: *u8 = ((tok as i64) + s) as *u8 165 let bl: i64 = es_slen(base) 166 if bl >= ES_NAME_CAP { return 0 } 167 var e: i64 = bl 168 var looked: i64 = 0 169 if es_ends(base, ".elf" as *u8) == 1 { e = bl - 4; looked = 1 } 170 if looked == 0 { if es_ends(base, ".cron.sh" as *u8) == 1 { e = bl - 8; looked = 1 } } 171 if looked == 0 { if es_ends(base, ".sh" as *u8) == 1 { e = bl - 3; looked = 1 } } 172 var k: i64 = 0 173 while k < e { out[k] = base[k]; k = k + 1 } 174 out[e] = 0 as u8 175 if looked == 1 { return 1 } 176 // a bare token that IS an organ name (nx_hostctl in a cron row): the caller decides by lookup 177 if e > 3 { if base[0] == (110 as u8) { if base[1] == (120 as u8) { if base[2] == (95 as u8) { return 1 } } } } 178 return 0 179} 180// walk one row of whitespace-separated tokens (a clock organ column, a cron row, a daemon argv), credit 181// every token that resolves to a table organ with flag f. Returns credits made. 182func es_credit_tokens(line: *u8, lstart: i64, lend: i64, arena: *u8, off: *i64, n: i64, st: *i64, f: i64) -> i64 { 183 let tok: *u8 = sys_mmap(ES_NAME_CAP + 8) 184 let nm: *u8 = sys_mmap(ES_NAME_CAP + 8) 185 var credits: i64 = 0 186 var i: i64 = lstart 187 while i < lend { 188 while i < lend { let c: i64 = line[i] as i64; if c == 32 { i = i + 1 } else { if c == 9 { i = i + 1 } else { if c == 124 { i = i + 1 } else { break } } } } 189 var j: i64 = i 190 var tl: i64 = 0 191 while j < lend { let c2: i64 = line[j] as i64; if c2 == 32 { break } if c2 == 9 { break } if c2 == 124 { break } if c2 == 10 { break } if tl < ES_NAME_CAP { tok[tl] = line[j]; tl = tl + 1 } j = j + 1 } 192 tok[tl] = 0 as u8 193 if tl > 0 { if es_organ_token(tok, nm) == 1 { 194 let idx: i64 = es_find(arena, off, n, nm) 195 if idx >= 0 { if st[idx * ES_F_N + f] == 0 { st[idx * ES_F_N + f] = 1; credits = credits + 1 } } 196 } } 197 i = j + 1 198 } 199 sys_munmap(tok, ES_NAME_CAP + 8); sys_munmap(nm, ES_NAME_CAP + 8) 200 return credits 201} 202// credit every row of a file (skipping # and ; comment rows); returns rows seen (the source size for the stamp) 203func es_credit_file(b: *u8, bn: i64, arena: *u8, off: *i64, n: i64, st: *i64, f: i64, rows_out: *i64) -> i64 { 204 var rows: i64 = 0 205 var credits: i64 = 0 206 var p: i64 = 0 207 while p < bn { 208 var e: i64 = p 209 while e < bn { if b[e] == (10 as u8) { break } e = e + 1 } 210 if e > p { if b[p] != (35 as u8) { if b[p] != (59 as u8) { 211 rows = rows + 1 212 credits = credits + es_credit_tokens(b, p, e, arena, off, n, st, f) 213 } } } 214 p = e + 1 215 } 216 rows_out[0] = rows 217 return credits 218} 219 220// credit every gate a ROSTER CONF names, each row read the way the beat that runs it reads it (nx_rosterconf_lib, the runner's 221// grr_load grammar) -- never through the organ-token heuristic above, which credits a bare token only when it starts nx_ and so 222// never credited a roster gate named _drv_proto_gate while the beat ran it. rows_out receives the rows that name a gate. 223func es_credit_roster(b: *u8, bn: i64, arena: *u8, off: *i64, n: i64, st: *i64, rows_out: *i64) -> i64 { 224 let nm: *u8 = sys_mmap(ES_NAME_CAP + 8) 225 var rows: i64 = 0 226 var credits: i64 = 0 227 var p: i64 = 0 228 while p < bn { 229 let e: i64 = rcf_line_end(b, bn, p) 230 let c0: i64 = rcf_row_start(b, p, e) 231 let gl: i64 = rcf_row_len(b, c0, e) 232 if gl > 0 { 233 rows = rows + 1 234 if gl < ES_NAME_CAP { 235 var k: i64 = 0 236 while k < gl { nm[k] = b[c0 + k]; k = k + 1 } 237 nm[gl] = 0 as u8 238 let idx: i64 = es_find(arena, off, n, nm) 239 if idx >= 0 { if st[idx * ES_F_N + ES_F_ROSTER] == 0 { st[idx * ES_F_N + ES_F_ROSTER] = 1; credits = credits + 1 } } 240 } 241 } 242 p = e + 1 243 } 244 sys_munmap(nm, ES_NAME_CAP + 8) 245 rows_out[0] = rows 246 return credits 247} 248 249// ---- enumerate promoted organs: *.elf directly under dir (exact suffix .elf; .elf.new/.elf.prev are not live) ---- 250func es_list_elfs(dir: *u8, arena: *u8, aused: *i64, acap: i64, off: *i64, n: *i64, ncap: i64, toolong: *i64) -> i64 { 251 let fd: i64 = sys_openat_rd(dir) 252 if fd < 0 { return 0 } 253 let dbuf: *u8 = sys_mmap(ES_DIRBUF) 254 var added: i64 = 0 255 var go: i64 = 1 256 while go == 1 { 257 let nr: i64 = sys_getdents64(fd, dbuf, ES_DIRBUF) 258 if nr <= 0 { go = 0 } else { 259 var o: i64 = 0 260 while o < nr { 261 let rec: *u8 = ((dbuf as i64) + o) as *u8 262 let ty: i64 = dirent_type(rec) 263 let nm: *u8 = dirent_name(rec) 264 if ty != 4 { if es_isdotdot(nm) == 0 { if es_ends(nm, ".elf" as *u8) == 1 { 265 let nl: i64 = es_slen(nm) - 4 266 if nl >= ES_NAME_CAP { toolong[0] = toolong[0] + 1 } else { 267 let tmp: *u8 = sys_mmap(ES_NAME_CAP + 8) 268 var k: i64 = 0 269 while k < nl { tmp[k] = nm[k]; k = k + 1 } 270 tmp[nl] = 0 as u8 271 if es_find(arena, off, n[0], tmp) < 0 { if n[0] < ncap { if aused[0] + nl + 1 < acap { 272 off[n[0]] = aused[0] 273 var q: i64 = 0 274 while q < nl { arena[aused[0] + q] = tmp[q]; q = q + 1 } 275 arena[aused[0] + nl] = 0 as u8 276 aused[0] = aused[0] + nl + 1 277 n[0] = n[0] + 1 278 added = added + 1 279 } } } 280 sys_munmap(tmp, ES_NAME_CAP + 8) 281 } 282 } } } 283 o = o + dirent_reclen(rec) 284 } 285 } 286 } 287 sys_close(fd) 288 sys_munmap(dbuf, ES_DIRBUF) 289 return added 290} 291// count directory entries (files) under dir, non-recursively -- the bound for the organ table 292func es_count_entries(dir: *u8) -> i64 { 293 let fd: i64 = sys_openat_rd(dir) 294 if fd < 0 { return 0 } 295 let dbuf: *u8 = sys_mmap(ES_DIRBUF) 296 var cnt: i64 = 0 297 var go: i64 = 1 298 while go == 1 { 299 let nr: i64 = sys_getdents64(fd, dbuf, ES_DIRBUF) 300 if nr <= 0 { go = 0 } else { 301 var o: i64 = 0 302 while o < nr { cnt = cnt + 1; o = o + dirent_reclen(((dbuf as i64) + o) as *u8) } 303 } 304 } 305 sys_close(fd) 306 sys_munmap(dbuf, ES_DIRBUF) 307 return cnt 308} 309 310// ---- the source walk: pass 0 sums .nx bytes (the bound for edges), pass 1 collects fork edges ---- 311// edges: esrc[k] = caller organ idx (table) or -1 when the caller is not a promoted organ, edst[k] = target idx 312// st2[0] files scanned, st2[1] bytes, st2[2] edges, st2[3] literals seen, st2[4] edge-cap hits 313func es_walk(pass: i64, path: *u8, path_n: i64, arena: *u8, off: *i64, n: i64, esrc: *i64, edst: *i64, ecap: i64, st2: *i64) -> i64 { 314 if path_n > ES_PATHCAP - 300 { return 0 } 315 path[path_n] = 0 as u8 316 let fd: i64 = sys_openat_rd(path) 317 if fd < 0 { return 0 } 318 let dbuf: *u8 = sys_mmap(ES_DIRBUF) 319 var go: i64 = 1 320 while go == 1 { 321 let nr: i64 = sys_getdents64(fd, dbuf, ES_DIRBUF) 322 if nr <= 0 { go = 0 } else { 323 var o: i64 = 0 324 while o < nr { 325 let rec: *u8 = ((dbuf as i64) + o) as *u8 326 let ty: i64 = dirent_type(rec) 327 let nm: *u8 = dirent_name(rec) 328 if es_isdotdot(nm) == 0 { 329 path[path_n] = 47 as u8 330 var cs: i64 = path_n + 1 331 var i: i64 = 0 332 while nm[i] != (0 as u8) { if cs < ES_PATHCAP - 1 { path[cs] = nm[i]; cs = cs + 1 } i = i + 1 } 333 path[cs] = 0 as u8 334 if ty == 4 { es_walk(pass, path, cs, arena, off, n, esrc, edst, ecap, st2) } 335 else { if es_ends(nm, ".nx" as *u8) == 1 { 336 if pass == 0 { 337 let f2: i64 = sys_openat_rd(path) 338 if f2 >= 0 { let sz: i64 = sys_lseek(f2, 0, 2); if sz > 0 { st2[1] = st2[1] + sz } sys_close(f2); st2[0] = st2[0] + 1 } 339 } else { 340 let lp: *i64 = sys_mmap(16) as *i64 341 let b: *u8 = es_read(path, lp) 342 let bn: i64 = lp[0] 343 if (b as i64) != 0 { 344 st2[0] = st2[0] + 1 345 // caller basename (without .nx) -> table idx (-1 when not a promoted organ) 346 let cb: *u8 = sys_mmap(ES_NAME_CAP + 8) 347 let nl: i64 = es_slen(nm) - 3 348 var ck: i64 = 0 349 while ck < nl { if ck < ES_NAME_CAP { cb[ck] = nm[ck] } ck = ck + 1 } 350 if nl < ES_NAME_CAP { cb[nl] = 0 as u8 } else { cb[ES_NAME_CAP - 1] = 0 as u8 } 351 let cidx: i64 = es_find(arena, off, n, cb) 352 // scan for "./<x>.elf "../<x>.elf and "_offc/<x>.elf -- the quote is the string-literal anchor. 353 // "../ (2026-09-17): nx_compare_regen chdirs into buildroot and forks ../<generator>.elf, so every 354 // generator it runs read REGISTERED-DARK on its own receipt until this opener was recognised. 355 let tok: *u8 = sys_mmap(ES_NAME_CAP + 8) 356 let nm2: *u8 = sys_mmap(ES_NAME_CAP + 8) 357 var q: i64 = 0 358 while q + ES_MIN_LIT <= bn { 359 if b[q] == (34 as u8) { 360 var hit: i64 = 0 361 if b[q+1] == (46 as u8) { if b[q+2] == (47 as u8) { hit = 1 } } 362 if b[q+1] == (46 as u8) { if b[q+2] == (46 as u8) { if b[q+3] == (47 as u8) { hit = 1 } } } 363 if b[q+1] == (95 as u8) { if b[q+2] == (111 as u8) { if b[q+3] == (102 as u8) { if b[q+4] == (102 as u8) { if b[q+5] == (99 as u8) { if b[q+6] == (47 as u8) { hit = 1 } } } } } } 364 if hit == 1 { 365 var t: i64 = q + 1 366 var tl: i64 = 0 367 while t < bn { let c: i64 = b[t] as i64; if c == 34 { break } if c == 32 { break } if c == 10 { break } if tl < ES_NAME_CAP { tok[tl] = b[t]; tl = tl + 1 } t = t + 1 } 368 tok[tl] = 0 as u8 369 if es_ends(tok, ".elf" as *u8) == 1 { 370 st2[3] = st2[3] + 1 371 if es_organ_token(tok, nm2) == 1 { 372 let tidx: i64 = es_find(arena, off, n, nm2) 373 if tidx >= 0 { if tidx != cidx { 374 if st2[2] < ecap { esrc[st2[2]] = cidx; edst[st2[2]] = tidx; st2[2] = st2[2] + 1 } else { st2[4] = st2[4] + 1 } 375 } } 376 } 377 } 378 } 379 } 380 q = q + 1 381 } 382 sys_munmap(tok, ES_NAME_CAP + 8); sys_munmap(nm2, ES_NAME_CAP + 8); sys_munmap(cb, ES_NAME_CAP + 8) 383 sys_munmap(b, bn + 8) 384 } 385 sys_munmap(lp as *u8, 16) 386 } 387 } } 388 } 389 o = o + dirent_reclen(rec) 390 } 391 } 392 } 393 sys_close(fd) 394 sys_munmap(dbuf, ES_DIRBUF) 395 return 0 396} 397// PLAN: a clock row that runs nx_plan_run.elf <id> causes every tool the plan's rows name to run, so those tools 398// are credited to the plan surface (the clock row is the cause, the plan the route). Without this every organ the 399// estate runs through its workflows-as-data plane read REGISTERED-DARK: measured 2026-09-17 on nx_search_ship 400// (clock row searchship-dry = nx_plan_run.elf searchship), and since the standing order is that work runs through 401// plans, the blind spot would have grown with every 1-2-3 step. The plan plane is read through the same CLI lane 402// as the clock plane; a plan row is seq TAB tool TAB args..., credited from the tool field to the row end. 403const ES_PLAN_PFX: *u8 = "knowledge/store/plan-" 404const ES_PLAN_RUNNER: *u8 = "nx_plan_run" 405func es_sep(c: i64) -> i64 { if c == 32 { return 1 } if c == 9 { return 1 } if c == 124 { return 1 } if c == 10 { return 1 } return 0 } 406func es_credit_plan(line: *u8, lstart: i64, lend: i64, arena: *u8, off: *i64, n: i64, st: *i64, plans: *i64) -> i64 { 407 let tok: *u8 = sys_mmap(ES_NAME_CAP + 8) 408 let nm: *u8 = sys_mmap(ES_NAME_CAP + 8) 409 var rows: i64 = 0 410 var i: i64 = lstart 411 while i < lend { 412 while i < lend { if es_sep(line[i] as i64) == 1 { i = i + 1 } else { break } } 413 var j: i64 = i 414 var tl: i64 = 0 415 while j < lend { if es_sep(line[j] as i64) == 1 { break } if tl < ES_NAME_CAP { tok[tl] = line[j]; tl = tl + 1 } j = j + 1 } 416 tok[tl] = 0 as u8 417 var is_runner: i64 = 0 418 if tl > 0 { if es_organ_token(tok, nm) == 1 { if es_eq(nm, ES_PLAN_RUNNER) == 1 { is_runner = 1 } } } 419 if is_runner == 1 { 420 var k: i64 = j 421 while k < lend { if es_sep(line[k] as i64) == 1 { k = k + 1 } else { break } } 422 var idl: i64 = 0 423 let pfx: *u8 = sys_mmap(ES_NAME_CAP + 64) 424 var o: i64 = es_cat(pfx, 0, ES_PLAN_PFX) 425 while k < lend { if es_sep(line[k] as i64) == 1 { break } if idl < ES_NAME_CAP { pfx[o] = line[k]; o = o + 1; idl = idl + 1 } k = k + 1 } 426 if idl > 0 { 427 pfx[o] = 45 as u8 428 o = o + 1 429 pfx[o] = 0 as u8 430 let pav: *i64 = sys_mmap(8 * 8) as *i64 431 pav[0] = "./nx_store_put.elf" as *u8 as i64 432 pav[1] = pfx as i64 433 pav[2] = "load" as *u8 as i64 434 pav[3] = 0 435 let pb: *u8 = sys_mmap(ES_PLANE_CAP) 436 let pl: *i64 = sys_mmap(16) as *i64 437 pl[0] = 0 438 tr_run_capture("./nx_store_put.elf" as *u8, pav, pb, ES_PLANE_CAP - 1, pl) 439 var p: i64 = 0 440 while p < pl[0] { 441 var e: i64 = p 442 while e < pl[0] { if pb[e] == (10 as u8) { break } e = e + 1 } 443 var c2: i64 = 0 - 1 444 var q: i64 = p 445 while q < e { if pb[q] == (9 as u8) { c2 = q + 1; q = e } q = q + 1 } 446 if c2 >= 0 { es_credit_tokens(pb, c2, e, arena, off, n, st, ES_F_PLAN); rows = rows + 1 } 447 p = e + 1 448 } 449 plans[0] = plans[0] + 1 450 sys_munmap(pb, ES_PLANE_CAP) 451 } 452 j = k 453 } 454 i = j + 1 455 } 456 sys_munmap(tok, ES_NAME_CAP + 8); sys_munmap(nm, ES_NAME_CAP + 8) 457 return rows 458} 459func es_on_surface(st: *i64, i: i64) -> i64 { 460 if st[i * ES_F_N + ES_F_CLOCK] == 1 { return 1 } 461 if st[i * ES_F_N + ES_F_CRON] == 1 { return 1 } 462 if st[i * ES_F_N + ES_F_DAEMON] == 1 { return 1 } 463 if st[i * ES_F_N + ES_F_ROSTER] == 1 { return 1 } 464 if st[i * ES_F_N + ES_F_ACTLOG] == 1 { return 1 } 465 if st[i * ES_F_N + ES_F_PLAN] == 1 { return 1 } 466 if st[i * ES_F_N + ES_F_FORK] >= 0 { return 1 } 467 return 0 468} 469 470// ---- `who <organ>`: THE READ VERB (2026-09-02, operator: capabilities, not a seat's hand greps) ---------- 471// The census above already answers "which surface runs this program" for every promoted organ, once a day, 472// into execsurface.tsv -- and the day it was needed ("what relaunches nx_daemon_supervisor?") a seat grepped 473// cron.reg, the clocksched plane, daemons.reg and the source tree by hand instead of asking the artifact. 474// A CENSUS NOBODY CAN ASK A QUESTION OF IS A FILE, NOT A CAPABILITY. This verb asks it: one name in, the 475// row decoded into a plain answer, the census stamp and its age beside it so a stale answer cannot pass 476// as a fresh one. It READS ONLY -- it never re-runs the census, so it is safe under any load. 477// exit: 0 ON-SURFACE | 1 NO-SURFACE (nothing in the estate launches it) | 2 NOT-IN-CENSUS | 3 UNOBSERVABLE 478const ESW_STAMP_KEY: *u8 = "# asof=" 479const ESW_BEAT_S: i64 = 86400 // the clock row's declared cadence for this census (execsurface 86400) 480const ESW_STALE_FACTOR: i64 = 2 // two missed beats = STALE, the same bound the cron watch uses 481// 1 when key (NUL-terminated) matches b at i, bounded by n. Every exit a return -- never a cursor write. 482func esw_key_at(b: *u8, n: i64, i: i64, key: *u8) -> i64 { 483 var k: i64 = 0 484 while key[k] != (0 as u8) { 485 if i + k >= n { return 0 } 486 if b[i + k] != key[k] { return 0 } 487 k = k + 1 488 } 489 return 1 490} 491func esw_field(row: *u8, n: i64, idx: i64, out: *u8, cap: i64) -> i64 { 492 var f: i64 = 0 493 var i: i64 = 0 494 var o: i64 = 0 495 while i < n { 496 if row[i] == (9 as u8) { f = f + 1 } 497 else { if f == idx { if o < cap - 1 { out[o] = row[i]; o = o + 1 } } } 498 if f > idx { i = n } 499 i = i + 1 500 } 501 out[o] = 0 as u8 502 return o 503} 504func es_who(name: *u8, census: *u8) -> i64 { 505 let lp: *i64 = sys_mmap(16) as *i64 506 let b: *u8 = es_read(census, lp) 507 if (b as i64) == 0 { 508 es_puts("NX-EXECSURFACE-WHO UNOBSERVABLE: census absent at " as *u8); es_puts(census); es_puts(" -- run nx_execsurface from the estate root first (it is a daily clock row)\n" as *u8) 509 return 3 510 } 511 let n: i64 = lp[0] 512 let fld: *u8 = sys_mmap(ES_NAME_CAP * 2) 513 var found: i64 = 0 - 1 514 var fend: i64 = 0 515 var asof: i64 = 0 - 1 516 var p: i64 = 0 517 while p < n { 518 var e: i64 = p 519 var eol: i64 = 0 520 while eol == 0 { if e >= n { eol = 1 } else { if b[e] == (10 as u8) { eol = 1 } else { e = e + 1 } } } 521 if e > p { 522 if b[p] == (35 as u8) { 523 // the stamp is the LAST line, anchored by position; parse asof= if this line carries it 524 // CURSOR-SENTINEL REMOVED (2026-09-02): this match used to exit its loop with `k = 99`, which then read 525 // ESW_STAMP_KEY[99] -- past the literal, into whatever rodata follows -- and looped for as long as that byte 526 // was non-zero. The identical idiom spun the fleet supervisor at 100 percent CPU for a day (nx_dsup_lib 527 // ds_conf_int carries the write-up); here it had not fired only because the byte after this literal happens 528 // to be zero in the current link. A bound the linker decides is not a bound. Every exit is a return now. 529 let same: i64 = esw_key_at(b, e, p, ESW_STAMP_KEY) 530 if same == 1 { 531 var v: i64 = 0 532 var q: i64 = p + 7 533 while q < e { let c: i64 = b[q] as i64; if c >= 48 { if c <= 57 { v = v * 10 + (c - 48); q = q + 1 } else { q = e } } else { q = e } } 534 asof = v 535 } 536 } else { 537 esw_field(((b as i64) + p) as *u8, e - p, 0, fld, ES_NAME_CAP * 2) 538 if es_eq(fld, name) == 1 { found = p; fend = e } 539 } 540 } 541 p = e + 1 542 } 543 let now: i64 = sys_now_realtime_sec() 544 var age: i64 = 0 - 1 545 if asof > 0 { age = now - asof } 546 es_puts("NX-EXECSURFACE-WHO name=" as *u8); es_puts(name); es_puts(" census=" as *u8); es_puts(census) 547 es_puts(" asof=" as *u8); es_putn(asof); es_puts(" age_s=" as *u8); es_putn(age) 548 var stale: i64 = 0 549 if age < 0 { stale = 1 } else { if age > ESW_BEAT_S * ESW_STALE_FACTOR { stale = 1 } } 550 es_puts(" census_stale=" as *u8); es_putn(stale); es_puts("\n" as *u8) 551 if found < 0 { 552 es_puts("NOT-IN-CENSUS: no row named " as *u8); es_puts(name); es_puts(" -- either it is not a promoted *.elf at the serving root or _offc, or the census predates it (asof above)\n" as *u8) 553 return 2 554 } 555 es_puts("row: " as *u8); sys_write(1, ((b as i64) + found) as *u8, fend - found); es_puts("\n" as *u8) 556 let f1: *u8 = sys_mmap(ES_NAME_CAP * 2) 557 var on: i64 = 0 558 es_puts("launched-by:" as *u8) 559 esw_field(((b as i64) + found) as *u8, fend - found, 1, f1, ES_NAME_CAP * 2); if f1[0] == (49 as u8) { es_puts(" clock" as *u8); on = 1 } 560 esw_field(((b as i64) + found) as *u8, fend - found, 2, f1, ES_NAME_CAP * 2); if f1[0] == (49 as u8) { es_puts(" cron" as *u8); on = 1 } 561 esw_field(((b as i64) + found) as *u8, fend - found, 3, f1, ES_NAME_CAP * 2); if f1[0] == (49 as u8) { es_puts(" daemon" as *u8); on = 1 } 562 esw_field(((b as i64) + found) as *u8, fend - found, 5, f1, ES_NAME_CAP * 2); if f1[0] == (49 as u8) { es_puts(" roster" as *u8); on = 1 } 563 esw_field(((b as i64) + found) as *u8, fend - found, 6, f1, ES_NAME_CAP * 2); if f1[0] == (49 as u8) { es_puts(" actlog" as *u8); on = 1 } 564 esw_field(((b as i64) + found) as *u8, fend - found, 4, f1, ES_NAME_CAP * 2); if f1[0] != (45 as u8) { es_puts(" fork:" as *u8); es_puts(f1); on = 1 } 565 esw_field(((b as i64) + found) as *u8, fend - found, 7, f1, ES_NAME_CAP * 2) 566 if es_eq(f1, "plan" as *u8) == 1 { es_puts(" plan" as *u8); on = 1 } 567 es_puts(" first_surface=" as *u8); es_puts(f1); es_puts("\n" as *u8) 568 if on == 1 { es_puts("ON-SURFACE\n" as *u8); return 0 } 569 es_puts("NO-SURFACE: nothing in the estate CAUSES this organ to run (clock, cron, daemons.reg, gate roster, MCP actlog and source forks all 0) -- a running instance was started by hand or by an out-of-tree shell, so there is no sanctioned relaunch path and nothing revives it. Adding it to daemons.reg or a clock row is the remedy; a debt row is the record.\n" as *u8) 570 return 1 571} 572 573func main(argc: i64, argv: *i64) -> i64 { 574 // `who <organ>` is the READ verb over the last census; it never re-runs the walk (safe under any load) 575 if argc >= 3 { if es_eq(argv[1] as *u8, "who" as *u8) == 1 { let wrc: i64 = es_who(argv[2] as *u8, "knowledge/status/execsurface.tsv" as *u8); sys_exit(wrc); return wrc } } 576 var outp: *u8 = "knowledge/status/execsurface.tsv" as *u8 577 if argc > 1 { outp = argv[1] as *u8 } 578 // ---- 1. the population: every *.elf at the serving root and under _offc/ (deduped by name) ---- 579 let ncap: i64 = es_count_entries("." as *u8) + es_count_entries("_offc" as *u8) + 1 580 let acap: i64 = ncap * ES_NAME_CAP 581 let arena: *u8 = sys_mmap(acap) 582 let aused: *i64 = sys_mmap(16) as *i64 583 aused[0] = 0 584 let off: *i64 = sys_mmap(ncap * 8) as *i64 585 let nn: *i64 = sys_mmap(16) as *i64 586 nn[0] = 0 587 let toolong: *i64 = sys_mmap(16) as *i64 588 toolong[0] = 0 589 es_list_elfs("." as *u8, arena, aused, acap, off, nn, ncap, toolong) 590 es_list_elfs("_offc" as *u8, arena, aused, acap, off, nn, ncap, toolong) 591 let n: i64 = nn[0] 592 if n <= 0 { 593 es_puts("NX-EXECSURFACE UNOBSERVABLE: no *.elf enumerated at . or _offc (run from the estate root) -- nothing written\n" as *u8) 594 sys_exit(3); return 3 595 } 596 let st: *i64 = sys_mmap(n * ES_F_N * 8) as *i64 597 var z: i64 = 0 598 while z < n * ES_F_N { st[z] = 0; z = z + 1 } 599 z = 0 600 while z < n { st[z * ES_F_N + ES_F_FORK] = 0 - 1; st[z * ES_F_N + ES_F_REF] = 0 - 1; z = z + 1 } 601 let rows: *i64 = sys_mmap(16) as *i64 602 // ---- 2. CLOCK: the live plane through the CLI lane (the MCP load verb reads planes empty) ---- 603 let pav: *i64 = sys_mmap(8 * 8) as *i64 604 pav[0] = "./nx_store_put.elf" as *u8 as i64 605 pav[1] = "knowledge/store/clocksched-" as *u8 as i64 606 pav[2] = "load" as *u8 as i64 607 pav[3] = 0 608 let plane: *u8 = sys_mmap(ES_PLANE_CAP) 609 let plen: *i64 = sys_mmap(16) as *i64 610 plen[0] = 0 611 tr_run_capture("./nx_store_put.elf" as *u8, pav, plane, ES_PLANE_CAP - 1, plen) 612 var plane_full: i64 = 0 613 if plen[0] >= ES_PLANE_CAP - 1 { plane_full = 1 } 614 // the organ column is the 4th TAB field: credit tokens from there to the end of the row 615 var clock_rows: i64 = 0 616 var plan_rows: i64 = 0 617 let plans: *i64 = sys_mmap(16) as *i64 618 plans[0] = 0 619 var p: i64 = 0 620 while p < plen[0] { 621 var e: i64 = p 622 while e < plen[0] { if plane[e] == (10 as u8) { break } e = e + 1 } 623 if e > p { 624 var tabs: i64 = 0 625 var c4: i64 = 0 - 1 626 var q: i64 = p 627 while q < e { if plane[q] == (9 as u8) { tabs = tabs + 1; if tabs == 3 { c4 = q + 1; q = e } } q = q + 1 } 628 if c4 >= 0 { clock_rows = clock_rows + 1; es_credit_tokens(plane, c4, e, arena, off, n, st, ES_F_CLOCK); plan_rows = plan_rows + es_credit_plan(plane, c4, e, arena, off, n, st, plans) } 629 } 630 p = e + 1 631 } 632 // ---- 3. CRON, 4. DAEMON, 5. ROSTER: flat registries ---- 633 let lp: *i64 = sys_mmap(16) as *i64 634 let cron: *u8 = es_read("cron.reg" as *u8, lp) 635 var cron_rows: i64 = 0 636 if (cron as i64) != 0 { es_credit_file(cron, lp[0], arena, off, n, st, ES_F_CRON, rows); cron_rows = rows[0] } 637 let dreg: *u8 = es_read("daemons.reg" as *u8, lp) 638 var daemon_rows: i64 = 0 639 if (dreg as i64) != 0 { es_credit_file(dreg, lp[0], arena, off, n, st, ES_F_DAEMON, rows); daemon_rows = rows[0] } 640 // ROSTER: every conf a gate roster beat runs, derived from the live plane read above (nx_rosterconf_lib: the runner's 641 // default first, then each conf a clock row runs through nx_gate_roster_run beat), each through the same reader 642 let rmeta: *i64 = sys_mmap(RCF_META_SLOTS * 8) as *i64 643 let rlist: *u8 = sys_mmap(rcf_confs_bound(plane, plen[0])) 644 let roster_pairs: i64 = rcf_confs(plane, plen[0], rlist, rmeta) 645 let rpath: *u8 = sys_mmap(ES_PATHCAP) 646 let rlo: *i64 = sys_mmap(16) as *i64 647 var roster_rows: i64 = 0 648 var roster_read: i64 = 0 649 var roster_confs: i64 = 0 650 var ri: i64 = 0 651 while ri < roster_pairs { 652 // every pair's conf, whatever journal its beat writes (the close ruler reads each beat's evidence from that journal), and 653 // each distinct conf once 654 var rl: i64 = 0 655 if rcf_pair_origin(rlist, rmeta[RCF_META_BYTES], ri, RCF_PART_CONF) == ri { 656 roster_confs = roster_confs + 1 657 rl = rcf_pair_conf(rlist, rmeta[RCF_META_BYTES], ri, rlo) 658 } 659 if rl > 0 { if rl < ES_PATHCAP { 660 var rq: i64 = 0 661 while rq < rl { rpath[rq] = rlist[rlo[0] + rq]; rq = rq + 1 } 662 rpath[rl] = 0 as u8 663 let rost: *u8 = es_read(rpath, lp) 664 if (rost as i64) != 0 { es_credit_roster(rost, lp[0], arena, off, n, st, rows); roster_rows = roster_rows + rows[0]; roster_read = roster_read + 1 } 665 } } 666 ri = ri + 1 667 } 668 // ---- 6. ACTLOG: the MCP tail, substring per name (the door the ladder already watched) ---- 669 let act: *u8 = es_read_tail("knowledge/status/actlog.jrnl" as *u8, ES_ACT_TAIL, lp) 670 let actn: i64 = lp[0] 671 if actn > 0 { 672 var ai: i64 = 0 673 while ai < n { 674 let nmi: *u8 = es_name(arena, off, ai) 675 let nl: i64 = es_slen(nmi) 676 var f: i64 = 0 677 var found: i64 = 0 678 while f + nl <= actn { 679 var k: i64 = 0 680 var same: i64 = 1 681 while k < nl { if act[f + k] != nmi[k] { same = 0; k = nl } else { k = k + 1 } } 682 if same == 1 { found = 1; f = actn } 683 f = f + 1 684 } 685 if found == 1 { st[ai * ES_F_N + ES_F_ACTLOG] = 1 } 686 ai = ai + 1 687 } 688 } 689 // ---- 7. FORK: two-pass source walk, then credit targets whose callers are on a surface (fixed point) ---- 690 let st2: *i64 = sys_mmap(8 * 8) as *i64 691 var zz: i64 = 0 692 while zz < 8 { st2[zz] = 0; zz = zz + 1 } 693 let path: *u8 = sys_mmap(ES_PATHCAP) 694 let root: *u8 = "buildroot/runtime" as *u8 695 var rn: i64 = es_cat(path, 0, root) 696 es_walk(0, path, rn, arena, off, n, 0 as *i64, 0 as *i64, 0, st2) 697 let total_src: i64 = st2[1] 698 let ecap: i64 = total_src / ES_MIN_LIT + 1 // a literal costs at least ES_MIN_LIT bytes: edges cannot exceed this 699 let esrc: *i64 = sys_mmap(ecap * 8) as *i64 700 let edst: *i64 = sys_mmap(ecap * 8) as *i64 701 st2[0] = 0; st2[1] = 0 702 rn = es_cat(path, 0, root) 703 es_walk(1, path, rn, arena, off, n, esrc, edst, ecap, st2) 704 let nedge: i64 = st2[2] 705 var hops: i64 = 0 706 var changed: i64 = 1 707 while changed == 1 { 708 changed = 0 709 hops = hops + 1 710 var k: i64 = 0 711 while k < nedge { 712 let c: i64 = esrc[k] 713 let t: i64 = edst[k] 714 if c >= 0 { 715 if st[t * ES_F_N + ES_F_FORK] < 0 { if es_on_surface(st, c) == 1 { st[t * ES_F_N + ES_F_FORK] = c; changed = 1 } } 716 } 717 // a caller that is a promoted organ is named; a literal in a lib or unbuilt source is still a 718 // claim (-2 = referenced by a non-promoted source), never silently a dark row 719 if st[t * ES_F_N + ES_F_REF] == 0 - 1 { if c >= 0 { st[t * ES_F_N + ES_F_REF] = c } else { st[t * ES_F_N + ES_F_REF] = 0 - 2 } } 720 if st[t * ES_F_N + ES_F_REF] == 0 - 2 { if c >= 0 { st[t * ES_F_N + ES_F_REF] = c } } 721 k = k + 1 722 } 723 if hops > n { changed = 0 } // a cycle cannot grow forever: bounded by the population 724 } 725 // ---- 8. rows + stamp, then truncate-write via tmp + rename ---- 726 let cap: i64 = aused[0] + n * ES_ROW_FIXED + ES_TAIL_FIXED + es_slen(outp) 727 let out: *u8 = sys_mmap(cap) 728 var o: i64 = 0 729 var on_surface: i64 = 0 730 var ref_only: i64 = 0 731 var dark: i64 = 0 732 var i: i64 = 0 733 while i < n { 734 let b0: i64 = i * ES_F_N 735 o = es_cat(out, o, es_name(arena, off, i)); out[o] = 9 as u8; o = o + 1 736 o = es_catn(out, o, st[b0 + ES_F_CLOCK]); out[o] = 9 as u8; o = o + 1 737 o = es_catn(out, o, st[b0 + ES_F_CRON]); out[o] = 9 as u8; o = o + 1 738 o = es_catn(out, o, st[b0 + ES_F_DAEMON]); out[o] = 9 as u8; o = o + 1 739 if st[b0 + ES_F_FORK] >= 0 { o = es_cat(out, o, es_name(arena, off, st[b0 + ES_F_FORK])) } else { out[o] = 45 as u8; o = o + 1 } 740 out[o] = 9 as u8; o = o + 1 741 o = es_catn(out, o, st[b0 + ES_F_ROSTER]); out[o] = 9 as u8; o = o + 1 742 o = es_catn(out, o, st[b0 + ES_F_ACTLOG]); out[o] = 9 as u8; o = o + 1 743 if st[b0 + ES_F_CLOCK] == 1 { o = es_cat(out, o, "clock" as *u8) } 744 else { if st[b0 + ES_F_CRON] == 1 { o = es_cat(out, o, "cron" as *u8) } 745 else { if st[b0 + ES_F_DAEMON] == 1 { o = es_cat(out, o, "daemon" as *u8) } 746 else { if st[b0 + ES_F_ROSTER] == 1 { o = es_cat(out, o, "roster" as *u8) } 747 else { if st[b0 + ES_F_ACTLOG] == 1 { o = es_cat(out, o, "actlog" as *u8) } 748 else { if st[b0 + ES_F_PLAN] == 1 { o = es_cat(out, o, "plan" as *u8) } 749 else { if st[b0 + ES_F_FORK] >= 0 { o = es_cat(out, o, "fork:" as *u8); o = es_cat(out, o, es_name(arena, off, st[b0 + ES_F_FORK])) } 750 else { if st[b0 + ES_F_REF] >= 0 { o = es_cat(out, o, "ref:" as *u8); o = es_cat(out, o, es_name(arena, off, st[b0 + ES_F_REF])) } 751 else { if st[b0 + ES_F_REF] == 0 - 2 { o = es_cat(out, o, "ref:unpromoted-source" as *u8) } 752 else { out[o] = 45 as u8; o = o + 1 } } } } } } } } } 753 out[o] = 10 as u8; o = o + 1 754 if es_on_surface(st, i) == 1 { on_surface = on_surface + 1 } else { if st[b0 + ES_F_REF] != 0 - 1 { ref_only = ref_only + 1 } else { dark = dark + 1 } } 755 i = i + 1 756 } 757 let asof: i64 = sys_now_realtime_sec() 758 o = es_cat(out, o, "# asof=" as *u8); o = es_catn(out, o, asof) 759 o = es_cat(out, o, " organs=" as *u8); o = es_catn(out, o, n) 760 o = es_cat(out, o, " on_surface=" as *u8); o = es_catn(out, o, on_surface) 761 o = es_cat(out, o, " ref_only=" as *u8); o = es_catn(out, o, ref_only) 762 o = es_cat(out, o, " dark=" as *u8); o = es_catn(out, o, dark) 763 o = es_cat(out, o, " sources=clock:" as *u8); o = es_catn(out, o, clock_rows) 764 o = es_cat(out, o, ",cron:" as *u8); o = es_catn(out, o, cron_rows) 765 o = es_cat(out, o, ",daemon:" as *u8); o = es_catn(out, o, daemon_rows) 766 o = es_cat(out, o, ",roster:" as *u8); o = es_catn(out, o, roster_rows) 767 o = es_cat(out, o, ",roster_confs:" as *u8); o = es_catn(out, o, roster_read) 768 o = es_cat(out, o, ",roster_beats:" as *u8); o = es_catn(out, o, rmeta[RCF_META_BEATS]) 769 o = es_cat(out, o, ",roster_beats_other_journal:" as *u8); o = es_catn(out, o, rmeta[RCF_META_OTHER]) 770 o = es_cat(out, o, ",actlog:" as *u8); o = es_catn(out, o, actn) 771 o = es_cat(out, o, ",plans:" as *u8); o = es_catn(out, o, plans[0]) 772 o = es_cat(out, o, ",plan_rows:" as *u8); o = es_catn(out, o, plan_rows) 773 o = es_cat(out, o, ",fork_files:" as *u8); o = es_catn(out, o, st2[0]) 774 o = es_cat(out, o, ",fork_literals:" as *u8); o = es_catn(out, o, st2[3]) 775 o = es_cat(out, o, ",fork_edges:" as *u8); o = es_catn(out, o, nedge) 776 o = es_cat(out, o, ",hops:" as *u8); o = es_catn(out, o, hops) 777 o = es_cat(out, o, " plane_capture_full=" as *u8); o = es_catn(out, o, plane_full) 778 o = es_cat(out, o, " edge_cap_hits=" as *u8); o = es_catn(out, o, st2[4]) 779 o = es_cat(out, o, " names_too_long=" as *u8); o = es_catn(out, o, toolong[0]) 780 o = es_cat(out, o, " blind=laptop-hooks,offhost-rosters,actlog-tail-window,runtime-assembled-fork-paths\n" as *u8) 781 let tmp: *u8 = sys_mmap(es_slen(outp) + 8) 782 var to: i64 = es_cat(tmp, 0, outp); to = es_cat(tmp, to, ".tmp" as *u8) 783 let fd: i64 = sys_openat_wr(tmp, MODE_0644) 784 if fd < 0 { es_puts("NX-EXECSURFACE WRITE-FAILED: cannot open " as *u8); es_puts(tmp); es_puts("\n" as *u8); sys_exit(4); return 4 } 785 var w: i64 = 0 786 while w < o { 787 let r: i64 = sys_write(fd, ((out as i64) + w) as *u8, o - w) 788 if r <= 0 { sys_close(fd); es_puts("NX-EXECSURFACE WRITE-FAILED: short write\n" as *u8); sys_exit(4); return 4 } 789 w = w + r 790 } 791 sys_fsync(fd) 792 sys_close(fd) 793 if sys_renameat(tmp, outp) != 0 { es_puts("NX-EXECSURFACE WRITE-FAILED: rename\n" as *u8); sys_exit(4); return 4 } 794 es_puts("NX-EXECSURFACE organs=" as *u8); es_putn(n) 795 es_puts(" on_surface=" as *u8); es_putn(on_surface) 796 es_puts(" ref_only=" as *u8); es_putn(ref_only) 797 es_puts(" dark=" as *u8); es_putn(dark) 798 es_puts(" sum=" as *u8); es_putn(on_surface + ref_only + dark) 799 es_puts(" clock_rows=" as *u8); es_putn(clock_rows) 800 es_puts(" cron_rows=" as *u8); es_putn(cron_rows) 801 es_puts(" daemon_rows=" as *u8); es_putn(daemon_rows) 802 es_puts(" roster_rows=" as *u8); es_putn(roster_rows) 803 es_puts(" roster_confs=" as *u8); es_putn(roster_read); es_puts("/" as *u8); es_putn(roster_confs) 804 es_puts(" roster_beats=" as *u8); es_putn(rmeta[RCF_META_BEATS]) 805 es_puts(" roster_beats_other_journal=" as *u8); es_putn(rmeta[RCF_META_OTHER]) 806 es_puts(" fork_files=" as *u8); es_putn(st2[0]) 807 es_puts(" fork_edges=" as *u8); es_putn(nedge) 808 es_puts(" hops=" as *u8); es_putn(hops) 809 es_puts(" plane_capture_full=" as *u8); es_putn(plane_full) 810 es_puts(" asof=" as *u8); es_putn(asof) 811 es_puts(" wrote=" as *u8); es_putn(o); es_puts(" of=" as *u8); es_puts(outp); es_puts("\n" as *u8) 812 return 0 813}