code wiki / _hdl_build / nx_nxe.nx

nx_nxe.nx

buildroot/runtime/_hdl_build/nx_nxe.nx

8669 B104 linesdepth 3pulls 3 transitivereach 0 importersview sourcekind tooltopic nxe
docsdependenciesstructsconstsfunctions

about

nx_nxe.nx -- the SOVEREIGN NISHI EXECUTABLE FORMAT (NXE). Our OWN file -- NOT an ELF knockoff. A UNIQUE exceed: it bakes in what ELF/Mach-O/PE LACK by default -- (1) INTEGRITY by construction: a content hash of the code section in the header; the loader VERIFIES it and REFUSES tampered binaries (ELF/Mach-O/PE have no built-in integrity -- they rely on external signing). (2) CAPABILITY MANIFEST (capability-based security, ef_capsec.raw): the binary DECLARES its caps (file/net/exec/ raw-hw); the loader enforces least-privilege -- an undeclared cap is denied. (ELF declares nothing.) (3) NEVER-BRICK tag (cardinal 26 IN THE FORMAT): a binary flagged HW_WRITE is REFUSED unless it carries a never-brick guarantee. The brand-critical law enforced at load, by construction. Layout (8-byte fields): [0]magic'NXE1' [8]version [16]arch [24]flags [32]caps [40]entry [48]code_off=80 [56]code_len [64]code_hash ; code@80. Writer + loader/verifier. ELF stays ONLY as last-mile to run under Linux until our own boot/loader. T1 write/load roundtrip. T2 integrity (verify ok; tampered code -> rejected). T3 capability (declared allowed, undeclared denied). T4 never-brick (HW_WRITE without a never-brick guarantee -> REFUSED; with it -> loads). expect_exit: 0 Sovereign: nx_syscalls.

dependencies 2 imports · 0 importers

nx_syscalls.nx nx_itoa_lib.nx nx_nxe.nx

imports: nx_syscalls.nxnx_itoa_lib.nx

imported by: nobody (leaf or entry point)

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

main g_puts sys_write sys_mmap nxe_write p64 code_hash nxe_load nxe_magic_ok nxe_integrity_ok r64 code_hash ↻ r64 ↻ nxe_magic_ok ↻ r64 ↻ g_pn nxi_out nxi_fd sys_mmap ↻ ccz_cat_num sys_write ↻ sys_munmap ck g_puts ↻ sys_openat_wr sys_write ↻ sys_close nxe_integrity_ok ↻ nxe_may r64 ↻ sys_openat_append sys_exit

structs

none

consts

16const K_MAGIC_5381: i64 = 5381
17const K_MAGIC_4096: i64 = 4096
31const HOFF: i64 = 80 // code offset

functions

19func g_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 2: ckmain calls 1: sys_write
24func g_pn(v: i64) -> i64 { nxi_out(v); return 0 }
called by 1: main calls 1: nxi_out
25func ck(name: *u8, c: i64) -> i64 { if c==1 { g_puts(" PASS " as *u8) } else { g_puts(" FAIL " as *u8) } g_puts(name); g_puts("\n" as *u8); return c }
called by 1: main calls 1: g_puts
26func have(path: *u8) -> i64 { let fd: i64=sys_openat_rd(path); if fd<0 { return 0 } sys_close(fd); return 1 }
27func p64(m: *u8, o: i64, v: i64) -> i64 { var i: i64=0; while i<8 { m[o+i]=((v>>(i*8))&255) as u8; i=i+1 } return 0 }
called by 1: nxe_write
28func r64(m: *u8, o: i64) -> i64 { var v: i64=0; var i: i64=0; while i<8 { v=v|((m[o+i] as i64)<<(i*8)); i=i+1 } return v }
29func code_hash(m: *u8, off: i64, n: i64) -> i64 { var h: i64=K_MAGIC_5381; var i: i64=0; while i<n { h=((h<<5)+h)+(m[off+i] as i64); i=i+1 } return h } // djb2 over the code
33func nxe_write(m: *u8, arch: i64, flags: i64, caps: i64, entry: i64, code: *u8, clen: i64) -> i64
called by 1: main calls 2: p64code_hash
40func nxe_magic_ok(m: *u8) -> i64 { if m[0]==(0x4E as u8) { if m[1]==(0x58 as u8) { if m[2]==(0x45 as u8) { if m[3]==(0x31 as u8) { return 1 } } } } return 0 }
called by 2: nxe_loadmain
41func nxe_integrity_ok(m: *u8) -> i64 { let clen: i64=r64(m,56); if code_hash(m,HOFF,clen)==r64(m,64) { return 1 } return 0 }
called by 2: nxe_loadmain calls 2: r64code_hash
42func nxe_may(m: *u8, cap: i64) -> i64 { return (r64(m,32)>>cap)&1 } // cap = bit index
called by 1: main calls 1: r64
44func nxe_load(m: *u8) -> i64
52func main() -> i64