env_internal.h (2380B)
1 #ifndef KIT_DRIVER_ENV_INTERNAL_H 2 #define KIT_DRIVER_ENV_INTERNAL_H 3 4 /* Internal header shared by every driver/env/ TU, regardless of host OS. 5 * 6 * Each TU implements one slice of the host environment with zero 7 * preprocessor conditionals -- selection is done by mk/env.mk, which 8 * picks at most one of {macos,linux,freebsd,windows}.c, one of 9 * icache_<arch>.c, and (on POSIX) one of uctx_<arch>_<os>.c per build. 10 * 11 * Scope of this header (must stay OS-neutral): 12 * - includes only of <stddef.h>/<stdint.h> and the libkit public API 13 * - the libc-pure vtables defined in common.c (g_heap_libc, g_diag_stderr) 14 * - the arch-only icache flush hook (icache_<arch>.c) 15 * 16 * The POSIX-shared surface (file I/O scaffold, exec_dual registry, signal 17 * machinery, the os_* hooks the per-OS POSIX file implements, ucontext 18 * marshalling) lives in env_posix.h. Windows has no POSIX overlap, so 19 * windows.c folds everything into a single TU and only needs this 20 * header. */ 21 22 #include <kit/compile.h> 23 #include <kit/core.h> 24 #include <kit/dbg.h> 25 #include <stddef.h> 26 #include <stdint.h> 27 28 #include "driver.h" 29 #include "env.h" 30 31 /* ---- vtable singletons wired into DriverEnv (common.c) ----------------- 32 * Defined in common.c and consumed by every host's driver_env_init. */ 33 extern KitHeap g_heap_libc; 34 extern KitDiagSink g_diag_stderr; 35 36 /* ---- compile metrics (common.c) ---------------------------------------- 37 * Process-wide KitProfiler storage, opt-in via the KIT_METRICS env var. The 38 * first call (from driver_env_init, before any compile runs) lazily allocates 39 * the profiler, wires the heap vtable's counter sink to it, and registers an 40 * atexit dump of every non-zero scope timer / counter. Returns NULL when 41 * KIT_METRICS is unset, so each host's driver_env_init can assign the result 42 * straight to DriverEnv.profiler (and thus KitContext.profiler) unconditionally 43 * -- libkit's metrics_scope and metrics_count hot path is a single NULL check 44 * when profiling is off. Idempotent: repeated calls return the same pointer. */ 45 KitProfiler* driver_metrics_profiler(void); 46 47 /* ---- icache (icache_<arch>.c) ------------------------------------------ 48 * Arch-only, OS-neutral. The POSIX dbg path delegates here from 49 * os_dbg_flush_icache; Windows uses FlushInstructionCache directly and 50 * does not consume this. */ 51 void env_flush_icache(void* addr, size_t n); 52 53 #endif