code wiki / _hdl_build / nx_lease.nx

nx_lease.nx

buildroot/runtime/_hdl_build/nx_lease.nx

14781 B365 linesdepth 2pulls 2 transitivereach 2 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

nx_lease.nx -- THE SOVEREIGN LEASE PRIMITIVE (eats debt seq12/D002: "WMS write lane unlocked = race debt; claims/lease it"). Advisory TTL leases for contended write lanes (ws_put / planes / MEMORY-class shared state): ACQUIRE is atomic (mkdirat -- EEXIST = held), takeover of a stale or released lease is CAS-VERIFIED (write own stamp via tmp+renameat, read back, own nonce wins -- last-writer-wins + verify = the loser backs off), RELEASE flips the stamp to released and NEVER unlinks or rmdirs (the never-unlink-lock law: lock dirs are additive; a released stamp is the reusable slot). Self-mkdirs knowledge/lease (rule 20). Stamp = one line: held|released<TAB>owner<TAB>epoch<TAB>ttl<TAB>nonce Stale = state held AND now > epoch + ttl (the HOLDER's declared ttl -- crash-safe by construction: a dead holder's lease self-expires; no daemon needed). nx_lease acquire <name> <owner> <ttl-sec> exit 0 ACQUIRED | 3 BUSY (holder shown) | 4 io nx_lease release <name> <owner> exit 0 RELEASED | 3 REFUSED not-holder | 4 io nx_lease check <name> exit 0 prints stamp | 1 free nx_lease selftest 7 teeth, verdict=GREEN/RED, exit 0/5 name grammar [a-zA-Z0-9_-] only (deny slash/dot/traversal by construction). expect_exit: 0 license_tier: ORIGINAL No hw writes (Rule 26).

dependencies 1 imports · 2 importers

nx_syscalls.nx nx_lease.nx nx_arbiter_gate.nx nx_gate_mutation_sweep.nx

imports: nx_syscalls.nx

imported by: nx_arbiter_gate.nxnx_gate_mutation_sweep.nx

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

main ls_werr sys_write ls_slen sys_exit sys_mmap ls_name_ok ls_acquire ls_mkdir sys_mmap ↻ ls_dirpath ls_cat ls_pid sys_now_realtime_sec sys_mmap ↻ sys_clock_gettime_real ls_claim sys_mmap ↻ ls_cat ↻ ls_catn sys_mmap ↻ sys_now_realtime_sec ↻ sys_openat_wr sys_write ↻ sys_close sys_renameat ls_read sys_openat_rd sys_read sys_close ↻ ls_parse2 ls_stamp_path ls_cat ↻ ls_read ↻ ls_parse2 ↻ ls_release sys_mmap ↻ ls_dirpath ↻ ls_stamp_path ↻ ls_read ↻

structs

none

consts

18const LS_MAGIC_3600: i64 = 3600
20const LS_STDERR: i64 = 2
21const LS_PATHCAP: i64 = 256
22const LS_STAMPCAP: i64 = 512
23const LS_MODE: i64 = 0x1a4
24const LS_DMODE: i64 = 0x1ed
25const LS_MKDIRAT: i64 = 258
26const LS_ATFDCWD: i64 = 0 - 100
27const LS_GETPID: i64 = 172
28const LS_TAB: i64 = 9
29const LS_NL: i64 = 10
30const LS_D0: i64 = 48
31const LS_D9: i64 = 57
32const LS_B10: i64 = 10
33const LS_NUMB: i64 = 24
34const LS_EXIT_USAGE: i64 = 2
35const LS_EXIT_BUSY: i64 = 3
36const LS_EXIT_IO: i64 = 4
37const LS_EXIT_SELF: i64 = 5
38const LS_V_A: i64 = 97
39const LS_V_R: i64 = 114
40const LS_V_C: i64 = 99
41const LS_V_S: i64 = 115
42const LS_NONCE_MOD: i64 = 1000000

functions

44func ls_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
called by 1: ls_werr
45func ls_werr(s: *u8) -> i64 { sys_write(LS_STDERR, s, ls_slen(s)); return 0 }
called by 1: main calls 2: sys_writels_slen
46func ls_wn(v: i64) -> i64
called by 1: main calls 2: sys_writesys_mmap
59func ls_cat(d: *u8, off: i64, s: *u8) -> i64
65func ls_catn(d: *u8, off: i64, v: i64) -> i64
called by 3: mainls_claimls_unclaim calls 1: sys_mmap
77func ls_eq(a: *u8, b: *u8) -> i64
called by 1: ls_release
84func ls_name_ok(s: *u8) -> i64
called by 1: main
100func ls_mkdir(p: *u8) -> i64 { return __syscall(LS_MKDIRAT, LS_ATFDCWD, p as i64, LS_DMODE, 0, 0, 0) }
called by 1: ls_acquire
101func ls_dirpath(name: *u8, out: *u8) -> i64
called by 3: ls_acquirels_releasemain calls 1: ls_cat
108func ls_read(path: *u8, buf: *u8, cap: i64) -> i64
128func ls_parse2(buf: *u8, n: i64, ob: *u8, obcap: i64) -> i64
160func ls_claim(dir: *u8, owner: *u8, ttl: i64, nonce: i64) -> i64
199func ls_stamp_path(dir: *u8, out: *u8) -> i64
206func ls_unclaim(dir: *u8, owner: *u8, nonce: i64) -> i64
237func ls_pid() -> i64 { return __syscall(LS_GETPID, 0, 0, 0, 0, 0, 0) }
239func ls_acquire(name: *u8, owner: *u8, ttl: i64, hb: *u8) -> i64
280func ls_release(name: *u8, owner: *u8) -> i64
297func main(argc: i64, argv: *i64) -> i64