code wiki / (root) / nx_sh.nx

nx_sh.nx source

↩ module page · 64 lines · 2295 B

1// nx_sh.nx -- the sovereign Nishi shell (orchestration primitives), bits-up. 2// 3// Operator 2026-06-02: "no more shells, just pure bits and hardware up nishi -- 4// if that requires us building a shell then lets do it." This is it: fork + 5// exec + wait + redirect, in pure NishiLang over raw syscalls, so our gates / 6// audits / build drivers are Nishi programs, not bash scripts. 7// 8// (External tools we exec -- the compiler, as, ld -- are the toolchain being 9// replaced by nxasm/nxld; this removes BASH from the orchestration layer.) 10// 11// license_tier: ORIGINAL 12 13import "nx_syscalls.nx" 14 15// build a null-terminated argv from up to 6 *u8 args (pass 0 to end early). 16func nx_sh_argv(a0: *u8, a1: *u8, a2: *u8, a3: *u8, a4: *u8, a5: *u8) -> *i64 { 17 let v: *i64 = sys_mmap(64) as *i64 18 v[0] = a0 as i64; v[1] = a1 as i64; v[2] = a2 as i64 19 v[3] = a3 as i64; v[4] = a4 as i64; v[5] = a5 as i64 20 v[6] = 0 21 return v 22} 23 24// run `path` with `argv`; inherit stdio. returns the child's exit code (or 127). 25func nx_sh_run(path: *u8, argv: *i64) -> i64 { 26 let pid: i64 = sys_fork() 27 if pid == 0 { 28 let envp: *i64 = sys_mmap(8) as *i64; envp[0] = 0 29 sys_execve(path, argv, envp) 30 sys_exit(127) 31 } 32 let st: *i64 = sys_mmap(16) as *i64 33 sys_wait4(pid, st, 0) 34 return wait_exit_code(st[0]) 35} 36 37// run with stdout redirected to out_fd (the `>` redirect). caller owns out_fd. 38func nx_sh_run_to(path: *u8, argv: *i64, out_fd: i64) -> i64 { 39 let pid: i64 = sys_fork() 40 if pid == 0 { 41 if out_fd >= 0 { sys_dup3(out_fd, 1, 0) } 42 let envp: *i64 = sys_mmap(8) as *i64; envp[0] = 0 43 sys_execve(path, argv, envp) 44 sys_exit(127) 45 } 46 let st: *i64 = sys_mmap(16) as *i64 47 sys_wait4(pid, st, 0) 48 return wait_exit_code(st[0]) 49} 50 51// run silently (stdout + stderr -> /dev/null). 52func nx_sh_run_quiet(path: *u8, argv: *i64) -> i64 { 53 let pid: i64 = sys_fork() 54 if pid == 0 { 55 let dn: i64 = sys_openat_wr("/dev/null" as *u8, 0) 56 if dn >= 0 { sys_dup3(dn, 1, 0); sys_dup3(dn, 2, 0) } 57 let envp: *i64 = sys_mmap(8) as *i64; envp[0] = 0 58 sys_execve(path, argv, envp) 59 sys_exit(127) 60 } 61 let st: *i64 = sys_mmap(16) as *i64 62 sys_wait4(pid, st, 0) 63 return wait_exit_code(st[0]) 64}