/****************************************************************************** __ ____ __ / / ___ ____ _/ __/_____________ _/ /__ / / / _ \/ __ `/ /_/ ___/ ___/ __ `/ / _ \ / /___/ __/ /_/ / __(__ ) /__/ /_/ / / __/ /_____/\___/\__,_/_/ /____/\___/\__,_/_/\___/ (C)opyright 2025-2026, Leafscale, LLC - https://www.leafscale.com Project: zyginit Filename: shutdown.reef Authors: Chris Tusa License: Description: PID-1 shutdown primitives — uadmin(2) FFI and shutdown-type constants. ******************************************************************************/ module shutdown export // Shutdown function codes (sys/uadmin.h A_SHUTDOWN fcn values) fn AD_HALT(): int fn AD_BOOT(): int fn AD_POWEROFF(): int // Symbolic shutdown-type codes used internally by zyginit. // These are NOT the uadmin AD_* codes — they're zyginit's own // enum for distinguishing what a shutdown was triggered as, // before it's mapped to AD_* at the actual uadmin call site. fn SHUT_NONE(): int fn SHUT_HALT(): int fn SHUT_REBOOT(): int fn SHUT_POWEROFF(): int // Map our internal type to the uadmin fcn code. fn to_ad_code(shut_type: int): int // Call uadmin(A_SHUTDOWN, fcn, 0). Returns 0 on success, -1 on error. // Only succeeds when running as PID 1. fn do_shutdown(fcn: int): int // Flush dirty page-cache buffers to disk (POSIX sync(2)). proc do_sync() end export extern "C" fn zyginit_shutdown(fcn: int): int extern "C" proc zyginit_sync() fn AD_HALT(): int return 0 end AD_HALT fn AD_BOOT(): int return 1 end AD_BOOT fn AD_POWEROFF(): int return 6 end AD_POWEROFF fn SHUT_NONE(): int return 0 end SHUT_NONE fn SHUT_HALT(): int return 1 end SHUT_HALT fn SHUT_REBOOT(): int return 2 end SHUT_REBOOT fn SHUT_POWEROFF(): int return 3 end SHUT_POWEROFF fn to_ad_code(shut_type: int): int if shut_type == SHUT_HALT() return AD_HALT() elif shut_type == SHUT_REBOOT() return AD_BOOT() elif shut_type == SHUT_POWEROFF() return AD_POWEROFF() end if // Default to halt for unknown / NONE return AD_HALT() end to_ad_code fn do_shutdown(fcn: int): int return zyginit_shutdown(fcn) end do_shutdown proc do_sync() zyginit_sync() end do_sync end module