nx_os_research_fetch.nx source
↩ module page · 65 lines · 4404 B
1// nx_os_research_fetch.nx -- SOVEREIGN researcher: GROUND the OS-capability census (Rule 4). To know where the
2// Nishi OS still lacks (beyond AI + hardware), fetch what a COMPLETE OS comprises -- kernel, filesystem, process
3// + memory management, device drivers, IPC, sockets, init/services -- plus the regex sources (the named gap to
4// make s-class exceed via a linear-time Thompson NFA). Mirrors the proven fetcher; saves to os_*.raw / rx_*.raw.
5// expect_exit: 0
6import "nx_syscalls.nx"
7import "nx_x509_trust_store.nx"
8import "nx_trust_store_load_from_certdata.nx"
9import "nx_https_fetch_follow.nx"
10const K_MAGIC_4194304: i64 = 4194304
11const K_MAGIC_8388608: i64 = 8388608
12
13func df_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
14func df_putn(v: i64) -> i64 {
15 if v == 0 { sys_write(1, "0" as *u8, 1); return 0 }
16 var m: i64 = v; if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m }
17 let d: *u8 = sys_mmap(24); var k: i64 = 0
18 while m > 0 { d[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 }
19 var j: i64 = k - 1
20 while j >= 0 { sys_write(1, ((d as i64)+j) as *u8, 1); j = j - 1 }
21 return 0
22}
23func have_file(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 } sys_close(fd); return 1 }
24func fetch_save(url: *u8, opath: *u8, store: *TrustStore, out: *u8, cap: i64) -> i64 {
25 if have_file(opath) == 1 { df_puts(opath); df_puts(" [have-skip]\n"); return 1 }
26 let status: *i64 = sys_mmap(8)
27 let n: i64 = nx_https_fetch_follow(url, store, out, cap, 6, status)
28 df_puts(url); df_puts(" status="); df_putn(status[0]); df_puts(" bytes="); df_putn(n)
29 if n <= 0 { df_puts(" FETCH-FAIL\n"); return 0 }
30 var gz: i64 = 0
31 if n >= 2 { if out[0] == 0x1f as u8 { if out[1] == 0x8b as u8 { gz = 1 } } }
32 if gz == 1 { df_puts(" [GZIP-skip]\n"); return 0 }
33 let fd: i64 = sys_openat_wr(opath, 0x1a4)
34 if fd < 0 { df_puts(" SAVE-FAIL\n"); return 0 }
35 sys_write(fd, out, n); sys_close(fd); df_puts(" SAVED\n"); return 1
36}
37
38func main() -> i64 {
39 let r: i64 = nx_trust_store_load_from_certdata("data/mozilla_certdata.txt" as *u8, 512, K_MAGIC_4194304)
40 if r <= 0 { df_puts("OS: certdata load failed\n"); return 1 }
41 let store: *TrustStore = r as *TrustStore
42 df_puts("CA roots="); df_putn(trust_store_count(store)); df_puts("\n")
43 let cap: i64 = K_MAGIC_8388608
44 let out: *u8 = sys_mmap(cap)
45 var ok: i64 = 0
46
47 df_puts("== what a COMPLETE OS comprises (the census BENCHMARK) ==\n")
48 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Operating_system" as *u8, "knowledge/fetched/os_os.raw" as *u8, store, out, cap)
49 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Kernel_(operating_system)" as *u8, "knowledge/fetched/os_kernel.raw" as *u8, store, out, cap)
50 ok = ok + fetch_save("https://en.wikipedia.org/wiki/File_system" as *u8, "knowledge/fetched/os_fs.raw" as *u8, store, out, cap)
51 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Process_management_(computing)" as *u8, "knowledge/fetched/os_proc.raw" as *u8, store, out, cap)
52 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Memory_management" as *u8, "knowledge/fetched/os_mem.raw" as *u8, store, out, cap)
53 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Device_driver" as *u8, "knowledge/fetched/os_driver.raw" as *u8, store, out, cap)
54 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Inter-process_communication" as *u8, "knowledge/fetched/os_ipc.raw" as *u8, store, out, cap)
55 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Network_socket" as *u8, "knowledge/fetched/os_socket.raw" as *u8, store, out, cap)
56 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Init" as *u8, "knowledge/fetched/os_init.raw" as *u8, store, out, cap)
57
58 df_puts("== regex (the named gap -> linear-time Thompson-NFA exceed) ==\n")
59 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Regular_expression" as *u8, "knowledge/fetched/rx_regex.raw" as *u8, store, out, cap)
60 ok = ok + fetch_save("https://en.wikipedia.org/wiki/ReDoS" as *u8, "knowledge/fetched/rx_redos.raw" as *u8, store, out, cap)
61 ok = ok + fetch_save("https://en.wikipedia.org/wiki/Thompson%27s_construction" as *u8, "knowledge/fetched/rx_thompson.raw" as *u8, store, out, cap)
62
63 df_puts("OS+REGEX RESEARCH SOURCES SAVED: "); df_putn(ok); df_puts(" / 12\n")
64 return 0
65}