code wiki / _hdl_build / nx_nxe.nx
nx_nxe.nx
buildroot/runtime/_hdl_build/nx_nxe.nx
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
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
structs
| none |
consts
| 16 | const K_MAGIC_5381: i64 = 5381 |
| 17 | const K_MAGIC_4096: i64 = 4096 |
| 31 | const HOFF: i64 = 80 // code offset |
functions
| 19 | func 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 } |
| 24 | func g_pn(v: i64) -> i64 { nxi_out(v); return 0 } |
| 25 | func 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 } |
| 26 | func have(path: *u8) -> i64 { let fd: i64=sys_openat_rd(path); if fd<0 { return 0 } sys_close(fd); return 1 } |
| 27 | func 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 |
| 28 | func 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 } |
| 29 | func 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 |
| 33 | func nxe_write(m: *u8, arch: i64, flags: i64, caps: i64, entry: i64, code: *u8, clen: i64) -> i64 |
| 40 | func 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 } |
| 41 | func 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 } |
| 42 | func nxe_may(m: *u8, cap: i64) -> i64 { return (r64(m,32)>>cap)&1 } // cap = bit index |
| 44 | func nxe_load(m: *u8) -> i64 |
| 52 | func main() -> i64 |