Milo is written in freestanding C++20 for AArch64 (-ffreestanding -fno-exceptions -fno-rtti) with a host-testable core (HOST_TEST). Rather than relying on ad-hoc C idioms or runtime-heavy abstractions, the codebase enforces a small set of deterministic systems-engineering patterns across kernel/, include/ddk/, drivers/, and tests/host/.
atexitMakefile, drivers/ddk.mk): All kernel and driver translation units compile with -std=c++20 -ffreestanding -fno-exceptions -fno-rtti -fno-threadsafe-statics -fno-use-cxa-atexit.include/ddk/Status.hpp, kernel/core/traits.hpp): Fallible operations return Kernel::DDK::Result<T> (paired with Kernel::DDK::Status) or kernel Result<T, E> instead of throwing exceptions. Callers inspect .is_ok() / .is_err() explicitly, enforced by [[nodiscard]].atexit-free singletons (drivers/dummy/DummyDriver.cpp, kernel/ddk/KernelPlatformServices.cpp): Out-of-tree DDK drivers must not assume kernel kmalloc/kfree or __cxa_atexit. DummyDriver uses aligned static storage with placement new (new (g_dummy_storage) DummyDriver()) and explicit destructor invocation (drv->~Driver()), while kernel_platform_services() returns a namespace-scope instance rather than a function-local static with a non-trivial destructor (which would emit a __cxa_atexit reference)..eh_frame), RTTI typeinfo bloat, and hidden heap allocations or atexit teardown chains in bare-metal EL1 code.__cxa_atexit / DSO Object Destructioninclude/ddk/Resources.hpp, include/ddk/Services.hpp): MmioRegion, DmaBuffer, IrqHandle, IrqLock, and EventHandle delete copy construction/assignment, implement move construction/assignment that null out the source handle, and deterministically release backing kernel resources via PlatformServices* in reset() / ~T().Kernel::Sync::IrqGuard (kernel/sync/IrqGuard.hpp) saves DAIF interrupt state on entry and restores it on scope exit.Kernel::Log::ScopedLevel (kernel/core/log.hpp) temporarily adjusts console log verbosity and restores the previous threshold when leaving scope.Kernel::Shell::Tests::TestSession (kernel/shell/tests/test_common.hpp) manages compact dot-progress output, console muting, and summary/failure reporting on scope exit.DummyDriver::init() automatically unmaps MmioRegion if alloc_dma() fails) without needing exceptions.=delete any copy, move, or destructor function, define or =delete them all (Rule of Five)arch/aarch64-linux-gnu/, kernel/hal/targets/qemu_virt/): Architecture-specific assembly, MMU page-table manipulation, and GIC/timer/board wiring live behind kernel/hal/*.hpp interfaces, keeping kernel/mm/, kernel/fs/, kernel/ipc/, kernel/net/, kernel/loader/, and kernel/process/ hardware-agnostic.include/ddk/Services.hpp, kernel/ddk/KernelPlatformServices.*): Modular drivers under drivers/ never touch global kernel symbols (alloc_frames, HAL::get_cpu(), WaitQueue). Instead, they receive Kernel::DDK::PlatformServices& and probe devices via Kernel::DDK::DeviceDescriptor (include/ddk/Bus.hpp).drivers/ddk.mk, Makefile): Driver translation units compile with DDK_CXXFLAGS passing only -I$(MILO_DDK_DIR)/include—omitting -Ikernel and -Iarch/...—so any accidental private kernel include fails immediately at compile time. make export-ddk packages include/ddk/ and drivers/ddk.mk into build/ddk/ so external out-of-tree driver builds use the exact same workflow.snitch + Sanitizers (tests/host/, Makefile): Architecture-agnostic kernel modules and DDK drivers compile natively on the host with -DHOST_TEST against tests/host/mocks/host_hal.cpp (a 16 MiB simulated RAM arena + mock MMU/CPU/console/IRQ HAL), running under AddressSanitizer and UndefinedBehaviorSanitizer (-fsanitize=address,undefined) and gcovr line/branch coverage (make test-host).kernel/shell/tests/, user/test_milo.c): test all runs 250+ in-kernel assertions in QEMU, and /bin/test_milo verifies the EL0 musl/syscall/VFS/devfs ABI end-to-end inside milo-sh or milo-bash.test_ddk.cpp, test_lazy_mm_suite.cpp, and test_loader_pipeline.cpp snapshot Kernel::MM::pfa_free_pages_count() before and after instantiation/teardown (including OOM rollback paths) and assert exact frame conservation.pfa_free_pages_count() invariants ensure zero physical page leaks across CoW, demand paging, and driver lifecycles.get_page / put_page)kernel/core/log.{hpp,cpp}): Kernel::Log::set_level() controls what prints to the UART console (kept quiet at Warn during boot and Off + muted console during compact TestSession dot-progress runs), while set_capture_level() (default Level::Trace) continuously records every event—including seq, monotonic ts_ns, level, tag, and msg—into an IrqGuard-protected 512-entry ring buffer.kernel/shell/shell.cpp, kernel/fs/devfs/devfs.cpp): Operators and test scripts can inspect captured logs on demand via logs / dmesg (--json, --tail N, --level L) or read /dev/kmsg from EL0 userspace as JSON Lines (.jsonl) without cluttering interactive console output.test all output concise (. for passes, detailed diagnostics only on failures) while preserving full forensic traces for post-mortem debugging and CI log parsing./dev/kmsg Ring Buffer Interfacemake quality gate (Makefile, scripts/): Runs four automated checks before commits:
format-check (clang-format --dry-run --Werror)license-check (scripts/check_license_headers.py --check enforcing SPDX-License-Identifier: GPL-3.0-only)lint-report (clang-tidy across compile_commands.json generated by scripts/generate_compile_commands.py)test-host (snitch ASan/UBSan suite + gcovr coverage reports).githooks/pre-commit, Makefile): make commit runs quality and sets MILO_MAKE_COMMIT=1, preventing unformatted, unlicensed, or failing code from being committed. Commit titles follow Conventional Commits (feat(...), fix(...), test(...), docs(...)).