interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / native / argus / Makefile

234 lines · 11145 bytes Raw Blame History
1# ARGUS-0 defensive plane, in C. No outside library; hosted libc + pthreads
2# only for tests and benchmarks (the library objects import no heap, I/O or clock).
3#
4# make build out/libargus.a
5# make test every lane test (B event/fuzz/ring, D core/determinism,
6# E detectors plain + UBSan) + the integration gates + the
7# hostile review (lane G; exit code counts: nonzero only on an
8# UNEXPECTED failure, EXPECTED-FAIL and N/A-v1 are reported)
9# make bench ring push/pop bench (lane B) + real-core ingest bench
10# make sanitize integration gates and hostile review under ASan+UBSan, the
11# integration gates under TSan, the ring under TSan (lane B)
12# and the detectors under ASan (lane E); Linux only
13# make clean
14#
15# Lane makefiles are invoked as sub-makes, never included: they each define
16# their own `clean`/`all` targets and their own OUT variables (lane D's default
17# out-d sat outside out/ and would be read by the recursive secret-negative
18# scan). Every lane's output is redirected under out/ from here; no lane .mk
19# file is edited.
20#
21# macOS (Apple clang 17, macOS 26.6): the ASan and TSan runtimes hang at
22# start-up, so there `make test` runs lane B's fuzz under UBSan only and
23# `make sanitize` is Linux-only.
24
25CC ?= cc
26AR ?= ar
27CFLAGS ?= -std=gnu11 -O2 -Wall -Wextra -Werror -fstack-protector-strong
28OUT ?= out
29UNAME_S := $(shell uname -s)
30
31SANFLAGS_ASAN = -fsanitize=address,undefined -fno-omit-frame-pointer -fno-sanitize-recover=all -g
32SANFLAGS_TSAN = -fsanitize=thread -fno-omit-frame-pointer -g
33# TSan on Linux aarch64 needs ASLR off (same rule as lane_b.mk).
34TSAN_RUN := $(shell [ "$$(uname -s)" = Linux ] && command -v setarch >/dev/null 2>&1 && echo setarch $$(uname -m) -R)
35
36LIB_SRC = argus_event.c argus_ring.c argus_core.c argus_detect.c sha256.c
37LIB_HDR = argus_abi.h argus_core.h argus_detect.h sha256.h
38LIB_OBJ = $(OUT)/obj/argus_event.o $(OUT)/obj/argus_ring.o $(OUT)/obj/argus_core.o \
39 $(OUT)/obj/argus_detect.o $(OUT)/obj/sha256.o
40LIB = $(OUT)/libargus.a
41
42# ---- ARGUS-1 lanes (docs/ARGUS1_PLAN.md) ------------------------------------
43# Lanes drop their files in without editing this Makefile. Every ARGUS-1 target is
44# guarded by $(wildcard ...): until its sources exist it prints "skipped" and passes.
45# Lane C: argus_contain.c/.h join libargus (and so the nm -u memory check, G7).
46CONTAIN_SRC := $(wildcard argus_contain.c)
47CONTAIN_HDR := $(wildcard argus_contain.h)
48LIB_SRC += $(CONTAIN_SRC)
49LIB_HDR += $(CONTAIN_HDR)
50LIB_OBJ += $(patsubst %.c,$(OUT)/obj/%.o,$(CONTAIN_SRC))
51# Lane G gate (native/capability) + lane X bridge: never part of libargus (the
52# hostile review links the archive alone and must not see any aienos_cap_* symbol).
53CAP_DIR = ../capability
54AUTH_SRC := $(wildcard $(CAP_DIR)/aienos_capability.c)
55GATE_SRC := $(wildcard $(CAP_DIR)/aienos_contain.c)
56BRIDGE_SRC := $(wildcard bridge/argus_aegis_bridge.c)
57BRIDGE_HDR := $(wildcard bridge/argus_aegis_bridge.h $(CAP_DIR)/aienos_contain.h $(CAP_DIR)/aienos_capability.h)
58# The full containment stack: present only when authority, gate and bridge all exist.
59STACK_SRC := $(if $(and $(AUTH_SRC),$(GATE_SRC),$(BRIDGE_SRC)),$(BRIDGE_SRC) $(GATE_SRC) $(AUTH_SRC))
60STACK_INC = -I. -Itests -Ibridge -I$(CAP_DIR)
61
62CONTAIN_TEST_SRC := $(wildcard tests/test_argus_contain.c)
63E2E_SRC := $(wildcard tests/test_argus_containment_e2e.c)
64CHOSTILE_SRC := $(wildcard tests/test_argus_contain_hostile.c)
65CBENCH_SRC := $(wildcard tests/bench_argus_contain.c)
66CONTAIN_TEST = $(OUT)/test_argus_contain
67E2E = $(OUT)/test_argus_containment_e2e
68CHOSTILE = $(OUT)/test_argus_contain_hostile
69CBENCH = $(OUT)/bench_argus_contain
70
71INT_SRC = tests/test_argus_integration.c tests/stub_state.c
72INT_HDR = tests/stub_state.h
73INT = $(OUT)/test_argus_integration
74
75# Hostile review: links the library archive only. It must never link the
76# capability authority (G-1: any aienos_cap_* reference would fail this link).
77HOSTILE_SRC = tests/test_argus_hostile.c
78HOSTILE = $(OUT)/test_argus_hostile
79
80SUBMAKE_VARS = CC="$(CC)" CFLAGS="$(CFLAGS)"
81ifeq ($(UNAME_S),Darwin)
82LANE_B_SAN = SANFLAGS="-fsanitize=undefined -fno-omit-frame-pointer -fno-sanitize-recover=all"
83else
84LANE_B_SAN =
85endif
86
87.PHONY: all lib test test-lanes test-integration test-hostile bench sanitize clean \
88 test-argus1 test-contain test-e2e test-contain-hostile test-contain-fp bench-contain sanitize-argus1
89
90all: lib
91lib: $(LIB)
92
93$(OUT)/obj:
94 mkdir -p $(OUT)/obj
95
96$(OUT)/obj/%.o: %.c $(LIB_HDR) | $(OUT)/obj
97 $(CC) $(CFLAGS) -c -o $@ $<
98
99$(LIB): $(LIB_OBJ)
100 rm -f $@
101 $(AR) rcs $@ $(LIB_OBJ)
102
103$(INT): $(INT_SRC) $(INT_HDR) $(LIB)
104 $(CC) $(CFLAGS) -I. -Itests -pthread -o $@ $(INT_SRC) $(LIB)
105
106$(HOSTILE): $(HOSTILE_SRC) $(LIB)
107 $(CC) $(CFLAGS) -I. -o $@ $(HOSTILE_SRC) $(LIB)
108
109$(OUT)/test_argus_hostile_asan: $(HOSTILE_SRC) $(LIB_SRC) $(LIB_HDR) | $(OUT)/obj
110 $(CC) $(CFLAGS) $(SANFLAGS_ASAN) -I. -o $@ $(HOSTILE_SRC) $(LIB_SRC)
111
112$(OUT)/test_argus_integration_asan: $(INT_SRC) $(INT_HDR) $(LIB_SRC) $(LIB_HDR) | $(OUT)/obj
113 $(CC) $(CFLAGS) $(SANFLAGS_ASAN) -I. -Itests -pthread -o $@ $(INT_SRC) $(LIB_SRC)
114
115$(OUT)/test_argus_integration_tsan: $(INT_SRC) $(INT_HDR) $(LIB_SRC) $(LIB_HDR) | $(OUT)/obj
116 $(CC) $(CFLAGS) $(SANFLAGS_TSAN) -I. -Itests -pthread -o $@ $(INT_SRC) $(LIB_SRC)
117
118# ---- ARGUS-1 executables and targets (skipped until the lane's files exist) ----
119ifneq ($(CONTAIN_TEST_SRC),)
120$(CONTAIN_TEST): $(CONTAIN_TEST_SRC) tests/stub_state.c $(INT_HDR) $(LIB)
121 $(CC) $(CFLAGS) -I. -Itests -o $@ $(CONTAIN_TEST_SRC) tests/stub_state.c $(LIB)
122test-contain: $(CONTAIN_TEST)
123 ./$(CONTAIN_TEST)
124else
125test-contain:
126 @echo "test-contain: skipped (tests/test_argus_contain.c not present yet, lane C)"
127endif
128
129ifneq ($(and $(E2E_SRC),$(STACK_SRC)),)
130$(E2E): $(E2E_SRC) $(STACK_SRC) $(BRIDGE_HDR) tests/stub_state.c $(INT_HDR) $(LIB)
131 $(CC) $(CFLAGS) $(STACK_INC) -pthread -o $@ $(E2E_SRC) $(STACK_SRC) tests/stub_state.c $(LIB)
132test-e2e: $(E2E)
133 ./$(E2E)
134else
135test-e2e:
136 @echo "test-e2e: skipped (needs tests/test_argus_containment_e2e.c + bridge + gate, lanes X/G)"
137endif
138
139ifneq ($(and $(CHOSTILE_SRC),$(STACK_SRC)),)
140$(CHOSTILE): $(CHOSTILE_SRC) $(STACK_SRC) $(BRIDGE_HDR) tests/stub_state.c $(INT_HDR) $(LIB)
141 $(CC) $(CFLAGS) $(STACK_INC) -pthread -o $@ $(CHOSTILE_SRC) $(STACK_SRC) tests/stub_state.c $(LIB)
142test-contain-hostile: $(CHOSTILE)
143 ./$(CHOSTILE)
144else
145test-contain-hostile:
146 @echo "test-contain-hostile: skipped (needs tests/test_argus_contain_hostile.c + bridge + gate, lanes H/X/G)"
147endif
148
149# Bench (lane F): never part of `make test`. Lane F takes ~/workspace/.argus-bench.lock and
150# refuses to start while ~/workspace/.spark-quiet exists.
151ifneq ($(and $(CBENCH_SRC),$(STACK_SRC)),)
152$(CBENCH): $(CBENCH_SRC) $(STACK_SRC) $(BRIDGE_HDR) tests/stub_state.c $(INT_HDR) $(LIB)
153 $(CC) $(CFLAGS) $(STACK_INC) -pthread -o $@ $(CBENCH_SRC) $(STACK_SRC) tests/stub_state.c $(LIB)
154test-contain-fp: $(CBENCH)
155 ./$(CBENCH) --gate-only
156bench-contain: $(CBENCH)
157 ./tests/run_argus1_bench.sh "./$(CBENCH)" contain "$(OUT)/test_argus_integration" "$(OUT)/lane_b"
158else
159test-contain-fp:
160 @echo "test-contain-fp: skipped (needs tests/bench_argus_contain.c + bridge + gate, lane F)"
161bench-contain:
162 @echo "bench-contain: skipped (needs tests/bench_argus_contain.c + bridge + gate, lane F)"
163endif
164
165test-argus1: test-contain test-e2e test-contain-hostile test-contain-fp test-containment-authority test-contain-symbols
166
167# The AEGIS gate tests live with the capability authority; keep them in the
168# one ARGUS-1 regression command so G12 cannot silently omit the authority path.
169test-containment-authority:
170 $(MAKE) -C ../capability test-contain
171
172# G11/I4: low-level event/ring code and the authority must not depend upward on
173# detection, containment, or the bridge. The gate has its own checks in the
174# capability Makefile; this checks the other direction across the three objects.
175test-contain-symbols: $(LIB) test-containment-authority
176 $(MAKE) -C ../capability out/aienos_capability.o
177 ./tests/check_argus1_symbols.sh $(OUT)/obj/argus_event.o $(OUT)/obj/argus_ring.o ../capability/out/aienos_capability.o
178
179# Linux only (called from `sanitize`): lane C unit test under ASan+UBSan, e2e under
180# ASan+UBSan and TSan, containment hostile under ASan+UBSan. Library sources are
181# recompiled with the sanitizer, as for the ARGUS-0 integration binaries.
182sanitize-argus1:
183ifneq ($(CONTAIN_TEST_SRC),)
184 $(CC) $(CFLAGS) $(SANFLAGS_ASAN) -I. -Itests -o $(OUT)/test_argus_contain_asan $(CONTAIN_TEST_SRC) tests/stub_state.c $(LIB_SRC)
185 ASAN_OPTIONS=detect_leaks=1 UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 ./$(OUT)/test_argus_contain_asan
186endif
187ifneq ($(and $(E2E_SRC),$(STACK_SRC)),)
188 $(CC) $(CFLAGS) $(SANFLAGS_ASAN) $(STACK_INC) -pthread -o $(OUT)/test_argus_containment_e2e_asan $(E2E_SRC) $(STACK_SRC) tests/stub_state.c $(LIB_SRC)
189 ASAN_OPTIONS=detect_leaks=1 UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 ./$(OUT)/test_argus_containment_e2e_asan
190 $(CC) $(CFLAGS) $(SANFLAGS_TSAN) $(STACK_INC) -pthread -o $(OUT)/test_argus_containment_e2e_tsan $(E2E_SRC) $(STACK_SRC) tests/stub_state.c $(LIB_SRC)
191 TSAN_OPTIONS=halt_on_error=1 $(TSAN_RUN) ./$(OUT)/test_argus_containment_e2e_tsan
192endif
193ifneq ($(and $(CHOSTILE_SRC),$(STACK_SRC)),)
194 $(CC) $(CFLAGS) $(SANFLAGS_ASAN) $(STACK_INC) -pthread -o $(OUT)/test_argus_contain_hostile_asan $(CHOSTILE_SRC) $(STACK_SRC) tests/stub_state.c $(LIB_SRC)
195 ASAN_OPTIONS=detect_leaks=1 UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 ./$(OUT)/test_argus_contain_hostile_asan
196endif
197 $(MAKE) -C ../capability sanitize
198 @echo "sanitize-argus1: done (targets whose sources are absent were skipped)"
199
200test: test-lanes test-integration test-hostile test-argus1
201
202test-lanes:
203 $(MAKE) -f lane_b.mk $(SUBMAKE_VARS) $(LANE_B_SAN) LANE_B_OUT=$(OUT)/lane_b test-event fuzz-event test-ring
204 $(MAKE) -f lane_d.mk $(SUBMAKE_VARS) OUT=$(OUT)/lane_d test-core test-determinism
205 $(MAKE) -f lane_e.mk $(SUBMAKE_VARS) OUT=$(OUT)/lane_e test-detect
206
207test-integration: $(INT)
208 ./$(INT) $(LIB_OBJ)
209
210test-hostile: $(HOSTILE)
211 ./$(HOSTILE)
212
213bench: $(INT) $(CBENCH)
214 ./tests/run_argus1_bench.sh "./$(CBENCH)" full "$(OUT)/test_argus_integration" "$(OUT)/lane_b"
215
216ifeq ($(UNAME_S),Darwin)
217sanitize:
218 @echo "sanitize: skipped on macOS (ASan/TSan runtimes hang at start-up); run on Linux"
219else
220sanitize: $(OUT)/test_argus_integration_asan $(OUT)/test_argus_integration_tsan $(OUT)/test_argus_hostile_asan $(LIB)
221 ASAN_OPTIONS=detect_leaks=1 UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 \
222 ./$(OUT)/test_argus_integration_asan $(LIB_OBJ)
223 ASAN_OPTIONS=detect_leaks=1 UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 \
224 ./$(OUT)/test_argus_hostile_asan
225 TSAN_OPTIONS=halt_on_error=1 $(TSAN_RUN) ./$(OUT)/test_argus_integration_tsan $(LIB_OBJ)
226 $(MAKE) -f lane_b.mk $(SUBMAKE_VARS) LANE_B_OUT=$(OUT)/lane_b test-ring-tsan
227 $(MAKE) -f lane_e.mk $(SUBMAKE_VARS) OUT=$(OUT)/lane_e test-detect-asan
228 $(MAKE) sanitize-argus1
229endif
230
231clean:
232 rm -rf $(OUT)
233
234.PHONY: test-argus1 test-containment-authority test-contain-symbols sanitize-argus1