nx_vsz_pig.nx source
↩ module page · 19 lines · 899 B
1// nx_vsz_pig.nx -- TEST FIXTURE for the VSZ watchdog's live kill-path proof: balloons its own VSZ to ~40GB
2// of VIRTUAL address space (anonymous mmap, untouched pages -> near-zero RSS, harmless) then sleeps forever.
3// The watchdog, given a conf row "nx_vsz_pig 30", must kill THIS and nothing else. license_tier: ORIGINAL
4import "nx_syscalls.nx"
5const K_MAGIC_1073741824: i64 = 1073741824
6const K_MAGIC_60000: i64 = 60000
7
8func main() -> i64 {
9 var i: i64 = 0
10 while i < 40 {
11 let p: *u8 = sys_mmap(K_MAGIC_1073741824) // 1 GiB virtual each; pages never touched
12 if (p as i64) > 0 { p[0] = 1 as u8 } // touch ONE byte per GiB so the map is real (RSS ~40 pages)
13 i = i + 1
14 }
15 sys_write(1, "pig: ~40GB VSZ, sleeping\n" as *u8, 25)
16 var go: i64 = 1
17 while go == 1 { sys_poll(0 as *u8, 0, K_MAGIC_60000) } // sovereign sleep loop
18 return 0
19}