code wiki / _hdl_build / nx_atomic_swap.nx

nx_atomic_swap.nx

buildroot/runtime/_hdl_build/nx_atomic_swap.nx

3400 B75 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind tooltopic atomic
docsdependenciesstructsconstsfunctions

about

nx_atomic_swap.nx -- DEP-001 (CALLOUT-012 deploy-exceed). Prove + register the ATOMIC content swap: write the new version to a temp file, then sys_renameat(temp, live) -> live is replaced in ONE atomic FS operation (a concurrent reader sees whole-old or whole-new, NEVER torn). This is the no-torn-deploy primitive the deploy-check named as a GAP (had via renameat, unregistered). Composes the PROVEN sys_renameat (nx_syscalls). Self-validating gate (ATOMICSWAPGATE): pre=old, swap rc=0, post=new (old GONE), temp consumed. license_tier: ORIGINAL

dependencies 1 imports · 0 importers

nx_syscalls.nx nx_atomic_swap.nx

imports: nx_syscalls.nx

imported by: nobody (leaf or entry point)

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

main sys_mmap aw_write sys_openat_wr sys_write aw_strlen sys_close aw_read sys_openat_rd sys_read sys_close ↻ aw_has sys_renameat aw_puts sys_write ↻ aw_putn sys_mmap ↻ sys_write ↻

structs

none

consts

8const AW_MAGIC_4096: i64 = 4096
10const AW_LIVE: *u8 = "/tmp/nx_asw_live"
11const AW_TMP: *u8 = "/tmp/nx_asw_tmp"
12const AW_V1: *u8 = "VERSION-1-OLD-content"
13const AW_V2: *u8 = "VERSION-2-NEW-content-atomic"

functions

15func aw_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
called by 1: main calls 1: sys_write
16func aw_putn(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); m=m/10; k=k+1}; var i: i64=0; while i<k {bb[i]=t[k-1-i]; i=i+1}; sys_write(1, bb, k); return 0 }
called by 1: main calls 2: sys_mmapsys_write
17func aw_strlen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
called by 1: aw_write
19func aw_write(path: *u8, content: *u8) -> i64
26func aw_read(path: *u8, buf: *u8, cap: i64) -> i64
called by 1: main calls 3: sys_openat_rdsys_readsys_close
35func aw_has(buf: *u8, n: i64, needle: *u8) -> i64
called by 1: main
43func main() -> i64