code wiki / _hdl_build / nx_doctor_apply.nx

nx_doctor_apply.nx

buildroot/runtime/_hdl_build/nx_doctor_apply.nx

5913 B98 linesdepth 3pulls 3 transitivereach 9 importersview sourcekind tooltopic doctor
docsdependenciesstructsconstsfunctions

about

nx_doctor_apply.nx -- THE NISHI DOCTOR's "graceful apply WITHOUT competition" core rung. Operator: route a fix through the Doctor so it is applied gracefully without racing a workstream that is concurrently editing the same shared organ. Synthesized from the Nishi Researcher's S-class corpus (knowledge/fetched/doc_*.raw): LOCK (mutual exclusion, axis A: nx_arbiter fl_acquire) + EXACT-CONTEXT-MATCH apply (axes B optimistic/CAS + C 3-way-merge/patch context: apply ONLY where the target region still matches the CURRENT file exactly-once -> a concurrent edit that touched my region makes the match FAIL = REFUSE, never clobber; an edit elsewhere leaves the match intact = apply = a clean merge for non-overlapping edits) + ATOMIC tmp+rename (axis F: no torn write). Fail-closed: any ambiguity (no match / multi-match) -> REFUSE. This does NOT verify or admit its own work (RACI: the Engineer re-verifies, the Warden admits) -- it is the safe APPLY primitive the Doctor's fix queue (next rung) drives one-at-a-time. usage: nx_doctor_apply <target> <oldstr-file> <newstr-file> [requester] reads oldstr/newstr from files so multi-line patches work (NUL-free byte spans). license_tier: ORIGINAL

dependencies 2 imports · 5 importers

nx_syscalls.nx nx_arbiter.nx nx_doctor_apply.nx nx_doctor_apply_gate.nx nx_doctor_queue.nx nx_doctor_queue_gate.nx nx_doctor_serve.nx nx_role_queue.nx

imports: nx_syscalls.nxnx_arbiter.nx

imported by: nx_doctor_apply_gate.nxnx_doctor_queue.nxnx_doctor_queue_gate.nxnx_doctor_serve.nxnx_role_queue.nx

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main da_w sys_write da_slen sys_mmap da_read sys_openat_rd sys_read sys_close doc_apply_mem fl_acquire fl_try fl_mkdir sys_mmap ↻ fl_path sys_openat_wr sys_flock sys_close ↻ fl_nap sys_mmap ↻ sys_mmap ↻ da_read ↻ fl_release sys_flock ↻ sys_close ↻ da_count da_match_at da_find da_match_at ↻ sys_openat_wr ↻ sys_write ↻ sys_close ↻ sys_renameat

structs

none

consts

19const DA_MAGIC_100000: i64 = 100000
20const DA_MAGIC_1024: i64 = 1024
22const DA_APPLIED: i64 = 0
23const DA_CONFLICT: i64 = 1 // target region not found -> already-applied OR changed by another -> NOT clobbered
24const DA_AMBIG: i64 = 2 // oldstr matches >1 -> refuse (will not guess which)
25const DA_ERR: i64 = 3
26const DA_CAP: i64 = 8388608 // 8 MiB bound -- source files are small; NEVER sys_read_file's 4 GiB (fork-hazard)
27const DA_LOCK: *u8 = "doctor_apply"

functions

29func da_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
30func da_w(s: *u8) -> i64 { return sys_write(1, s, da_slen(s)) }
called by 1: main calls 2: sys_writeda_slen
33func da_read(path: *u8, buf: *u8, cap: i64) -> i64
40func da_match_at(hay: *u8, i: i64, needle: *u8, nlen: i64) -> i64
called by 2: da_countda_find
44func da_count(hay: *u8, hn: i64, needle: *u8, nlen: i64) -> i64
called by 1: doc_apply_mem calls 1: da_match_at
50func da_find(hay: *u8, hn: i64, needle: *u8, nlen: i64) -> i64
called by 1: doc_apply_mem calls 1: da_match_at
58func doc_apply_mem(target: *u8, oldstr: *u8, oldlen: i64, newstr: *u8, newlen: i64) -> i64
86func main(argc: i64, argv: *i64) -> i64