code wiki / _hdl_build / nx_nxe_loader.nx

nx_nxe_loader.nx

buildroot/runtime/_hdl_build/nx_nxe_loader.nx

7292 B92 linesdepth 6pulls 7 transitivereach 0 importersview sourcekind tooltopic nxe
docsdependenciesstructsconstsfunctions

about

nx_nxe_loader.nx -- GATE: the NATIVE NXE LOADER that VERIFIES then EXECUTES (composes nx_nxe_lib, rule-15 DRY). Closes the EXEC-FORMAT census gap ("emit organs AS .nxe + a native NXE loader/boot" -- organs were ELF-only, the NXE format was write+header-check only). This loader actually RUNS the code section: mmap RWX -> copy the verified code -> cast the entry to a function pointer -> CALL it on this machine (proven by nx_nxe_exec_probe). THE EXCEED vs ELF/Mach-O/PE (grounded osb_elf/osb_loader): verify-BEFORE-execute BY CONSTRUCTION. An ELF loader maps+jumps to whatever bytes are present; NXE refuses to even map-exec a binary that fails ANY of: (1) INTEGRITY -- a FIPS-180-4 SHA-256 of the code section, baked in the header; a tampered byte -> refused. (2) CAPABILITY -- the binary must DECLARE the EXEC capability to be executed (least-privilege manifest). (3) NEVER-BRICK (cardinal 26 in the format) -- a HW_WRITE binary without a never-brick proof -> refused. Only after all three pass does a single byte execute. Payload = a REAL function f(x)=x*x+1 in x86_64 machine code. T1 write+load+EXECUTE (f(7)=50, f(12)=145). T2 tamper->SHA-256 fail->REFUSED(-2), never executes. T3 no-EXEC-cap->REFUSED(-4). T4 HW_WRITE w/o never-brick->REFUSED(-3); with proof->runs. T5 disk .nxe round-trips+runs. expect_exit: 0 Sovereign: nx_cc->nxasm via nx_syscalls + canonical nx_sha256. NEVER-BRICK: RAM + a file, 0 firmware.

dependencies 2 imports · 0 importers

nx_nxe_lib.nx nx_itoa_lib.nx nx_nxe_loader.nx

imports: nx_nxe_lib.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 emit_payload nxe_write nxe_p64 sha256_digest sys_mmap sha256_init sys_mmap ↻ sha256_k sha256_update sha256_compress_ni_blocks blk_set_byte sha256_compress sha256_compress_ni blk_word blk_byte sha256_final blk_set_byte ↻ sha256_compress ↻ nxe_load_exec nxe_magic_ok nxe_integrity_ok nxe_r64 sys_mmap ↻ sha256_digest ↻ nxe_r64 ↻ nxe_may nxe_r64 ↻ nxe_mmap_rwx g_pn nxi_out nxi_fd sys_mmap ↻ ccz_cat_num sys_write sys_munmap ck g_puts ↻ nxe_size

structs

none

consts

17const K_MAGIC_4096: i64 = 4096

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
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 wlog(fd: i64, s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(fd,s,n); return 0 }
called by 1: main
29func emit_payload(dst: *u8) -> i64
called by 1: main
37func main() -> i64