// Started by the packaged BusyBox init through /etc/inittab on a diskless guest. module main import os #include #include #include #include fn C.open(&char, int, ...) int fn C.dup2(int, int) int fn C.close(int) int fn C.reboot(int) int fn C.malloc_trim(uint) int fn C.malloc_usable_size(voidptr) uint fn run(argv []string) !string { result := os.exec(argv) if result.exit_code != 0 { return error('${argv} exited ${result.exit_code}: ${result.output}') } return result.output.trim_space() } fn check(argv []string, expected string) ! { actual := run(argv)! if actual != expected { return error('${argv}: expected ${expected}, got ${actual}') } println('${argv} -> ${actual}') } fn verify() ! { for path in ['/sbin/init', '/bin/sh', '/bin/cat'] { if !os.is_link(path) || os.real_path(path) != '/bin/busybox' { return error('${path} must resolve to /bin/busybox') } } check(['/bin/busybox', 'uname', '-m'], 'x86_64')! check(['/bin/sh', '-c', r'echo $((6 * 7))'], '42')! check(['/bin/busybox', 'ash', '-c', r'echo $((3 * 7))'], '21')! check(['/bin/cat', '/etc/inittab'], '::sysinit:/busybox-probe')! println(run(['/bin/busybox', 'sha256sum', '/bin/busybox'])!) $if packaged_musl ? { listing := run(['/lib/ld-musl-x86_64.so.1', '--list', '/busybox-probe'])! if !listing.contains('libc.musl-x86_64.so.1 => /lib/ld-musl-x86_64.so.1') { return error('unexpected dynamic dependencies: ${listing}') } println(listing) println(run(['/bin/busybox', 'sha256sum', '/lib/ld-musl-x86_64.so.1'])!) // A freed 256 KiB mapping falls in a retained bucket in the Vinix allocator. C.malloc_trim(0) buffer := unsafe { C.malloc(256 * 1024) } if buffer == unsafe { nil } { return error('malloc failed to provide 256 KiB') } capacity := C.malloc_usable_size(buffer) unsafe { C.free(buffer) } if capacity < 256 * 1024 { return error('malloc supplied a truncated allocation') } if C.malloc_trim(0) == 0 { return error('malloc_trim did not release a mapping after free') } println('Packaged musl released a mapping with malloc_trim.') } } fn main() { if os.getppid() != 1 || run(['/bin/busybox', 'uname', '-s']) or { '' } != 'Vinix' { eprintln('requires a Vinix guest with the probe started directly by init') exit(2) } fd := C.open(c'/dev/com1', C.O_WRONLY) if fd < 0 || C.dup2(fd, 1) < 0 || C.dup2(fd, 2) < 0 { exit(2) } if fd > 2 { C.close(fd) } verify() or { eprintln('VPAC BUSYBOX GUEST FAIL ${err}') C.reboot(C.RB_POWER_OFF) exit(1) } println('VPAC BUSYBOX GUEST PASS') C.reboot(C.RB_POWER_OFF) }