Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/native/argus/tests/stub_state.h # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / native / argus / tests / stub_state.h` 119 lines ยท 5879 bytes Raw Blame History 1 /* SPDX-License-Identifier: Apache-2.0 2 * Copyright 2026 Drake Stapleton (AIEN / aien-dev) 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 /* 18 * stub_state.h -- test-only, in-memory ArgusStateOps over small arrays, plus 19 * the deterministic synthetic corpora (lane E). 20 * 21 * This is NOT the ARGUS core. Lane D owns the real shadow state 22 * (argus_core.c). The stub exists so detector tests can populate shadow state 23 * directly, and so the corpora can be replayed without the core. 24 * stub_state_apply() is a tiny reference "apply" whose rules are the lane E 25 * proposal for how the core updates shadow state (see stub_state.c). 26 * 27 * The stub never defines struct ArgusStateView: a StubState pointer is cast 28 * to the opaque view type and back, so this file links next to argus_core.c. 29 */ 30 #ifndef ARGUS_STUB_STATE_H 31 #define ARGUS_STUB_STATE_H 32 #include "../argus_abi.h" 33 34 #define STUB_MAX_CAPS 128 35 #define STUB_MAX_MACHINES 16 36 #define STUB_MAX_ARTIFACTS 128 37 #define STUB_MAX_LEASES 64 38 #define STUB_MAX_PROVIDERS 16 39 40 typedef struct { 41 ArgusCapShadow caps[STUB_MAX_CAPS]; 42 size_t n_caps; 43 ArgusMachineShadow machines[STUB_MAX_MACHINES]; 44 size_t n_machines; 45 ArgusArtifactShadow artifacts[STUB_MAX_ARTIFACTS]; 46 size_t n_artifacts; 47 ArgusLeaseShadow leases[STUB_MAX_LEASES]; 48 size_t n_leases; 49 ArgusProviderShadow providers[STUB_MAX_PROVIDERS]; 50 size_t n_providers; 51 ArgusWorldShadow worlds[ARGUS_WORLD_STORES]; /* per store (v1.1), insertion order */ 52 size_t n_worlds; 53 uint8_t policy[ARGUS_DIGEST_LEN]; 54 uint8_t runtime[ARGUS_DIGEST_LEN]; 55 } StubState; 56 57 void stub_state_init(StubState *s); 58 const ArgusStateOps *stub_state_ops(void); 59 const ArgusStateView *stub_state_view(const StubState *s); 60 61 /* Direct population for tests. Insert or replace by key. ARGUS_ERR_FULL when full. */ 62 int stub_put_cap(StubState *s, const ArgusCapShadow *c); 63 int stub_put_machine(StubState *s, const ArgusMachineShadow *m); 64 int stub_put_artifact(StubState *s, const ArgusArtifactShadow *a); 65 int stub_put_lease(StubState *s, const ArgusLeaseShadow *l); 66 int stub_put_provider(StubState *s, const ArgusProviderShadow *p); 67 /* Set (insert or replace) the World shadow of one store. ARGUS_ERR_FULL when ARGUS_WORLD_STORES are taken. */ 68 int stub_set_world(StubState *s, uint32_t store_id, uint64_t generation, const uint8_t digest[ARGUS_DIGEST_LEN], uint64_t sequence); 69 70 /* Reference apply of one event AFTER detection, following the argus_abi.h apply 71 * rules and machine lifecycle (see stub_state.c). */ 72 int stub_state_apply(StubState *s, const ArgusEvent *ev); 73 74 /* Local copy of lane B's argus_event_min_class table (weakest legal class per 75 * kind) used by the corpus generators until integration. */ 76 uint8_t stub_min_class(uint16_t kind); 77 78 /* ---- corpora ---------------------------------------------------------------- */ 79 80 typedef struct { 81 uint64_t sequence; /* the injected event */ 82 uint16_t code; /* ARGUS_F_* expected on that event */ 83 } ArgusExpectedFinding; 84 85 /* Deterministic synthetic "legal day": exactly `max` events (sequence 1..max), 86 * every one legal under the argus_abi.h validate and apply rules, every one 87 * attributed to a joined machine, lease ids never reused. Replayed through 88 * detect-then-apply it must yield ZERO findings (ARGUS_FALSE_POSITIVE_BASELINE, 89 * synthetic). Returns events written. */ 90 size_t argus_corpus_benign(ArgusEvent *out, size_t max, uint64_t seed); 91 92 /* The same legal day with violations injected on a fixed cadence (one every 93 * ARGUS_CORPUS_HOSTILE_EVERY events, cycling through 28 injection types that 94 * cover all twelve detectors, codes 1..10, 14 and 15). 95 * Each injected event triggers exactly one finding; the (sequence, code) 96 * pairs are written to `expect` (up to expect_max, count in *n_expect). 97 * Returns events written (exactly `max`). */ 98 #define ARGUS_CORPUS_HOSTILE_EVERY 50u 99 size_t argus_corpus_hostile(ArgusEvent *out, size_t max, uint64_t seed, 100 ArgusExpectedFinding *expect, size_t expect_max, size_t *n_expect); 101 102 /* ARGUS-1 stress inputs. These are legal, deterministic event streams; the 103 * stale-use storm has 256 principals (including protected cap 0), and each 104 * use after the seed grants is a confirmed stale-generation trigger. */ 105 size_t argus_corpus_containment_storm(ArgusEvent *out, size_t capacity, 106 size_t stale_uses, uint64_t seed); 107 size_t argus_corpus_cap0_framing(ArgusEvent *out, size_t capacity, 108 size_t stale_uses, uint64_t seed); 109 /* table_kind is one of MACHINE_JOINED, CREDENTIAL_LEASE_CREATED, 110 * PROVIDER_DISCOVERED, or ARTIFACT_ADMITTED. `slots` events fill its shadow; 111 * `overflows` additional unique entries exercise first/later saturation. */ 112 size_t argus_corpus_table_saturation(ArgusEvent *out, size_t capacity, 113 uint16_t table_kind, size_t slots, 114 size_t overflows, uint64_t seed); 115 /* Repeated grant/use/revoke/regrant cycles over ordinary leaf slots. */ 116 size_t argus_corpus_authority_churn(ArgusEvent *out, size_t capacity, 117 size_t cycles, uint64_t seed); 118 119 #endif /* ARGUS_STUB_STATE_H */